135 require_once(dirname(__FILE__).
'/config/tcpdf_config.php');
142 require_once(dirname(__FILE__).
'/unicode_data.php');
147 require_once(dirname(__FILE__).
'/htmlcolors.php');
149 if (!class_exists(
'TCPDF',
false)) {
153 define(
'PDF_PRODUCER',
'TCPDF 4.6.022 (http://www.tcpdf.org)');
197 protected $pages = array();
215 protected $CurOrientation;
221 protected $pagedim = array();
300 protected $oldcMargin;
324 protected $LineWidth;
330 protected $CoreFonts;
336 protected $fonts = array();
342 protected $FontFiles = array();
348 protected $diffs = array();
354 protected $images = array();
360 protected $PageAnnots = array();
366 protected $links = array();
372 protected $FontFamily;
378 protected $FontStyle;
385 protected $FontAscent;
392 protected $FontDescent;
398 protected $underline;
404 protected $CurrentFont;
410 protected $FontSizePt;
422 protected $DrawColor;
428 protected $FillColor;
434 protected $TextColor;
440 protected $ColorFlag;
446 protected $AutoPageBreak;
452 protected $PageBreakTrigger;
458 protected $InFooter =
false;
470 protected $LayoutMode;
482 protected $subject =
'';
488 protected $author =
'';
494 protected $keywords =
'';
500 protected $creator =
'';
506 protected $AliasNbPages =
'{nb}';
512 protected $AliasNumPage =
'{pnb}';
536 protected $imgscale = 1;
544 protected $isunicode =
false;
551 protected $PDFVersion =
'1.7';
560 protected $header_margin;
566 protected $footer_margin;
573 protected $original_lMargin;
580 protected $original_rMargin;
586 protected $header_font;
592 protected $footer_font;
604 protected $barcode =
false;
610 protected $print_header =
true;
616 protected $print_footer =
true;
622 protected $header_logo =
'';
628 protected $header_logo_width = 30;
634 protected $header_title =
'';
640 protected $header_string =
'';
646 protected $default_table_columns = 4;
655 protected $HREF = array();
661 protected $fontlist = array();
673 protected $listordered = array();
679 protected $listcount = array();
685 protected $listnum = 0;
691 protected $listindent;
703 protected $tempfontsize = 10;
709 protected $lispacer =
'';
716 protected $encoding =
'UTF-8';
723 protected $internal_encoding;
730 protected $rtl =
false;
737 protected $tmprtl =
false;
746 protected $encrypted;
774 protected $enc_obj_id;
781 protected $last_rc4_key;
788 protected $last_rc4_key_c;
794 protected $padding =
"\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
800 protected $encryption_key;
809 protected $outlines = array();
816 protected $OutlineRoot;
826 protected $javascript =
'';
840 protected $linethrough;
857 protected $ur_document;
864 protected $ur_annots;
878 protected $ur_signature;
892 protected $newpagegroup = array();
899 protected $pagegroups;
906 protected $currpagegroup;
913 protected $visibility =
'all';
920 protected $n_ocg_print;
927 protected $n_ocg_view;
934 protected $extgstates;
941 protected $jpeg_quality;
948 protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
955 protected $viewer_preferences;
969 protected $gradients = array();
977 protected $intmrk = array();
985 protected $cntmrk = array();
992 protected $footerpos = array();
1000 protected $footerlen = array();
1007 protected $newline =
true;
1014 protected $endlinex = 0;
1021 protected $linestyleWidth =
'';
1028 protected $linestyleCap =
'0 J';
1035 protected $linestyleJoin =
'0 j';
1042 protected $linestyleDash =
'[] 0 d';
1049 protected $openMarkedContent =
false;
1056 protected $htmlvspace = 0;
1063 protected $spot_colors = array();
1070 protected $lisymbol =
'';
1077 protected $epsmarker =
'x#!#EPS#!#x';
1084 protected $transfmatrix = array();
1091 protected $booklet =
false;
1098 protected $feps = 0.005;
1105 protected $tagvspaces = array();
1113 protected $customlistindent = -1;
1120 protected $opencell =
true;
1127 protected $embeddedfiles = array();
1134 protected $premode =
false;
1142 protected $transfmrk = array();
1149 protected $htmlLinkColorArray = array(0, 0, 255);
1156 protected $htmlLinkFontStyle =
'U';
1163 protected $numpages = 0;
1170 protected $pagelen = array();
1177 protected $numimages = 0;
1184 protected $imagekeys = array();
1191 protected $bufferlen = 0;
1198 protected $diskcache =
false;
1205 protected $numfonts = 0;
1212 protected $fontkeys = array();
1219 protected $pageopen = array();
1226 protected $default_monospaced_font =
'courier';
1240 protected $cache_file_lenght = array();
1247 protected $thead =
'';
1254 protected $theadMargins = array();
1261 protected $cache_UTF8StringToArray = array();
1268 protected $cache_maxsize_UTF8StringToArray = 8;
1275 protected $cache_size_UTF8StringToArray = 0;
1282 protected $sign =
false;
1289 protected $signature_data = array();
1296 protected $signature_max_lenght = 5120;
1303 protected $re_spaces =
'/[\s]/';
1310 protected $sig_obj_id = 0;
1329 public function __construct($orientation=
'P', $unit=
'mm', $format=
'A4',
$unicode=
true, $encoding=
'UTF-8', $diskcache=
false) {
1331 if (function_exists(
'mb_internal_encoding') AND mb_internal_encoding()) {
1332 $this->internal_encoding = mb_internal_encoding();
1333 mb_internal_encoding(
'ASCII');
1336 $this->diskcache = $diskcache ?
true :
false;
1339 $this->tmprtl =
false;
1345 $this->transfmrk[0] = array();
1346 $this->pagedim = array();
1349 $this->pages = array();
1351 $this->fonts = array();
1352 $this->FontFiles = array();
1353 $this->diffs = array();
1354 $this->images = array();
1355 $this->links = array();
1356 $this->gradients = array();
1357 $this->InFooter =
false;
1359 $this->FontFamily =
'helvetica';
1360 $this->FontStyle =
'';
1361 $this->FontSizePt = 12;
1362 $this->underline =
false;
1363 $this->linethrough =
false;
1364 $this->DrawColor =
'0 G';
1365 $this->FillColor =
'0 g';
1366 $this->TextColor =
'0 g';
1367 $this->ColorFlag =
false;
1369 $this->encrypted =
false;
1370 $this->last_rc4_key =
'';
1371 $this->padding =
"\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
1373 $this->CoreFonts = array(
1374 'courier'=>
'Courier',
1375 'courierB'=>
'Courier-Bold',
1376 'courierI'=>
'Courier-Oblique',
1377 'courierBI'=>
'Courier-BoldOblique',
1378 'helvetica'=>
'Helvetica',
1379 'helveticaB'=>
'Helvetica-Bold',
1380 'helveticaI'=>
'Helvetica-Oblique',
1381 'helveticaBI'=>
'Helvetica-BoldOblique',
1382 'times'=>
'Times-Roman',
1383 'timesB'=>
'Times-Bold',
1384 'timesI'=>
'Times-Italic',
1385 'timesBI'=>
'Times-BoldItalic',
1387 'zapfdingbats'=>
'ZapfDingbats'
1390 $this->setPageUnit($unit);
1392 $this->setPageFormat($format, $orientation);
1394 $margin = 28.35 / $this->k;
1395 $this->SetMargins($margin, $margin);
1397 $this->cMargin = $margin / 10;
1399 $this->LineWidth = 0.57 / $this->k;
1400 $this->linestyleWidth = sprintf(
'%.2F w', ($this->LineWidth * $this->k));
1401 $this->linestyleCap =
'0 J';
1402 $this->linestyleJoin =
'0 j';
1403 $this->linestyleDash =
'[] 0 d';
1405 $this->SetAutoPageBreak(
true, (2 * $margin));
1407 $this->SetDisplayMode(
'fullwidth');
1409 $this->SetCompression(
true);
1411 $this->PDFVersion =
'1.7';
1412 $this->encoding = $encoding;
1413 $this->HREF = array();
1414 $this->getFontsList();
1415 $this->fgcolor = array(
'R' => 0,
'G' => 0,
'B' => 0);
1416 $this->bgcolor = array(
'R' => 255,
'G' => 255,
'B' => 255);
1417 $this->extgstates = array();
1419 $this->sign =
false;
1421 $this->ur_document =
'/FullSave';
1422 $this->ur_annots =
'/Create/Delete/Modify/Copy/Import/Export';
1423 $this->ur_form =
'/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
1424 $this->ur_signature =
'/Modify';
1426 $this->jpeg_quality = 75;
1428 $this->utf8Bidi(array(
''),
'');
1430 $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
1432 if ($this->isunicode AND (@preg_match(
'/\pL/u',
'a') == 1)) {
1438 $this->re_spaces =
'/[\s\p{Z}]/u';
1441 $this->re_spaces =
'/[\s]/';
1450 public function __destruct() {
1452 if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
1453 mb_internal_encoding($this->internal_encoding);
1456 $this->_destroy(
true);
1465 public function setPageUnit($unit) {
1467 switch (strtolower($unit)) {
1476 $this->k = $this->dpi / 25.4;
1481 $this->k = $this->dpi / 2.54;
1486 $this->k = $this->dpi;
1491 $this->Error(
'Incorrect unit: '.$unit);
1495 if (isset($this->CurOrientation)) {
1496 $this->setPageOrientation($this->CurOrientation);
1507 public function setPageFormat($format, $orientation=
'P') {
1509 if (is_string($format)) {
1512 switch (strtoupper($format)) {
1513 case '4A0': {$format = array(4767.87,6740.79);
break;}
1514 case '2A0': {$format = array(3370.39,4767.87);
break;}
1515 case 'A0': {$format = array(2383.94,3370.39);
break;}
1516 case 'A1': {$format = array(1683.78,2383.94);
break;}
1517 case 'A2': {$format = array(1190.55,1683.78);
break;}
1518 case 'A3': {$format = array(841.89,1190.55);
break;}
1519 case 'A4':
default: {$format = array(595.28,841.89);
break;}
1520 case 'A5': {$format = array(419.53,595.28);
break;}
1521 case 'A6': {$format = array(297.64,419.53);
break;}
1522 case 'A7': {$format = array(209.76,297.64);
break;}
1523 case 'A8': {$format = array(147.40,209.76);
break;}
1524 case 'A9': {$format = array(104.88,147.40);
break;}
1525 case 'A10': {$format = array(73.70,104.88);
break;}
1526 case 'B0': {$format = array(2834.65,4008.19);
break;}
1527 case 'B1': {$format = array(2004.09,2834.65);
break;}
1528 case 'B2': {$format = array(1417.32,2004.09);
break;}
1529 case 'B3': {$format = array(1000.63,1417.32);
break;}
1530 case 'B4': {$format = array(708.66,1000.63);
break;}
1531 case 'B5': {$format = array(498.90,708.66);
break;}
1532 case 'B6': {$format = array(354.33,498.90);
break;}
1533 case 'B7': {$format = array(249.45,354.33);
break;}
1534 case 'B8': {$format = array(175.75,249.45);
break;}
1535 case 'B9': {$format = array(124.72,175.75);
break;}
1536 case 'B10': {$format = array(87.87,124.72);
break;}
1537 case 'C0': {$format = array(2599.37,3676.54);
break;}
1538 case 'C1': {$format = array(1836.85,2599.37);
break;}
1539 case 'C2': {$format = array(1298.27,1836.85);
break;}
1540 case 'C3': {$format = array(918.43,1298.27);
break;}
1541 case 'C4': {$format = array(649.13,918.43);
break;}
1542 case 'C5': {$format = array(459.21,649.13);
break;}
1543 case 'C6': {$format = array(323.15,459.21);
break;}
1544 case 'C7': {$format = array(229.61,323.15);
break;}
1545 case 'C8': {$format = array(161.57,229.61);
break;}
1546 case 'C9': {$format = array(113.39,161.57);
break;}
1547 case 'C10': {$format = array(79.37,113.39);
break;}
1548 case 'RA0': {$format = array(2437.80,3458.27);
break;}
1549 case 'RA1': {$format = array(1729.13,2437.80);
break;}
1550 case 'RA2': {$format = array(1218.90,1729.13);
break;}
1551 case 'RA3': {$format = array(864.57,1218.90);
break;}
1552 case 'RA4': {$format = array(609.45,864.57);
break;}
1553 case 'SRA0': {$format = array(2551.18,3628.35);
break;}
1554 case 'SRA1': {$format = array(1814.17,2551.18);
break;}
1555 case 'SRA2': {$format = array(1275.59,1814.17);
break;}
1556 case 'SRA3': {$format = array(907.09,1275.59);
break;}
1557 case 'SRA4': {$format = array(637.80,907.09);
break;}
1558 case 'LETTER': {$format = array(612.00,792.00);
break;}
1559 case 'LEGAL': {$format = array(612.00,1008.00);
break;}
1560 case 'EXECUTIVE': {$format = array(521.86,756.00);
break;}
1561 case 'FOLIO': {$format = array(612.00,936.00);
break;}
1563 $this->fwPt = $format[0];
1564 $this->fhPt = $format[1];
1566 $this->fwPt = $format[0] * $this->k;
1567 $this->fhPt = $format[1] * $this->k;
1569 $this->setPageOrientation($orientation);
1580 public function setPageOrientation($orientation, $autopagebreak=
'', $bottommargin=
'') {
1581 $orientation = strtoupper($orientation);
1582 if (($orientation ==
'P') OR ($orientation ==
'PORTRAIT')) {
1583 $this->CurOrientation =
'P';
1584 $this->wPt = $this->fwPt;
1585 $this->hPt = $this->fhPt;
1586 }
elseif (($orientation ==
'L') OR ($orientation ==
'LANDSCAPE')) {
1587 $this->CurOrientation =
'L';
1588 $this->wPt = $this->fhPt;
1589 $this->hPt = $this->fwPt;
1591 $this->Error(
'Incorrect orientation: '.$orientation);
1593 $this->w = $this->wPt / $this->k;
1594 $this->h = $this->hPt / $this->k;
1595 if ($this->empty_string($autopagebreak)) {
1596 if (isset($this->AutoPageBreak)) {
1597 $autopagebreak = $this->AutoPageBreak;
1599 $autopagebreak =
true;
1602 if ($this->empty_string($bottommargin)) {
1603 if (isset($this->bMargin)) {
1604 $bottommargin = $this->bMargin;
1607 $bottommargin = 2 * 28.35 / $this->k;
1610 $this->SetAutoPageBreak($autopagebreak, $bottommargin);
1612 $this->pagedim[$this->page] = array(
'w' => $this->wPt,
'h' => $this->hPt,
'wk' => $this->w,
'hk' => $this->h,
'tm' => $this->tMargin,
'bm' => $bottommargin,
'lm' => $this->lMargin,
'rm' => $this->rMargin,
'pb' => $autopagebreak,
'or' => $this->CurOrientation,
'olm' => $this->original_lMargin,
'orm' => $this->original_rMargin);
1621 public function setSpacesRE($re=
'/[\s]/') {
1626 $this->re_spaces = $re;
1636 public function setRTL($enable, $resetx=
true) {
1637 $enable = $enable ?
true :
false;
1638 $resetx = ($resetx AND ($enable != $this->rtl));
1639 $this->rtl = $enable;
1640 $this->tmprtl =
false;
1652 public function getRTL() {
1662 public function setTempRTL($mode) {
1667 $this->tmprtl = $mode;
1679 public function setLastH($h) {
1689 public function getLastH() {
1690 return $this->lasth;
1700 public function setImageScale($scale) {
1701 $this->imgscale = $scale;
1711 public function getImageScale() {
1712 return $this->imgscale;
1724 public function getPageDimensions($pagenum=
'') {
1725 if (empty($pagenum)) {
1726 $pagenum = $this->page;
1728 return $this->pagedim[$pagenum];
1740 public function getPageWidth($pagenum=
'') {
1741 if (empty($pagenum)) {
1744 return $this->pagedim[$pagenum][
'w'];
1756 public function getPageHeight($pagenum=
'') {
1757 if (empty($pagenum)) {
1760 return $this->pagedim[$pagenum][
'h'];
1772 public function getBreakMargin($pagenum=
'') {
1773 if (empty($pagenum)) {
1774 return $this->bMargin;
1776 return $this->pagedim[$pagenum][
'bm'];
1786 public function getScaleFactor() {
1799 public function SetMargins($left, $top, $right=-1) {
1801 $this->lMargin = $left;
1802 $this->tMargin = $top;
1806 $this->rMargin = $right;
1816 public function SetLeftMargin($margin) {
1818 $this->lMargin=$margin;
1819 if (($this->page > 0) AND ($this->x < $margin)) {
1831 public function SetTopMargin($margin) {
1833 $this->tMargin=$margin;
1834 if (($this->page > 0) AND ($this->y < $margin)) {
1846 public function SetRightMargin($margin) {
1847 $this->rMargin=$margin;
1848 if (($this->page > 0) AND ($this->x > ($this->w - $margin))) {
1849 $this->x = $this->w - $margin;
1860 public function SetCellPadding($pad) {
1861 $this->cMargin = $pad;
1872 public function SetAutoPageBreak($auto, $margin=0) {
1874 $this->AutoPageBreak = $auto;
1875 $this->bMargin = $margin;
1876 $this->PageBreakTrigger = $this->h - $margin;
1887 public function SetDisplayMode($zoom, $layout=
'SinglePage', $mode=
'UseNone') {
1889 if (($zoom ==
'fullpage') OR ($zoom ==
'fullwidth') OR ($zoom ==
'real') OR ($zoom ==
'default') OR (!is_string($zoom))) {
1890 $this->ZoomMode = $zoom;
1892 $this->Error(
'Incorrect zoom display mode: '.$zoom);
1897 case 'SinglePage': {
1898 $this->LayoutMode =
'SinglePage';
1903 $this->LayoutMode =
'OneColumn';
1907 case 'TwoColumnLeft': {
1908 $this->LayoutMode =
'TwoColumnLeft';
1911 case 'TwoColumnRight': {
1912 $this->LayoutMode =
'TwoColumnRight';
1915 case 'TwoPageLeft': {
1916 $this->LayoutMode =
'TwoPageLeft';
1919 case 'TwoPageRight': {
1920 $this->LayoutMode =
'TwoPageRight';
1924 $this->LayoutMode =
'SinglePage';
1929 $this->PageMode =
'UseNone';
1932 case 'UseOutlines': {
1933 $this->PageMode =
'UseOutlines';
1937 $this->PageMode =
'UseThumbs';
1940 case 'FullScreen': {
1941 $this->PageMode =
'FullScreen';
1945 $this->PageMode =
'UseOC';
1949 $this->PageMode =
'UseAttachments';
1953 $this->PageMode =
'UseNone';
1965 public function SetCompression($compress) {
1967 if (function_exists(
'gzcompress')) {
1968 $this->compress = $compress;
1970 $this->compress =
false;
1981 public function SetTitle(
$title) {
1993 public function SetSubject($subject) {
1995 $this->subject = $subject;
2005 public function SetAuthor($author) {
2007 $this->author = $author;
2017 public function SetKeywords($keywords) {
2019 $this->keywords = $keywords;
2029 public function SetCreator($creator) {
2031 $this->creator = $creator;
2041 public function Error($msg) {
2043 $this->_destroy(
true);
2045 die(
'<strong>TCPDF ERROR: </strong>'.$msg);
2056 public function Open() {
2069 public function Close() {
2070 if ($this->state == 3) {
2073 if ($this->page == 0) {
2081 $this->_destroy(
false);
2092 public function setPage($pnum, $resetmargins=
false) {
2093 if ($pnum == $this->page) {
2096 if (($pnum > 0) AND ($pnum <= $this->numpages)) {
2100 $oldpage = $this->page;
2101 $this->page = $pnum;
2102 $this->wPt = $this->pagedim[$this->page][
'w'];
2103 $this->hPt = $this->pagedim[$this->page][
'h'];
2104 $this->w = $this->wPt / $this->k;
2105 $this->h = $this->hPt / $this->k;
2106 $this->tMargin = $this->pagedim[$this->page][
'tm'];
2107 $this->bMargin = $this->pagedim[$this->page][
'bm'];
2108 $this->original_lMargin = $this->pagedim[$this->page][
'olm'];
2109 $this->original_rMargin = $this->pagedim[$this->page][
'orm'];
2110 $this->AutoPageBreak = $this->pagedim[$this->page][
'pb'];
2111 $this->CurOrientation = $this->pagedim[$this->page][
'or'];
2112 $this->SetAutoPageBreak($this->AutoPageBreak, $this->bMargin);
2115 if ($resetmargins) {
2116 $this->lMargin = $this->pagedim[$this->page][
'olm'];
2117 $this->rMargin = $this->pagedim[$this->page][
'orm'];
2118 $this->SetY($this->tMargin);
2121 if ($this->pagedim[$this->page][
'olm'] != $this->pagedim[$oldpage][
'olm']) {
2122 $deltam = $this->pagedim[$this->page][
'olm'] - $this->pagedim[$this->page][
'orm'];
2123 $this->lMargin += $deltam;
2124 $this->rMargin -= $deltam;
2128 $this->Error(
'Wrong page number on setPage() function.');
2139 public function lastPage($resetmargins=
false) {
2140 $this->setPage($this->getNumPages(), $resetmargins);
2150 public function getPage() {
2162 public function getNumPages() {
2163 return $this->numpages;
2175 public function AddPage($orientation=
'', $format=
'') {
2176 if (!isset($this->original_lMargin)) {
2177 $this->original_lMargin = $this->lMargin;
2179 if (!isset($this->original_rMargin)) {
2180 $this->original_rMargin = $this->rMargin;
2185 $this->startPage($orientation, $format);
2194 protected function endPage() {
2196 if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
2199 $this->InFooter =
true;
2205 $this->pageopen[$this->page] =
false;
2206 $this->InFooter =
false;
2218 protected function startPage($orientation=
'', $format=
'') {
2219 if ($this->numpages > $this->page) {
2221 $this->setPage($this->page + 1);
2222 $this->SetY($this->tMargin);
2226 if ($this->state == 0) {
2230 $this->swapMargins($this->booklet);
2232 $gvars = $this->getGraphicVars();
2234 $this->_beginpage($orientation, $format);
2236 $this->pageopen[$this->page] =
true;
2238 $this->setGraphicVars($gvars);
2240 $this->setPageMark();
2244 $this->setGraphicVars($gvars);
2246 $this->setPageMark();
2248 $this->setTableHeader();
2258 public function setPageMark() {
2259 $this->intmrk[$this->page] = $this->pagelen[$this->page];
2260 $this->setContentMark();
2269 protected function setContentMark($page=0) {
2271 $page = $this->page;
2273 if (isset($this->footerlen[$page])) {
2274 $this->cntmrk[$page] = $this->pagelen[$page] - $this->footerlen[$page];
2276 $this->cntmrk[$page] = $this->pagelen[$page];
2288 public function setHeaderData($ln=
'', $lw=0, $ht=
'', $hs=
'') {
2289 $this->header_logo = $ln;
2290 $this->header_logo_width = $lw;
2291 $this->header_title = $ht;
2292 $this->header_string = $hs;
2302 public function getHeaderData() {
2304 $ret[
'logo'] = $this->header_logo;
2305 $ret[
'logo_width'] = $this->header_logo_width;
2306 $ret[
'title'] = $this->header_title;
2307 $ret[
'string'] = $this->header_string;
2317 public function setHeaderMargin($hm=10) {
2318 $this->header_margin = $hm;
2327 public function getHeaderMargin() {
2328 return $this->header_margin;
2337 public function setFooterMargin($fm=10) {
2338 $this->footer_margin = $fm;
2347 public function getFooterMargin() {
2348 return $this->footer_margin;
2355 public function setPrintHeader($val=
true) {
2356 $this->print_header = $val;
2364 public function setPrintFooter($val=
true) {
2365 $this->print_footer = $val;
2373 public function getImageRBX() {
2374 return $this->img_rb_x;
2382 public function getImageRBY() {
2383 return $this->img_rb_y;
2391 public function Header() {
2392 $ormargins = $this->getOriginalMargins();
2393 $headerfont = $this->getHeaderFont();
2394 $headerdata = $this->getHeaderData();
2395 if (($headerdata[
'logo']) AND ($headerdata[
'logo'] != K_BLANK_IMAGE)) {
2396 $this->Image(K_PATH_IMAGES.$headerdata[
'logo'], $this->GetX(), $this->getHeaderMargin(), $headerdata[
'logo_width']);
2397 $imgy = $this->getImageRBY();
2399 $imgy = $this->GetY();
2401 $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
2403 if ($this->getRTL()) {
2404 $header_x = $ormargins[
'right'] + ($headerdata[
'logo_width'] * 1.1);
2406 $header_x = $ormargins[
'left'] + ($headerdata[
'logo_width'] * 1.1);
2408 $this->SetTextColor(0, 0, 0);
2410 $this->SetFont($headerfont[0],
'B', $headerfont[2] + 1);
2411 $this->SetX($header_x);
2412 $this->Cell(0, $cell_height, $headerdata[
'title'], 0, 1,
'', 0,
'', 0);
2414 $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
2415 $this->SetX($header_x);
2416 $this->MultiCell(0, $cell_height, $headerdata[
'string'], 0,
'', 0, 1,
'',
'',
true, 0,
false);
2418 $this->SetLineStyle(array(
'width' => 0.85 / $this->getScaleFactor(),
'cap' =>
'butt',
'join' =>
'miter',
'dash' => 0,
'color' => array(0, 0, 0)));
2419 $this->SetY((2.835 / $this->getScaleFactor()) + max($imgy, $this->GetY()));
2420 if ($this->getRTL()) {
2421 $this->SetX($ormargins[
'right']);
2423 $this->SetX($ormargins[
'left']);
2425 $this->Cell(0, 0,
'',
'T', 0,
'C');
2433 public function Footer() {
2434 $cur_y = $this->GetY();
2435 $ormargins = $this->getOriginalMargins();
2436 $this->SetTextColor(0, 0, 0);
2438 $line_width = 0.85 / $this->getScaleFactor();
2439 $this->SetLineStyle(array(
'width' => $line_width,
'cap' =>
'butt',
'join' =>
'miter',
'dash' => 0,
'color' => array(0, 0, 0)));
2441 $barcode = $this->getBarcode();
2442 if (!empty($barcode)) {
2443 $this->Ln($line_width);
2444 $barcode_width = round(($this->getPageWidth() - $ormargins[
'left'] - $ormargins[
'right'])/3);
2445 $this->write1DBarcode($barcode,
'C128B', $this->GetX(), $cur_y + $line_width, $barcode_width, (($this->getFooterMargin() / 3) - $line_width), 0.3,
'',
'');
2447 if (empty($this->pagegroups)) {
2448 $pagenumtxt = $this->l[
'w_page'].
' '.$this->getAliasNumPage().
' / '.$this->getAliasNbPages();
2450 $pagenumtxt = $this->l[
'w_page'].
' '.$this->getPageNumGroupAlias().
' / '.$this->getPageGroupAlias();
2452 $this->SetY($cur_y);
2454 if ($this->getRTL()) {
2455 $this->SetX($ormargins[
'right']);
2456 $this->Cell(0, 0, $pagenumtxt,
'T', 0,
'L');
2458 $this->SetX($ormargins[
'left']);
2459 $this->Cell(0, 0, $pagenumtxt,
'T', 0,
'R');
2468 protected function setHeader() {
2469 if ($this->print_header) {
2470 $lasth = $this->lasth;
2472 $this->rMargin = $this->original_rMargin;
2473 $this->lMargin = $this->original_lMargin;
2477 $this->SetXY($this->original_rMargin, $this->header_margin);
2479 $this->SetXY($this->original_lMargin, $this->header_margin);
2481 $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
2485 $this->SetXY($this->original_rMargin, $this->tMargin);
2487 $this->SetXY($this->original_lMargin, $this->tMargin);
2490 $this->lasth = $lasth;
2499 protected function setFooter() {
2502 $gvars = $this->getGraphicVars();
2504 $this->footerpos[$this->page] = $this->pagelen[$this->page];
2506 if ($this->print_footer) {
2507 $lasth = $this->lasth;
2509 $this->rMargin = $this->original_rMargin;
2510 $this->lMargin = $this->original_lMargin;
2513 $footer_y = $this->h - $this->footer_margin;
2515 $this->SetXY($this->original_rMargin, $footer_y);
2517 $this->SetXY($this->original_lMargin, $footer_y);
2519 $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]);
2523 $this->SetXY($this->original_rMargin, $this->tMargin);
2525 $this->SetXY($this->original_lMargin, $this->tMargin);
2528 $this->lasth = $lasth;
2531 $this->setGraphicVars($gvars);
2533 $this->footerlen[$this->page] = $this->pagelen[$this->page] - $this->footerpos[$this->page] + 1;
2541 protected function setTableHeader() {
2542 if (isset($this->theadMargins[
'top'])) {
2544 $this->tMargin = $this->theadMargins[
'top'];
2545 $this->pagedim[$this->page][
'tm'] = $this->tMargin;
2546 $this->y = $this->tMargin;
2548 if (!$this->empty_string($this->thead)) {
2550 $prev_lMargin = $this->lMargin;
2551 $prev_rMargin = $this->rMargin;
2552 $this->lMargin = $this->pagedim[$this->page][
'olm'];
2553 $this->rMargin = $this->pagedim[$this->page][
'orm'];
2554 $this->cMargin = $this->theadMargins[
'cmargin'];
2556 $this->writeHTML($this->thead,
false,
false,
false,
false,
'');
2558 if (!isset($this->theadMargins[
'top'])) {
2559 $this->theadMargins[
'top'] = $this->tMargin;
2562 $this->pagedim[$this->page][
'tm'] = $this->tMargin;
2564 $this->lMargin = $prev_lMargin;
2565 $this->rMargin = $prev_rMargin;
2576 public function PageNo() {
2592 public function AddSpotColor(
$name, $c, $m,
$y, $k) {
2593 if (!isset($this->spot_colors[
$name])) {
2594 $i = 1 + count($this->spot_colors);
2595 $this->spot_colors[
$name] = array(
'i' => $i,
'c' => $c,
'm' => $m,
'y' =>
$y,
'k' => $k);
2608 public function SetDrawColorArray($color) {
2609 if (isset($color)) {
2610 $color = array_values($color);
2611 $r = isset($color[0]) ? $color[0] : -1;
2612 $g = isset($color[1]) ? $color[1] : -1;
2613 $b = isset($color[2]) ? $color[2] : -1;
2614 $k = isset($color[3]) ? $color[3] : -1;
2616 $this->SetDrawColor($r, $g, $b, $k);
2631 public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1) {
2633 if (!is_numeric($col1)) {
2636 if (!is_numeric($col2)) {
2639 if (!is_numeric($col3)) {
2642 if (!is_numeric($col4)) {
2646 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
2648 $this->DrawColor = sprintf(
'%.3F G', $col1/255);
2651 $this->DrawColor = sprintf(
'%.3F %.3F %.3F RG', $col1/255, $col2/255, $col3/255);
2654 $this->DrawColor = sprintf(
'%.3F %.3F %.3F %.3F K', $col1/100, $col2/100, $col3/100, $col4/100);
2656 if ($this->page > 0) {
2657 $this->_out($this->DrawColor);
2669 public function SetDrawSpotColor(
$name, $tint=100) {
2670 if (!isset($this->spot_colors[
$name])) {
2671 $this->Error(
'Undefined spot color: '.$name);
2673 $this->DrawColor = sprintf(
'/CS%d CS %.3F SCN', $this->spot_colors[$name][
'i'], $tint/100);
2674 if ($this->page > 0) {
2675 $this->_out($this->DrawColor);
2688 public function SetFillColorArray($color) {
2689 if (isset($color)) {
2690 $color = array_values($color);
2691 $r = isset($color[0]) ? $color[0] : -1;
2692 $g = isset($color[1]) ? $color[1] : -1;
2693 $b = isset($color[2]) ? $color[2] : -1;
2694 $k = isset($color[3]) ? $color[3] : -1;
2696 $this->SetFillColor($r, $g, $b, $k);
2711 public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1) {
2713 if (!is_numeric($col1)) {
2716 if (!is_numeric($col2)) {
2719 if (!is_numeric($col3)) {
2722 if (!is_numeric($col4)) {
2726 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
2728 $this->FillColor = sprintf(
'%.3F g', $col1/255);
2729 $this->bgcolor = array(
'G' => $col1);
2732 $this->FillColor = sprintf(
'%.3F %.3F %.3F rg', $col1/255, $col2/255, $col3/255);
2733 $this->bgcolor = array(
'R' => $col1,
'G' => $col2,
'B' => $col3);
2736 $this->FillColor = sprintf(
'%.3F %.3F %.3F %.3F k', $col1/100, $col2/100, $col3/100, $col4/100);
2737 $this->bgcolor = array(
'C' => $col1,
'M' => $col2,
'Y' => $col3,
'K' => $col4);
2739 $this->ColorFlag = ($this->FillColor != $this->TextColor);
2740 if ($this->page > 0) {
2741 $this->_out($this->FillColor);
2753 public function SetFillSpotColor($name, $tint=100) {
2754 if (!isset($this->spot_colors[$name])) {
2755 $this->Error(
'Undefined spot color: '.$name);
2757 $this->FillColor = sprintf(
'/CS%d cs %.3F scn', $this->spot_colors[$name][
'i'], $tint/100);
2758 $this->ColorFlag = ($this->FillColor != $this->TextColor);
2759 if ($this->page > 0) {
2760 $this->_out($this->FillColor);
2772 public function SetTextColorArray($color) {
2773 if (isset($color)) {
2774 $color = array_values($color);
2775 $r = isset($color[0]) ? $color[0] : -1;
2776 $g = isset($color[1]) ? $color[1] : -1;
2777 $b = isset($color[2]) ? $color[2] : -1;
2778 $k = isset($color[3]) ? $color[3] : -1;
2780 $this->SetTextColor($r, $g, $b, $k);
2795 public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1) {
2797 if (!is_numeric($col1)) {
2800 if (!is_numeric($col2)) {
2803 if (!is_numeric($col3)) {
2806 if (!is_numeric($col4)) {
2810 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
2812 $this->TextColor = sprintf(
'%.3F g', $col1/255);
2813 $this->fgcolor = array(
'G' => $col1);
2816 $this->TextColor = sprintf(
'%.3F %.3F %.3F rg', $col1/255, $col2/255, $col3/255);
2817 $this->fgcolor = array(
'R' => $col1,
'G' => $col2,
'B' => $col3);
2820 $this->TextColor = sprintf(
'%.3F %.3F %.3F %.3F k', $col1/100, $col2/100, $col3/100, $col4/100);
2821 $this->fgcolor = array(
'C' => $col1,
'M' => $col2,
'Y' => $col3,
'K' => $col4);
2823 $this->ColorFlag = ($this->FillColor != $this->TextColor);
2834 public function SetTextSpotColor($name, $tint=100) {
2835 if (!isset($this->spot_colors[$name])) {
2836 $this->Error(
'Undefined spot color: '.$name);
2838 $this->TextColor = sprintf(
'/CS%d cs %.3F scn', $this->spot_colors[$name][
'i'], $tint/100);
2839 $this->ColorFlag = ($this->FillColor != $this->TextColor);
2840 if ($this->page > 0) {
2841 $this->_out($this->TextColor);
2856 public function GetStringWidth($s, $fontname=
'', $fontstyle=
'', $fontsize=0) {
2857 return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl), $fontname, $fontstyle, $fontsize);
2871 public function GetArrStringWidth($sa, $fontname=
'', $fontstyle=
'', $fontsize=0) {
2873 if (!$this->empty_string($fontname)) {
2874 $prev_FontFamily = $this->FontFamily;
2875 $prev_FontStyle = $this->FontStyle;
2876 $prev_FontSizePt = $this->FontSizePt;
2877 $this->SetFont($fontname, $fontstyle, $fontsize);
2880 foreach ($sa as $char) {
2881 $w += $this->GetCharWidth($char);
2884 if (!$this->empty_string($fontname)) {
2885 $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
2898 public function GetCharWidth($char) {
2903 $cw = &$this->CurrentFont[
'cw'];
2904 if (isset(
$cw[$char])) {
2906 }
elseif (isset($this->CurrentFont[
'dw'])) {
2908 $w = $this->CurrentFont[
'dw'];
2915 return ($w * $this->FontSize / 1000);
2925 public function GetNumChars($s) {
2926 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
2927 return count($this->UTF8StringToArray($s));
2937 protected function getFontsList() {
2938 $fontsdir = opendir($this->_getfontpath());
2939 while ((
$file = readdir($fontsdir)) !==
false) {
2940 if (substr(
$file, -4) ==
'.php') {
2941 array_push($this->fontlist, strtolower(basename(
$file,
'.php')));
2944 closedir($fontsdir);
2959 public function AddFont($family, $style=
'', $fontfile=
'') {
2960 if ($this->empty_string($family)) {
2961 if (!$this->empty_string($this->FontFamily)) {
2962 $family = $this->FontFamily;
2964 $this->Error(
'Empty font family');
2967 $family = strtolower($family);
2968 if ((!$this->isunicode) AND ($family ==
'arial')) {
2969 $family =
'helvetica';
2971 if (($family ==
'symbol') OR ($family ==
'zapfdingbats')) {
2974 $tempstyle = strtoupper($style);
2977 if (strpos($tempstyle,
'U') !==
false) {
2978 $this->underline =
true;
2980 $this->underline =
false;
2983 if (strpos($tempstyle,
'D') !==
false) {
2984 $this->linethrough =
true;
2986 $this->linethrough =
false;
2989 if (strpos($tempstyle,
'B') !==
false) {
2993 if (strpos($tempstyle,
'I') !==
false) {
2997 $fontkey = $family.$style;
2998 $font_style = $style.($this->underline ?
'U' :
'').($this->linethrough ?
'D' :
'');
2999 $fontdata = array(
'fontkey' => $fontkey,
'family' => $family,
'style' => $font_style);
3001 if ($this->getFontBuffer($fontkey) !==
false) {
3012 if (!$this->empty_string($fontfile)) {
3013 $fontdir = dirname($fontfile);
3014 if ($this->empty_string($fontdir) OR ($fontdir ==
'.')) {
3021 if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
3023 $fontfile1 = str_replace(
' ',
'', $family).strtolower($style).
'.php';
3024 $fontfile2 = str_replace(
' ',
'', $family).
'.php';
3026 if (file_exists($fontdir.$fontfile1)) {
3027 $fontfile = $fontdir.$fontfile1;
3028 }
elseif (file_exists($this->_getfontpath().$fontfile1)) {
3029 $fontfile = $this->_getfontpath().$fontfile1;
3030 }
elseif (file_exists($fontfile1)) {
3031 $fontfile = $fontfile1;
3032 }
elseif (file_exists($fontdir.$fontfile2)) {
3033 $fontfile = $fontdir.$fontfile2;
3034 }
elseif (file_exists($this->_getfontpath().$fontfile2)) {
3035 $fontfile = $this->_getfontpath().$fontfile2;
3037 $fontfile = $fontfile2;
3041 if (file_exists($fontfile)) {
3044 $this->Error(
'Could not include font definition file: '.$family.
'');
3047 if ((!isset(
$type)) OR (!isset(
$cw))) {
3048 $this->Error(
'The font definition file has a bad format: '.$fontfile.
'');
3050 if (!isset(
$file)) {
3056 if (!isset(
$dw) OR $this->empty_string(
$dw)) {
3058 if (isset(
$desc[
'MissingWidth']) AND (
$desc[
'MissingWidth'] > 0)) {
3068 if (
$type ==
'cidfont0') {
3070 $styles = array(
'' =>
'',
'B' =>
',Bold',
'I' =>
',Italic',
'BI' =>
',BoldItalic');
3071 $sname = $name.$styles[$bistyle];
3072 if ((strpos($bistyle,
'B') !==
false) AND (isset(
$desc[
'StemV'])) AND (
$desc[
'StemV'] == 70)) {
3073 $desc[
'StemV'] = 120;
3075 $this->setFontBuffer($fontkey, array(
'i' => $this->numfonts,
'type' =>
$type,
'name' => $sname,
'desc' =>
$desc,
'cidinfo' =>
$cidinfo,
'up' =>
$up,
'ut' =>
$ut,
'cw' =>
$cw,
'dw' =>
$dw,
'enc' =>
$enc));
3077 $this->setFontBuffer($fontkey, array(
'i' => $this->numfonts,
'type' =>
'core',
'name' => $this->CoreFonts[$fontkey],
'up' => -100,
'ut' => 50,
'cw' =>
$cw,
'dw' =>
$dw));
3079 $this->setFontBuffer($fontkey, array(
'i' => $this->numfonts,
'type' =>
$type,
'name' => $name,
'up' =>
$up,
'ut' =>
$ut,
'cw' =>
$cw,
'dw' =>
$dw,
'file' =>
$file,
'enc' =>
$enc,
'desc' =>
$desc));
3081 $this->setFontBuffer($fontkey, array(
'i' => $this->numfonts,
'type' =>
$type,
'name' => $name,
'desc' =>
$desc,
'up' =>
$up,
'ut' =>
$ut,
'cw' =>
$cw,
'dw' =>
$dw,
'enc' =>
$enc,
'file' =>
$file,
'ctg' =>
$ctg));
3083 $this->Error(
'Unknow font type: '.
$type.
'');
3088 $nb = count($this->diffs);
3089 for ($i=1; $i <= $nb; ++$i) {
3090 if ($this->diffs[$i] ==
$diff) {
3099 $this->setFontSubBuffer($fontkey,
'diff',
$d);
3101 if (!$this->empty_string(
$file)) {
3102 if ((strcasecmp(
$type,
'TrueType') == 0) OR (strcasecmp(
$type,
'TrueTypeUnicode') == 0)) {
3105 $this->FontFiles[
$file] = array(
'length1' => $size1,
'length2' => $size2,
'fontdir' => $fontdir);
3125 public function SetFont($family, $style=
'',
$size=0, $fontfile=
'') {
3128 $size = $this->FontSizePt;
3131 $fontdata = $this->AddFont($family, $style, $fontfile);
3132 $this->FontFamily = $fontdata[
'family'];
3133 $this->FontStyle = $fontdata[
'style'];
3134 $this->CurrentFont = $this->getFontBuffer($fontdata[
'fontkey']);
3135 $this->SetFontSize(
$size);
3145 public function SetFontSize(
$size) {
3147 $this->FontSizePt =
$size;
3148 $this->FontSize =
$size / $this->k;
3149 if (isset($this->CurrentFont[
'desc'][
'Ascent']) AND ($this->CurrentFont[
'desc'][
'Ascent'] > 0)) {
3150 $this->FontAscent = $this->CurrentFont[
'desc'][
'Ascent'] * $this->FontSize / 1000;
3152 $this->FontAscent = 0.8 * $this->FontSize;
3154 if (isset($this->CurrentFont[
'desc'][
'Descent']) AND ($this->CurrentFont[
'desc'][
'Descent'] > 0)) {
3155 $this->FontDescent = - $this->CurrentFont[
'desc'][
'Descent'] * $this->FontSize / 1000;
3157 $this->FontDescent = 0.2 * $this->FontSize;
3159 if (($this->page > 0) AND (isset($this->CurrentFont[
'i']))) {
3160 $this->_out(sprintf(
'BT /F%d %.2F Tf ET', $this->CurrentFont[
'i'], $this->FontSizePt));
3170 public function SetDefaultMonospacedFont($font) {
3171 $this->default_monospaced_font = $font;
3181 public function AddLink() {
3183 $n = count($this->links) + 1;
3184 $this->links[
$n] = array(0, 0);
3197 public function SetLink($link,
$y=0, $page=-1) {
3202 $page = $this->page;
3204 $this->links[$link] = array($page,
$y);
3220 public function Link(
$x,
$y, $w, $h, $link, $spaces=0) {
3221 $this->Annotation(
$x,
$y, $w, $h, $link, array(
'Subtype'=>
'Link'), $spaces);
3237 public function Annotation(
$x,
$y, $w, $h, $text, $opt=array(
'Subtype'=>
'Text'), $spaces=0) {
3239 if (isset($this->transfmatrix)) {
3240 $maxid = count($this->transfmatrix) - 1;
3241 for ($i=$maxid; $i >= 0; $i--) {
3242 $ctm = $this->transfmatrix[$i];
3243 if (isset($ctm[
'a'])) {
3245 $y = ($this->h -
$y) * $this->k;
3251 $x1 = ($ctm[
'a'] * $xt) + ($ctm[
'c'] * $yt) + $ctm[
'e'];
3252 $y1 = ($ctm[
'b'] * $xt) + ($ctm[
'd'] * $yt) + $ctm[
'f'];
3256 $x2 = ($ctm[
'a'] * $xt) + ($ctm[
'c'] * $yt) + $ctm[
'e'];
3257 $y2 = ($ctm[
'b'] * $xt) + ($ctm[
'd'] * $yt) + $ctm[
'f'];
3261 $x3 = ($ctm[
'a'] * $xt) + ($ctm[
'c'] * $yt) + $ctm[
'e'];
3262 $y3 = ($ctm[
'b'] * $xt) + ($ctm[
'd'] * $yt) + $ctm[
'f'];
3266 $x4 = ($ctm[
'a'] * $xt) + ($ctm[
'c'] * $yt) + $ctm[
'e'];
3267 $y4 = ($ctm[
'b'] * $xt) + ($ctm[
'd'] * $yt) + $ctm[
'f'];
3269 $x = min($x1, $x2, $x3, $x4);
3270 $y = max($y1, $y2, $y3, $y4);
3271 $w = (max($x1, $x2, $x3, $x4) -
$x) / $this->k;
3272 $h = (
$y - min($y1, $y2, $y3, $y4)) / $this->k;
3274 $y = $this->h - (
$y / $this->k);
3278 if ($this->page <= 0) {
3281 $page = $this->page;
3283 $this->PageAnnots[$page][] = array(
'x' =>
$x,
'y' =>
$y,
'w' => $w,
'h' => $h,
'txt' => $text,
'opt' => $opt,
'numspaces' => $spaces);
3284 if (($opt[
'Subtype'] ==
'FileAttachment') AND (!$this->empty_string($opt[
'FS'])) AND file_exists($opt[
'FS']) AND (!isset($this->embeddedfiles[basename($opt[
'FS'])]))) {
3285 $this->embeddedfiles[basename($opt[
'FS'])] = array(
'file' => $opt[
'FS'],
'n' => (count($this->embeddedfiles) + 100000));
3295 protected function _putEmbeddedFiles() {
3296 reset($this->embeddedfiles);
3297 foreach ($this->embeddedfiles as
$filename => $filedata) {
3298 $data = file_get_contents($filedata[
'file']);
3300 if ($this->compress) {
3302 $filter =
' /Filter /FlateDecode';
3304 $this->offsets[$filedata[
'n']] = $this->bufferlen;
3305 $this->_out($filedata[
'n'].
' 0 obj');
3306 $this->_out(
'<</Type /EmbeddedFile'.
$filter.
' /Length '.strlen(
$data).
' >>');
3307 $this->_putstream(
$data);
3308 $this->_out(
'endobj');
3326 public function Text(
$x,
$y, $txt, $stroke=0, $clip=
false) {
3330 $s = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl);
3331 $l = $this->GetArrStringWidth($s);
3332 $xr = $this->w -
$x - $this->GetArrStringWidth($s);
3337 if (($stroke > 0) AND (!$clip)) {
3338 $opt .=
'1 Tr '.intval($stroke).
' w ';
3339 }
elseif (($stroke > 0) AND $clip) {
3340 $opt .=
'5 Tr '.intval($stroke).
' w ';
3344 $s = sprintf(
'BT %.2F %.2F Td %s(%s) Tj ET 0 Tr', $xr * $this->k, ($this->h-
$y) * $this->k, $opt, $this->_escapetext($txt));
3345 if ($this->underline AND ($txt!=
'')) {
3346 $s .=
' '.$this->_dounderline($xr,
$y, $txt);
3348 if ($this->linethrough AND ($txt!=
'')) {
3349 $s .=
' '.$this->_dolinethrough($xr,
$y, $txt);
3351 if ($this->ColorFlag AND (!$clip)) {
3352 $s=
'q '.$this->TextColor.
' '.$s.
' Q';
3366 public function AcceptPageBreak() {
3367 return $this->AutoPageBreak;
3379 protected function checkPageBreak($h=0,
$y=
'', $addpage=
true) {
3380 if ($this->empty_string(
$y)) {
3383 if (((
$y + $h) > $this->PageBreakTrigger) AND (!$this->InFooter) AND ($this->AcceptPageBreak())) {
3387 $this->AddPage($this->CurOrientation);
3388 $this->y = $this->tMargin;
3389 $oldpage = $this->page - 1;
3391 if ($this->pagedim[$this->page][
'orm'] != $this->pagedim[$oldpage][
'orm']) {
3392 $this->x =
$x - ($this->pagedim[$this->page][
'orm'] - $this->pagedim[$oldpage][
'orm']);
3397 if ($this->pagedim[$this->page][
'olm'] != $this->pagedim[$oldpage][
'olm']) {
3398 $this->x =
$x + ($this->pagedim[$this->page][
'olm'] - $this->pagedim[$oldpage][
'olm']);
3427 public function Cell($w, $h=0, $txt=
'', $border=0, $ln=0, $align=
'', $fill=0, $link=
'', $stretch=0, $ignore_min_height=
false) {
3429 $min_cell_height = $this->FontSize * $this->cell_height_ratio;
3430 if ($h < $min_cell_height) {
3431 $h = $min_cell_height;
3433 $this->checkPageBreak($h);
3434 $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height));
3444 public function removeSHY($txt=
'') {
3455 $txt = preg_replace(
'/([\\xc2]{1}[\\xad]{1})/',
'', $txt);
3456 if (!$this->isunicode) {
3457 $txt = preg_replace(
'/([\\xad]{1})/',
'', $txt);
3479 protected function getCellCode($w, $h=0, $txt=
'', $border=0, $ln=0, $align=
'', $fill=0, $link=
'', $stretch=0, $ignore_min_height=
false) {
3480 $txt = $this->removeSHY($txt);
3482 if (!$ignore_min_height) {
3483 $min_cell_height = $this->FontSize * $this->cell_height_ratio;
3484 if ($h < $min_cell_height) {
3485 $h = $min_cell_height;
3489 if ($this->empty_string($w) OR ($w <= 0)) {
3491 $w = $this->x - $this->lMargin;
3493 $w = $this->w - $this->rMargin -
$this->x;
3497 if (($fill == 1) OR ($border == 1)) {
3499 $op = ($border == 1) ?
'B' :
'f';
3504 $xk = (($this->x - $w) * $k);
3506 $xk = ($this->x * $k);
3508 $s .= sprintf(
'%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h - $this->y) * $k), ($w * $k), (-$h * $k), $op);
3510 if (is_string($border)) {
3511 $lm = ($this->LineWidth / 2);
3514 if (strpos($border,
'L') !==
false) {
3516 $xk = (
$x - $w) * $k;
3520 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h -
$y + $lm) * $k), $xk, (($this->h - (
$y + $h + $lm)) * $k));
3522 if (strpos($border,
'T') !==
false) {
3524 $xk = (
$x - $w + $lm) * $k;
3525 $xwk = (
$x - $lm) * $k;
3527 $xk = (
$x - $lm) * $k;
3528 $xwk = (
$x + $w + $lm) * $k;
3530 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h -
$y) * $k), $xwk, (($this->h -
$y) * $k));
3532 if (strpos($border,
'R') !==
false) {
3536 $xk = (
$x + $w) * $k;
3538 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h -
$y + $lm) * $k), $xk, (($this->h - (
$y + $h + $lm))* $k));
3540 if (strpos($border,
'B') !==
false) {
3542 $xk = (
$x - $w + $lm) * $k;
3543 $xwk = (
$x - $lm) * $k;
3545 $xk = (
$x - $lm) * $k;
3546 $xwk = (
$x + $w + $lm) * $k;
3548 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ', $xk, (($this->h - (
$y + $h)) * $k), $xwk, (($this->h - (
$y + $h)) * $k));
3553 $width = $this->GetStringWidth($txt);
3555 $ratio = ($w - (2 * $this->cMargin)) / $width;
3558 if (($stretch > 0) AND (($ratio < 1) OR (($ratio > 1) AND (($stretch % 2) == 0)))) {
3562 $char_space = (($w - $width - (2 * $this->cMargin)) * $this->k) / max($this->GetNumChars($txt)-1,1);
3564 $rs .= sprintf(
'BT %.2F Tc ET ', $char_space);
3568 $horiz_scale = $ratio * 100.0;
3570 $rs .= sprintf(
'BT %.2F Tz ET ', $horiz_scale);
3573 $width = $w - (2 * $this->cMargin);
3577 if ($align ==
'L') {
3579 $dx = $w - $width - $this->cMargin;
3581 $dx = $this->cMargin;
3583 }
elseif ($align ==
'R') {
3585 $dx = $this->cMargin;
3587 $dx = $w - $width - $this->cMargin;
3589 }
elseif ($align ==
'C') {
3590 $dx = ($w - $width) / 2;
3591 }
elseif ($align ==
'J') {
3593 $dx = $w - $width - $this->cMargin;
3595 $dx = $this->cMargin;
3598 $dx = $this->cMargin;
3600 if ($this->ColorFlag) {
3601 $s .=
'q '.$this->TextColor.
' ';
3603 $txt2 = $this->_escapetext($txt);
3605 $xdk = ($this->x - $dx - $width) * $k;
3607 $xdk = ($this->x + $dx) * $k;
3610 if ($align ==
'J') {
3612 $ns = substr_count($txt,
' ');
3613 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
3615 $width = $this->GetStringWidth(str_replace(
' ',
'', $txt));
3617 $spacewidth = ($w - $width - (2 * $this->cMargin)) / ($ns?$ns:1) / $this->FontSize / $this->k;
3619 $txt2 = str_replace(chr(0).
' ',
') '.(-2830 * $spacewidth).
' (', $txt2);
3622 $width = $this->GetStringWidth($txt);
3623 $spacewidth = (($w - $width - (2 * $this->cMargin)) / ($ns?$ns:1)) * $this->k;
3624 $rs .= sprintf(
'BT %.3F Tw ET ', $spacewidth);
3629 $basefonty = $this->y + ($h/2) + ($this->FontSize/3);
3631 $s .= sprintf(
'BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
3633 $xdx = $this->x - $dx - $width;
3635 $xdx = $this->x + $dx;
3637 if ($this->underline) {
3638 $s .=
' '.$this->_dounderline($xdx, $basefonty, $txt);
3640 if ($this->linethrough) {
3641 $s .=
' '.$this->_dolinethrough($xdx, $basefonty, $txt);
3643 if ($this->ColorFlag) {
3647 $this->Link($xdx, $this->y + (($h - $this->FontSize)/2), $width, $this->FontSize, $link, substr_count($txt, chr(32)));
3657 $rs .=
' BT 0 Tc ET';
3658 }
elseif ($stretch > 0) {
3660 $rs .=
' BT 100 Tz ET';
3664 if (!(($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) AND ($align ==
'J')) {
3665 $rs .=
' BT 0 Tw ET';
3673 $this->x = $this->w - $this->rMargin;
3675 $this->x = $this->lMargin;
3686 $gstyles =
''.$this->linestyleWidth.
' '.$this->linestyleCap.
' '.$this->linestyleJoin.
' '.$this->linestyleDash.
' '.$this->DrawColor.
' '.$this->FillColor.
"\n";
3714 public function MultiCell($w, $h, $txt, $border=0, $align=
'J', $fill=0, $ln=1,
$x=
'',
$y=
'', $reseth=
true, $stretch=0, $ishtml=
false, $autopadding=
true, $maxh=0) {
3715 if ($this->empty_string($this->lasth) OR $reseth) {
3717 $this->lasth = $this->FontSize * $this->cell_height_ratio;
3719 if (!$this->empty_string(
$y)) {
3725 $this->checkPageBreak($h);
3728 $startpage = $this->page;
3729 if (!$this->empty_string(
$x)) {
3734 if ($this->empty_string($w) OR ($w <= 0)) {
3736 $w = $this->x - $this->lMargin;
3738 $w = $this->w - $this->rMargin -
$this->x;
3742 $lMargin = $this->lMargin;
3743 $rMargin = $this->rMargin;
3745 $this->SetRightMargin($this->w - $this->x);
3746 $this->SetLeftMargin($this->x - $w);
3748 $this->SetLeftMargin($this->x);
3749 $this->SetRightMargin($this->w - $this->x - $w);
3754 if ($this->cMargin < ($this->LineWidth / 2)) {
3755 $this->cMargin = ($this->LineWidth / 2);
3758 if (($this->lasth - $this->FontSize) < $this->LineWidth) {
3759 $this->y += $this->LineWidth / 2;
3762 $this->y += $this->cMargin;
3766 $this->writeHTML($txt,
true, 0, $reseth,
true, $align);
3770 $nl = $this->Write($this->lasth, $txt,
'', 0, $align,
true, $stretch,
false,
false, $maxh);
3774 $this->y += $this->cMargin;
3776 if (($this->lasth - $this->FontSize) < $this->LineWidth) {
3777 $this->y += $this->LineWidth / 2;
3783 $endpage = $this->page;
3785 if ($endpage > $startpage) {
3787 for ($page=$startpage; $page <= $endpage; ++$page) {
3788 $this->setPage($page);
3789 if ($page == $startpage) {
3791 $h = $this->getPageHeight() - $starty - $this->getBreakMargin();
3792 $cborder = $this->getBorderMode($border, $position=
'start');
3793 }
elseif ($page == $endpage) {
3794 $this->y = $this->tMargin;
3795 $h = $currentY - $this->tMargin;
3796 $cborder = $this->getBorderMode($border, $position=
'end');
3798 $this->y = $this->tMargin;
3799 $h = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin();
3800 $cborder = $this->getBorderMode($border, $position=
'middle');
3804 if ($page > $startpage) {
3805 if (($this->rtl) AND ($this->pagedim[$page][
'orm'] != $this->pagedim[$startpage][
'orm'])) {
3806 $nx =
$x + ($this->pagedim[$page][
'orm'] - $this->pagedim[$startpage][
'orm']);
3807 }
elseif ((!$this->rtl) AND ($this->pagedim[$page][
'olm'] != $this->pagedim[$startpage][
'olm'])) {
3808 $nx =
$x + ($this->pagedim[$page][
'olm'] - $this->pagedim[$startpage][
'olm']);
3812 $ccode = $this->getCellCode($w, $h,
'', $cborder, 1,
'', $fill,
'', 0,
false);
3813 if ($cborder OR $fill) {
3814 $pagebuff = $this->getPageBuffer($this->page);
3815 $pstart = substr($pagebuff, 0, $this->intmrk[$this->page]);
3816 $pend = substr($pagebuff, $this->intmrk[$this->page]);
3817 $this->setPageBuffer($this->page, $pstart.$ccode.
"\n".$pend);
3818 $this->intmrk[$this->page] += strlen($ccode.
"\n");
3822 $h = max($h, ($currentY -
$y));
3827 $ccode = $this->getCellCode($w, $h,
'', $border, 1,
'', $fill,
'', 0,
true);
3828 if ($border OR $fill) {
3829 if (end($this->transfmrk[$this->page]) !==
false) {
3830 $pagemarkkey = key($this->transfmrk[$this->page]);
3831 $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
3832 }
elseif ($this->InFooter) {
3833 $pagemark = &$this->footerpos[$this->page];
3835 $pagemark = &$this->intmrk[$this->page];
3837 $pagebuff = $this->getPageBuffer($this->page);
3838 $pstart = substr($pagebuff, 0, $pagemark);
3839 $pend = substr($pagebuff, $pagemark);
3840 $this->setPageBuffer($this->page, $pstart.$ccode.
"\n".$pend);
3841 $pagemark += strlen($ccode.
"\n");
3845 $currentY = $this->GetY();
3847 $this->SetLeftMargin($lMargin);
3848 $this->SetRightMargin($rMargin);
3851 $this->SetY($currentY);
3853 $this->SetX(
$x + $w);
3857 $this->setPage($startpage);
3859 $this->SetX(
$x + $w);
3861 $this->setContentMark();
3873 protected function getBorderMode($border, $position=
'start') {
3874 if ((!$this->opencell) AND ($border == 1)) {
3878 switch ($position) {
3883 if (!(
false === strpos($border,
'L'))) {
3886 if (!(
false === strpos($border,
'T'))) {
3889 if (!(
false === strpos($border,
'R'))) {
3892 if ((!$this->opencell) AND (!(
false === strpos($border,
'B')))) {
3902 if (!(
false === strpos($border,
'L'))) {
3905 if ((!$this->opencell) AND (!(
false === strpos($border,
'T')))) {
3908 if (!(
false === strpos($border,
'R'))) {
3911 if ((!$this->opencell) AND (!(
false === strpos($border,
'B')))) {
3921 if (!(
false === strpos($border,
'L'))) {
3924 if ((!$this->opencell) AND (!(
false === strpos($border,
'T')))) {
3927 if (!(
false === strpos($border,
'R'))) {
3930 if (!(
false === strpos($border,
'B'))) {
3952 public function getNumLines($txt, $w=0) {
3954 if ($this->empty_string($w) OR ($w <= 0)) {
3956 $w = $this->x - $this->lMargin;
3958 $w = $this->w - $this->rMargin -
$this->x;
3962 $wmax = $w - (2 * $this->cMargin);
3964 $txt = str_replace(
"\r",
'', $txt);
3966 if (substr($txt,-1) ==
"\n") {
3967 $txt = substr($txt, 0, -1);
3970 $txtblocks = explode(
"\n", $txt);
3972 foreach ($txtblocks as $block) {
3974 $lines += $this->empty_string($block) ? 1 : (ceil($this->GetStringWidth($block) / $wmax));
3995 public function Write($h, $txt, $link=
'', $fill=0, $align=
'', $ln=
false, $stretch=0, $firstline=
false, $firstblock=
false, $maxh=0) {
3996 if (strlen($txt) == 0) {
4000 $s = str_replace(
"\r",
'', $txt);
4014 $chrwidth = $this->GetCharWidth(
'.');
4016 $chars = $this->UTF8StringToArray($s);
4018 $uchars = $this->UTF8ArrayToUniArray($chars);
4020 $nb = count($chars);
4022 $shy_replacement = 45;
4023 $shy_replacement_char = $this->unichr($shy_replacement);
4025 $shy_replacement_width = $this->GetCharWidth($shy_replacement);
4030 $maxy = $this->y + $maxh - $h - (2 * $this->cMargin);
4033 $w = $this->x - $this->lMargin;
4035 $w = $this->w - $this->rMargin -
$this->x;
4038 $wmax = $w - (2 * $this->cMargin);
4039 if ((!$firstline) AND (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax))) {
4052 if (($maxh > 0) AND ($this->y >= $maxy) ) {
4059 if ($align ==
'J') {
4068 $tmpstr = $this->UniArrSubString($uchars, $j, $i);
4071 $tmparr = array_slice($chars, $j, $i);
4073 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
4075 $linew = $this->GetArrStringWidth($tmparr);
4078 $this->endlinex = $startx - $linew;
4080 $this->endlinex = $startx + $linew;
4083 $tmpcmargin = $this->cMargin;
4088 $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
4091 $this->cMargin = $tmpcmargin;
4092 return ($this->UniArrSubString($uchars, $i));
4100 if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
4102 $this->AcceptPageBreak();
4104 $w = $this->getRemainingWidth();
4105 $wmax = $w - (2 * $this->cMargin);
4112 if (($c != 160) AND (($c == 173) OR preg_match($this->re_spaces, $this->unichr($c)))) {
4123 if ((($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) AND ($arabic)) {
4126 $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, $i-$j+1),
'', $this->tmprtl));
4128 $l += $this->GetCharWidth($c);
4130 if ((
$l > $wmax) OR ($shy AND ((
$l + $shy_replacement_width) > $wmax)) ) {
4134 if (($this->rtl AND ($this->x <= ($this->w - $this->rMargin - $chrwidth)))
4135 OR ((!$this->rtl) AND ($this->x >= ($this->lMargin + $chrwidth)))) {
4137 $this->Cell($w, $h,
'', 0, 1);
4140 return ($this->UniArrSubString($uchars, $j));
4144 $tmpstr = $this->UniArrSubString($uchars, $j, $i);
4147 $tmparr = array_slice($chars, $j, $i);
4149 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
4151 $linew = $this->GetArrStringWidth($tmparr);
4154 $this->endlinex = $startx - $linew;
4156 $this->endlinex = $startx + $linew;
4159 $tmpcmargin = $this->cMargin;
4164 $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
4167 $this->cMargin = $tmpcmargin;
4168 return ($this->UniArrSubString($uchars, $i));
4175 if ($this->rtl AND (!$firstblock)) {
4182 $shy_width = $shy_replacement_width;
4184 $shy_char_left = $shy_replacement_char;
4185 $shy_char_right =
'';
4187 $shy_char_left =
'';
4188 $shy_char_right = $shy_replacement_char;
4192 $shy_char_left =
'';
4193 $shy_char_right =
'';
4195 $tmpstr = $this->UniArrSubString($uchars, $j, ($sep + $endspace));
4198 $tmparr = array_slice($chars, $j, ($sep + $endspace));
4200 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
4202 $linew = $this->GetArrStringWidth($tmparr);
4205 $this->endlinex = $startx - $linew - $shy_width;
4207 $this->endlinex = $startx + $linew + $shy_width;
4210 $tmpcmargin = $this->cMargin;
4216 $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
4220 $this->cMargin = $tmpcmargin;
4221 return ($this->UniArrSubString($uchars, ($sep + $endspace)));
4229 if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND (!$this->InFooter)) {
4231 $this->AcceptPageBreak();
4233 $w = $this->getRemainingWidth();
4234 $wmax = $w - (2 * $this->cMargin);
4274 $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
4277 $tmparr = array_slice($chars, $j, $nb);
4279 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl);
4281 $linew = $this->GetArrStringWidth($tmparr);
4284 $this->endlinex = $startx - $linew;
4286 $this->endlinex = $startx + $linew;
4289 $tmpcmargin = $this->cMargin;
4294 $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
4297 $this->cMargin = $tmpcmargin;
4298 return ($this->UniArrSubString($uchars, $nb));
4313 protected function getRemainingWidth() {
4315 return ($this->x - $this->lMargin);
4317 return ($this->w - $this->rMargin - $this->x);
4329 public function UTF8ArrSubString($strarr,
$start=
'', $end=
'') {
4330 if (strlen(
$start) == 0) {
4333 if (strlen($end) == 0) {
4334 $end = count($strarr);
4337 for ($i=
$start; $i < $end; ++$i) {
4338 $string .= $this->unichr($strarr[$i]);
4352 public function UniArrSubString($uniarr,
$start=
'', $end=
'') {
4353 if (strlen(
$start) == 0) {
4356 if (strlen($end) == 0) {
4357 $end = count($uniarr);
4360 for ($i=
$start; $i < $end; ++$i) {
4361 $string .= $uniarr[$i];
4373 public function UTF8ArrayToUniArray($ta) {
4374 return array_map(array($this,
'unichr'), $ta);
4385 public function unichr($c) {
4386 if (!$this->isunicode) {
4393 return chr(0xC0 | $c >> 6).chr(0x80 | $c & 0x3F);
4394 }
elseif ($c <= 0xFFFF) {
4396 return chr(0xE0 | $c >> 12).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
4397 }
elseif ($c <= 0x10FFFF) {
4399 return chr(0xF0 | $c >> 18).chr(0x80 | $c >> 12 & 0x3F).chr(0x80 | $c >> 6 & 0x3F).chr(0x80 | $c & 0x3F);
4435 public function Image(
$file,
$x=
'',
$y=
'', $w=0, $h=0,
$type=
'', $link=
'', $align=
'', $resize=
false, $dpi=300, $palign=
'', $ismask=
false, $imgmask=
false, $border=0, $fitbox=
false) {
4443 $imsize = @getimagesize(
$file);
4444 if ($imsize === FALSE) {
4447 $imsize = @getimagesize(
$file);
4448 if ($imsize === FALSE) {
4449 $this->Error(
'[Image] No such file or directory in '.
$file);
4453 list($pixw, $pixh) = $imsize;
4455 if (($w <= 0) AND ($h <= 0)) {
4457 $w = $this->pixelsToUnits($pixw);
4458 $h = $this->pixelsToUnits($pixh);
4460 $w = $h * $pixw / $pixh;
4462 $h = $w * $pixh / $pixw;
4463 }
elseif ($fitbox AND ($w > 0) AND ($h > 0)) {
4465 if ((($w * $pixh) / ($h * $pixw)) < 1) {
4466 $h = $w * $pixh / $pixw;
4468 $w = $h * $pixw / $pixh;
4472 $neww = round($w * $this->k * $dpi / $this->dpi);
4473 $newh = round($h * $this->k * $dpi / $this->dpi);
4475 if (($neww * $newh) >= ($pixw * $pixh)) {
4479 if (!in_array(
$file, $this->imagekeys)) {
4482 $fileinfo = pathinfo(
$file);
4483 if (isset($fileinfo[
'extension']) AND (!$this->empty_string($fileinfo[
'extension']))) {
4484 $type = $fileinfo[
'extension'];
4486 $this->Error(
'Image file has no extension and no type was specified: '.
$file);
4490 if (
$type ==
'jpg') {
4493 $mqr = get_magic_quotes_runtime();
4494 set_magic_quotes_runtime(0);
4496 $mtd =
'_parse'.$type;
4498 $gdfunction =
'imagecreatefrom'.$type;
4500 if ((method_exists($this, $mtd)) AND (!($resize AND function_exists($gdfunction)))) {
4502 $info = $this->$mtd(
$file);
4503 if ($info ==
'pngalpha') {
4504 return $this->ImagePngAlpha(
$file,
$x,
$y, $w, $h,
'PNG', $link, $align, $resize, $dpi, $palign);
4508 if (function_exists($gdfunction)) {
4512 $imgr = imagecreatetruecolor($neww, $newh);
4513 imagecopyresampled($imgr,
$img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
4514 $info = $this->_toJPEG($imgr);
4516 $info = $this->_toJPEG(
$img);
4518 }
elseif (extension_loaded(
'imagick')) {
4520 $img =
new Imagick();
4523 $img->resizeImage($neww, $newh, 10, 1,
false);
4525 $img->setCompressionQuality($this->jpeg_quality);
4526 $img->setImageFormat(
'jpeg');
4527 $tempname = tempnam(K_PATH_CACHE,
'jpg_');
4528 $img->writeImage($tempname);
4529 $info = $this->_parsejpeg($tempname);
4536 if ($info ===
false) {
4540 set_magic_quotes_runtime($mqr);
4543 $info[
'cs'] =
'DeviceGray';
4545 $info[
'i'] = $this->numimages + 1;
4546 if ($imgmask !==
false) {
4547 $info[
'masked'] = $imgmask;
4550 $this->setImageBuffer(
$file, $info);
4552 $info = $this->getImageBuffer(
$file);
4555 if ($this->checkPageBreak($h,
$y)) {
4556 $y = $this->GetY() + $this->cMargin;
4559 $this->img_rb_y =
$y + $h;
4562 if ($palign ==
'L') {
4563 $ximg = $this->lMargin;
4565 $this->img_rb_x = $ximg + $w;
4566 }
elseif ($palign ==
'C') {
4567 $ximg = ($this->w -
$x - $w) / 2;
4569 $this->img_rb_x = $ximg + $w;
4571 $ximg = $this->w -
$x - $w;
4573 $this->img_rb_x = $ximg;
4576 if ($palign ==
'R') {
4577 $ximg = $this->w - $this->rMargin - $w;
4579 $this->img_rb_x = $ximg;
4580 }
elseif ($palign ==
'C') {
4581 $ximg = ($this->w -
$x - $w) / 2;
4583 $this->img_rb_x = $ximg + $w;
4587 $this->img_rb_x = $ximg + $w;
4592 $xkimg = ($this->pagedim[$this->page][
'w'] + 10);
4594 $xkimg = $ximg * $this->k;
4596 $this->_out(sprintf(
'q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q', ($w * $this->k), ($h * $this->k), $xkimg, (($this->h - (
$y + $h)) * $this->k), $info[
'i']));
4597 if (!empty($border)) {
4602 $this->Cell($w, $h,
'', $border, 0,
'', 0,
'', 0);
4607 $this->Link($ximg,
$y, $w, $h, $link, 0);
4613 $this->x = $this->img_rb_x;
4617 $this->y =
$y + round($h/2);
4618 $this->x = $this->img_rb_x;
4622 $this->y = $this->img_rb_y;
4623 $this->x = $this->img_rb_x;
4627 $this->SetY($this->img_rb_y);
4634 $this->endlinex = $this->img_rb_x;
4646 protected function _toJPEG($image) {
4647 $tempname = tempnam(K_PATH_CACHE,
'jpg_');
4648 imagejpeg($image, $tempname, $this->jpeg_quality);
4649 imagedestroy($image);
4650 $retvars = $this->_parsejpeg($tempname);
4662 protected function _parsejpeg(
$file) {
4663 $a = getimagesize(
$file);
4665 $this->Error(
'Missing or incorrect image file: '.
$file);
4668 $this->Error(
'Not a JPEG file: '.
$file);
4670 if ((!isset($a[
'channels'])) OR ($a[
'channels'] == 3)) {
4671 $colspace =
'DeviceRGB';
4672 }
elseif ($a[
'channels'] == 4) {
4673 $colspace =
'DeviceCMYK';
4675 $colspace =
'DeviceGray';
4677 $bpc = isset($a[
'bits']) ? $a[
'bits'] : 8;
4679 return array(
'w' => $a[0],
'h' => $a[1],
'cs' => $colspace,
'bpc' => $bpc,
'f' =>
'DCTDecode',
'data' =>
$data);
4688 protected function _parsepng(
$file) {
4691 $this->Error(
'Can\'t open image file: '.
$file);
4694 if (fread(
$f, 8) != chr(137).
'PNG'.chr(13).chr(10).chr(26).chr(10)) {
4695 $this->Error(
'Not a PNG file: '.
$file);
4699 if (fread(
$f, 4) !=
'IHDR') {
4700 $this->Error(
'Incorrect PNG file: '.
$file);
4702 $w = $this->_freadint(
$f);
4703 $h = $this->_freadint(
$f);
4704 $bpc = ord(fread(
$f, 1));
4710 $ct = ord(fread(
$f, 1));
4712 $colspace =
'DeviceGray';
4714 $colspace =
'DeviceRGB';
4716 $colspace =
'Indexed';
4722 if (ord(fread(
$f, 1)) != 0) {
4727 if (ord(fread(
$f, 1)) != 0) {
4732 if (ord(fread(
$f, 1)) != 0) {
4738 $parms =
'/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).
' /BitsPerComponent '.$bpc.
' /Columns '.$w.
'>>';
4744 $n = $this->_freadint(
$f);
4746 if (
$type ==
'PLTE') {
4748 $pal = $this->rfread(
$f,
$n);
4752 $t = $this->rfread(
$f,
$n);
4754 $trns = array(ord(substr(
$t, 1, 1)));
4756 $trns = array(ord(substr(
$t, 1, 1)), ord(substr(
$t, 3, 1)), ord(substr(
$t, 5, 1)));
4758 $pos = strpos(
$t, chr(0));
4759 if ($pos !==
false) {
4760 $trns = array($pos);
4771 $this->rfread(
$f,
$n + 4);
4774 if (($colspace ==
'Indexed') AND (empty($pal))) {
4780 return array(
'w' => $w,
'h' => $h,
'cs' => $colspace,
'bpc' => $bpc,
'f' =>
'FlateDecode',
'parms' => $parms,
'pal' => $pal,
'trns' => $trns,
'data' =>
$data);
4793 protected function rfread($handle, $length) {
4794 $data = fread($handle, $length);
4795 if (
$data ===
false) {
4823 protected function ImagePngAlpha(
$file,
$x=
'',
$y=
'', $w=0, $h=0,
$type=
'', $link=
'', $align=
'', $resize=
false, $dpi=300, $palign=
'') {
4825 list($wpx, $hpx) = getimagesize(
$file);
4828 $imgalpha = imagecreate($wpx, $hpx);
4830 for ($c = 0; $c < 256; ++$c) {
4831 ImageColorAllocate($imgalpha, $c, $c, $c);
4834 for ($xpx = 0; $xpx < $wpx; ++$xpx) {
4835 for ($ypx = 0; $ypx < $hpx; ++$ypx) {
4836 $colorindex = imagecolorat(
$img, $xpx, $ypx);
4837 $col = imagecolorsforindex(
$img, $colorindex);
4838 imagesetpixel($imgalpha, $xpx, $ypx, $this->getGDgamma((127 - $col[
'alpha']) * 255 / 127));
4842 $tempfile_alpha = tempnam(K_PATH_CACHE,
'mska_');
4843 imagepng($imgalpha, $tempfile_alpha);
4844 imagedestroy($imgalpha);
4846 $imgplain = imagecreatetruecolor($wpx, $hpx);
4847 imagecopy($imgplain,
$img, 0, 0, 0, 0, $wpx, $hpx);
4849 $tempfile_plain = tempnam(K_PATH_CACHE,
'mskp_');
4850 imagepng($imgplain, $tempfile_plain);
4851 imagedestroy($imgplain);
4853 $imgmask = $this->Image($tempfile_alpha,
$x,
$y, $w, $h,
'PNG',
'',
'', $resize, $dpi,
'',
true,
false);
4855 $this->Image($tempfile_plain,
$x,
$y, $w, $h,
$type, $link, $align, $resize, $dpi, $palign,
false, $imgmask);
4857 unlink($tempfile_alpha);
4858 unlink($tempfile_plain);
4867 protected function getGDgamma($v) {
4868 return (pow(($v / 255), 2.2) * 255);
4880 public function Ln($h=
'', $cell=
false) {
4883 $cellmargin = $this->cMargin;
4888 $this->x = $this->w - $this->rMargin - $cellmargin;
4890 $this->x = $this->lMargin + $cellmargin;
4892 if (is_string($h)) {
4893 $this->y += $this->lasth;
4897 $this->newline =
true;
4908 public function GetX() {
4911 return ($this->w - $this->x);
4924 public function GetAbsX() {
4935 public function GetY() {
4948 public function SetX(
$x) {
4952 $this->x = $this->w -
$x;
4960 $this->x = $this->w +
$x;
4966 if ($this->x > $this->w) {
4967 $this->x = $this->w;
4980 public function SetY(
$y, $resetx=
true) {
4984 $this->x = $this->w - $this->rMargin;
4986 $this->x = $this->lMargin;
4992 $this->y = $this->h +
$y;
4997 if ($this->y > $this->h) {
4998 $this->y = $this->h;
5011 public function SetXY(
$x,
$y) {
5027 public function Output($name=
'doc.pdf', $dest=
'I') {
5030 if ($this->state < 3) {
5034 if (is_bool($dest)) {
5035 $dest = $dest ?
'D' :
'F';
5037 $dest = strtoupper($dest);
5039 $name = preg_replace(
'/[\s]+/',
'_', $name);
5040 $name = preg_replace(
'/[^a-zA-Z0-9_\.-]/',
'', $name);
5045 $pdfdoc = $this->getBuffer();
5047 $pdfdoc = substr($pdfdoc, 0, -1);
5049 if (isset($this->diskcache) AND $this->diskcache) {
5051 unlink($this->buffer);
5053 unset($this->buffer);
5055 $tmppos = strpos($pdfdoc,
'/ByteRange[0 ********** ********** **********]') + 58;
5056 $pdfdoc = substr($pdfdoc, 0, $tmppos).substr($pdfdoc, $tmppos + $this->signature_max_lenght);
5058 $byte_range = array();
5060 $byte_range[1] = $tmppos - 1;
5061 $byte_range[2] = $byte_range[1] + $this->signature_max_lenght;
5062 $byte_range[3] = strlen($pdfdoc) - $byte_range[1];
5064 $byterange = sprintf(
'/ByteRange[0 %010u %010u %010u]', $byte_range[1], $byte_range[2], $byte_range[3]);
5065 $pdfdoc = str_replace(
'/ByteRange[0 ********** ********** **********]', $byterange, $pdfdoc);
5067 $tempdoc = tempnam(K_PATH_CACHE,
'tmppdf_');
5068 $f = fopen($tempdoc,
'wb');
5070 $this->Error(
'Unable to create temporary file: '.$tempdoc);
5072 $pdfdoc_lenght = strlen($pdfdoc);
5073 fwrite(
$f, $pdfdoc, $pdfdoc_lenght);
5076 $tempsign = tempnam(K_PATH_CACHE,
'tmpsig_');
5077 if (empty($this->signature_data[
'extracerts'])) {
5078 openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data[
'signcert'], array($this->signature_data[
'privkey'], $this->signature_data[
'password']), array(), PKCS7_BINARY | PKCS7_DETACHED);
5080 openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data[
'signcert'], array($this->signature_data[
'privkey'], $this->signature_data[
'password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data[
'extracerts']);
5084 $signature = file_get_contents($tempsign,
false, null, $pdfdoc_lenght);
5087 $signature = substr($signature, (strpos($signature,
"%%EOF\n\n------") + 13));
5088 $tmparr = explode(
"\n\n", $signature);
5089 $signature = $tmparr[1];
5092 $signature = base64_decode(trim($signature));
5094 $signature = current(unpack(
'H*', $signature));
5095 $signature = str_pad($signature, $this->signature_max_lenght,
'0');
5097 $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).$signature.substr($pdfdoc, (0 - $byte_range[3]));
5098 $this->diskcache =
false;
5099 $this->buffer = &$pdfdoc;
5100 $this->bufferlen = strlen($pdfdoc);
5105 if (ob_get_contents()) {
5106 $this->Error(
'Some data has already been output, can\'t send PDF file');
5108 if (php_sapi_name() !=
'cli') {
5110 header(
'Content-Type: application/pdf');
5111 if (headers_sent()) {
5112 $this->Error(
'Some data has already been output to browser, can\'t send PDF file');
5114 header(
'Cache-Control: public, must-revalidate, max-age=0');
5115 header(
'Pragma: public');
5116 header(
'Expires: Sat, 26 Jul 1997 05:00:00 GMT');
5117 header(
'Last-Modified: '.gmdate(
'D, d M Y H:i:s').
' GMT');
5118 header(
'Content-Length: '.$this->bufferlen);
5119 header(
'Content-Disposition: inline; filename="'.basename($name).
'";');
5121 echo $this->getBuffer();
5126 if (ob_get_contents()) {
5127 $this->Error(
'Some data has already been output, can\'t send PDF file');
5129 header(
'Content-Description: File Transfer');
5130 if (headers_sent()) {
5131 $this->Error(
'Some data has already been output to browser, can\'t send PDF file');
5133 header(
'Cache-Control: public, must-revalidate, max-age=0');
5134 header(
'Pragma: public');
5135 header(
'Expires: Sat, 26 Jul 1997 05:00:00 GMT');
5136 header(
'Last-Modified: '.gmdate(
'D, d M Y H:i:s').
' GMT');
5138 header(
'Content-Type: application/force-download');
5139 header(
'Content-Type: application/octet-stream',
false);
5140 header(
'Content-Type: application/download',
false);
5141 header(
'Content-Type: application/pdf',
false);
5143 header(
'Content-Disposition: attachment; filename="'.basename($name).
'";');
5144 header(
'Content-Transfer-Encoding: binary');
5145 header(
'Content-Length: '.$this->bufferlen);
5146 echo $this->getBuffer();
5151 if ($this->diskcache) {
5152 copy($this->buffer, $name);
5154 $f = fopen($name,
'wb');
5156 $this->Error(
'Unable to create output file: '.$name);
5158 fwrite(
$f, $this->getBuffer(), $this->bufferlen);
5165 return $this->getBuffer();
5168 $this->Error(
'Incorrect output destination: '.$dest);
5181 public function _destroy($destroyall=
false, $preserve_objcopy=
false) {
5182 if ($destroyall AND isset($this->diskcache) AND $this->diskcache AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer))) {
5184 unlink($this->buffer);
5186 foreach (array_keys(get_object_vars($this)) as $val) {
5187 if ($destroyall OR (
5188 ($val !=
'internal_encoding')
5189 AND ($val !=
'state')
5190 AND ($val !=
'bufferlen')
5191 AND ($val !=
'buffer')
5192 AND ($val !=
'diskcache')
5193 AND ($val !=
'sign')
5194 AND ($val !=
'signature_data')
5195 AND ($val !=
'signature_max_lenght')
5197 if (!$preserve_objcopy OR ($val !=
'objcopy')) {
5208 protected function _dochecks() {
5211 $this->Error(
'Don\'t alter the locale before including class file');
5214 if (sprintf(
'%.1F', 1.0) !=
'1.0') {
5215 setlocale(LC_NUMERIC,
'C');
5224 protected function _getfontpath() {
5225 if (!defined(
'K_PATH_FONTS') AND is_dir(dirname(__FILE__).
'/fonts')) {
5226 define(
'K_PATH_FONTS', dirname(__FILE__).
'/fonts/');
5228 return defined(
'K_PATH_FONTS') ? K_PATH_FONTS :
'';
5235 protected function _putpages() {
5236 $nb = $this->numpages;
5237 if (!empty($this->AliasNbPages)) {
5238 $nbs = $this->formatPageNumber($nb);
5239 $nbu = $this->UTF8ToUTF16BE($nbs,
false);
5240 $alias_a = $this->_escape($this->AliasNbPages);
5241 $alias_au = $this->_escape(
'{'.$this->AliasNbPages.
'}');
5242 if ($this->isunicode) {
5243 $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages));
5244 $alias_bu = $this->_escape($this->UTF8ToLatin1(
'{'.$this->AliasNbPages.
'}'));
5245 $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages,
false, $this->tmprtl));
5246 $alias_cu = $this->_escape($this->utf8StrRev(
'{'.$this->AliasNbPages.
'}',
false, $this->tmprtl));
5249 if (!empty($this->AliasNumPage)) {
5250 $alias_pa = $this->_escape($this->AliasNumPage);
5251 $alias_pau = $this->_escape(
'{'.$this->AliasNumPage.
'}');
5252 if ($this->isunicode) {
5253 $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage));
5254 $alias_pbu = $this->_escape($this->UTF8ToLatin1(
'{'.$this->AliasNumPage.
'}'));
5255 $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage,
false, $this->tmprtl));
5256 $alias_pcu = $this->_escape($this->utf8StrRev(
'{'.$this->AliasNumPage.
'}',
false, $this->tmprtl));
5260 $filter = ($this->compress) ?
'/Filter /FlateDecode ' :
'';
5261 for (
$n=1;
$n <= $nb; ++
$n) {
5262 $temppage = $this->getPageBuffer(
$n);
5263 if (!empty($this->pagegroups)) {
5264 if(isset($this->newpagegroup[
$n])) {
5268 foreach ($this->pagegroups as $k => $v) {
5270 $vs = $this->formatPageNumber($v);
5271 $vu = $this->UTF8ToUTF16BE($vs,
false);
5272 $alias_ga = $this->_escape($k);
5273 $alias_gau = $this->_escape(
'{'.$k.
'}');
5274 if ($this->isunicode) {
5275 $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
5276 $alias_gbu = $this->_escape($this->UTF8ToLatin1(
'{'.$k.
'}'));
5277 $alias_gc = $this->_escape($this->utf8StrRev($k,
false, $this->tmprtl));
5278 $alias_gcu = $this->_escape($this->utf8StrRev(
'{'.$k.
'}',
false, $this->tmprtl));
5280 $temppage = str_replace($alias_gau, $vu, $temppage);
5281 if ($this->isunicode) {
5282 $temppage = str_replace($alias_gbu, $vu, $temppage);
5283 $temppage = str_replace($alias_gcu, $vu, $temppage);
5284 $temppage = str_replace($alias_gb, $vs, $temppage);
5285 $temppage = str_replace($alias_gc, $vs, $temppage);
5287 $temppage = str_replace($alias_ga, $vs, $temppage);
5289 $pvs = $this->formatPageNumber($pagegroupnum);
5290 $pvu = $this->UTF8ToUTF16BE($pvs,
false);
5291 $pk = str_replace(
'{nb',
'{pnb', $k);
5292 $alias_pga = $this->_escape($pk);
5293 $alias_pgau = $this->_escape(
'{'.$pk.
'}');
5294 if ($this->isunicode) {
5295 $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
5296 $alias_pgbu = $this->_escape($this->UTF8ToLatin1(
'{'.$pk.
'}'));
5297 $alias_pgc = $this->_escape($this->utf8StrRev($pk,
false, $this->tmprtl));
5298 $alias_pgcu = $this->_escape($this->utf8StrRev(
'{'.$pk.
'}',
false, $this->tmprtl));
5300 $temppage = str_replace($alias_pgau, $pvu, $temppage);
5301 if ($this->isunicode) {
5302 $temppage = str_replace($alias_pgbu, $pvu, $temppage);
5303 $temppage = str_replace($alias_pgcu, $pvu, $temppage);
5304 $temppage = str_replace($alias_pgb, $pvs, $temppage);
5305 $temppage = str_replace($alias_pgc, $pvs, $temppage);
5307 $temppage = str_replace($alias_pga, $pvs, $temppage);
5310 if (!empty($this->AliasNbPages)) {
5312 $temppage = str_replace($alias_au, $nbu, $temppage);
5313 if ($this->isunicode) {
5314 $temppage = str_replace($alias_bu, $nbu, $temppage);
5315 $temppage = str_replace($alias_cu, $nbu, $temppage);
5316 $temppage = str_replace($alias_b, $nbs, $temppage);
5317 $temppage = str_replace($alias_c, $nbs, $temppage);
5319 $temppage = str_replace($alias_a, $nbs, $temppage);
5321 if (!empty($this->AliasNumPage)) {
5323 $pnbs = $this->formatPageNumber($n);
5324 $pnbu = $this->UTF8ToUTF16BE($pnbs,
false);
5325 $temppage = str_replace($alias_pau, $pnbu, $temppage);
5326 if ($this->isunicode) {
5327 $temppage = str_replace($alias_pbu, $pnbu, $temppage);
5328 $temppage = str_replace($alias_pcu, $pnbu, $temppage);
5329 $temppage = str_replace($alias_pb, $pnbs, $temppage);
5330 $temppage = str_replace($alias_pc, $pnbs, $temppage);
5332 $temppage = str_replace($alias_pa, $pnbs, $temppage);
5334 $temppage = str_replace($this->epsmarker,
'', $temppage);
5338 $this->_out(
'<</Type /Page');
5339 $this->_out(
'/Parent 1 0 R');
5340 $this->_out(sprintf(
'/MediaBox [0 0 %.2F %.2F]', $this->pagedim[$n][
'w'], $this->pagedim[$n][
'h']));
5341 $this->_out(
'/Resources 2 0 R');
5342 $this->_putannots($n);
5343 $this->_out(
'/Contents '.($this->
n + 1).
' 0 R>>');
5344 $this->_out(
'endobj');
5346 $p = ($this->compress) ? gzcompress($temppage) : $temppage;
5348 $this->_out(
'<<'.
$filter.
'/Length '.strlen($p).
'>>');
5349 $this->_putstream($p);
5350 $this->_out(
'endobj');
5351 if ($this->diskcache) {
5353 unlink($this->pages[$n]);
5357 $this->offsets[1] = $this->bufferlen;
5358 $this->_out(
'1 0 obj');
5359 $this->_out(
'<</Type /Pages');
5361 for ($i=0; $i < $nb; ++$i) {
5362 $kids .= (3 + (2 * $i)).
' 0 R ';
5364 $this->_out($kids.
']');
5365 $this->_out(
'/Count '.$nb);
5368 $this->_out(
'endobj');
5380 protected function _putannots($n) {
5381 if (isset($this->PageAnnots[$n])) {
5382 $annots =
'/Annots [';
5383 foreach ($this->PageAnnots[$n] as
$key => $pl) {
5384 $pl[
'opt'] = array_change_key_case($pl[
'opt'], CASE_LOWER);
5385 $a = $pl[
'x'] * $this->k;
5386 $b = $this->pagedim[
$n][
'h'] - ($pl[
'y'] * $this->k);
5387 $c = $pl[
'w'] * $this->k;
5388 $d = $pl[
'h'] * $this->k;
5389 $rect = sprintf(
'%.2F %.2F %.2F %.2F', $a, $b, $a+$c, $b-
$d);
5391 $annots .=
'<</Type /Annot';
5392 $annots .=
' /Subtype /'.$pl[
'opt'][
'subtype'];
5393 $annots .=
' /Rect ['.$rect.
']';
5394 $annots .=
' /Contents '.$this->_textstring($pl[
'txt']);
5396 $annots .=
' /NM '.$this->_textstring(sprintf(
'%04u-%04u', $n,
$key));
5397 $annots .=
' /M '.$this->_datastring(
'D:'.date(
'YmdHis'));
5398 if (isset($pl[
'opt'][
'f'])) {
5400 if (is_array($pl[
'opt'][
'f'])) {
5401 foreach ($pl[
'opt'][
'f'] as
$f) {
5402 switch (strtolower($f)) {
5435 case 'togglenoview': {
5439 case 'lockedcontents': {
5449 $annots .=
' /F '.intval($val);
5453 $annots .=
' /Border [';
5454 if (isset($pl[
'opt'][
'border']) AND (count($pl[
'opt'][
'border']) >= 3)) {
5455 $annots .= intval($pl[
'opt'][
'border'][0]).
' ';
5456 $annots .= intval($pl[
'opt'][
'border'][1]).
' ';
5457 $annots .= intval($pl[
'opt'][
'border'][2]);
5458 if (isset($pl[
'opt'][
'border'][3]) AND is_array($pl[
'opt'][
'border'][3])) {
5460 foreach ($pl[
'opt'][
'border'][3] as $dash) {
5461 $annots .= intval($dash).
' ';
5469 if (isset($pl[
'opt'][
'bs']) AND (is_array($pl[
'opt'][
'bs']))) {
5470 $annots .=
' /BS <<Type /Border';
5471 if (isset($pl[
'opt'][
'bs'][
'w'])) {
5472 $annots .=
' /W '.sprintf(
"%.4F", floatval($pl[
'opt'][
'bs'][
'w']));
5474 $bstyles = array(
'S',
'D',
'B',
'I',
'U');
5475 if (isset($pl[
'opt'][
'bs'][
's']) AND in_array($pl[
'opt'][
'bs'][
's'], $bstyles)) {
5476 $annots .=
' /S /'.$pl[
'opt'][
'bs'][
's'];
5478 if (isset($pl[
'opt'][
'bs'][
'd']) AND (is_array($pl[
'opt'][
'bs'][
'd']))) {
5480 foreach ($pl[
'opt'][
'bs'][
'd'] as $cord) {
5481 $cord = floatval($cord);
5482 $annots .= sprintf(
" %.4F", $cord);
5488 if (isset($pl[
'opt'][
'be']) AND (is_array($pl[
'opt'][
'be']))) {
5489 $annots .=
' /BE <<';
5490 $bstyles = array(
'S',
'C');
5491 if (isset($pl[
'opt'][
'be'][
's']) AND in_array($pl[
'opt'][
'be'][
's'], $markups)) {
5492 $annots .=
' /S /'.$pl[
'opt'][
'bs'][
's'];
5494 $annots .=
' /S /S';
5496 if (isset($pl[
'opt'][
'be'][
'i']) AND ($pl[
'opt'][
'be'][
'i'] >= 0) AND ($pl[
'opt'][
'be'][
'i'] <= 2)) {
5497 $annots .=
' /I '.sprintf(
" %.4F", $pl[
'opt'][
'be'][
'i']);
5502 if (isset($pl[
'opt'][
'c']) AND (is_array($pl[
'opt'][
'c']))) {
5503 foreach ($pl[
'opt'][
'c'] as $col) {
5504 $col = intval($col);
5505 $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255);
5506 $annots .= sprintf(
" %.4F", $color);
5512 $markups = array(
'text',
'freetext',
'line',
'square',
'circle',
'polygon',
'polyline',
'highlight',
'underline',
'squiggly',
'strikeout',
'stamp',
'caret',
'ink',
'fileattachment',
'sound');
5513 if (in_array(strtolower($pl[
'opt'][
'subtype']), $markups)) {
5515 if (isset($pl[
'opt'][
't']) AND is_string($pl[
'opt'][
't'])) {
5516 $annots .=
' /T '.$this->_textstring($pl[
'opt'][
't']);
5519 if (isset($pl[
'opt'][
'ca'])) {
5520 $annots .=
' /CA '.sprintf(
"%.4F", floatval($pl[
'opt'][
'ca']));
5522 if (isset($pl[
'opt'][
'rc'])) {
5523 $annots .=
' /RC '.$this->_textstring($pl[
'opt'][
'rc']);
5525 $annots .=
' /CreationDate '.$this->_datastring(
'D:'.date(
'YmdHis'));
5527 if (isset($pl[
'opt'][
'subj'])) {
5528 $annots .=
' /Subj '.$this->_textstring($pl[
'opt'][
'subj']);
5534 switch (strtolower($pl[
'opt'][
'subtype'])) {
5536 if (isset($pl[
'opt'][
'open'])) {
5537 $annots .=
' /Open '. (strtolower($pl[
'opt'][
'open']) ==
'true' ?
'true' :
'false');
5539 $iconsapp = array(
'Comment',
'Help',
'Insert',
'Key',
'NewParagraph',
'Note',
'Paragraph');
5540 if (isset($pl[
'opt'][
'name']) AND in_array($pl[
'opt'][
'name'], $iconsapp)) {
5541 $annots .=
' /Name /'.$pl[
'opt'][
'name'];
5543 $annots .=
' /Name /Note';
5545 $statemodels = array(
'Marked',
'Review');
5546 if (isset($pl[
'opt'][
'statemodel']) AND in_array($pl[
'opt'][
'statemodel'], $statemodels)) {
5547 $annots .=
' /StateModel /'.$pl[
'opt'][
'statemodel'];
5549 $pl[
'opt'][
'statemodel'] =
'Marked';
5550 $annots .=
' /StateModel /'.$pl[
'opt'][
'statemodel'];
5552 if ($pl[
'opt'][
'statemodel'] ==
'Marked') {
5553 $states = array(
'Accepted',
'Unmarked');
5555 $states = array(
'Accepted',
'Rejected',
'Cancelled',
'Completed',
'None');
5557 if (isset($pl[
'opt'][
'state']) AND in_array($pl[
'opt'][
'state'], $states)) {
5558 $annots .=
' /State /'.$pl[
'opt'][
'state'];
5560 if ($pl[
'opt'][
'statemodel'] ==
'Marked') {
5561 $annots .=
' /State /Unmarked';
5563 $annots .=
' /State /None';
5569 if(is_string($pl[
'txt'])) {
5571 $annots .=
' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl[
'txt'])).
'>>';
5574 $l = $this->links[$pl[
'txt']];
5575 $annots .= sprintf(
' /Dest [%d 0 R /XYZ 0 %.2F null]', (1 + (2 *
$l[0])), ($this->pagedim[
$l[0]][
'h'] - (
$l[1] * $this->k)));
5577 $hmodes = array(
'N',
'I',
'O',
'P');
5578 if (isset($pl[
'opt'][
'h']) AND in_array($pl[
'opt'][
'h'], $hmodes)) {
5579 $annots .=
' /H /'.$pl[
'opt'][
'h'];
5581 $annots .=
' /H /I';
5588 $annots .=
' /DA '.$this->_textstring($pl[
'txt']);
5589 if (isset($pl[
'opt'][
'q']) AND ($pl[
'opt'][
'q'] >= 0) AND ($pl[
'opt'][
'q'] <= 2)) {
5590 $annots .=
' /Q '.intval($pl[
'opt'][
'q']);
5592 if (isset($pl[
'opt'][
'rc'])) {
5593 $annots .=
' /RC '.$this->_textstring($pl[
'opt'][
'rc']);
5595 if (isset($pl[
'opt'][
'ds'])) {
5596 $annots .=
' /DS '.$this->_textstring($pl[
'opt'][
'ds']);
5598 if (isset($pl[
'opt'][
'cl']) AND is_array($pl[
'opt'][
'cl'])) {
5599 $annots .=
' /CL [';
5600 foreach ($pl[
'opt'][
'cl'] as $cl) {
5601 $annots .= sprintf(
"%.4F ", $cl * $this->k);
5605 $tfit = array(
'FreeTextCallout',
'FreeTextTypeWriter');
5606 if (isset($pl[
'opt'][
'it']) AND in_array($pl[
'opt'][
'it'], $tfit)) {
5607 $annots .=
' /IT '.$pl[
'opt'][
'it'];
5609 if (isset($pl[
'opt'][
'rd']) AND is_array($pl[
'opt'][
'rd'])) {
5610 $l = $pl[
'opt'][
'rd'][0] * $this->k;
5611 $r = $pl[
'opt'][
'rd'][1] * $this->k;
5612 $t = $pl[
'opt'][
'rd'][2] * $this->k;
5613 $b = $pl[
'opt'][
'rd'][3] * $this->k;
5614 $annots .=
' /RD ['.sprintf(
'%.2F %.2F %.2F %.2F',
$l, $r,
$t, $b).
']';
5659 case 'fileattachment': {
5660 if (!isset($pl[
'opt'][
'fs'])) {
5664 if (isset($this->embeddedfiles[
$filename][
'n'])) {
5665 $annots .=
' /FS <</Type /Filespec /F '.$this->_datastring($filename).
' /EF <</F '.$this->embeddedfiles[
$filename][
'n'].
' 0 R>> >>';
5666 $iconsapp = array(
'Graph',
'Paperclip',
'PushPin',
'Tag');
5667 if (isset($pl[
'opt'][
'name']) AND in_array($pl[
'opt'][
'name'], $iconsapp)) {
5668 $annots .=
' /Name /'.$pl[
'opt'][
'name'];
5670 $annots .=
' /Name /PushPin';
5676 if (!isset($pl[
'opt'][
'sound'])) {
5679 $filename = basename($pl[
'opt'][
'sound']);
5680 if (isset($this->embeddedfiles[$filename][
'n'])) {
5682 $iconsapp = array(
'Speaker',
'Mic');
5683 if (isset($pl[
'opt'][
'name']) AND in_array($pl[
'opt'][
'name'], $iconsapp)) {
5684 $annots .=
' /Name /'.$pl[
'opt'][
'name'];
5686 $annots .=
' /Name /Speaker';
5696 $hmode = array(
'N',
'I',
'O',
'P',
'T');
5697 if (isset($pl[
'opt'][
'h']) AND in_array($pl[
'opt'][
'h'], $hmode)) {
5698 $annots .=
' /H /'.$pl[
'opt'][
'h'];
5700 if (isset($pl[
'opt'][
'mk']) AND (is_array($pl[
'opt'][
'mk']))) {
5701 $annots .=
' /MK <<';
5710 case 'printermark': {
5729 $this->_out($annots);
5737 protected function _putfonts() {
5739 foreach ($this->diffs as
$diff) {
5742 $this->_out(
'<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.
']>>');
5743 $this->_out(
'endobj');
5745 $mqr = get_magic_quotes_runtime();
5746 set_magic_quotes_runtime(0);
5747 foreach ($this->FontFiles as
$file => $info) {
5749 $fontdir = $info[
'fontdir'];
5753 if (file_exists($fontdir.$file)) {
5754 $fontfile = $fontdir.$file;
5755 }
elseif (file_exists($this->_getfontpath().
$file)) {
5756 $fontfile = $this->_getfontpath().$file;
5760 if (!$this->empty_string($fontfile)) {
5761 $font = file_get_contents($fontfile);
5762 $compressed = (substr(
$file, -2) ==
'.z');
5763 if ((!$compressed) AND (isset($info[
'length2']))) {
5764 $header = (ord($font{0}) == 128);
5767 $font = substr($font, 6);
5769 if ($header AND (ord($font{$info[
'length1']}) == 128)) {
5771 $font = substr($font, 0, $info[
'length1']).substr($font, ($info[
'length1'] + 6));
5776 $this->_out(
'<</Length '.strlen($font));
5778 $this->_out(
'/Filter /FlateDecode');
5780 $this->_out(
'/Length1 '.$info[
'length1']);
5781 if (isset($info[
'length2'])) {
5782 $this->_out(
'/Length2 '.$info[
'length2'].
' /Length3 0');
5785 $this->_putstream($font);
5786 $this->_out(
'endobj');
5789 set_magic_quotes_runtime($mqr);
5790 foreach ($this->fontkeys as $k) {
5792 $this->setFontSubBuffer($k,
'n', $this->
n + 1);
5793 $font = $this->getFontBuffer($k);
5794 $type = $font[
'type'];
5795 $name = $font[
'name'];
5796 if (
$type ==
'core') {
5799 $this->_out(
'<</Type /Font');
5800 $this->_out(
'/BaseFont /'.$name);
5801 $this->_out(
'/Subtype /Type1');
5802 if (($name !=
'symbol') AND ($name !=
'zapfdingbats')) {
5803 $this->_out(
'/Encoding /WinAnsiEncoding');
5806 $this->_out(
'endobj');
5810 $this->_out(
'<</Type /Font');
5811 $this->_out(
'/BaseFont /'.$name);
5812 $this->_out(
'/Subtype /'.
$type);
5813 $this->_out(
'/FirstChar 32 /LastChar 255');
5814 $this->_out(
'/Widths '.($this->
n + 1).
' 0 R');
5815 $this->_out(
'/FontDescriptor '.($this->
n + 2).
' 0 R');
5817 if (isset($font[
'diff'])) {
5818 $this->_out(
'/Encoding '.($nf + $font[
'diff']).
' 0 R');
5820 $this->_out(
'/Encoding /WinAnsiEncoding');
5824 $this->_out(
'endobj');
5829 for ($i = 32; $i < 256; ++$i) {
5832 $this->_out($s.
']');
5833 $this->_out(
'endobj');
5836 $s =
'<</Type /FontDescriptor /FontName /'.$name;
5837 foreach ($font[
'desc'] as $k => $v) {
5838 $s .=
' /'.$k.
' '.$v.
'';
5840 if (!$this->empty_string($font[
'file'])) {
5841 $s .=
' /FontFile'.($type ==
'Type1' ?
'' :
'2').
' '.$this->FontFiles[$font[
'file']][
'n'].
' 0 R';
5843 $this->_out($s.
'>>');
5844 $this->_out(
'endobj');
5847 $mtd =
'_put'.strtolower(
$type);
5848 if (!method_exists($this, $mtd)) {
5849 $this->Error(
'Unsupported font type: '.
$type);
5864 protected function _putfontwidths($font, $cidoffset=0) {
5872 foreach ($font[
'cw'] as
$cid => $width) {
5874 if ($width != $font[
'dw']) {
5875 if (
$cid == ($prevcid + 1)) {
5877 if ($width == $prevwidth) {
5878 if ($width == $range[$rangeid][0]) {
5879 $range[$rangeid][] = $width;
5881 array_pop($range[$rangeid]);
5883 $rangeid = $prevcid;
5884 $range[$rangeid] = array();
5885 $range[$rangeid][] = $prevwidth;
5886 $range[$rangeid][] = $width;
5889 $range[$rangeid][
'interval'] =
true;
5894 $range[$rangeid] = array();
5895 $range[$rangeid][] = $width;
5897 $range[$rangeid][] = $width;
5904 $range[$rangeid] = array();
5905 $range[$rangeid][] = $width;
5909 $prevwidth = $width;
5916 foreach ($range as $k => $ws) {
5918 if (($k == $nextk) AND (!$prevint) AND ((!isset($ws[
'interval'])) OR ($cws < 4))) {
5919 if (isset($range[$k][
'interval'])) {
5920 unset($range[$k][
'interval']);
5922 $range[$prevk] = array_merge($range[$prevk], $range[$k]);
5928 if (isset($ws[
'interval'])) {
5934 unset($range[$k][
'interval']);
5942 foreach ($range as $k => $ws) {
5943 if (count(array_count_values($ws)) == 1) {
5945 $w .=
' '.$k.
' '.($k + count($ws) - 1).
' '.$ws[0];
5948 $w .=
' '.$k.
' [ '.implode(
' ', $ws).
' ]';
5951 $this->_out(
'/W ['.$w.
' ]');
5962 protected function _puttruetypeunicode($font) {
5966 $this->_out(
'<</Type /Font');
5967 $this->_out(
'/Subtype /Type0');
5968 $this->_out(
'/BaseFont /'.$font[
'name'].
'');
5969 $this->_out(
'/Encoding /Identity-H');
5970 $this->_out(
'/ToUnicode /Identity-H');
5971 $this->_out(
'/DescendantFonts ['.($this->
n + 1).
' 0 R]');
5973 $this->_out(
'endobj');
5977 $this->_out(
'<</Type /Font');
5978 $this->_out(
'/Subtype /CIDFontType2');
5979 $this->_out(
'/BaseFont /'.$font[
'name'].
'');
5981 $cidinfo =
'/Registry '.$this->_datastring(
'Adobe');
5982 $cidinfo .=
' /Ordering '.$this->_datastring(
'Identity');
5984 $this->_out(
'/CIDSystemInfo <<'.
$cidinfo.
'>>');
5985 $this->_out(
'/FontDescriptor '.($this->
n + 1).
' 0 R');
5986 $this->_out(
'/DW '.$font[
'dw'].
'');
5987 $this->_putfontwidths($font, 0);
5988 $this->_out(
'/CIDToGIDMap '.($this->
n + 2).
' 0 R');
5990 $this->_out(
'endobj');
5994 $this->_out(
'<</Type /FontDescriptor');
5995 $this->_out(
'/FontName /'.$font[
'name']);
5996 foreach ($font[
'desc'] as
$key => $value) {
5997 $this->_out(
'/'.
$key.
' '.$value);
6000 if (!$this->empty_string($font[
'file'])) {
6002 $this->_out(
'/FontFile2 '.$this->FontFiles[$font[
'file']][
'n'].
' 0 R');
6003 $fontdir = $this->FontFiles[$font[
'file']][
'fontdir'];
6006 $this->_out(
'endobj');
6008 if (isset($font[
'ctg']) AND (!$this->empty_string($font[
'ctg']))) {
6012 $ctgfile = strtolower($font[
'ctg']);
6016 if (file_exists($fontdir.$ctgfile)) {
6017 $fontfile = $fontdir.$ctgfile;
6018 }
elseif (file_exists($this->_getfontpath().$ctgfile)) {
6019 $fontfile = $this->_getfontpath().$ctgfile;
6020 }
elseif (file_exists($ctgfile)) {
6021 $fontfile = $ctgfile;
6023 if ($this->empty_string($fontfile)) {
6024 $this->Error(
'Font file not found: '.$ctgfile);
6026 $size = filesize($fontfile);
6027 $this->_out(
'<</Length '.
$size.
'');
6028 if (substr($fontfile, -2) ==
'.z') {
6032 $this->_out(
'/Filter /FlateDecode');
6035 $this->_putstream(file_get_contents($fontfile));
6037 $this->_out(
'endobj');
6047 protected function _putcidfont0($font) {
6049 if (isset($font[
'cidinfo'][
'uni2cid'])) {
6051 $uni2cid = $font[
'cidinfo'][
'uni2cid'];
6053 foreach ($font[
'cw'] as $uni => $width) {
6054 if (isset($uni2cid[$uni])) {
6055 $cw[($uni2cid[$uni] + $cidoffset)] = $width;
6060 $font = array_merge($font, array(
'cw' =>
$cw));
6062 $name = $font[
'name'];
6063 $enc = $font[
'enc'];
6065 $longname = $name.
'-'.
$enc;
6070 $this->_out(
'<</Type /Font');
6071 $this->_out(
'/BaseFont /'.$longname);
6072 $this->_out(
'/Subtype /Type0');
6074 $this->_out(
'/Encoding /'.
$enc);
6076 $this->_out(
'/DescendantFonts ['.($this->
n + 1).
' 0 R]');
6078 $this->_out(
'endobj');
6080 $this->_out(
'<</Type /Font');
6081 $this->_out(
'/BaseFont /'.$name);
6082 $this->_out(
'/Subtype /CIDFontType0');
6083 $cidinfo =
'/Registry '.$this->_datastring($font[
'cidinfo'][
'Registry']);
6084 $cidinfo .=
' /Ordering '.$this->_datastring($font[
'cidinfo'][
'Ordering']);
6085 $cidinfo .=
' /Supplement '.$font[
'cidinfo'][
'Supplement'];
6086 $this->_out(
'/CIDSystemInfo <<'.
$cidinfo.
'>>');
6087 $this->_out(
'/FontDescriptor '.($this->
n + 1).
' 0 R');
6088 $this->_out(
'/DW '.$font[
'dw']);
6089 $this->_putfontwidths($font, $cidoffset);
6091 $this->_out(
'endobj');
6093 $s =
'<</Type /FontDescriptor /FontName /'.$name;
6094 foreach ($font[
'desc'] as $k => $v) {
6095 if ($k !=
'Style') {
6096 $s .=
' /'.$k.
' '.$v.
'';
6099 $this->_out($s.
'>>');
6100 $this->_out(
'endobj');
6107 protected function _putimages() {
6108 $filter = ($this->compress) ?
'/Filter /FlateDecode ' :
'';
6109 foreach ($this->imagekeys as
$file) {
6110 $info = $this->getImageBuffer($file);
6112 $this->setImageSubBuffer($file,
'n', $this->
n);
6113 $this->_out(
'<</Type /XObject');
6114 $this->_out(
'/Subtype /Image');
6115 $this->_out(
'/Width '.$info[
'w']);
6116 $this->_out(
'/Height '.$info[
'h']);
6117 if (isset($info[
'masked'])) {
6118 $this->_out(
'/SMask '.($this->
n - 1).
' 0 R');
6120 if ($info[
'cs'] ==
'Indexed') {
6121 $this->_out(
'/ColorSpace [/Indexed /DeviceRGB '.((strlen($info[
'pal']) / 3) - 1).
' '.($this->
n + 1).
' 0 R]');
6123 $this->_out(
'/ColorSpace /'.$info[
'cs']);
6124 if ($info[
'cs'] ==
'DeviceCMYK') {
6125 $this->_out(
'/Decode [1 0 1 0 1 0 1 0]');
6128 $this->_out(
'/BitsPerComponent '.$info[
'bpc']);
6129 if (isset($info[
'f'])) {
6130 $this->_out(
'/Filter /'.$info[
'f']);
6132 if (isset($info[
'parms'])) {
6133 $this->_out($info[
'parms']);
6135 if (isset($info[
'trns']) AND is_array($info[
'trns'])) {
6137 $count_info = count($info[
'trns']);
6138 for ($i=0; $i < $count_info; ++$i) {
6139 $trns .= $info[
'trns'][$i].
' '.$info[
'trns'][$i].
' ';
6141 $this->_out(
'/Mask ['.$trns.
']');
6143 $this->_out(
'/Length '.strlen($info[
'data']).
'>>');
6144 $this->_putstream($info[
'data']);
6145 $this->_out(
'endobj');
6147 if ($info[
'cs'] ==
'Indexed') {
6149 $pal = ($this->compress) ? gzcompress($info[
'pal']) : $info[
'pal'];
6150 $this->_out(
'<<'.
$filter.
'/Length '.strlen($pal).
'>>');
6151 $this->_putstream($pal);
6152 $this->_out(
'endobj');
6162 protected function _putspotcolors() {
6163 foreach ($this->spot_colors as $name => $color) {
6166 $this->_out(
'[/Separation /'.str_replace(
' ',
'#20', $name));
6167 $this->_out(
'/DeviceCMYK <<');
6168 $this->_out(
'/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
6169 $this->_out(sprintf(
'/C1 [%.4F %.4F %.4F %.4F] ', $color[
'c']/100, $color[
'm']/100, $color[
'y']/100, $color[
'k']/100));
6170 $this->_out(
'/FunctionType 2 /Domain [0 1] /N 1>>]');
6171 $this->_out(
'endobj');
6179 protected function _putxobjectdict() {
6180 foreach ($this->imagekeys as $file) {
6181 $info = $this->getImageBuffer($file);
6182 $this->_out(
'/I'.$info[
'i'].
' '.$info[
'n'].
' 0 R');
6190 protected function _putresourcedict() {
6191 $this->_out(
'/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
6192 $this->_out(
'/Font <<');
6193 foreach ($this->fontkeys as $fontkey) {
6194 $font = $this->getFontBuffer($fontkey);
6195 $this->_out(
'/F'.$font[
'i'].
' '.$font[
'n'].
' 0 R');
6198 $this->_out(
'/XObject <<');
6199 $this->_putxobjectdict();
6202 $this->_out(
'/Properties <</OC1 '.$this->n_ocg_print.
' 0 R /OC2 '.$this->n_ocg_view.
' 0 R>>');
6204 $this->_out(
'/ExtGState <<');
6205 foreach ($this->extgstates as $k => $extgstate) {
6206 $this->_out(
'/GS'.$k.
' '.$extgstate[
'n'].
' 0 R');
6210 if (isset($this->gradients) AND (count($this->gradients) > 0)) {
6211 $this->_out(
'/Shading <<');
6212 foreach ($this->gradients as $id => $grad) {
6213 $this->_out(
'/Sh'.$id.
' '.$grad[
'id'].
' 0 R');
6218 if (isset($this->spot_colors) AND (count($this->spot_colors) > 0)) {
6219 $this->_out(
'/ColorSpace <<');
6220 foreach ($this->spot_colors as $color) {
6221 $this->_out(
'/CS'.$color[
'i'].
' '.$color[
'n'].
' 0 R');
6231 protected function _putresources() {
6232 $this->_putextgstates();
6235 $this->_putimages();
6236 $this->_putspotcolors();
6237 $this->_putshaders();
6239 $this->offsets[2] = $this->bufferlen;
6240 $this->_out(
'2 0 obj');
6242 $this->_putresourcedict();
6244 $this->_out(
'endobj');
6245 $this->_putjavascript();
6246 $this->_putbookmarks();
6247 $this->_putEmbeddedFiles();
6249 if ($this->encrypted) {
6253 $this->_putencryption();
6255 $this->_out(
'endobj');
6264 protected function _putinfo() {
6265 if ($this->empty_string($this->title)) {
6268 $this->_out(
'/Title '.$this->_textstring($this->title));
6269 if ($this->empty_string($this->author)) {
6270 $this->author =
'?';
6272 $this->_out(
'/Author '.$this->_textstring($this->author));
6273 if ($this->empty_string($this->subject)) {
6274 $this->subject =
'?';
6276 $this->_out(
'/Subject '.$this->_textstring($this->subject));
6277 if ($this->empty_string($this->keywords)) {
6278 $this->keywords =
'?';
6280 $this->_out(
'/Keywords '.$this->_textstring($this->keywords));
6281 if ($this->empty_string($this->creator)) {
6282 $this->creator =
'?';
6284 $this->_out(
'/Creator '.$this->_textstring($this->creator));
6285 if (defined(
'PDF_PRODUCER')) {
6286 $this->_out(
'/Producer '.$this->_textstring(PDF_PRODUCER));
6288 $this->_out(
'/Producer '.$this->_textstring(
'TCPDF'));
6290 $this->_out(
'/CreationDate '.$this->_datastring(
'D:'.date(
'YmdHis')));
6291 $this->_out(
'/ModDate '.$this->_datastring(
'D:'.date(
'YmdHis')));
6298 protected function _putcatalog() {
6299 $this->_out(
'/Type /Catalog');
6300 $this->_out(
'/Pages 1 0 R');
6301 if ($this->ZoomMode ==
'fullpage') {
6302 $this->_out(
'/OpenAction [3 0 R /Fit]');
6303 }
elseif ($this->ZoomMode ==
'fullwidth') {
6304 $this->_out(
'/OpenAction [3 0 R /FitH null]');
6305 }
elseif ($this->ZoomMode ==
'real') {
6306 $this->_out(
'/OpenAction [3 0 R /XYZ null null 1]');
6307 }
elseif (!is_string($this->ZoomMode)) {
6308 $this->_out(
'/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode / 100).
']');
6310 if (isset($this->LayoutMode) AND (!$this->empty_string($this->LayoutMode))) {
6311 $this->_out(
'/PageLayout /'.$this->LayoutMode.
'');
6313 if (isset($this->PageMode) AND (!$this->empty_string($this->PageMode))) {
6314 $this->_out(
'/PageMode /'.$this->PageMode);
6316 if (isset($this->l[
'a_meta_language'])) {
6317 $this->_out(
'/Lang /'.$this->l[
'a_meta_language']);
6319 $this->_out(
'/Names <<');
6320 if (!$this->empty_string($this->javascript)) {
6321 $this->_out(
'/JavaScript '.($this->n_js).
' 0 R');
6324 if (count($this->outlines) > 0) {
6325 $this->_out(
'/Outlines '.$this->OutlineRoot.
' 0 R');
6326 $this->_out(
'/PageMode /UseOutlines');
6328 $this->_putviewerpreferences();
6329 $p = $this->n_ocg_print.
' 0 R';
6330 $v = $this->n_ocg_view.
' 0 R';
6331 $as =
'<</Event /Print /OCGs ['.$p.
' '.$v.
'] /Category [/Print]>> <</Event /View /OCGs ['.$p.
' '.$v.
'] /Category [/View]>>';
6332 $this->_out(
'/OCProperties <</OCGs ['.$p.
' '.$v.
'] /D <</ON ['.$p.
'] /OFF ['.$v.
'] /AS ['.$as.
']>>>>');
6334 if ($this->sign AND isset($this->signature_data[
'cert_type'])) {
6335 if ($this->signature_data[
'cert_type'] > 0) {
6336 $this->_out(
'/AcroForm<<');
6337 $this->_out(
'/Fields ['.$this->sig_obj_id.
' 0 R]');
6338 $this->_out(
'/NeedAppearances false');
6339 $this->_out(
'/SigFlags 3');
6341 $this->_out(
'/Perms<</DocMDP '.($this->sig_obj_id + 1).
' 0 R>>');
6343 $this->_out(
'/Perms<</UR3 '.($this->sig_obj_id + 1).
' 0 R>>');
6354 protected function _putviewerpreferences() {
6355 $this->_out(
'/ViewerPreferences<<');
6357 $this->_out(
'/Direction /R2L');
6359 $this->_out(
'/Direction /L2R');
6361 if (isset($this->viewer_preferences[
'HideToolbar']) AND ($this->viewer_preferences[
'HideToolbar'])) {
6362 $this->_out(
'/HideToolbar true');
6364 if (isset($this->viewer_preferences[
'HideMenubar']) AND ($this->viewer_preferences[
'HideMenubar'])) {
6365 $this->_out(
'/HideMenubar true');
6367 if (isset($this->viewer_preferences[
'HideWindowUI']) AND ($this->viewer_preferences[
'HideWindowUI'])) {
6368 $this->_out(
'/HideWindowUI true');
6370 if (isset($this->viewer_preferences[
'FitWindow']) AND ($this->viewer_preferences[
'FitWindow'])) {
6371 $this->_out(
'/FitWindow true');
6373 if (isset($this->viewer_preferences[
'CenterWindow']) AND ($this->viewer_preferences[
'CenterWindow'])) {
6374 $this->_out(
'/CenterWindow true');
6376 if (isset($this->viewer_preferences[
'DisplayDocTitle']) AND ($this->viewer_preferences[
'DisplayDocTitle'])) {
6377 $this->_out(
'/DisplayDocTitle true');
6379 if (isset($this->viewer_preferences[
'NonFullScreenPageMode'])) {
6380 $this->_out(
'/NonFullScreenPageMode /'.$this->viewer_preferences[
'NonFullScreenPageMode'].
'');
6382 if (isset($this->viewer_preferences[
'ViewArea'])) {
6383 $this->_out(
'/ViewArea /'.$this->viewer_preferences[
'ViewArea']);
6385 if (isset($this->viewer_preferences[
'ViewClip'])) {
6386 $this->_out(
'/ViewClip /'.$this->viewer_preferences[
'ViewClip']);
6388 if (isset($this->viewer_preferences[
'PrintArea'])) {
6389 $this->_out(
'/PrintArea /'.$this->viewer_preferences[
'PrintArea']);
6391 if (isset($this->viewer_preferences[
'PrintClip'])) {
6392 $this->_out(
'/PrintClip /'.$this->viewer_preferences[
'PrintClip']);
6394 if (isset($this->viewer_preferences[
'PrintScaling'])) {
6395 $this->_out(
'/PrintScaling /'.$this->viewer_preferences[
'PrintScaling']);
6397 if (isset($this->viewer_preferences[
'Duplex']) AND (!$this->empty_string($this->viewer_preferences[
'Duplex']))) {
6398 $this->_out(
'/Duplex /'.$this->viewer_preferences[
'Duplex']);
6400 if (isset($this->viewer_preferences[
'PickTrayByPDFSize'])) {
6401 if ($this->viewer_preferences[
'PickTrayByPDFSize']) {
6402 $this->_out(
'/PickTrayByPDFSize true');
6404 $this->_out(
'/PickTrayByPDFSize false');
6407 if (isset($this->viewer_preferences[
'PrintPageRange'])) {
6408 $PrintPageRangeNum =
'';
6409 foreach ($this->viewer_preferences[
'PrintPageRange'] as $k => $v) {
6410 $PrintPageRangeNum .=
' '.($v - 1).
'';
6412 $this->_out(
'/PrintPageRange ['.substr($PrintPageRangeNum,1).
']');
6414 if (isset($this->viewer_preferences[
'NumCopies'])) {
6415 $this->_out(
'/NumCopies '.intval($this->viewer_preferences[
'NumCopies']));
6424 protected function _puttrailer() {
6425 $this->_out(
'/Size '.($this->
n + 1));
6426 $this->_out(
'/Root '.$this->
n.
' 0 R');
6427 $this->_out(
'/Info '.($this->
n - 1).
' 0 R');
6428 if ($this->encrypted) {
6429 $this->_out(
'/Encrypt '.$this->enc_obj_id.
' 0 R');
6430 $this->_out(
'/ID [()()]');
6438 protected function _putheader() {
6439 $this->_out(
'%PDF-'.$this->PDFVersion);
6446 protected function _enddoc() {
6448 $this->_putheader();
6450 $this->_putresources();
6452 if ($this->sign AND isset($this->signature_data[
'cert_type'])) {
6454 $this->sig_obj_id = $this->_newobj();
6456 $this->_out(
'/FT /Sig');
6457 $this->_out(
'/T '.$this->_textstring(
'SIGNATURE'));
6458 $this->_out(
'/Ff 0');
6459 $this->_out(
'/V '.($this->sig_obj_id + 1).
' 0 R');
6461 $this->_out(
'endobj');
6465 $this->_putsignature();
6466 $this->_putursignature();
6468 $this->_out(
'endobj');
6475 $this->_out(
'endobj');
6479 $this->_putcatalog();
6481 $this->_out(
'endobj');
6483 $o = $this->bufferlen;
6484 $this->_out(
'xref');
6485 $this->_out(
'0 '.($this->
n + 1));
6486 $this->_out(
'0000000000 65535 f ');
6488 $this->_out(sprintf(
'%010d 00000 n ', $this->offsets[$i]));
6490 if (isset($this->embeddedfiles) AND count($this->embeddedfiles) > 0) {
6491 $this->_out(
'100000 '.count($this->embeddedfiles));
6492 foreach ($this->embeddedfiles as $filename => $filedata) {
6493 $this->_out(sprintf(
'%010d 00000 n ', $this->offsets[$filedata[
'n']]));
6497 $this->_out(
'trailer');
6499 $this->_puttrailer();
6501 $this->_out(
'startxref');
6503 $this->_out(
'%%EOF');
6505 if ($this->diskcache) {
6507 foreach ($this->imagekeys as
$key) {
6509 unlink($this->images[$key]);
6511 foreach ($this->fontkeys as $key) {
6513 unlink($this->fonts[$key]);
6524 protected function _beginpage($orientation=
'', $format=
'') {
6526 $this->setPageBuffer($this->page,
'');
6528 $this->transfmrk[$this->page] = array();
6530 if ($this->empty_string($orientation)) {
6531 if (isset($this->CurOrientation)) {
6532 $orientation = $this->CurOrientation;
6537 if ($this->empty_string($format)) {
6538 $this->setPageOrientation($orientation);
6540 $this->setPageFormat($format, $orientation);
6543 $this->x = $this->w - $this->rMargin;
6545 $this->x = $this->lMargin;
6547 $this->y = $this->tMargin;
6548 if (isset($this->newpagegroup[$this->page])) {
6550 $n =
sizeof($this->pagegroups) + 1;
6551 $alias =
'{nb'.$n.
'}';
6552 $this->pagegroups[$alias] = 1;
6553 $this->currpagegroup = $alias;
6554 }
elseif ($this->currpagegroup) {
6555 ++$this->pagegroups[$this->currpagegroup];
6563 protected function _endpage() {
6564 $this->setVisibility(
'all');
6573 protected function _newobj() {
6575 $this->offsets[
$this->n] = $this->bufferlen;
6576 $this->_out($this->
n.
' 0 obj');
6587 protected function _dounderline(
$x,
$y, $txt) {
6588 $up = $this->CurrentFont[
'up'];
6589 $ut = $this->CurrentFont[
'ut'];
6590 $w = $this->GetStringWidth($txt);
6591 return sprintf(
'%.2F %.2F %.2F %.2F re f',
$x * $this->k, ($this->h - (
$y -
$up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, -
$ut / 1000 * $this->FontSizePt);
6601 protected function _dolinethrough(
$x,
$y, $txt) {
6602 $up = $this->CurrentFont[
'up'];
6603 $ut = $this->CurrentFont[
'ut'];
6604 $w = $this->GetStringWidth($txt);
6605 return sprintf(
'%.2F %.2F %.2F %.2F re f',
$x * $this->k, ($this->h - (
$y - ($this->FontSize/2) -
$up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, -
$ut / 1000 * $this->FontSizePt);
6614 protected function _freadint($f) {
6615 $a = unpack(
'Ni', fread($f, 4));
6625 protected function _escape($s) {
6627 return strtr($s, array(
')' =>
'\\)',
'(' =>
'\\(',
'\\' =>
'\\\\', chr(13) =>
'\r'));
6636 protected function _datastring($s) {
6637 if ($this->encrypted) {
6638 $s = $this->_RC4($this->_objectkey($this->
n), $s);
6640 return '('. $this->_escape($s).
')';
6649 protected function _textstring($s) {
6650 if ($this->isunicode) {
6652 $s = $this->UTF8ToUTF16BE($s,
true);
6654 return $this->_datastring($s);
6663 protected function _escapetext($s) {
6664 if ($this->isunicode) {
6665 if (($this->CurrentFont[
'type'] ==
'core') OR ($this->CurrentFont[
'type'] ==
'TrueType') OR ($this->CurrentFont[
'type'] ==
'Type1')) {
6666 $s = $this->UTF8ToLatin1($s);
6669 $s = $this->utf8StrRev($s,
false, $this->tmprtl);
6672 return $this->_escape($s);
6680 protected function _putstream($s) {
6681 if ($this->encrypted) {
6682 $s = $this->_RC4($this->_objectkey($this->
n), $s);
6684 $this->_out(
'stream');
6686 $this->_out(
'endstream');
6694 protected function _out($s) {
6695 if ($this->state == 2) {
6696 if ((!$this->InFooter) AND isset($this->footerlen[$this->page]) AND ($this->footerlen[$this->page] > 0)) {
6698 $pagebuff = $this->getPageBuffer($this->page);
6699 $page = substr($pagebuff, 0, -$this->footerlen[$this->page]);
6700 $footer = substr($pagebuff, -$this->footerlen[$this->page]);
6701 $this->setPageBuffer($this->page, $page.$s.
"\n".$footer);
6703 $this->footerpos[$this->page] += strlen($s.
"\n");
6705 $this->setPageBuffer($this->page, $s.
"\n",
true);
6708 $this->setBuffer($s.
"\n");
6746 protected function UTF8StringToArray($str) {
6747 if (isset($this->cache_UTF8StringToArray[
'_'.$str])) {
6749 return($this->cache_UTF8StringToArray[
'_'.$str]);
6752 if ($this->cache_size_UTF8StringToArray >= $this->cache_maxsize_UTF8StringToArray) {
6754 array_shift($this->cache_UTF8StringToArray);
6756 ++$this->cache_size_UTF8StringToArray;
6757 if (!$this->isunicode) {
6760 $strlen = strlen($str);
6761 for ($i=0; $i < $strlen; ++$i) {
6762 $strarr[] = ord($str{$i});
6765 $this->cache_UTF8StringToArray[
'_'.$str] = $strarr;
6772 $length = strlen($str);
6773 for ($i = 0; $i < $length; ++$i) {
6774 $char = ord($str{$i});
6775 if (count($bytes) == 0) {
6776 if ($char <= 0x7F) {
6779 }
elseif (($char >> 0x05) == 0x06) {
6780 $bytes[] = ($char - 0xC0) << 0x06;
6782 }
elseif (($char >> 0x04) == 0x0E) {
6783 $bytes[] = ($char - 0xE0) << 0x0C;
6785 }
elseif (($char >> 0x03) == 0x1E) {
6786 $bytes[] = ($char - 0xF0) << 0x12;
6794 }
elseif (($char >> 0x06) == 0x02) {
6795 $bytes[] = $char - 0x80;
6796 if (count($bytes) == $numbytes) {
6799 for ($j = 1; $j < $numbytes; ++$j) {
6800 $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
6802 if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
6823 $this->cache_UTF8StringToArray[
'_'.$str] =
$unicode;
6837 protected function UTF8ToUTF16BE($str, $setbom=
true) {
6838 if (!$this->isunicode) {
6841 $unicode = $this->UTF8StringToArray($str);
6842 return $this->arrUTF8ToUTF16BE(
$unicode, $setbom);
6853 protected function UTF8ToLatin1($str) {
6855 if (!$this->isunicode) {
6859 $unicode = $this->UTF8StringToArray($str);
6862 $outstr .= chr($char);
6863 }
elseif (array_key_exists($char, $utf8tolatin)) {
6865 $outstr .= chr($utf8tolatin[$char]);
6866 }
elseif ($char == 0xFFFD) {
6913 protected function arrUTF8ToUTF16BE(
$unicode, $setbom=
true) {
6916 $outstr .=
"\xFE\xFF";
6919 if ($char == 0xFFFD) {
6920 $outstr .=
"\xFF\xFD";
6921 }
elseif ($char < 0x10000) {
6922 $outstr .= chr($char >> 0x08);
6923 $outstr .= chr($char & 0xFF);
6926 $w1 = 0xD800 | ($char >> 0x10);
6927 $w2 = 0xDC00 | ($char & 0x3FF);
6928 $outstr .= chr($w1 >> 0x08);
6929 $outstr .= chr($w1 & 0xFF);
6930 $outstr .= chr($w2 >> 0x08);
6931 $outstr .= chr($w2 & 0xFF);
6944 public function setHeaderFont($font) {
6945 $this->header_font = $font;
6954 public function getHeaderFont() {
6955 return $this->header_font;
6964 public function setFooterFont($font) {
6965 $this->footer_font = $font;
6974 public function getFooterFont() {
6975 return $this->footer_font;
6984 public function setLanguageArray($language) {
6985 $this->l = $language;
6986 if (isset($this->l[
'a_meta_dir'])) {
6987 $this->rtl = $this->l[
'a_meta_dir']==
'rtl' ?
true :
false;
6997 public function getPDFData() {
6998 if ($this->state < 3) {
7001 return $this->buffer;
7015 public function addHtmlLink($url, $name, $fill=0, $firstline=
false, $color=
'', $style=-1) {
7016 if (!$this->empty_string($url) AND ($url{0} ==
'#')) {
7018 $page = intval(substr($url, 1));
7019 $url = $this->AddLink();
7020 $this->SetLink($url, 0, $page);
7023 $prevcolor = $this->fgcolor;
7024 $prevstyle = $this->FontStyle;
7025 if (empty($color)) {
7026 $this->SetTextColorArray($this->htmlLinkColorArray);
7028 $this->SetTextColorArray($color);
7031 $this->SetFont(
'', $this->FontStyle.$this->htmlLinkFontStyle);
7033 $this->SetFont(
'', $this->FontStyle.$style);
7035 $ret = $this->Write($this->lasth, $name, $url, $fill,
'',
false, 0, $firstline);
7037 $this->SetFont(
'', $prevstyle);
7038 $this->SetTextColorArray($prevcolor);
7048 public function convertHTMLColorToDec($color=
'#FFFFFF') {
7050 $returncolor =
false;
7051 $color = preg_replace(
'/[\s]*/',
'', $color);
7052 $color = strtolower($color);
7053 if (strlen($color) == 0) {
7056 if (substr($color, 0, 3) ==
'rgb') {
7057 $codes = substr($color, 4);
7058 $codes = str_replace(
')',
'', $codes);
7059 $returncolor = explode(
',', $codes, 3);
7060 return $returncolor;
7062 if (substr($color, 0, 1) !=
'#') {
7064 if (isset($webcolor[$color])) {
7065 $color_code = $webcolor[$color];
7070 $color_code = substr($color, 1);
7072 switch (strlen($color_code)) {
7075 $r = substr($color_code, 0, 1);
7076 $g = substr($color_code, 1, 1);
7077 $b = substr($color_code, 2, 1);
7078 $returncolor[
'R'] = hexdec($r.$r);
7079 $returncolor[
'G'] = hexdec($g.$g);
7080 $returncolor[
'B'] = hexdec($b.$b);
7085 $returncolor[
'R'] = hexdec(substr($color_code, 0, 2));
7086 $returncolor[
'G'] = hexdec(substr($color_code, 2, 2));
7087 $returncolor[
'B'] = hexdec(substr($color_code, 4, 2));
7091 return $returncolor;
7101 public function pixelsToUnits($px) {
7102 return ($px / ($this->imgscale * $this->k));
7112 public function unhtmlentities($text_to_convert) {
7113 return html_entity_decode($text_to_convert, ENT_QUOTES, $this->encoding);
7125 protected function _objectkey($n) {
7126 return substr($this->_md5_16($this->encryption_key.pack(
'VXxx', $n)), 0, 10);
7134 protected function _putencryption() {
7135 $this->_out(
'/Filter /Standard');
7136 $this->_out(
'/V 1');
7137 $this->_out(
'/R 2');
7138 $this->_out(
'/O ('.$this->_escape($this->Ovalue).
')');
7139 $this->_out(
'/U ('.$this->_escape($this->Uvalue).
')');
7140 $this->_out(
'/P '.$this->Pvalue);
7153 protected function _RC4(
$key, $text) {
7154 if ($this->last_rc4_key !=
$key) {
7155 $k = str_repeat(
$key, ((256 / strlen(
$key)) + 1));
7156 $rc4 = range(0, 255);
7158 for ($i = 0; $i < 256; ++$i) {
7160 $j = ($j +
$t + ord($k{$i})) % 256;
7161 $rc4[$i] = $rc4[$j];
7164 $this->last_rc4_key =
$key;
7165 $this->last_rc4_key_c = $rc4;
7167 $rc4 = $this->last_rc4_key_c;
7169 $len = strlen($text);
7173 for ($i = 0; $i < $len; ++$i) {
7174 $a = ($a + 1) % 256;
7176 $b = ($b +
$t) % 256;
7177 $rc4[$a] = $rc4[$b];
7179 $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
7180 $out .= chr(ord($text{$i}) ^ $k);
7193 protected function _md5_16($str) {
7194 return pack(
'H*', md5($str));
7206 protected function _Ovalue($user_pass, $owner_pass) {
7207 $tmp = $this->_md5_16($owner_pass);
7208 $owner_RC4_key = substr($tmp, 0, 5);
7209 return $this->_RC4($owner_RC4_key, $user_pass);
7219 protected function _Uvalue() {
7220 return $this->_RC4($this->encryption_key, $this->padding);
7232 protected function _generateencryptionkey($user_pass, $owner_pass, $protection) {
7234 $user_pass = substr($user_pass.$this->padding, 0, 32);
7235 $owner_pass = substr($owner_pass.$this->padding, 0, 32);
7237 $this->Ovalue = $this->_Ovalue($user_pass, $owner_pass);
7239 $tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection).
"\xFF\xFF\xFF");
7240 $this->encryption_key = substr($tmp, 0, 5);
7242 $this->Uvalue = $this->_Uvalue();
7244 $this->Pvalue = -(($protection^255) + 1);
7264 public function SetProtection($permissions=array(), $user_pass=
'', $owner_pass=null) {
7265 $options = array(
'print' => 4,
'modify' => 8,
'copy' => 16,
'annot-forms' => 32);
7267 foreach ($permissions as $permission) {
7268 if (!isset($options[$permission])) {
7269 $this->Error(
'Incorrect permission: '.$permission);
7271 $protection += $options[$permission];
7273 if ($owner_pass === null) {
7274 $owner_pass = uniqid(rand());
7276 $this->encrypted =
true;
7277 $this->_generateencryptionkey($user_pass, $owner_pass, $protection);
7292 public function StartTransform() {
7294 $this->transfmrk[$this->page][] = $this->pagelen[$this->page];
7305 public function StopTransform() {
7307 if (isset($this->transfmatrix)) {
7308 array_pop($this->transfmatrix);
7310 array_pop($this->transfmrk[$this->page]);
7321 public function ScaleX($s_x,
$x=
'',
$y=
'') {
7322 $this->Scale($s_x, 100,
$x,
$y);
7334 public function ScaleY($s_y,
$x=
'',
$y=
'') {
7335 $this->Scale(100, $s_y,
$x,
$y);
7347 public function ScaleXY($s,
$x=
'',
$y=
'') {
7348 $this->Scale($s, $s,
$x,
$y);
7361 public function Scale($s_x, $s_y,
$x=
'',
$y=
'') {
7371 if (($s_x == 0) OR ($s_y == 0)) {
7372 $this->Error(
'Please do not use values equal to zero for scaling');
7374 $y = ($this->h -
$y) * $this->k;
7383 $tm[4] =
$x * (1 - $s_x);
7384 $tm[5] =
$y * (1 - $s_y);
7386 $this->Transform($tm);
7396 public function MirrorH(
$x=
'') {
7397 $this->Scale(-100, 100,
$x);
7407 public function MirrorV(
$y=
'') {
7408 $this->Scale(100, -100,
'',
$y);
7419 public function MirrorP(
$x=
'',
$y=
'') {
7420 $this->Scale(-100, -100,
$x,
$y);
7432 public function MirrorL($angle=0,
$x=
'',
$y=
'') {
7433 $this->Scale(-100, 100,
$x,
$y);
7434 $this->Rotate(-2*($angle-90),
$x,
$y);
7444 public function TranslateX($t_x) {
7445 $this->Translate($t_x, 0);
7455 public function TranslateY($t_y) {
7456 $this->Translate(0, $t_y);
7467 public function Translate($t_x, $t_y) {
7476 $tm[4] = $t_x * $this->k;
7477 $tm[5] = -$t_y * $this->k;
7479 $this->Transform($tm);
7491 public function Rotate($angle,
$x=
'',
$y=
'') {
7502 $y = ($this->h -
$y) * $this->k;
7505 $tm[0] = cos(deg2rad($angle));
7506 $tm[1] = sin(deg2rad($angle));
7509 $tm[4] =
$x + ($tm[1] *
$y) - ($tm[0] *
$x);
7510 $tm[5] =
$y - ($tm[0] *
$y) - ($tm[1] *
$x);
7512 $this->Transform($tm);
7524 public function SkewX($angle_x,
$x=
'',
$y=
'') {
7525 $this->Skew($angle_x, 0,
$x,
$y);
7537 public function SkewY($angle_y,
$x=
'',
$y=
'') {
7538 $this->Skew(0, $angle_y,
$x,
$y);
7551 public function Skew($angle_x, $angle_y,
$x=
'',
$y=
'') {
7560 $angle_x = -$angle_x;
7562 if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
7563 $this->Error(
'Please use values between -90 and +90 degrees for Skewing.');
7566 $y = ($this->h -
$y) * $this->k;
7569 $tm[1] = tan(deg2rad($angle_y));
7570 $tm[2] = tan(deg2rad($angle_x));
7572 $tm[4] = -$tm[2] *
$y;
7573 $tm[5] = -$tm[1] *
$x;
7575 $this->Transform($tm);
7584 protected function Transform($tm) {
7585 $this->_out(sprintf(
'%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
7587 $this->transfmatrix[] = array(
'a' => $tm[0],
'b' => $tm[1],
'c' => $tm[2],
'd' => $tm[3],
'e' => $tm[4],
'f' => $tm[5]);
7589 if (end($this->transfmrk[$this->page]) !==
false) {
7590 $key = key($this->transfmrk[$this->page]);
7591 $this->transfmrk[$this->page][
$key] = $this->pagelen[$this->page];
7608 public function SetLineWidth($width) {
7610 $this->LineWidth = $width;
7611 $this->linestyleWidth = sprintf(
'%.2F w', ($width * $this->k));
7612 if ($this->page > 0) {
7613 $this->_out($this->linestyleWidth);
7624 public function GetLineWidth() {
7625 return $this->LineWidth;
7649 public function SetLineStyle($style) {
7651 if (isset($width)) {
7652 $width_prev = $this->LineWidth;
7653 $this->SetLineWidth($width);
7654 $this->LineWidth = $width_prev;
7657 $ca = array(
'butt' => 0,
'round'=> 1,
'square' => 2);
7658 if (isset($ca[$cap])) {
7659 $this->linestyleCap = $ca[$cap].
' J';
7660 $this->_out($this->linestyleCap);
7664 $ja = array(
'miter' => 0,
'round' => 1,
'bevel' => 2);
7665 if (isset($ja[$join])) {
7666 $this->linestyleJoin = $ja[$join].
' j';
7667 $this->_out($this->linestyleJoin);
7673 if (preg_match(
'/^.+,/', $dash) > 0) {
7674 $tab = explode(
',', $dash);
7676 $tab = array($dash);
7679 foreach (
$tab as $i => $v) {
7681 $dash_string .=
' ';
7683 $dash_string .= sprintf(
"%.2F", $v);
7686 if (!isset($phase) OR !$dash) {
7689 $this->linestyleDash = sprintf(
"[%s] %.2F d", $dash_string, $phase);
7690 $this->_out($this->linestyleDash);
7692 if (isset($color)) {
7693 $this->SetDrawColorArray($color);
7704 protected function _outPoint(
$x,
$y) {
7708 $this->_out(sprintf(
"%.2F %.2F m",
$x * $this->k, ($this->h -
$y) * $this->k));
7718 protected function _outLine(
$x,
$y) {
7722 $this->_out(sprintf(
"%.2F %.2F l",
$x * $this->k, ($this->h -
$y) * $this->k));
7735 protected function _outRect(
$x,
$y, $w, $h, $op) {
7737 $x = $this->w -
$x - $w;
7739 $this->_out(sprintf(
'%.2F %.2F %.2F %.2F re %s',
$x*$this->k, ($this->h-
$y)*$this->k, $w*$this->k, -$h*$this->k, $op));
7754 protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
7756 $x1 = $this->w - $x1;
7757 $x2 = $this->w - $x2;
7758 $x3 = $this->w - $x3;
7760 $this->_out(sprintf(
"%.2F %.2F %.2F %.2F %.2F %.2F c", $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k, $x3 * $this->k, ($this->h - $y3) * $this->k));
7774 public function Line($x1, $y1, $x2, $y2, $style=array()) {
7776 $this->SetLineStyle($style);
7778 $this->_outPoint($x1, $y1);
7779 $this->_outLine($x2, $y2);
7809 public function Rect(
$x,
$y, $w, $h, $style=
'', $border_style=array(), $fill_color=array()) {
7810 if (!(
false === strpos($style,
'F')) AND isset($fill_color)) {
7811 $this->SetFillColorArray($fill_color);
7816 $border_style = array();
7817 $this->_outRect(
$x,
$y, $w, $h, $op);
7822 if ((!$border_style) OR (isset($border_style[
'all']))) {
7824 if (isset($border_style[
'all'])) {
7825 $this->SetLineStyle($border_style[
'all']);
7826 $border_style = array();
7831 $this->_outRect(
$x,
$y, $w, $h, $op);
7836 $this->_outRect(
$x,
$y, $w, $h, $op);
7841 $this->_outRect(
$x,
$y, $w, $h, $op);
7846 if ((!$border_style) OR (isset($border_style[
'all']))) {
7847 if (isset($border_style[
'all']) AND $border_style[
'all']) {
7848 $this->SetLineStyle($border_style[
'all']);
7849 $border_style = array();
7851 $this->_outRect(
$x,
$y, $w, $h, $op);
7856 if ($border_style) {
7857 $border_style2 = array();
7858 foreach ($border_style as $line => $value) {
7859 $lenght = strlen($line);
7860 for ($i = 0; $i < $lenght; ++$i) {
7861 $border_style2[$line[$i]] = $value;
7864 $border_style = $border_style2;
7865 if (isset($border_style[
'L']) AND $border_style[
'L']) {
7866 $this->Line(
$x,
$y,
$x,
$y + $h, $border_style[
'L']);
7868 if (isset($border_style[
'T']) AND $border_style[
'T']) {
7869 $this->Line(
$x,
$y,
$x + $w,
$y, $border_style[
'T']);
7871 if (isset($border_style[
'R']) AND $border_style[
'R']) {
7872 $this->Line(
$x + $w,
$y,
$x + $w,
$y + $h, $border_style[
'R']);
7874 if (isset($border_style[
'B']) AND $border_style[
'B']) {
7875 $this->Line(
$x,
$y + $h,
$x + $w,
$y + $h, $border_style[
'B']);
7907 public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style=
'', $line_style=array(), $fill_color=array()) {
7908 if (!(
false === strpos($style,
'F')) AND isset($fill_color)) {
7909 $this->SetFillColorArray($fill_color);
7914 $line_style = array();
7936 $this->SetLineStyle($line_style);
7938 $this->_outPoint($x0, $y0);
7939 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
7964 public function Polycurve($x0, $y0, $segments, $style=
'', $line_style=array(), $fill_color=array()) {
7965 if (!(
false === strpos($style,
'F')) AND isset($fill_color)) {
7966 $this->SetFillColorArray($fill_color);
7971 $line_style = array();
7993 $this->SetLineStyle($line_style);
7995 $this->_outPoint($x0, $y0);
7996 foreach ($segments as $segment) {
7997 list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
7998 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
8028 public function Ellipse($x0, $y0, $rx, $ry=0, $angle=0, $astart=0, $afinish=360, $style=
'', $line_style=array(), $fill_color=array(), $nc=8) {
8030 $this->StartTransform();
8031 $this->Rotate($angle, $x0, $y0);
8032 $this->Ellipse($x0, $y0, $rx, $ry, 0, $astart, $afinish, $style, $line_style, $fill_color, $nc);
8033 $this->StopTransform();
8037 if (!(
false === strpos($style,
'F')) AND isset($fill_color)) {
8038 $this->SetFillColorArray($fill_color);
8043 $line_style = array();
8069 $this->SetLineStyle($line_style);
8079 $astart = deg2rad((
float) $astart);
8080 $afinish = deg2rad((
float) $afinish);
8081 $total_angle = $afinish - $astart;
8082 $dt = $total_angle / $nc;
8085 $y0 = ($this->h - $y0) * $this->k;
8087 $a0 = $x0 + ($rx * cos($t1));
8088 $b0 = $y0 + ($ry * sin($t1));
8089 $c0 = -$rx * sin($t1);
8090 $d0 = $ry * cos($t1);
8091 $this->_outPoint($a0 / $this->k, $this->h - ($b0 / $this->k));
8092 for ($i = 1; $i <= $nc; ++$i) {
8094 $t1 = ($i * $dt) + $astart;
8095 $a1 = $x0 + ($rx * cos($t1));
8096 $b1 = $y0 + ($ry * sin($t1));
8097 $c1 = -$rx * sin($t1);
8098 $d1 = $ry * cos($t1);
8099 $this->_outCurve(($a0 + ($c0 * $dtm)) / $this->k, $this->h - (($b0 + ($d0 * $dtm)) / $this->k), ($a1 - ($c1 * $dtm)) / $this->k, $this->h - (($b1 - ($d1 * $dtm)) / $this->k), $a1 / $this->k, $this->h - ($b1 / $this->k));
8132 public function Circle($x0, $y0, $r, $astart=0, $afinish=360, $style=
'', $line_style=array(), $fill_color=array(), $nc=8) {
8133 $this->Ellipse($x0, $y0, $r, 0, 0, $astart, $afinish, $style, $line_style, $fill_color, $nc);
8157 public function Polygon($p, $style=
'', $line_style=array(), $fill_color=array()) {
8158 $np = count($p) / 2;
8159 if (!(
false === strpos($style,
'F')) AND isset($fill_color)) {
8160 $this->SetFillColorArray($fill_color);
8164 $line_style = array();
8188 if (isset($line_style[
'all'])) {
8189 $this->SetLineStyle($line_style[
'all']);
8194 $this->_outPoint($p[0], $p[1]);
8195 for ($i = 2; $i < ($np * 2); $i = $i + 2) {
8196 $this->_outLine($p[$i], $p[$i + 1]);
8198 $this->_outLine($p[0], $p[1]);
8201 $p[($np * 2)] = $p[0];
8202 $p[(($np * 2) + 1)] = $p[1];
8203 for ($i = 0; $i < $np; ++$i) {
8204 if (isset($line_style[$i]) AND ($line_style[$i] != 0)) {
8205 $this->Line($p[($i * 2)], $p[(($i * 2) + 1)], $p[(($i * 2) + 2)], $p[(($i * 2) + 3)], $line_style[$i]);
8211 $this->_outPoint($p[0], $p[1]);
8212 for ($i = 2; $i < ($np * 2); $i = $i + 2) {
8213 $this->_outLine($p[$i], $p[$i + 1]);
8215 $this->_outLine($p[0], $p[1]);
8256 public function RegularPolygon($x0, $y0, $r, $ns, $angle=0, $draw_circle=
false, $style=
'', $line_style=array(), $fill_color=array(), $circle_style=
'', $circle_outLine_style=array(), $circle_fill_color=array()) {
8261 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
8264 for ($i = 0; $i < $ns; ++$i) {
8265 $a = $angle + ($i * 360 / $ns);
8266 $a_rad = deg2rad((
float) $a);
8267 $p[] = $x0 + ($r * sin($a_rad));
8268 $p[] = $y0 + ($r * cos($a_rad));
8270 $this->Polygon($p, $style, $line_style, $fill_color);
8311 public function StarPolygon($x0, $y0, $r, $nv, $ng, $angle=0, $draw_circle=
false, $style=
'', $line_style=array(), $fill_color=array(), $circle_style=
'', $circle_outLine_style=array(), $circle_fill_color=array()) {
8316 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
8320 for ($i = 0; $i < $nv; ++$i) {
8321 $a = $angle + ($i * 360 / $nv);
8322 $a_rad = deg2rad((
float) $a);
8323 $p2[] = $x0 + ($r * sin($a_rad));
8324 $p2[] = $y0 + ($r * cos($a_rad));
8331 $p[] = $p2[($i * 2) + 1];
8332 $visited[$i] =
true;
8335 }
while (!$visited[$i]);
8336 $this->Polygon($p, $style, $line_style, $fill_color);
8360 public function RoundedRect(
$x,
$y, $w, $h, $r, $round_corner=
'1111', $style=
'', $border_style=array(), $fill_color=array()) {
8361 if (
'0000' == $round_corner) {
8362 $this->Rect(
$x,
$y, $w, $h, $style, $border_style, $fill_color);
8364 if (!(
false === strpos($style,
'F')) AND isset($fill_color)) {
8365 $this->SetFillColorArray($fill_color);
8369 $border_style = array();
8391 if ($border_style) {
8392 $this->SetLineStyle($border_style);
8394 $MyArc = 4 / 3 * (sqrt(2) - 1);
8395 $this->_outPoint(
$x + $r,
$y);
8398 $this->_outLine($xc,
$y);
8399 if ($round_corner[0]) {
8400 $this->_outCurve($xc + ($r * $MyArc), $yc - $r, $xc + $r, $yc - ($r * $MyArc), $xc + $r, $yc);
8402 $this->_outLine(
$x + $w,
$y);
8406 $this->_outLine(
$x + $w, $yc);
8407 if ($round_corner[1]) {
8408 $this->_outCurve($xc + $r, $yc + ($r * $MyArc), $xc + ($r * $MyArc), $yc + $r, $xc, $yc + $r);
8410 $this->_outLine(
$x + $w,
$y + $h);
8414 $this->_outLine($xc,
$y + $h);
8415 if ($round_corner[2]) {
8416 $this->_outCurve($xc - ($r * $MyArc), $yc + $r, $xc - $r, $yc + ($r * $MyArc), $xc - $r, $yc);
8418 $this->_outLine(
$x,
$y + $h);
8422 $this->_outLine(
$x, $yc);
8423 if ($round_corner[3]) {
8424 $this->_outCurve($xc - $r, $yc - ($r * $MyArc), $xc - ($r * $MyArc), $yc - $r, $xc, $yc - $r);
8426 $this->_outLine(
$x,
$y);
8427 $this->_outLine(
$x + $r,
$y);
8445 public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
8447 $this->Line($x0, $y0, $x1, $y1);
8449 $dir_angle = rad2deg(atan2(($y0 - $y1), ($x0 - $x1)));
8452 $x2L = $x1 + ($arm_size * cos(deg2rad($dir_angle + $arm_angle)));
8453 $y2L = $y1 + ($arm_size * sin(deg2rad($dir_angle + $arm_angle)));
8455 $x2R = $x1 + ($arm_size * cos(deg2rad($dir_angle - $arm_angle)));
8456 $y2R = $y1 + ($arm_size * sin(deg2rad($dir_angle - $arm_angle)));
8457 if($head_style > 0) {
8459 $this->Polygon(array($x1, $y1, $x2L, $y2L, $x2R, $y2R), (($head_style === 1) ?
'D' :
'DF'), array(), array());
8462 $this->Line($x1, $y1, $x2L, $y2L);
8464 $this->Line($x1, $y1, $x2R, $y2R);
8480 protected function utf8StrRev($str, $setbom=
false, $forcertl=
false) {
8481 return $this->arrUTF8ToUTF16BE($this->utf8Bidi($this->UTF8StringToArray($str), $str, $forcertl), $setbom);
8494 protected function utf8Bidi($ta, $str=
'', $forcertl=
false) {
8500 if ($this->empty_string($str)) {
8502 $str = $this->UTF8ArrSubString($ta);
8516 $numchars = count($ta);
8518 if ($forcertl ==
'R') {
8520 }
elseif ($forcertl ==
'L') {
8525 for ($i=0; $i < $numchars; ++$i) {
8526 $type = $unicode[$ta[$i]];
8541 $remember = array();
8543 $sor = $pel % 2 ?
'R' :
'L';
8547 $chardata = Array();
8551 for ($i=0; $i < $numchars; ++$i) {
8552 if ($ta[$i] ==
K_RLE) {
8556 $next_level = $cel + ($cel % 2) + 1;
8557 if ($next_level < 62) {
8558 $remember[] = array(
'num' =>
K_RLE,
'cel' => $cel,
'dos' => $dos);
8562 $eor = $cel % 2 ?
'R' :
'L';
8568 $next_level = $cel + 2 - ($cel % 2);
8569 if ( $next_level < 62 ) {
8570 $remember[] = array(
'num' =>
K_LRE,
'cel' => $cel,
'dos' => $dos);
8574 $eor = $cel % 2 ?
'R' :
'L';
8580 $next_level = $cel + ($cel % 2) + 1;
8581 if ($next_level < 62) {
8582 $remember[] = array(
'num' =>
K_RLO,
'cel' => $cel,
'dos' => $dos);
8586 $eor = $cel % 2 ?
'R' :
'L';
8592 $next_level = $cel + 2 - ($cel % 2);
8593 if ( $next_level < 62 ) {
8594 $remember[] = array(
'num' =>
K_LRO,
'cel' => $cel,
'dos' => $dos);
8598 $eor = $cel % 2 ?
'R' :
'L';
8602 if (count($remember)) {
8603 $last = count($remember ) - 1;
8604 if (($remember[$last][
'num'] ==
K_RLE) OR
8605 ($remember[$last][
'num'] ==
K_LRE) OR
8606 ($remember[$last][
'num'] ==
K_RLO) OR
8607 ($remember[$last][
'num'] ==
K_LRO)) {
8608 $match = array_pop($remember);
8609 $cel = $match[
'cel'];
8610 $dos = $match[
'dos'];
8612 $eor = ($cel > $match[
'cel'] ? $cel : $match[
'cel']) % 2 ?
'R' :
'L';
8616 ($ta[$i] !=
K_LRE) AND
8617 ($ta[$i] !=
K_RLO) AND
8618 ($ta[$i] !=
K_LRO) AND
8619 ($ta[$i] !=
K_PDF)) {
8626 if (isset($unicode[$ta[$i]])) {
8627 $chardir = $unicode[$ta[$i]];
8633 $chardata[] = array(
'char' => $ta[$i],
'level' => $cel,
'type' => $chardir,
'sor' => $sor,
'eor' => $eor);
8644 $numchars = count($chardata);
8649 for ($i=0; $i < $numchars; ++$i) {
8650 if ($chardata[$i][
'type'] ==
'NSM') {
8652 $chardata[$i][
'type'] = $chardata[$i][
'sor'];
8654 $chardata[$i][
'type'] = $chardata[($i-1)][
'type'];
8657 if ($chardata[$i][
'level'] != $prevlevel) {
8662 $prevlevel = $chardata[$i][
'level'];
8668 for ($i=0; $i < $numchars; ++$i) {
8669 if ($chardata[$i][
'char'] ==
'EN') {
8670 for ($j=$levcount; $j >= 0; $j--) {
8671 if ($chardata[$j][
'type'] ==
'AL') {
8672 $chardata[$i][
'type'] =
'AN';
8673 }
elseif (($chardata[$j][
'type'] ==
'L') OR ($chardata[$j][
'type'] ==
'R')) {
8678 if ($chardata[$i][
'level'] != $prevlevel) {
8683 $prevlevel = $chardata[$i][
'level'];
8687 for ($i=0; $i < $numchars; ++$i) {
8688 if ($chardata[$i][
'type'] ==
'AL') {
8689 $chardata[$i][
'type'] =
'R';
8696 for ($i=0; $i < $numchars; ++$i) {
8697 if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)][
'level'] == $prevlevel)) {
8698 if (($chardata[$i][
'type'] ==
'ES') AND ($chardata[($i-1)][
'type'] ==
'EN') AND ($chardata[($i+1)][
'type'] ==
'EN')) {
8699 $chardata[$i][
'type'] =
'EN';
8700 }
elseif (($chardata[$i][
'type'] ==
'CS') AND ($chardata[($i-1)][
'type'] ==
'EN') AND ($chardata[($i+1)][
'type'] ==
'EN')) {
8701 $chardata[$i][
'type'] =
'EN';
8702 }
elseif (($chardata[$i][
'type'] ==
'CS') AND ($chardata[($i-1)][
'type'] ==
'AN') AND ($chardata[($i+1)][
'type'] ==
'AN')) {
8703 $chardata[$i][
'type'] =
'AN';
8706 if ($chardata[$i][
'level'] != $prevlevel) {
8711 $prevlevel = $chardata[$i][
'level'];
8717 for ($i=0; $i < $numchars; ++$i) {
8718 if ($chardata[$i][
'type'] ==
'ET') {
8719 if (($levcount > 0) AND ($chardata[($i-1)][
'type'] ==
'EN')) {
8720 $chardata[$i][
'type'] =
'EN';
8723 while (($j < $numchars) AND ($chardata[$j][
'level'] == $prevlevel)) {
8724 if ($chardata[$j][
'type'] ==
'EN') {
8725 $chardata[$i][
'type'] =
'EN';
8727 }
elseif ($chardata[$j][
'type'] !=
'ET') {
8734 if ($chardata[$i][
'level'] != $prevlevel) {
8739 $prevlevel = $chardata[$i][
'level'];
8745 for ($i=0; $i < $numchars; ++$i) {
8746 if (($chardata[$i][
'type'] ==
'ET') OR ($chardata[$i][
'type'] ==
'ES') OR ($chardata[$i][
'type'] ==
'CS')) {
8747 $chardata[$i][
'type'] =
'ON';
8749 if ($chardata[$i][
'level'] != $prevlevel) {
8754 $prevlevel = $chardata[$i][
'level'];
8760 for ($i=0; $i < $numchars; ++$i) {
8761 if ($chardata[$i][
'char'] ==
'EN') {
8762 for ($j=$levcount; $j >= 0; $j--) {
8763 if ($chardata[$j][
'type'] ==
'L') {
8764 $chardata[$i][
'type'] =
'L';
8765 }
elseif ($chardata[$j][
'type'] ==
'R') {
8770 if ($chardata[$i][
'level'] != $prevlevel) {
8775 $prevlevel = $chardata[$i][
'level'];
8781 for ($i=0; $i < $numchars; ++$i) {
8782 if (($levcount > 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)][
'level'] == $prevlevel)) {
8783 if (($chardata[$i][
'type'] ==
'N') AND ($chardata[($i-1)][
'type'] ==
'L') AND ($chardata[($i+1)][
'type'] ==
'L')) {
8784 $chardata[$i][
'type'] =
'L';
8785 }
elseif (($chardata[$i][
'type'] ==
'N') AND
8786 (($chardata[($i-1)][
'type'] ==
'R') OR ($chardata[($i-1)][
'type'] ==
'EN') OR ($chardata[($i-1)][
'type'] ==
'AN')) AND
8787 (($chardata[($i+1)][
'type'] ==
'R') OR ($chardata[($i+1)][
'type'] ==
'EN') OR ($chardata[($i+1)][
'type'] ==
'AN'))) {
8788 $chardata[$i][
'type'] =
'R';
8789 }
elseif ($chardata[$i][
'type'] ==
'N') {
8791 $chardata[$i][
'type'] = $chardata[$i][
'sor'];
8793 }
elseif (($levcount == 0) AND (($i+1) < $numchars) AND ($chardata[($i+1)][
'level'] == $prevlevel)) {
8795 if (($chardata[$i][
'type'] ==
'N') AND ($chardata[$i][
'sor'] ==
'L') AND ($chardata[($i+1)][
'type'] ==
'L')) {
8796 $chardata[$i][
'type'] =
'L';
8797 }
elseif (($chardata[$i][
'type'] ==
'N') AND
8798 (($chardata[$i][
'sor'] ==
'R') OR ($chardata[$i][
'sor'] ==
'EN') OR ($chardata[$i][
'sor'] ==
'AN')) AND
8799 (($chardata[($i+1)][
'type'] ==
'R') OR ($chardata[($i+1)][
'type'] ==
'EN') OR ($chardata[($i+1)][
'type'] ==
'AN'))) {
8800 $chardata[$i][
'type'] =
'R';
8801 }
elseif ($chardata[$i][
'type'] ==
'N') {
8803 $chardata[$i][
'type'] = $chardata[$i][
'sor'];
8805 }
elseif (($levcount > 0) AND ((($i+1) == $numchars) OR (($i+1) < $numchars) AND ($chardata[($i+1)][
'level'] != $prevlevel))) {
8807 if (($chardata[$i][
'type'] ==
'N') AND ($chardata[($i-1)][
'type'] ==
'L') AND ($chardata[$i][
'eor'] ==
'L')) {
8808 $chardata[$i][
'type'] =
'L';
8809 }
elseif (($chardata[$i][
'type'] ==
'N') AND
8810 (($chardata[($i-1)][
'type'] ==
'R') OR ($chardata[($i-1)][
'type'] ==
'EN') OR ($chardata[($i-1)][
'type'] ==
'AN')) AND
8811 (($chardata[$i][
'eor'] ==
'R') OR ($chardata[$i][
'eor'] ==
'EN') OR ($chardata[$i][
'eor'] ==
'AN'))) {
8812 $chardata[$i][
'type'] =
'R';
8813 }
elseif ($chardata[$i][
'type'] ==
'N') {
8815 $chardata[$i][
'type'] = $chardata[$i][
'sor'];
8817 }
elseif ($chardata[$i][
'type'] ==
'N') {
8819 $chardata[$i][
'type'] = $chardata[$i][
'sor'];
8821 if ($chardata[$i][
'level'] != $prevlevel) {
8826 $prevlevel = $chardata[$i][
'level'];
8831 for ($i=0; $i < $numchars; ++$i) {
8832 $odd = $chardata[$i][
'level'] % 2;
8834 if (($chardata[$i][
'type'] ==
'L') OR ($chardata[$i][
'type'] ==
'AN') OR ($chardata[$i][
'type'] ==
'EN')) {
8835 $chardata[$i][
'level'] += 1;
8838 if ($chardata[$i][
'type'] ==
'R') {
8839 $chardata[$i][
'level'] += 1;
8840 }
elseif (($chardata[$i][
'type'] ==
'AN') OR ($chardata[$i][
'type'] ==
'EN')) {
8841 $chardata[$i][
'level'] += 2;
8844 $maxlevel = max($chardata[$i][
'level'],$maxlevel);
8852 for ($i=0; $i < $numchars; ++$i) {
8853 if (($chardata[$i][
'type'] ==
'B') OR ($chardata[$i][
'type'] ==
'S')) {
8854 $chardata[$i][
'level'] = $pel;
8855 }
elseif ($chardata[$i][
'type'] ==
'WS') {
8857 while ($j < $numchars) {
8858 if ((($chardata[$j][
'type'] ==
'B') OR ($chardata[$j][
'type'] ==
'S')) OR
8859 (($j == ($numchars-1)) AND ($chardata[$j][
'type'] ==
'WS'))) {
8860 $chardata[$i][
'level'] = $pel;
8862 }
elseif ($chardata[$j][
'type'] !=
'WS') {
8873 $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
8874 $alfletter = array(1570,1571,1573,1575);
8875 $chardata2 = $chardata;
8879 for ($i=0; $i < $numchars; ++$i) {
8880 if (($unicode[$chardata[$i][
'char']] ==
'AL') OR ($chardata[$i][
'char'] == 32) OR ($chardata[$i][
'char'] == 8204)) {
8881 $charAL[
$x] = $chardata[$i];
8882 $charAL[
$x][
'i'] = $i;
8883 $chardata[$i][
'x'] =
$x;
8888 for ($i=0; $i < $numchars; ++$i) {
8889 $thischar = $chardata[$i];
8891 $prevchar = $chardata[($i-1)];
8895 if (($i+1) < $numchars) {
8896 $nextchar = $chardata[($i+1)];
8900 if ($unicode[$thischar[
'char']] ==
'AL') {
8901 $x = $thischar[
'x'];
8903 $prevchar = $charAL[(
$x-1)];
8907 if ((
$x+1) < $numAL) {
8908 $nextchar = $charAL[(
$x+1)];
8913 if (($prevchar !==
false) AND ($prevchar[
'char'] == 1604) AND (in_array($thischar['
char'], $alfletter))) {
8917 $prevchar = $charAL[(
$x-2)];
8925 if (($prevchar !==
false) AND ($nextchar !==
false) AND
8926 (($unicode[$prevchar['
char']] == 'AL') OR ($unicode[$prevchar['
char']] == 'NSM')) AND
8927 (($unicode[$nextchar['
char']] == 'AL') OR ($unicode[$nextchar['
char']] == 'NSM')) AND
8928 ($prevchar['type'] == $thischar['type']) AND
8929 ($nextchar['type'] == $thischar['type']) AND
8930 ($nextchar['
char'] != 1567)) {
8931 if (in_array($prevchar[
'char'], $endedletter)) {
8932 if (isset($arabicarr[$thischar[
'char']][2])) {
8934 $chardata2[$i][
'char'] = $arabicarr[$thischar[
'char']][2];
8937 if (isset($arabicarr[$thischar[
'char']][3])) {
8939 $chardata2[$i][
'char'] = $arabicarr[$thischar[
'char']][3];
8942 }
elseif (($nextchar !==
false) AND
8943 (($unicode[$nextchar[
'char']] ==
'AL') OR ($unicode[$nextchar[
'char']] ==
'NSM')) AND
8944 ($nextchar[
'type'] == $thischar[
'type']) AND
8945 ($nextchar[
'char'] != 1567)) {
8946 if (isset($arabicarr[$chardata[$i][
'char']][2])) {
8948 $chardata2[$i][
'char'] = $arabicarr[$thischar[
'char']][2];
8950 }
elseif ((($prevchar !==
false) AND
8951 (($unicode[$prevchar[
'char']] ==
'AL') OR ($unicode[$prevchar[
'char']] ==
'NSM')) AND
8952 ($prevchar[
'type'] == $thischar[
'type'])) OR
8953 (($nextchar !==
false) AND ($nextchar[
'char'] == 1567))) {
8955 if (($i > 1) AND ($thischar[
'char'] == 1607) AND
8956 ($chardata[$i-1][
'char'] == 1604) AND
8957 ($chardata[$i-2][
'char'] == 1604)) {
8960 $chardata2[$i-2][
'char'] =
false;
8961 $chardata2[$i-1][
'char'] =
false;
8962 $chardata2[$i][
'char'] = 65010;
8964 if (($prevchar !==
false) AND in_array($prevchar[
'char'], $endedletter)) {
8965 if (isset($arabicarr[$thischar[
'char']][0])) {
8967 $chardata2[$i][
'char'] = $arabicarr[$thischar[
'char']][0];
8970 if (isset($arabicarr[$thischar[
'char']][1])) {
8972 $chardata2[$i][
'char'] = $arabicarr[$thischar[
'char']][1];
8976 }
elseif (isset($arabicarr[$thischar[
'char']][0])) {
8978 $chardata2[$i][
'char'] = $arabicarr[$thischar[
'char']][0];
8983 $chardata2[($charAL[(
$x-1)][
'i'])][
'char'] =
false;
8991 $cw = &$this->CurrentFont[
'cw'];
8992 for ($i = 0; $i < ($numchars-1); ++$i) {
8993 if (($chardata2[$i][
'char'] == 1617) AND (isset($diacritics[($chardata2[$i+1][
'char'])]))) {
8995 if (isset(
$cw[($diacritics[($chardata2[$i+1][
'char'])])])) {
8996 $chardata2[$i][
'char'] =
false;
8997 $chardata2[$i+1][
'char'] = $diacritics[($chardata2[$i+1][
'char'])];
9002 foreach ($chardata2 as
$key => $value) {
9003 if ($value[
'char'] ===
false) {
9004 unset($chardata2[
$key]);
9007 $chardata = array_values($chardata2);
9008 $numchars = count($chardata);
9016 for ($j=$maxlevel; $j > 0; $j--) {
9017 $ordarray = Array();
9020 for ($i=0; $i < $numchars; ++$i) {
9021 if ($chardata[$i][
'level'] >= $j) {
9023 if (isset($unicode_mirror[$chardata[$i][
'char']])) {
9025 $chardata[$i][
'char'] = $unicode_mirror[$chardata[$i][
'char']];
9027 $revarr[] = $chardata[$i];
9030 $revarr = array_reverse($revarr);
9031 $ordarray = array_merge($ordarray, $revarr);
9035 $ordarray[] = $chardata[$i];
9039 $revarr = array_reverse($revarr);
9040 $ordarray = array_merge($ordarray, $revarr);
9042 $chardata = $ordarray;
9045 $ordarray = array();
9046 for ($i=0; $i < $numchars; ++$i) {
9047 $ordarray[] = $chardata[$i][
'char'];
9065 public function Bookmark($txt, $level=0,
$y=-1, $page=
'') {
9069 if (isset($this->outlines[0])) {
9070 $lastoutline = end($this->outlines);
9071 $maxlevel = $lastoutline[
'l'] + 1;
9075 if ($level > $maxlevel) {
9082 $page = $this->PageNo();
9084 $this->outlines[] = array(
't' => $txt,
'l' => $level,
'y' =>
$y,
'p' => $page);
9093 protected function _putbookmarks() {
9094 $nb = count($this->outlines);
9100 foreach ($this->outlines as $i => $o) {
9102 $parent = $lru[($o[
'l'] - 1)];
9104 $this->outlines[$i][
'parent'] = $parent;
9105 $this->outlines[$parent][
'last'] = $i;
9106 if ($o[
'l'] > $level) {
9108 $this->outlines[$parent][
'first'] = $i;
9111 $this->outlines[$i][
'parent'] = $nb;
9113 if (($o[
'l'] <= $level) AND ($i > 0)) {
9115 $prev = $lru[$o[
'l']];
9116 $this->outlines[$prev][
'next'] = $i;
9117 $this->outlines[$i][
'prev'] = $prev;
9124 foreach ($this->outlines as $i => $o) {
9126 $this->_out(
'<</Title '.$this->_textstring($o[
't']));
9127 $this->_out(
'/Parent '.($n + $o[
'parent']).
' 0 R');
9128 if (isset($o[
'prev']))
9129 $this->_out(
'/Prev '.($n + $o[
'prev']).
' 0 R');
9130 if (isset($o[
'next']))
9131 $this->_out(
'/Next '.($n + $o[
'next']).
' 0 R');
9132 if (isset($o[
'first']))
9133 $this->_out(
'/First '.($n + $o[
'first']).
' 0 R');
9134 if (isset($o[
'last']))
9135 $this->_out(
'/Last '.($n + $o[
'last']).
' 0 R');
9136 $this->_out(sprintf(
'/Dest [%d 0 R /XYZ 0 %.2F null]', (1 + (2 * $o[
'p'])), ($this->pagedim[$o[
'p']][
'h'] - ($o[
'y'] * $this->k))));
9137 $this->_out(
'/Count 0>>');
9138 $this->_out(
'endobj');
9143 $this->_out(
'<</Type /Outlines /First '.$n.
' 0 R');
9144 $this->_out(
'/Last '.($n + $lru[0]).
' 0 R>>');
9145 $this->_out(
'endobj');
9157 public function IncludeJS($script) {
9158 $this->javascript .= $script;
9167 protected function _putjavascript() {
9168 if (empty($this->javascript)) {
9172 $js1 = sprintf(
"ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);",
'tcpdfdocsaved',
'text', 0, 0, 1, 0, 1);
9173 $js2 =
"getField('tcpdfdocsaved').value = 'saved';";
9177 $this->_out(
'/Names [(EmbeddedJS) '.($this->
n + 1).
' 0 R ]');
9179 $this->_out(
'endobj');
9182 $this->_out(
'/S /JavaScript');
9183 $this->_out(
'/JS '.$this->_textstring($js1.
"\n".$this->javascript.
"\n".$js2));
9185 $this->_out(
'endobj');
9195 protected function _JScolor($color) {
9196 static $aColors = array(
'transparent',
'black',
'white',
'red',
'green',
'blue',
'cyan',
'magenta',
'yellow',
'dkGray',
'gray',
'ltGray');
9197 if (substr($color,0,1) ==
'#') {
9198 return sprintf(
"['RGB',%.3F,%.3F,%.3F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255);
9200 if (!in_array($color,$aColors)) {
9201 $this->Error(
'Invalid color: '.$color);
9203 return 'color.'.$color;
9219 protected function _addfield(
$type, $name,
$x,
$y, $w, $h, $prop) {
9224 $this->javascript .=
"if(getField('tcpdfdocsaved').value != 'saved') {";
9226 $this->javascript .= sprintf(
"f".$name.
"=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", $name,
$type, $this->PageNo()-1,
$x*$k, ($this->h-
$y)*$k+1, (
$x+$w)*$k, ($this->h-
$y-$h)*$k+1).
"\n";
9227 $this->javascript .=
'f'.$name.
'.textSize='.$this->FontSizePt.
";\n";
9228 while (list(
$key, $val) = each($prop)) {
9229 if (strcmp(substr(
$key, -5),
'Color') == 0) {
9230 $val = $this->_JScolor($val);
9232 $val =
"'".$val.
"'";
9234 $this->javascript .=
'f'.$name.
'.'.
$key.
'='.$val.
";\n";
9241 $this->javascript .=
'}';
9254 public function TextField($name, $w, $h, $prop=array()) {
9255 $this->_addfield(
'text', $name, $this->x, $this->y, $w, $h, $prop);
9267 public function RadioButton($name, $w, $prop=array()) {
9268 if (!isset($prop[
'strokeColor'])) {
9269 $prop[
'strokeColor']=
'black';
9271 $this->_addfield(
'radiobutton', $name, $this->x, $this->y, $w, $w, $prop);
9285 public function ListBox($name, $w, $h, $values, $prop=array()) {
9286 if (!isset($prop[
'strokeColor'])) {
9287 $prop[
'strokeColor'] =
'ltGray';
9289 $this->_addfield(
'listbox', $name, $this->x, $this->y, $w, $h, $prop);
9291 foreach ($values as $value) {
9292 $s .=
"'".addslashes($value).
"',";
9294 $this->javascript .=
'f'.$name.
'.setItems(['.substr($s, 0, -1).
"]);\n";
9308 public function ComboBox($name, $w, $h, $values, $prop=array()) {
9309 $this->_addfield(
'combobox', $name, $this->x, $this->y, $w, $h, $prop);
9311 foreach ($values as $value) {
9312 $s .=
"'".addslashes($value).
"',";
9314 $this->javascript .=
'f'.$name.
'.setItems(['.substr($s, 0, -1).
"]);\n";
9327 public function CheckBox($name, $w, $checked=
false, $prop=array()) {
9328 $prop[
'value'] = ($checked ?
'Yes' :
'Off');
9329 if (!isset($prop[
'strokeColor'])) {
9330 $prop[
'strokeColor'] =
'black';
9332 $this->_addfield(
'checkbox', $name, $this->x, $this->y, $w, $w, $prop);
9347 public function Button($name, $w, $h, $caption, $action, $prop=array()) {
9348 if (!isset($prop[
'strokeColor'])) {
9349 $prop[
'strokeColor'] =
'black';
9351 if (!isset($prop[
'borderStyle'])) {
9352 $prop[
'borderStyle'] =
'beveled';
9354 $this->_addfield(
'button', $name, $this->x, $this->y, $w, $h, $prop);
9355 $this->javascript .=
'f'.$name.
".buttonSetCaption('".addslashes($caption).
"');\n";
9356 $this->javascript .=
'f'.$name.
".setAction('MouseUp','".addslashes($action).
"');\n";
9357 $this->javascript .=
'f'.$name.
".highlight='push';\n";
9358 $this->javascript .=
'f'.$name.
".print=false;\n";
9370 protected function _putursignature() {
9371 if ((!$this->sign) OR (isset($this->signature_data[
'cert_type']) AND ($this->signature_data[
'cert_type'] > 0))) {
9374 $this->_out(
'/Type/Sig');
9375 $this->_out(
'/Filter/Adobe.PPKLite');
9376 $this->_out(
'/SubFilter/adbe.pkcs7.detached');
9377 $this->_out(
'/ByteRange[0 ********** ********** **********]');
9378 $this->_out(
'/Contents<>'.str_repeat(
' ', $this->signature_max_lenght));
9380 $this->_out(
'/Reference');
9383 $this->_out(
'/Type/SigRef');
9384 $this->_out(
'/TransformMethod/UR3');
9385 $this->_out(
'/TransformParams');
9387 $this->_out(
'/Type/TransformParams');
9388 $this->_out(
'/V/2.2');
9389 if (!$this->empty_string($this->ur_document)) {
9390 $this->_out(
'/Document['.$this->ur_document.
']');
9392 if (!$this->empty_string($this->ur_annots)) {
9393 $this->_out(
'/Annots['.$this->ur_annots.
']');
9395 if (!$this->empty_string($this->ur_form)) {
9396 $this->_out(
'/Form['.$this->ur_form.
']');
9398 if (!$this->empty_string($this->ur_signature)) {
9399 $this->_out(
'/Signature['.$this->ur_signature.
']');
9405 $this->_out(
'/M '.$this->_datastring(
'D:'.date(
'YmdHisO')));
9414 protected function _putsignature() {
9415 if ((!$this->sign) OR (isset($this->signature_data[
'cert_type']) AND ($this->signature_data[
'cert_type'] <= 0))) {
9418 $this->_out(
'/Type/Sig');
9419 $this->_out(
'/Filter/Adobe.PPKLite');
9420 $this->_out(
'/SubFilter/adbe.pkcs7.detached');
9421 $this->_out(
'/ByteRange[0 ********** ********** **********]');
9422 $this->_out(
'/Contents<>'.str_repeat(
' ', $this->signature_max_lenght));
9423 $this->_out(
'/Reference');
9426 $this->_out(
'/Type/SigRef');
9427 $this->_out(
'/TransformMethod/DocMDP');
9428 $this->_out(
'/TransformParams');
9430 $this->_out(
'/Type/TransformParams');
9431 $this->_out(
'/V/1.2');
9432 $this->_out(
'/P '.$this->signature_data[
'cert_type'].
'');
9436 $this->_out(
'/M '.$this->_datastring(
'D:'.date(
'YmdHisO')));
9437 if (isset($this->signature_data[
'info'][
'Name']) AND !$this->empty_string($this->signature_data[
'info'][
'Name'])) {
9438 $this->_out(
'/Name '.$this->_textstring($this->signature_data[
'info'][
'Name']).
'');
9440 if (isset($this->signature_data[
'info'][
'Location']) AND !$this->empty_string($this->signature_data[
'info'][
'Location'])) {
9441 $this->_out(
'/Location '.$this->_textstring($this->signature_data[
'info'][
'Location']).
'');
9443 if (isset($this->signature_data[
'info'][
'Reason']) AND !$this->empty_string($this->signature_data[
'info'][
'Reason'])) {
9444 $this->_out(
'/Reason '.$this->_textstring($this->signature_data[
'info'][
'Reason']).
'');
9446 if (isset($this->signature_data[
'info'][
'ContactInfo']) AND !$this->empty_string($this->signature_data[
'info'][
'ContactInfo'])) {
9447 $this->_out(
'/ContactInfo '.$this->_textstring($this->signature_data[
'info'][
'ContactInfo']).
'');
9465 public function setUserRights(
9467 $document=
'/FullSave',
9468 $annots=
'/Create/Delete/Modify/Copy/Import/Export',
9469 $form=
'/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
9470 $signature=
'/Modify') {
9471 $this->ur = $enable;
9472 $this->ur_document = $document;
9473 $this->ur_annots = $annots;
9474 $this->ur_form = $form;
9475 $this->ur_signature = $signature;
9491 public function setSignature($signing_cert=
'', $private_key=
'', $private_key_password=
'', $extracerts=
'', $cert_type=2, $info=array()) {
9494 $this->signature_data = array();
9495 if (strlen($signing_cert) == 0) {
9496 $signing_cert =
'file://'.dirname(__FILE__).
'/tcpdf.pem';
9498 if (strlen($private_key) == 0) {
9499 $private_key = $signing_cert;
9501 $this->signature_data[
'signcert'] = $signing_cert;
9502 $this->signature_data[
'privkey'] = $private_key;
9503 $this->signature_data[
'password'] = $private_key_password;
9504 $this->signature_data[
'extracerts'] = $extracerts;
9505 $this->signature_data[
'cert_type'] = $cert_type;
9506 $this->signature_data[
'info'] = $info;
9516 public function startPageGroup($page=
'') {
9518 $page = $this->page + 1;
9520 $this->newpagegroup[$page] =
true;
9531 public function AliasNbPages($alias=
'{nb}') {
9532 $this->AliasNbPages = $alias;
9543 public function getAliasNbPages() {
9544 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
9545 return '{'.$this->AliasNbPages.
'}';
9547 return $this->AliasNbPages;
9558 public function AliasNumPage($alias=
'{pnb}') {
9560 $this->AliasNumPage = $alias;
9571 public function getAliasNumPage() {
9572 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
9573 return '{'.$this->AliasNumPage.
'}';
9575 return $this->AliasNumPage;
9584 public function getGroupPageNo() {
9585 return $this->pagegroups[$this->currpagegroup];
9594 public function getGroupPageNoFormatted() {
9595 return $this->formatPageNumber($this->getGroupPageNo());
9606 public function getPageGroupAlias() {
9607 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
9608 return '{'.$this->currpagegroup.
'}';
9610 return $this->currpagegroup;
9621 public function getPageNumGroupAlias() {
9622 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
9623 return '{'.str_replace(
'{nb',
'{pnb', $this->currpagegroup).
'}';
9625 return str_replace(
'{nb',
'{pnb', $this->currpagegroup);
9635 protected function formatPageNumber($num) {
9636 return number_format((
float)$num, 0,
'',
'.');
9647 protected function formatTOCPageNumber($num) {
9648 return number_format((
float)$num, 0,
'',
'.');
9657 public function PageNoFormatted() {
9658 return $this->formatPageNumber($this->PageNo());
9666 protected function _putocg() {
9669 $this->_out(
'<</Type /OCG /Name '.$this->_textstring(
'print'));
9670 $this->_out(
'/Usage <</Print <</PrintState /ON>> /View <</ViewState /OFF>>>>>>');
9671 $this->_out(
'endobj');
9674 $this->_out(
'<</Type /OCG /Name '.$this->_textstring(
'view'));
9675 $this->_out(
'/Usage <</Print <</PrintState /OFF>> /View <</ViewState /ON>>>>>>');
9676 $this->_out(
'endobj');
9687 public function setVisibility($v) {
9688 if ($this->openMarkedContent) {
9691 $this->openMarkedContent =
false;
9695 $this->_out(
'/OC /OC1 BDC');
9696 $this->openMarkedContent =
true;
9700 $this->_out(
'/OC /OC2 BDC');
9701 $this->openMarkedContent =
true;
9709 $this->Error(
'Incorrect visibility: '.$v);
9713 $this->visibility = $v;
9723 protected function addExtGState($parms) {
9724 $n = count($this->extgstates) + 1;
9725 $this->extgstates[
$n][
'parms'] = $parms;
9735 protected function setExtGState($gs) {
9736 $this->_out(sprintf(
'/GS%d gs', $gs));
9745 protected function _putextgstates() {
9746 $ne = count($this->extgstates);
9747 for ($i = 1; $i <= $ne; ++$i) {
9749 $this->extgstates[$i][
'n'] =
$this->n;
9750 $this->_out(
'<</Type /ExtGState');
9751 foreach ($this->extgstates[$i][
'parms'] as $k => $v) {
9752 $this->_out(
'/'.$k.
' '.$v);
9755 $this->_out(
'endobj');
9766 public function setAlpha($alpha, $bm=
'Normal') {
9767 $gs = $this->addExtGState(array(
'ca' => $alpha,
'CA' => $alpha,
'BM' =>
'/'.$bm));
9768 $this->setExtGState($gs);
9777 public function setJPEGQuality($quality) {
9778 if (($quality < 1) OR ($quality > 100)) {
9781 $this->jpeg_quality = intval($quality);
9790 public function setDefaultTableColumns($cols=4) {
9791 $this->default_table_columns = intval($cols);
9800 public function setCellHeightRatio($h) {
9801 $this->cell_height_ratio = $h;
9809 public function getCellHeightRatio() {
9810 return $this->cell_height_ratio;
9819 public function setPDFVersion($version=
'1.7') {
9820 $this->PDFVersion = $version;
9849 public function setViewerPreferences($preferences) {
9850 $this->viewer_preferences = $preferences;
9866 public function LinearGradient(
$x,
$y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
9867 $this->Clip(
$x,
$y, $w, $h);
9868 $this->Gradient(2, $col1, $col2, $coords);
9884 public function RadialGradient(
$x,
$y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
9885 $this->Clip(
$x,
$y, $w, $h);
9886 $this->Gradient(3, $col1, $col2, $coords);
9906 public function CoonsPatchMesh(
$x,
$y, $w, $h, $col1=array(), $col2=array(), $col3=array(), $col4=array(), $coords=array(0.00,0.0,0.33,0.00,0.67,0.00,1.00,0.00,1.00,0.33,1.00,0.67,1.00,1.00,0.67,1.00,0.33,1.00,0.00,1.00,0.00,0.67,0.00,0.33), $coords_min=0, $coords_max=1) {
9907 $this->Clip(
$x,
$y, $w, $h);
9908 $n = count($this->gradients) + 1;
9909 $this->gradients[
$n][
'type'] = 6;
9911 if (!isset($coords[0][
'f'])) {
9913 if (!isset($col1[1])) {
9914 $col1[1] = $col1[2] = $col1[0];
9916 if (!isset($col2[1])) {
9917 $col2[1] = $col2[2] = $col2[0];
9919 if (!isset($col3[1])) {
9920 $col3[1] = $col3[2] = $col3[0];
9922 if (!isset($col4[1])) {
9923 $col4[1] = $col4[2] = $col4[0];
9925 $patch_array[0][
'f'] = 0;
9926 $patch_array[0][
'points'] = $coords;
9927 $patch_array[0][
'colors'][0][
'r'] = $col1[0];
9928 $patch_array[0][
'colors'][0][
'g'] = $col1[1];
9929 $patch_array[0][
'colors'][0][
'b'] = $col1[2];
9930 $patch_array[0][
'colors'][1][
'r'] = $col2[0];
9931 $patch_array[0][
'colors'][1][
'g'] = $col2[1];
9932 $patch_array[0][
'colors'][1][
'b'] = $col2[2];
9933 $patch_array[0][
'colors'][2][
'r'] = $col3[0];
9934 $patch_array[0][
'colors'][2][
'g'] = $col3[1];
9935 $patch_array[0][
'colors'][2][
'b'] = $col3[2];
9936 $patch_array[0][
'colors'][3][
'r'] = $col4[0];
9937 $patch_array[0][
'colors'][3][
'g'] = $col4[1];
9938 $patch_array[0][
'colors'][3][
'b'] = $col4[2];
9941 $patch_array = $coords;
9945 $this->gradients[
$n][
'stream'] =
'';
9946 $count_patch = count($patch_array);
9947 for ($i=0; $i < $count_patch; ++$i) {
9948 $this->gradients[
$n][
'stream'] .= chr($patch_array[$i][
'f']);
9949 $count_points = count($patch_array[$i][
'points']);
9950 for ($j=0; $j < $count_points; ++$j) {
9952 $patch_array[$i][
'points'][$j] = (($patch_array[$i][
'points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
9953 if ($patch_array[$i][
'points'][$j] < 0) {
9954 $patch_array[$i][
'points'][$j] = 0;
9956 if ($patch_array[$i][
'points'][$j] > $bpcd) {
9957 $patch_array[$i][
'points'][$j] = $bpcd;
9959 $this->gradients[
$n][
'stream'] .= chr(floor($patch_array[$i][
'points'][$j] / 256));
9960 $this->gradients[
$n][
'stream'] .= chr(floor($patch_array[$i][
'points'][$j] % 256));
9962 $count_cols = count($patch_array[$i][
'colors']);
9963 for ($j=0; $j < $count_cols; ++$j) {
9965 $this->gradients[
$n][
'stream'] .= chr($patch_array[$i][
'colors'][$j][
'r']);
9966 $this->gradients[
$n][
'stream'] .= chr($patch_array[$i][
'colors'][$j][
'g']);
9967 $this->gradients[
$n][
'stream'] .= chr($patch_array[$i][
'colors'][$j][
'b']);
9971 $this->_out(
'/Sh'.$n.
' sh');
9986 protected function Clip(
$x,
$y, $w, $h) {
9988 $x = $this->w -
$x - $w;
9993 $s .= sprintf(
' %.2F %.2F %.2F %.2F re W n',
$x*$this->k, ($this->h-
$y)*$this->k, $w*$this->k, -$h*$this->k);
9995 $s .= sprintf(
' %.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k, $h*$this->k,
$x*$this->k, ($this->h-(
$y+$h))*$this->k);
10009 protected function Gradient(
$type, $col1, $col2, $coords) {
10010 $n = count($this->gradients) + 1;
10011 $this->gradients[
$n][
'type'] =
$type;
10012 if (!isset($col1[1])) {
10013 $col1[1]=$col1[2]=$col1[0];
10015 $this->gradients[
$n][
'col1'] = sprintf(
'%.3F %.3F %.3F', ($col1[0]/255), ($col1[1]/255), ($col1[2]/255));
10016 if (!isset($col2[1])) {
10017 $col2[1] = $col2[2] = $col2[0];
10019 $this->gradients[
$n][
'col2'] = sprintf(
'%.3F %.3F %.3F', ($col2[0]/255), ($col2[1]/255), ($col2[2]/255));
10020 $this->gradients[
$n][
'coords'] = $coords;
10022 $this->_out(
'/Sh'.$n.
' sh');
10033 function _putshaders() {
10034 foreach ($this->gradients as $id => $grad) {
10035 if (($grad[
'type'] == 2) OR ($grad[
'type'] == 3)) {
10038 $this->_out(
'/FunctionType 2');
10039 $this->_out(
'/Domain [0.0 1.0]');
10040 $this->_out(
'/C0 ['.$grad[
'col1'].
']');
10041 $this->_out(
'/C1 ['.$grad[
'col2'].
']');
10042 $this->_out(
'/N 1');
10044 $this->_out(
'endobj');
10049 $this->_out(
'/ShadingType '.$grad[
'type']);
10050 $this->_out(
'/ColorSpace /DeviceRGB');
10051 if ($grad[
'type'] == 2) {
10052 $this->_out(sprintf(
'/Coords [%.3F %.3F %.3F %.3F]', $grad[
'coords'][0], $grad[
'coords'][1], $grad[
'coords'][2], $grad[
'coords'][3]));
10053 $this->_out(
'/Function '.$f1.
' 0 R');
10054 $this->_out(
'/Extend [true true] ');
10056 }
elseif ($grad[
'type'] == 3) {
10059 $this->_out(sprintf(
'/Coords [%.3F %.3F 0 %.3F %.3F %.3F]', $grad[
'coords'][0], $grad[
'coords'][1], $grad[
'coords'][2], $grad[
'coords'][3], $grad[
'coords'][4]));
10060 $this->_out(
'/Function '.$f1.
' 0 R');
10061 $this->_out(
'/Extend [true true] ');
10063 }
elseif ($grad[
'type'] == 6) {
10064 $this->_out(
'/BitsPerCoordinate 16');
10065 $this->_out(
'/BitsPerComponent 8');
10066 $this->_out(
'/Decode[0 1 0 1 0 1 0 1 0 1]');
10067 $this->_out(
'/BitsPerFlag 8');
10068 $this->_out(
'/Length '.strlen($grad[
'stream']));
10070 $this->_putstream($grad[
'stream']);
10072 $this->_out(
'endobj');
10073 $this->gradients[$id][
'id'] =
$this->n;
10083 protected function _outarc($x1, $y1, $x2, $y2, $x3, $y3 ) {
10085 $this->_out(sprintf(
'%.2F %.2F %.2F %.2F %.2F %.2F c', $x1*$this->k, ($h-$y1)*$this->k, $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
10103 public function PieSector($xc, $yc, $r, $a, $b, $style=
'FD',
$cw=
true, $o=90) {
10105 $xc = $this->w - $xc;
10115 $a = ($a % 360) + 360;
10116 $b = ($b % 360) + 360;
10120 $b = $b / 360 * 2 * M_PI;
10121 $a = $a / 360 * 2 * M_PI;
10130 }
elseif ($style==
'FD' or $style==
'DF') {
10136 $MyArc = 4/3 * (1 - cos(
$d/2)) / sin(
$d/2) * $r;
10139 $this->_out(sprintf(
'%.2F %.2F m', ($xc)*$k, ($hp-$yc)*$k));
10141 $this->_out(sprintf(
'%.2F %.2F l', ($xc+$r*cos($a))*$k, (($hp-($yc-$r*sin($a)))*$k)));
10143 if (
$d < (M_PI/2)) {
10144 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
10147 $MyArc = 4/3*(1-cos(
$d/8))/sin(
$d/8)*$r;
10148 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
10151 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
10154 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b) );
10157 $this->_outarc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b));
10181 public function ImageEps($file,
$x=
'',
$y=
'', $w=0, $h=0, $link=
'', $useBoundingBox=
true, $align=
'', $palign=
'', $border=0) {
10189 $data = file_get_contents($file);
10190 if (
$data ===
false) {
10191 $this->Error(
'EPS file not found: '.$file);
10195 preg_match(
"/%%Creator:([^\r\n]+)/",
$data, $regs); # find Creator
10196 if (count($regs) > 1) {
10197 $version_str = trim($regs[1]); # e.g.
"Adobe Illustrator(R) 8.0"
10198 if (strpos($version_str,
'Adobe Illustrator') !==
false) {
10199 $versexp = explode(
' ', $version_str);
10200 $version = (float)array_pop($versexp);
10201 if ($version >= 9) {
10202 $this->Error(
'This version of Adobe Illustrator file is not supported: '.$file);
10212 preg_match(
"/%%BoundingBox:([^\r\n]+)/",
$data, $regs);
10213 if (count($regs) > 1) {
10214 list($x1, $y1, $x2, $y2) = explode(
' ', trim($regs[1]));
10216 $this->Error(
'No BoundingBox found in EPS file: '.$file);
10226 $end = strpos(
$data,
'%%PageTrailer');
10227 if ($end===
false) {
10228 $end = strpos(
$data,
'showpage');
10234 $scale_x = $w / (($x2 - $x1) / $k);
10236 $scale_y = $h / (($y2 - $y1) / $k);
10238 $scale_y = $scale_x;
10239 $h = ($y2 - $y1) / $k * $scale_y;
10243 $scale_y = $h / (($y2 - $y1) / $k);
10244 $scale_x = $scale_y;
10245 $w = ($x2-$x1) / $k * $scale_x;
10247 $w = ($x2 - $x1) / $k;
10248 $h = ($y2 - $y1) / $k;
10252 if ($this->checkPageBreak($h,
$y)) {
10253 $y = $this->GetY() + $this->cMargin;
10256 $this->img_rb_y =
$y + $h;
10259 if ($palign ==
'L') {
10260 $ximg = $this->lMargin;
10262 $this->img_rb_x = $ximg + $w;
10263 }
elseif ($palign ==
'C') {
10264 $ximg = ($this->w -
$x - $w) / 2;
10266 $this->img_rb_x = $ximg + $w;
10268 $ximg = $this->w -
$x - $w;
10270 $this->img_rb_x = $ximg;
10273 if ($palign ==
'R') {
10274 $ximg = $this->w - $this->rMargin - $w;
10276 $this->img_rb_x = $ximg;
10277 }
elseif ($palign ==
'C') {
10278 $ximg = ($this->w -
$x - $w) / 2;
10280 $this->img_rb_x = $ximg + $w;
10284 $this->img_rb_x = $ximg + $w;
10287 if ($useBoundingBox) {
10288 $dx = $ximg * $k - $x1;
10289 $dy =
$y * $k - $y1;
10295 $this->_out(
'q'.$this->epsmarker);
10297 $this->_out(sprintf(
'%.3F %.3F %.3F %.3F %.3F %.3F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 *
$y * $k) - ($y2 - $y1))));
10299 if (isset($scale_x)) {
10300 $this->_out(sprintf(
'%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
10303 preg_match(
'/[\r\n]+/s',
$data, $regs);
10304 $lines = explode($regs[0],
$data);
10306 $cnt = count($lines);
10307 for ($i=0; $i < $cnt; ++$i) {
10308 $line = $lines[$i];
10309 if (($line ==
'') OR ($line{0} ==
'%')) {
10312 $len = strlen($line);
10313 $chunks = explode(
' ', $line);
10314 $cmd = array_pop($chunks);
10316 if ((
$cmd ==
'Xa') OR (
$cmd ==
'XA')) {
10317 $b = array_pop($chunks);
10318 $g = array_pop($chunks);
10319 $r = array_pop($chunks);
10320 $this->_out(
''.$r.
' '.$g.
' '.$b.
' '.(
$cmd==
'Xa'?
'rg':
'RG'));
10342 $this->_out($line);
10346 list($c,$m,
$y,$k) = $chunks;
10347 $this->_out(
''.$c.
' '.$m.
' '.
$y.
' '.$k.
' k');
10351 list($c,$m,
$y,$k) = $chunks;
10352 $this->_out(
''.$c.
' '.$m.
' '.
$y.
' '.$k.
' K');
10360 $line{$len-1} = strtolower(
$cmd);
10361 $this->_out($line);
10366 $this->_out(
$cmd .
'*');
10373 $max = min($i+5, $cnt);
10374 for ($j=$i+1; $j < $max; ++$j)
10375 $isU = ($isU OR (($lines[$j] ==
'U') OR ($lines[$j] ==
'*U')));
10395 $this->_out($this->epsmarker.
'Q');
10396 if (!empty($border)) {
10401 $this->Cell($w, $h,
'', $border, 0,
'', 0,
'', 0);
10406 $this->Link($ximg,
$y, $w, $h, $link, 0);
10412 $this->x = $this->img_rb_x;
10416 $this->y =
$y + round($h/2);
10417 $this->x = $this->img_rb_x;
10421 $this->y = $this->img_rb_y;
10422 $this->x = $this->img_rb_x;
10426 $this->SetY($this->img_rb_y);
10433 $this->endlinex = $this->img_rb_x;
10441 public function setBarcode($bc=
'') {
10442 $this->barcode = $bc;
10451 public function getBarcode() {
10452 return $this->barcode;
10470 public function write1DBarcode($code,
$type,
$x=
'',
$y=
'', $w=
'', $h=
'', $xres=0.4, $style=
'', $align=
'') {
10471 if ($this->empty_string($code)) {
10474 require_once(dirname(__FILE__).
'/barcodes.php');
10476 $gvars = $this->getGraphicVars();
10479 $arrcode = $barcodeobj->getBarcodeArray();
10480 if ($arrcode ===
false) {
10481 $this->Error(
'Error in 1D barcode string');
10484 if (!isset($style[
'position'])) {
10486 $style[
'position'] =
'R';
10488 $style[
'position'] =
'L';
10491 if (!isset($style[
'padding'])) {
10492 $style[
'padding'] = 0;
10494 if (!isset($style[
'fgcolor'])) {
10495 $style[
'fgcolor'] = array(0,0,0);
10497 if (!isset($style[
'bgcolor'])) {
10498 $style[
'bgcolor'] =
false;
10500 if (!isset($style[
'border'])) {
10501 $style[
'border'] =
false;
10503 if (!isset($style[
'text'])) {
10504 $style[
'text'] =
false;
10507 if ($style[
'text'] AND isset($style[
'font'])) {
10508 if (isset($style[
'fontsize'])) {
10509 $fontsize = $style[
'fontsize'];
10513 $this->SetFont($style[
'font'],
'', $fontsize);
10515 if (!isset($style[
'stretchtext'])) {
10516 $style[
'stretchtext'] = 4;
10519 $this->SetDrawColorArray($style[
'fgcolor']);
10520 $this->SetTextColorArray($style[
'fgcolor']);
10521 if ($this->empty_string($w) OR ($w <= 0)) {
10523 $w = $this->x - $this->lMargin;
10525 $w = $this->w - $this->rMargin -
$this->x;
10528 if ($this->empty_string(
$x)) {
10529 $x = $this->GetX();
10532 $x = $this->w -
$x;
10534 if ($this->empty_string(
$y)) {
10535 $y = $this->GetY();
10537 if ($this->empty_string($xres)) {
10540 $fbw = ($arrcode[
'maxw'] * $xres) + (2 * $style[
'padding']);
10541 $extraspace = ($this->cell_height_ratio * $fontsize / $this->k) + (2 * $style[
'padding']);
10542 if ($this->empty_string($h) OR ($h <= 0)) {
10543 $h = 10 + $extraspace;
10545 if ($this->checkPageBreak($h)) {
10549 $barh = $h - $extraspace;
10550 switch ($style[
'position']) {
10560 $xdiff = (($w - $fbw) / 2);
10562 $xpos =
$x - $w + $xdiff;
10564 $xpos =
$x + $xdiff;
10572 $xpos =
$x + $w - $fbw;
10578 $xres = ($w - (2 * $style[
'padding'])) / $arrcode[
'maxw'];
10587 $xpos_rect = $xpos;
10588 $xpos = $xpos_rect + $style[
'padding'];
10589 $xpos_text = $xpos;
10591 $tempRTL = $this->rtl;
10592 $this->rtl =
false;
10594 if ($style[
'bgcolor']) {
10595 $this->Rect($xpos_rect,
$y, $fbw, $h,
'DF',
'', $style[
'bgcolor']);
10596 }
elseif ($style[
'border']) {
10597 $this->Rect($xpos_rect,
$y, $fbw, $h,
'D');
10600 if ($arrcode !==
false) {
10601 foreach ($arrcode[
'bcode'] as $k => $v) {
10602 $bw = ($v[
'w'] * $xres);
10605 $ypos =
$y + $style[
'padding'] + ($v[
'p'] * $barh / $arrcode[
'maxh']);
10606 $this->Rect($xpos, $ypos, $bw, ($v[
'h'] * $barh / $arrcode[
'maxh']),
'F', array(), $style[
'fgcolor']);
10612 if ($style[
'text']) {
10614 $this->x = $xpos_text;
10615 $this->y =
$y + $style[
'padding'] + $barh;
10616 $this->Cell(($arrcode[
'maxw'] * $xres), ($this->cell_height_ratio * $fontsize / $this->k), $code, 0, 0,
'C', 0,
'', $style[
'stretchtext']);
10619 $this->rtl = $tempRTL;
10621 $this->setGraphicVars($gvars);
10623 $this->img_rb_y =
$y + $h;
10626 $this->img_rb_x = ($this->w -
$x - $w);
10629 $this->img_rb_x =
$x + $w;
10635 $this->x = $this->img_rb_x;
10639 $this->y =
$y + round($h/2);
10640 $this->x = $this->img_rb_x;
10644 $this->y = $this->img_rb_y;
10645 $this->x = $this->img_rb_x;
10649 $this->SetY($this->img_rb_y);
10673 public function writeBarcode(
$x,
$y, $w, $h,
$type, $style, $font, $xres, $code) {
10680 'fgcolor' => array(0,0,0),
10681 'bgcolor' =>
false,
10688 $newstyle[
'border'] =
true;
10691 $newstyle[
'bgcolor'] =
false;
10694 $newstyle[
'position'] =
'C';
10696 $newstyle[
'position'] =
'L';
10697 }
elseif ($style & 16) {
10698 $newstyle[
'position'] =
'R';
10700 if ($style & 128) {
10701 $newstyle[
'text'] =
true;
10703 if ($style & 256) {
10704 $newstyle[
'stretchtext'] = 4;
10706 $this->write1DBarcode($code,
$type,
$x,
$y, $w, $h, $xres, $newstyle,
'');
10723 public function write2DBarcode($code,
$type,
$x=
'',
$y=
'', $w=
'', $h=
'', $style=
'', $align=
'') {
10724 if ($this->empty_string($code)) {
10727 require_once(dirname(__FILE__).
'/2dbarcodes.php');
10729 $gvars = $this->getGraphicVars();
10732 $arrcode = $barcodeobj->getBarcodeArray();
10733 if ($arrcode ===
false) {
10734 $this->Error(
'Error in 2D barcode string');
10737 if (!isset($style[
'padding'])) {
10738 $style[
'padding'] = 0;
10740 if (!isset($style[
'fgcolor'])) {
10741 $style[
'fgcolor'] = array(0,0,0);
10743 if (!isset($style[
'bgcolor'])) {
10744 $style[
'bgcolor'] =
false;
10746 if (!isset($style[
'border'])) {
10747 $style[
'border'] =
false;
10750 $this->SetDrawColorArray($style[
'fgcolor']);
10751 if ($this->empty_string(
$x)) {
10752 $x = $this->GetX();
10755 $x = $this->w -
$x;
10757 if ($this->empty_string(
$y)) {
10758 $y = $this->GetY();
10760 if ($this->empty_string($w) OR ($w <= 0)) {
10762 $w =
$x - $this->lMargin;
10764 $w = $this->w - $this->rMargin -
$x;
10767 if ($this->empty_string($h) OR ($h <= 0)) {
10771 if ($this->checkPageBreak($h)) {
10775 $bw = $w - (2 * $style[
'padding']);
10776 $bh = $h - (2 * $style[
'padding']);
10783 $xpos += $style[
'padding'];
10784 $ypos =
$y + $style[
'padding'];
10786 $tempRTL = $this->rtl;
10787 $this->rtl =
false;
10789 if ($style[
'bgcolor']) {
10790 $this->Rect(
$x,
$y, $w, $h,
'DF',
'', $style[
'bgcolor']);
10791 }
elseif ($style[
'border']) {
10792 $this->Rect(
$x,
$y, $w, $h,
'D');
10795 if ($arrcode !==
false) {
10796 $rows = $arrcode[
'num_rows'];
10797 $cols = $arrcode[
'num_cols'];
10802 for ($r = 0; $r < $rows; ++$r) {
10805 for ($c = 0; $c < $cols; ++$c) {
10806 if ($arrcode[
'bcode'][$r][$c] == 1) {
10808 $this->Rect($xr, $ypos,
$cw, $ch,
'F', array(), $style[
'fgcolor']);
10816 $this->rtl = $tempRTL;
10818 $this->setGraphicVars($gvars);
10820 $this->img_rb_y =
$y + $h;
10823 $this->img_rb_x = ($this->w -
$x - $w);
10826 $this->img_rb_x =
$x + $w;
10832 $this->x = $this->img_rb_x;
10836 $this->y =
$y + round($h/2);
10837 $this->x = $this->img_rb_x;
10841 $this->y = $this->img_rb_y;
10842 $this->x = $this->img_rb_x;
10846 $this->SetY($this->img_rb_y);
10870 public function getMargins() {
10872 'left' => $this->lMargin,
10873 'right' => $this->rMargin,
10874 'top' => $this->tMargin,
10875 'bottom' => $this->bMargin,
10876 'header' => $this->header_margin,
10877 'footer' => $this->footer_margin,
10878 'cell' => $this->cMargin,
10893 public function getOriginalMargins() {
10895 'left' => $this->original_lMargin,
10896 'right' => $this->original_rMargin
10907 public function getFontSize() {
10908 return $this->FontSize;
10917 public function getFontSizePt() {
10918 return $this->FontSizePt;
10927 public function getFontFamily() {
10928 return $this->FontFamily;
10937 public function getFontStyle() {
10938 return $this->FontStyle;
10961 public function writeHTMLCell($w, $h,
$x,
$y, $html=
'', $border=0, $ln=0, $fill=0, $reseth=
true, $align=
'', $autopadding=
true) {
10962 return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln,
$x,
$y, $reseth, 0,
true, $autopadding, 0);
10973 protected function getHtmlDomArray($html) {
10975 $html = strip_tags($html,
'<marker/><a><b><blockquote><br><br/><dd><del><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><li><ol><p><pre><small><span><strong><sub><sup><table><tablehead><tcpdf><td><th><thead><tr><tt><u><ul>');
10977 $html = preg_replace(
'/<pre/',
'<xre', $html);
10978 $html = preg_replace(
'/<(table|tr|td|th|tcpdf|blockquote|dd|div|dt|h1|h2|h3|h4|h5|h6|br|hr|li|ol|ul|p)([^>]*)>[\n\r\t]+/',
'<\\1\\2>', $html);
10979 $html = preg_replace(
'@(\r\n|\r)@',
"\n", $html);
10980 $repTable = array(
"\t" =>
' ',
"\0" =>
' ',
"\x0B" =>
' ',
"\\" =>
"\\\\");
10981 $html = strtr($html, $repTable);
10983 while (($offset < strlen($html)) AND ($pos = strpos($html,
'</pre>', $offset)) !==
false) {
10984 $html_a = substr($html, 0, $offset);
10985 $html_b = substr($html, $offset, ($pos - $offset + 6));
10986 while (preg_match(
"'<xre([^>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
10988 $html_b = preg_replace(
"'<xre([^>]*)>(.*?)\n(.*?)</pre>'si",
"<xre\\1>\\2<br />\\3</pre>", $html_b);
10990 $html = $html_a.$html_b.substr($html, $pos + 6);
10991 $offset = strlen($html_a.$html_b);
10993 $html = str_replace(
"\n",
' ', $html);
10995 $html = preg_replace(
'/[\s]+<\/(table|tr|td|th|ul|ol|li)>/',
'</\\1>', $html);
10996 $html = preg_replace(
'/[\s]+<(tr|td|th|ul|ol|li|br)/',
'<\\1', $html);
10997 $html = preg_replace(
'/<\/(table|tr|td|th|blockquote|dd|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|ul|p)>[\s]+</',
'</\\1><', $html);
10998 $html = preg_replace(
'/<\/(td|th)>/',
'<marker style="font-size:0"/></\\1>', $html);
10999 $html = preg_replace(
'/<\/table>([\s]*)<marker style="font-size:0"\/>/',
'</table>', $html);
11000 $html = preg_replace(
'/<img/',
' <img', $html);
11001 $html = preg_replace(
'/<img([^>]*)>/xi',
'<img\\1><span></span>', $html);
11002 $html = preg_replace(
'/<xre/',
'<pre', $html);
11004 $html = preg_replace(
'/^[\s]+/',
'', $html);
11005 $html = preg_replace(
'/[\s]+$/',
'', $html);
11007 $tagpattern =
'/(<[^>]+>)/';
11009 $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
11011 $maxel = count($a);
11016 $dom[
$key] = array();
11018 $dom[
$key][
'tag'] =
false;
11019 $dom[
$key][
'value'] =
'';
11020 $dom[
$key][
'parent'] = 0;
11021 $dom[
$key][
'fontname'] = $this->FontFamily;
11022 $dom[
$key][
'fontstyle'] = $this->FontStyle;
11023 $dom[
$key][
'fontsize'] = $this->FontSizePt;
11024 $dom[
$key][
'bgcolor'] =
false;
11025 $dom[
$key][
'fgcolor'] = $this->fgcolor;
11026 $dom[
$key][
'align'] =
'';
11027 $dom[
$key][
'listtype'] =
'';
11031 array_push($level, 0);
11032 while ($elkey < $maxel) {
11033 $dom[
$key] = array();
11034 $element = $a[$elkey];
11035 $dom[
$key][
'elkey'] = $elkey;
11036 if (preg_match($tagpattern, $element)) {
11038 $element = substr($element, 1, -1);
11040 preg_match(
'/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
11041 $tagname = strtolower($tag[1]);
11043 if ($tagname ==
'thead') {
11044 if ($element{0} ==
'/') {
11052 $dom[
$key][
'tag'] =
true;
11053 $dom[
$key][
'value'] = $tagname;
11054 if ($element{0} ==
'/') {
11056 $dom[
$key][
'opening'] =
false;
11057 $dom[
$key][
'parent'] = end($level);
11059 $dom[
$key][
'fontname'] = $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'fontname'];
11060 $dom[
$key][
'fontstyle'] = $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'fontstyle'];
11061 $dom[
$key][
'fontsize'] = $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'fontsize'];
11062 $dom[
$key][
'bgcolor'] = $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'bgcolor'];
11063 $dom[
$key][
'fgcolor'] = $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'fgcolor'];
11064 $dom[
$key][
'align'] = $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'align'];
11065 if (isset($dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'listtype'])) {
11066 $dom[
$key][
'listtype'] = $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'listtype'];
11069 if (($dom[
$key][
'value'] ==
'tr') AND (!isset($dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'cols']))) {
11070 $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'cols'] = $dom[($dom[
$key][
'parent'])][
'cols'];
11072 if (($dom[
$key][
'value'] ==
'td') OR ($dom[
$key][
'value'] ==
'th')) {
11073 $dom[($dom[
$key][
'parent'])][
'content'] =
'';
11074 for ($i = ($dom[
$key][
'parent'] + 1); $i <
$key; ++$i) {
11075 $dom[($dom[
$key][
'parent'])][
'content'] .= $a[$dom[$i][
'elkey']];
11080 if (($dom[
$key][
'value'] ==
'tr') AND ($dom[($dom[
$key][
'parent'])][
'thead'] ==
true)) {
11081 if ($this->empty_string($dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'thead'])) {
11082 $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'thead'] = $a[$dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'elkey']];
11084 for ($i = $dom[
$key][
'parent']; $i <=
$key; ++$i) {
11085 $dom[($dom[($dom[
$key][
'parent'])][
'parent'])][
'thead'] .= $a[$dom[$i][
'elkey']];
11088 if (($dom[
$key][
'value'] ==
'table') AND (!$this->empty_string($dom[($dom[
$key][
'parent'])][
'thead']))) {
11089 $dom[($dom[
$key][
'parent'])][
'thead'] .=
'</tablehead>';
11093 $dom[
$key][
'opening'] =
true;
11094 $dom[
$key][
'parent'] = end($level);
11095 if (substr($element, -1, 1) !=
'/') {
11097 array_push($level,
$key);
11098 $dom[
$key][
'self'] =
false;
11100 $dom[
$key][
'self'] =
true;
11105 $parentkey = $dom[
$key][
'parent'];
11106 $dom[
$key][
'fontname'] = $dom[$parentkey][
'fontname'];
11107 $dom[
$key][
'fontstyle'] = $dom[$parentkey][
'fontstyle'];
11108 $dom[
$key][
'fontsize'] = $dom[$parentkey][
'fontsize'];
11109 $dom[
$key][
'bgcolor'] = $dom[$parentkey][
'bgcolor'];
11110 $dom[
$key][
'fgcolor'] = $dom[$parentkey][
'fgcolor'];
11111 $dom[
$key][
'align'] = $dom[$parentkey][
'align'];
11112 $dom[
$key][
'listtype'] = $dom[$parentkey][
'listtype'];
11115 preg_match_all(
'/([^=\s]*)=["]?([^"]*)["]?/', $element, $attr_array, PREG_PATTERN_ORDER);
11116 $dom[
$key][
'attribute'] = array();
11117 while (list($id, $name) = each($attr_array[1])) {
11118 $dom[
$key][
'attribute'][strtolower($name)] = $attr_array[2][$id];
11121 if (isset($dom[
$key][
'attribute'][
'style'])) {
11123 preg_match_all(
'/([^;:\s]*):([^;]*)/', $dom[$key][
'attribute'][
'style'], $style_array, PREG_PATTERN_ORDER);
11124 $dom[
$key][
'style'] = array();
11125 while (list($id, $name) = each($style_array[1])) {
11126 $dom[
$key][
'style'][strtolower($name)] = trim($style_array[2][$id]);
11129 if (isset($dom[$key][
'style'][
'font-family'])) {
11131 if (isset($dom[$key][
'style'][
'font-family'])) {
11132 $fontslist = preg_split(
'/[,]/', strtolower($dom[$key][
'style'][
'font-family']));
11133 foreach ($fontslist as $font) {
11134 $font = trim(strtolower($font));
11135 if (in_array($font, $this->fontlist) OR in_array($font, $this->fontkeys)) {
11136 $dom[
$key][
'fontname'] = $font;
11143 if (isset($dom[$key][
'style'][
'list-style-type'])) {
11144 $dom[
$key][
'listtype'] = trim(strtolower($dom[$key][
'style'][
'list-style-type']));
11145 if ($dom[$key][
'listtype'] ==
'inherit') {
11146 $dom[
$key][
'listtype'] = $dom[$parentkey][
'listtype'];
11150 if (isset($dom[$key][
'style'][
'font-size'])) {
11151 $fsize = trim($dom[$key][
'style'][
'font-size']);
11155 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'] - 4;
11159 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'] - 3;
11163 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'] - 2;
11167 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'];
11171 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'] + 2;
11175 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'] + 4;
11179 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'] + 6;
11184 $dom[
$key][
'fontsize'] = $dom[$parentkey][
'fontsize'] - 3;
11188 $dom[
$key][
'fontsize'] = $dom[$parentkey][
'fontsize'] + 3;
11192 $dom[
$key][
'fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey][
'fontsize'],
'pt',
true);
11197 if (isset($dom[$key][
'style'][
'font-weight']) AND (strtolower($dom[$key][
'style'][
'font-weight']{0}) ==
'b')) {
11198 $dom[
$key][
'fontstyle'] .=
'B';
11200 if (isset($dom[$key][
'style'][
'font-style']) AND (strtolower($dom[$key][
'style'][
'font-style']{0}) ==
'i')) {
11201 $dom[
$key][
'fontstyle'] .=
'"I';
11204 if (isset($dom[$key][
'style'][
'color']) AND (!$this->empty_string($dom[$key][
'style'][
'color']))) {
11205 $dom[
$key][
'fgcolor'] = $this->convertHTMLColorToDec($dom[$key][
'style'][
'color']);
11208 if (isset($dom[$key][
'style'][
'background-color']) AND (!$this->empty_string($dom[$key][
'style'][
'background-color']))) {
11209 $dom[
$key][
'bgcolor'] = $this->convertHTMLColorToDec($dom[$key][
'style'][
'background-color']);
11212 if (isset($dom[$key][
'style'][
'text-decoration'])) {
11213 $decors = explode(
' ', strtolower($dom[$key][
'style'][
'text-decoration']));
11214 foreach ($decors as $dec) {
11216 if (!$this->empty_string($dec)) {
11217 if ($dec{0} ==
'u') {
11218 $dom[
$key][
'fontstyle'] .=
'U';
11219 }
elseif ($dec{0} ==
'l') {
11220 $dom[
$key][
'fontstyle'] .=
'D';
11226 if (isset($dom[$key][
'style'][
'width'])) {
11227 $dom[
$key][
'width'] = $dom[
$key][
'style'][
'width'];
11230 if (isset($dom[$key][
'style'][
'height'])) {
11231 $dom[
$key][
'height'] = $dom[
$key][
'style'][
'height'];
11234 if (isset($dom[$key][
'style'][
'text-align'])) {
11235 $dom[
$key][
'align'] = strtoupper($dom[$key][
'style'][
'text-align']{0});
11238 if (isset($dom[$key][
'style'][
'border'])) {
11239 $dom[
$key][
'attribute'][
'border'] = $dom[
$key][
'style'][
'border'];
11243 if ($dom[$key][
'value'] ==
'font') {
11245 if (isset($dom[$key][
'attribute'][
'face'])) {
11246 $fontslist = preg_split(
'/[,]/', strtolower($dom[$key][
'attribute'][
'face']));
11247 foreach ($fontslist as $font) {
11248 $font = trim(strtolower($font));
11249 if (in_array($font, $this->fontlist) OR in_array($font, $this->fontkeys)) {
11250 $dom[
$key][
'fontname'] = $font;
11256 if (isset($dom[$key][
'attribute'][
'size'])) {
11258 if ($dom[$key][
'attribute'][
'size']{0} ==
'+') {
11259 $dom[
$key][
'fontsize'] = $dom[($dom[
$key][
'parent'])][
'fontsize'] + intval(substr($dom[$key][
'attribute'][
'size'], 1));
11260 }
elseif ($dom[$key][
'attribute'][
'size']{0} ==
'-') {
11261 $dom[
$key][
'fontsize'] = $dom[($dom[
$key][
'parent'])][
'fontsize'] - intval(substr($dom[$key][
'attribute'][
'size'], 1));
11263 $dom[
$key][
'fontsize'] = intval($dom[$key][
'attribute'][
'size']);
11266 $dom[
$key][
'fontsize'] = intval($dom[$key][
'attribute'][
'size']);
11271 if ((($dom[$key][
'value'] ==
'ul') OR ($dom[$key][
'value'] ==
'ol') OR ($dom[$key][
'value'] ==
'dl'))
11272 AND (!isset($dom[$key][
'align']) OR $this->empty_string($dom[$key][
'align']) OR ($dom[$key][
'align'] !=
'J'))) {
11274 $dom[
$key][
'align'] =
'R';
11276 $dom[
$key][
'align'] =
'L';
11279 if (($dom[$key][
'value'] ==
'small') OR ($dom[$key][
'value'] ==
'sup') OR ($dom[$key][
'value'] ==
'sub')) {
11280 $dom[
$key][
'fontsize'] = $dom[
$key][
'fontsize'] * K_SMALL_RATIO;
11282 if (($dom[$key][
'value'] ==
'strong') OR ($dom[$key][
'value'] ==
'b')) {
11283 $dom[
$key][
'fontstyle'] .=
'B';
11285 if (($dom[$key][
'value'] ==
'em') OR ($dom[$key][
'value'] ==
'i')) {
11286 $dom[
$key][
'fontstyle'] .=
'I';
11288 if ($dom[$key][
'value'] ==
'u') {
11289 $dom[
$key][
'fontstyle'] .=
'U';
11291 if ($dom[$key][
'value'] ==
'del') {
11292 $dom[
$key][
'fontstyle'] .=
'D';
11294 if (($dom[$key][
'value'] ==
'pre') OR ($dom[$key][
'value'] ==
'tt')) {
11295 $dom[
$key][
'fontname'] = $this->default_monospaced_font;
11297 if (($dom[$key][
'value']{0} ==
'h') AND (intval($dom[$key][
'value']{1}) > 0) AND (intval($dom[$key][
'value']{1}) < 7)) {
11298 $headsize = (4 - intval($dom[$key][
'value']{1})) * 2;
11299 $dom[
$key][
'fontsize'] = $dom[0][
'fontsize'] + $headsize;
11300 $dom[
$key][
'fontstyle'] .=
'B';
11302 if (($dom[$key][
'value'] ==
'table')) {
11303 $dom[
$key][
'rows'] = 0;
11304 $dom[
$key][
'trids'] = array();
11305 $dom[
$key][
'thead'] =
'';
11307 if (($dom[$key][
'value'] ==
'tr')) {
11308 $dom[
$key][
'cols'] = 0;
11310 ++$dom[($dom[
$key][
'parent'])][
'rows'];
11312 array_push($dom[($dom[$key][
'parent'])][
'trids'], $key);
11314 $dom[
$key][
'thead'] =
true;
11316 $dom[
$key][
'thead'] =
false;
11319 if (($dom[$key][
'value'] ==
'th') OR ($dom[$key][
'value'] ==
'td')) {
11320 if (isset($dom[$key][
'attribute'][
'colspan'])) {
11321 $colspan = intval($dom[$key][
'attribute'][
'colspan']);
11325 $dom[
$key][
'attribute'][
'colspan'] = $colspan;
11326 $dom[($dom[
$key][
'parent'])][
'cols'] += $colspan;
11329 if (isset($dom[$key][
'attribute'][
'color']) AND (!$this->empty_string($dom[$key][
'attribute'][
'color']))) {
11330 $dom[
$key][
'fgcolor'] = $this->convertHTMLColorToDec($dom[$key][
'attribute'][
'color']);
11333 if (isset($dom[$key][
'attribute'][
'bgcolor']) AND (!$this->empty_string($dom[$key][
'attribute'][
'bgcolor']))) {
11334 $dom[
$key][
'bgcolor'] = $this->convertHTMLColorToDec($dom[$key][
'attribute'][
'bgcolor']);
11337 if (isset($dom[$key][
'attribute'][
'width'])) {
11338 $dom[
$key][
'width'] = $dom[
$key][
'attribute'][
'width'];
11341 if (isset($dom[$key][
'attribute'][
'height'])) {
11342 $dom[
$key][
'height'] = $dom[
$key][
'attribute'][
'height'];
11345 if (isset($dom[$key][
'attribute'][
'align']) AND (!$this->empty_string($dom[$key][
'attribute'][
'align'])) AND ($dom[$key][
'value'] !==
'img')) {
11346 $dom[
$key][
'align'] = strtoupper($dom[$key][
'attribute'][
'align']{0});
11351 $dom[
$key][
'tag'] =
false;
11352 $dom[
$key][
'value'] = stripslashes($this->unhtmlentities($element));
11353 $dom[
$key][
'parent'] = end($level);
11373 public function writeHTML($html, $ln=
true, $fill=
false, $reseth=
false, $cell=
false, $align=
'') {
11374 $gvars = $this->getGraphicVars();
11376 $prevPage = $this->page;
11377 $prevlMargin = $this->lMargin;
11378 $prevrMargin = $this->rMargin;
11379 $curfontname = $this->FontFamily;
11380 $curfontstyle = $this->FontStyle;
11381 $curfontsize = $this->FontSizePt;
11382 $this->newline =
true;
11385 $startlinepage = $this->page;
11389 $blocktags = array(
'blockquote',
'br',
'dd',
'div',
'dt',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'hr',
'li',
'ol',
'p',
'ul',
'tcpdf');
11390 $this->premode =
false;
11391 if (isset($this->PageAnnots[$this->page])) {
11392 $pask = count($this->PageAnnots[$this->page]);
11396 if (isset($this->footerlen[$this->page])) {
11397 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
11399 $this->footerpos[$this->page] = $this->pagelen[$this->page];
11401 $startlinepos = $this->footerpos[$this->page];
11405 $w = $this->x - $this->lMargin;
11407 $w = $this->w - $this->rMargin -
$this->x;
11409 $w -= (2 * $this->cMargin);
11412 $this->x -= $this->cMargin;
11414 $this->x += $this->cMargin;
11417 if ($this->customlistindent >= 0) {
11418 $this->listindent = $this->customlistindent;
11420 $this->listindent = $this->GetStringWidth(
'0000');
11422 $this->listnum = 0;
11423 if (($this->empty_string($this->lasth)) OR ($reseth)) {
11425 $this->lasth = $this->FontSize * $this->cell_height_ratio;
11427 $dom = $this->getHtmlDomArray($html);
11428 $maxel = count($dom);
11430 while ($key < $maxel) {
11431 if ($dom[$key][
'tag'] OR ($key == 0)) {
11432 if ((($dom[$key][
'value'] ==
'table') OR ($dom[$key][
'value'] ==
'tr')) AND (isset($dom[$key][
'align']))) {
11433 $dom[
$key][
'align'] = ($this->rtl) ?
'R' :
'L';
11436 if ((!$this->newline)
11437 AND ($dom[$key][
'value'] ==
'img')
11438 AND (isset($dom[$key]['attribute']['height']))
11439 AND ($dom[$key]['attribute']['height'] > 0)) {
11441 $imgh = $this->getHTMLUnitToUnits($dom[$key][
'attribute'][
'height'], $this->lasth,
'px');
11442 if (!$this->InFooter) {
11444 $this->checkPageBreak($imgh);
11446 if ($this->page > $startlinepage) {
11448 if (isset($this->footerlen[$startlinepage])) {
11449 $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
11452 $pagebuff = $this->getPageBuffer($startlinepage);
11453 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
11454 $tstart = substr($pagebuff, 0, $startlinepos);
11455 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
11457 $this->setPageBuffer($startlinepage, $tstart.
''.$tend);
11458 $pagebuff = $this->getPageBuffer($this->page);
11459 $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
11460 $tend = substr($pagebuff, $this->cntmrk[$this->page]);
11462 $yshift = $minstartliney -
$this->y;
11463 $try = sprintf(
'1 0 0 1 0 %.3F cm', ($yshift * $this->k));
11464 $this->setPageBuffer($this->page, $tstart.
"\nq\n".$try.
"\n".$linebeg.
"\nQ\n".$tend);
11466 if (isset($this->PageAnnots[$this->page])) {
11467 $next_pask = count($this->PageAnnots[$this->page]);
11471 if (isset($this->PageAnnots[$startlinepage])) {
11472 foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
11473 if ($pak >= $pask) {
11474 $this->PageAnnots[$this->page][] = $pac;
11475 unset($this->PageAnnots[$startlinepage][$pak]);
11476 $npak = count($this->PageAnnots[$this->page]) - 1;
11477 $this->PageAnnots[$this->page][$npak][
'y'] -= $yshift;
11482 $pask = $next_pask;
11483 $startlinepos = $this->cntmrk[$this->page];
11484 $startlinepage = $this->page;
11487 $this->y += (($curfontsize / $this->k) - $imgh);
11488 $minstartliney = min($this->y, $minstartliney);
11489 }
elseif (isset($dom[$key][
'fontname']) OR isset($dom[$key][
'fontstyle']) OR isset($dom[$key][
'fontsize'])) {
11491 $pfontname = $curfontname;
11492 $pfontstyle = $curfontstyle;
11493 $pfontsize = $curfontsize;
11494 $fontname = isset($dom[$key][
'fontname']) ? $dom[
$key][
'fontname'] : $curfontname;
11495 $fontstyle = isset($dom[$key][
'fontstyle']) ? $dom[
$key][
'fontstyle'] : $curfontstyle;
11496 $fontsize = isset($dom[$key][
'fontsize']) ? $dom[
$key][
'fontsize'] : $curfontsize;
11497 if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)) {
11498 $this->SetFont($fontname, $fontstyle, $fontsize);
11499 $this->lasth = $this->FontSize * $this->cell_height_ratio;
11500 if (is_numeric($fontsize) AND ($fontsize > 0)
11501 AND is_numeric($curfontsize) AND ($curfontsize > 0)
11502 AND ($fontsize != $curfontsize) AND (!$this->newline)
11503 AND ($key < ($maxel - 1))
11505 if ((!$this->newline) AND ($this->page > $startlinepage)) {
11507 if (isset($this->footerlen[$startlinepage])) {
11508 $curpos = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
11511 $pagebuff = $this->getPageBuffer($startlinepage);
11512 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
11513 $tstart = substr($pagebuff, 0, $startlinepos);
11514 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
11516 $this->setPageBuffer($startlinepage, $tstart.
''.$tend);
11517 $pagebuff = $this->getPageBuffer($this->page);
11518 $tstart = substr($pagebuff, 0, $this->cntmrk[$this->page]);
11519 $tend = substr($pagebuff, $this->cntmrk[$this->page]);
11521 $yshift = $minstartliney -
$this->y;
11522 $try = sprintf(
'1 0 0 1 0 %.3F cm', ($yshift * $this->k));
11523 $this->setPageBuffer($this->page, $tstart.
"\nq\n".$try.
"\n".$linebeg.
"\nQ\n".$tend);
11525 if (isset($this->PageAnnots[$this->page])) {
11526 $next_pask = count($this->PageAnnots[$this->page]);
11530 if (isset($this->PageAnnots[$startlinepage])) {
11531 foreach ($this->PageAnnots[$startlinepage] as $pak => $pac) {
11532 if ($pak >= $pask) {
11533 $this->PageAnnots[$this->page][] = $pac;
11534 unset($this->PageAnnots[$startlinepage][$pak]);
11535 $npak = count($this->PageAnnots[$this->page]) - 1;
11536 $this->PageAnnots[$this->page][$npak][
'y'] -= $yshift;
11540 $pask = $next_pask;
11542 $this->y += (($curfontsize - $fontsize) / $this->k);
11543 $minstartliney = min($this->y, $minstartliney);
11545 $curfontname = $fontname;
11546 $curfontstyle = $fontstyle;
11547 $curfontsize = $fontsize;
11550 if (($plalign ==
'J') AND (in_array($dom[$key][
'value'], $blocktags))) {
11554 $curpos = $this->pagelen[$startlinepage];
11555 if (isset($dom[$key][
'bgcolor']) AND ($dom[$key][
'bgcolor'] !==
false)) {
11556 $this->SetFillColorArray($dom[$key][
'bgcolor']);
11559 $wfill = $fill |
false;
11561 if (isset($dom[$key][
'fgcolor']) AND ($dom[$key][
'fgcolor'] !==
false)) {
11562 $this->SetTextColorArray($dom[$key][
'fgcolor']);
11564 if (isset($dom[$key][
'align'])) {
11565 $lalign = $dom[
$key][
'align'];
11567 if ($this->empty_string($lalign)) {
11572 if ($this->newline AND (strlen($dom[$key][
'value']) > 0) AND ($dom[$key][
'value'] !=
'td') AND ($dom[$key][
'value'] !=
'th')) {
11575 if (isset($startlinex)) {
11576 $yshift = $minstartliney - $startliney;
11577 if (($yshift > 0) OR ($this->page > $startlinepage)) {
11580 if ((isset($plalign) AND ((($plalign ==
'C') OR ($plalign ==
'J') OR (($plalign ==
'R') AND (!$this->rtl)) OR (($plalign ==
'L') AND ($this->rtl))))) OR ($yshift < 0)) {
11582 $linew = abs($this->endlinex - $startlinex);
11583 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
11584 if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
11585 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
11586 $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
11587 }
elseif (isset($opentagpos)) {
11588 $midpos = $opentagpos;
11589 }
elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
11590 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
11591 $midpos = $this->footerpos[$startlinepage];
11596 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
11597 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
11599 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
11604 if ($this->lMargin != $prevlMargin) {
11605 $tw += ($prevlMargin - $this->lMargin);
11607 if ($this->rMargin != $prevrMargin) {
11608 $tw += ($prevrMargin - $this->rMargin);
11610 $mdiff = abs($tw - $linew);
11612 if ($plalign ==
'C') {
11614 $t_x = -($mdiff / 2);
11616 $t_x = ($mdiff / 2);
11618 }
elseif (($plalign ==
'R') AND (!$this->rtl)) {
11621 }
elseif (($plalign ==
'L') AND ($this->rtl)) {
11624 }
elseif (($plalign ==
'J') AND ($plalign == $lalign)) {
11626 if ($this->rtl OR $this->tmprtl) {
11627 $t_x = $this->lMargin - $this->endlinex;
11633 $pmidtemp = preg_replace(
'/[\\\][\(]/x',
'\\#!#OP#!#', $pmidtemp);
11634 $pmidtemp = preg_replace(
'/[\\\][\)]/x',
'\\#!#CP#!#', $pmidtemp);
11636 if (preg_match_all(
'/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER)) {
11637 $maxkk = count($lnstring[1]) - 1;
11638 for ($kk=0; $kk <= $maxkk; ++$kk) {
11640 $lnstring[1][$kk] = str_replace(
'#!#OP#!#',
'(', $lnstring[1][$kk]);
11641 $lnstring[1][$kk] = str_replace(
'#!#CP#!#',
')', $lnstring[1][$kk]);
11642 if ($kk == $maxkk) {
11643 if ($this->rtl OR $this->tmprtl) {
11644 $tvalue = ltrim($lnstring[1][$kk]);
11646 $tvalue = rtrim($lnstring[1][$kk]);
11649 $tvalue = $lnstring[1][$kk];
11652 $no += substr_count($lnstring[1][$kk], chr(32));
11653 $ns += substr_count($tvalue, chr(32));
11655 if ($this->rtl OR $this->tmprtl) {
11656 $t_x = $this->lMargin - $this->endlinex - (($no - $ns - 1) * $this->GetStringWidth(chr(32)));
11659 $spacewidth = (($tw - $linew + (($no - $ns) * $this->GetStringWidth(chr(32)))) / ($ns?$ns:1)) * $this->k;
11660 $spacewidthu = ($tw - $linew + ($no * $this->GetStringWidth(chr(32)))) / ($ns?$ns:1) / $this->FontSize / $this->k;
11666 $prev_epsposbeg = 0;
11668 while (preg_match(
'/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE, $offset) == 1) {
11669 if ($this->rtl OR $this->tmprtl) {
11670 $spacew = ($spacewidth * ($nsmax - $ns));
11672 $spacew = ($spacewidth * $ns);
11674 $offset = $strpiece[2][1] + strlen($strpiece[2][0]);
11675 $epsposbeg = strpos($pmid,
'q'.$this->epsmarker, $offset);
11676 $epsposend = strpos($pmid, $this->epsmarker.
'Q', $offset) + strlen($this->epsmarker.
'Q');
11677 if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend))
11678 OR (($epsposbeg ===
false) AND ($epsposend > 0) AND ($offset < $epsposend))) {
11680 $trx = sprintf(
'1 0 0 1 %.3F 0 cm', $spacew);
11681 $epsposbeg = strpos($pmid,
'q'.$this->epsmarker, ($prev_epsposbeg - 6));
11682 $pmid_b = substr($pmid, 0, $epsposbeg);
11683 $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
11684 $pmid_e = substr($pmid, $epsposend);
11685 $pmid = $pmid_b.
"\nq\n".$trx.
"\n".$pmid_m.
"\nQ\n".$pmid_e;
11686 $offset = $epsposend;
11689 $prev_epsposbeg = $epsposbeg;
11692 switch ($strpiece[2][0]) {
11698 preg_match(
'/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].
')[\s]('.$strpiece[2][0].
')([\s]*)/x', $pmid, $xmatches);
11699 $currentxpos = $xmatches[1];
11700 if (($strcount <= $maxkk) AND ($strpiece[2][0] ==
'Td')) {
11701 if ($strcount == $maxkk) {
11702 if ($this->rtl OR $this->tmprtl) {
11703 $tvalue = $lnstring[1][$strcount];
11705 $tvalue = rtrim($lnstring[1][$strcount]);
11708 $tvalue = $lnstring[1][$strcount];
11710 $ns += substr_count($tvalue, chr(32));
11713 if ($this->rtl OR $this->tmprtl) {
11714 $spacew = ($spacewidth * ($nsmax - $ns));
11717 $pmid = preg_replace_callback(
'/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].
')[\s]('.$strpiece[2][0].
')([\s]*)/x',
11718 create_function(
'$matches',
'global $spacew;
11719 $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
11720 return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1);
11725 preg_match(
'/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].
')[\s]('.$strpiece[2][0].
')([\s]*)/x', $pmid, $xmatches);
11726 $currentxpos = $xmatches[1];
11728 $pmid = preg_replace_callback(
'/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].
')[\s]('.$strpiece[2][0].
')([\s]*)/x',
11729 create_function(
'$matches',
'global $spacew;
11730 $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
11731 return "".$newx." ".$matches[2]." ".$matches[3]." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1);
11736 preg_match(
'/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].
')[\s]('.$strpiece[2][0].
')([\s]*)/x', $pmid, $xmatches);
11737 $currentxpos = $xmatches[1];
11739 $pmid = preg_replace_callback(
'/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].
')[\s]('.$strpiece[2][0].
')([\s]*)/x',
11740 create_function(
'$matches',
'global $spacew;
11741 $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew));
11742 $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew));
11743 $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew));
11744 return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1);
11749 if (isset($this->PageAnnots[$this->page])) {
11750 foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
11751 if (($pac[
'y'] >= $minstartliney) AND (($pac[
'x'] * $this->k) >= ($currentxpos - $this->feps)) AND (($pac[
'x'] * $this->k) <= ($currentxpos + $this->feps))) {
11752 $this->PageAnnots[$this->page][$pak][
'x'] += ($spacew / $this->k);
11753 $this->PageAnnots[$this->page][$pak][
'w'] += (($spacewidth * $pac[
'numspaces']) / $this->k);
11760 $pmid = str_replace(
'x*#!#*x',
'', $pmid);
11761 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
11763 $spacew = $spacewidthu;
11766 $pmidtemp = preg_replace(
'/[\\\][\(]/x',
'\\#!#OP#!#', $pmidtemp);
11767 $pmidtemp = preg_replace(
'/[\\\][\)]/x',
'\\#!#CP#!#', $pmidtemp);
11768 $pmid = preg_replace_callback(
"/\[\(([^\)]*)\)\]/x",
11769 create_function(
'$matches',
'global $spacew;
11770 $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
11771 $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
11772 return "[(".str_replace(chr(0).chr(32), ") ".(-2830 * $spacew)." (", $matches[1]).")]";'), $pmidtemp);
11773 $this->setPageBuffer($startlinepage, $pstart.
"\n".$pmid.
"\n".$pend);
11774 $endlinepos = strlen($pstart.
"\n".$pmid.
"\n");
11777 $rs = sprintf(
"%.3F Tw", $spacewidth);
11778 $pmid = preg_replace(
"/\[\(/x", $rs.
' [(', $pmid);
11779 $this->setPageBuffer($startlinepage, $pstart.
"\n".$pmid.
"\nBT 0 Tw ET\n".$pend);
11780 $endlinepos = strlen($pstart.
"\n".$pmid.
"\nBT 0 Tw ET\n");
11784 if (($t_x != 0) OR ($yshift < 0)) {
11786 $trx = sprintf(
'1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
11787 $this->setPageBuffer($startlinepage, $pstart.
"\nq\n".$trx.
"\n".$pmid.
"\nQ\n".$pend);
11788 $endlinepos = strlen($pstart.
"\nq\n".$trx.
"\n".$pmid.
"\nQ\n");
11790 if (isset($this->PageAnnots[$this->page])) {
11791 foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
11792 if ($pak >= $pask) {
11793 $this->PageAnnots[$this->page][$pak][
'x'] += $t_x;
11794 $this->PageAnnots[$this->page][$pak][
'y'] -= $yshift;
11798 $this->y -= $yshift;
11802 $this->newline =
false;
11803 $pbrk = $this->checkPageBreak($this->lasth);
11804 $this->SetFont($fontname, $fontstyle, $fontsize);
11806 $this->SetFillColorArray($this->bgcolor);
11811 $startlinepage = $this->page;
11812 if (isset($endlinepos) AND (!$pbrk)) {
11813 $startlinepos = $endlinepos;
11814 unset($endlinepos);
11816 if (isset($this->footerlen[$this->page])) {
11817 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
11819 $this->footerpos[$this->page] = $this->pagelen[$this->page];
11821 $startlinepos = $this->footerpos[$this->page];
11823 $plalign = $lalign;
11824 if (isset($this->PageAnnots[$this->page])) {
11825 $pask = count($this->PageAnnots[$this->page]);
11830 if (isset($opentagpos)) {
11831 unset($opentagpos);
11833 if ($dom[$key][
'tag']) {
11834 if ($dom[$key][
'opening']) {
11835 if ($dom[$key][
'value'] ==
'table') {
11837 $wtmp = $this->x - $this->lMargin;
11839 $wtmp = $this->w - $this->rMargin -
$this->x;
11841 $wtmp -= (2 * $this->cMargin);
11843 if (isset($dom[$key][
'width'])) {
11844 $table_width = $this->getHTMLUnitToUnits($dom[$key][
'width'], $wtmp,
'px');
11846 $table_width = $wtmp;
11850 if (($dom[$key][
'value'] ==
'td') OR ($dom[$key][
'value'] ==
'th')) {
11851 $trid = $dom[
$key][
'parent'];
11852 $table_el = $dom[$trid][
'parent'];
11853 if (!isset($dom[$table_el][
'cols'])) {
11854 $dom[$table_el][
'cols'] = $trid[
'cols'];
11856 $oldmargin = $this->cMargin;
11857 if (isset($dom[($dom[$trid][
'parent'])][
'attribute'][
'cellpadding'])) {
11858 $currentcmargin = $this->getHTMLUnitToUnits($dom[($dom[$trid][
'parent'])][
'attribute'][
'cellpadding'], 1,
'px');
11860 $currentcmargin = 0;
11862 $this->cMargin = $currentcmargin;
11863 if (isset($dom[($dom[$trid][
'parent'])][
'attribute'][
'cellspacing'])) {
11864 $cellspacing = $this->getHTMLUnitToUnits($dom[($dom[$trid][
'parent'])][
'attribute'][
'cellspacing'], 1,
'px');
11869 $cellspacingx = -$cellspacing;
11871 $cellspacingx = $cellspacing;
11873 $colspan = $dom[
$key][
'attribute'][
'colspan'];
11874 $wtmp = ($colspan * ($table_width / $dom[$table_el][
'cols']));
11875 if (isset($dom[$key][
'width'])) {
11876 $cellw = $this->getHTMLUnitToUnits($dom[$key][
'width'], $wtmp,
'px');
11880 if (isset($dom[$key][
'height'])) {
11882 $cellh = $this->getHTMLUnitToUnits($dom[$key][
'height'], 0,
'px');
11886 $cellw -= $cellspacing;
11887 if (isset($dom[$key][
'content'])) {
11888 $cell_content = $dom[
$key][
'content'];
11890 $cell_content =
' ';
11892 $tagtype = $dom[
$key][
'value'];
11894 while (($key < $maxel) AND (!(($dom[$key][
'tag']) AND (!$dom[$key][
'opening']) AND ($dom[$key][
'value'] == $tagtype) AND ($dom[$key][
'parent'] == $parentid)))) {
11898 if (!isset($dom[$trid][
'startpage'])) {
11899 $dom[$trid][
'startpage'] = $this->page;
11901 $this->setPage($dom[$trid][
'startpage']);
11903 if (!isset($dom[$trid][
'starty'])) {
11906 $this->y = $dom[$trid][
'starty'];
11908 if (!isset($dom[$trid][
'startx'])) {
11911 $this->x += ($cellspacingx / 2);
11912 if (isset($dom[$parentid][
'attribute'][
'rowspan'])) {
11913 $rowspan = intval($dom[$parentid][
'attribute'][
'rowspan']);
11918 if (isset($dom[$table_el][
'rowspans'])) {
11920 $rskmax = count($dom[$table_el][
'rowspans']);
11921 while ($rsk < $rskmax) {
11922 $trwsp = $dom[$table_el][
'rowspans'][$rsk];
11923 $rsstartx = $trwsp[
'startx'];
11924 $rsendx = $trwsp[
'endx'];
11926 if ($trwsp[
'startpage'] < $this->page) {
11927 if (($this->rtl) AND ($this->pagedim[$this->page][
'orm'] != $this->pagedim[$trwsp[
'startpage']][
'orm'])) {
11928 $dl = ($this->pagedim[$this->page][
'orm'] - $this->pagedim[$trwsp[
'startpage']][
'orm']);
11931 }
elseif ((!$this->rtl) AND ($this->pagedim[$this->page][
'olm'] != $this->pagedim[$trwsp[
'startpage']][
'olm'])) {
11932 $dl = ($this->pagedim[$this->page][
'olm'] - $this->pagedim[$trwsp[
'startpage']][
'olm']);
11937 if (($trwsp[
'rowspan'] > 0)
11938 AND ($rsstartx > ($this->x - $cellspacing - $currentcmargin - $this->feps))
11939 AND ($rsstartx < ($this->x + $cellspacing + $currentcmargin + $this->feps))
11940 AND (($trwsp['starty'] < ($this->y - $this->feps)) OR ($trwsp['startpage'] < $this->page))) {
11942 $this->x = $rsendx + $cellspacingx;
11943 if (($trwsp[
'rowspan'] == 1)
11944 AND (isset($dom[$trid][
'endy']))
11945 AND (isset($dom[$trid][
'endpage']))
11946 AND ($trwsp[
'endpage'] == $dom[$trid][
'endpage'])) {
11948 $dom[$table_el][
'rowspans'][$rsk][
'endy'] = max($dom[$trid][
'endy'], $trwsp[
'endy']);
11949 $dom[$trid][
'endy'] = $dom[$table_el][
'rowspans'][$rsk][
'endy'];
11958 if ($rowspan > 1) {
11959 if (isset($this->footerlen[$this->page])) {
11960 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
11962 $this->footerpos[$this->page] = $this->pagelen[$this->page];
11964 $trintmrkpos = $this->footerpos[$this->page];
11965 $trsid = array_push($dom[$table_el][
'rowspans'], array(
'trid' => $trid,
'rowspan' => $rowspan,
'mrowspan' => $rowspan,
'colspan' => $colspan,
'startpage' => $this->page,
'startx' => $this->x,
'starty' => $this->y,
'intmrkpos' => $trintmrkpos));
11967 $cellid = array_push($dom[$trid][
'cellpos'], array(
'startx' => $this->x));
11968 if ($rowspan > 1) {
11969 $dom[$trid][
'cellpos'][($cellid - 1)][
'rowspanid'] = ($trsid - 1);
11972 if (isset($dom[$parentid][
'bgcolor']) AND ($dom[$parentid][
'bgcolor'] !==
false)) {
11973 $dom[$trid][
'cellpos'][($cellid - 1)][
'bgcolor'] = $dom[$parentid][
'bgcolor'];
11975 $prevLastH = $this->lasth;
11977 $this->MultiCell($cellw, $cellh, $cell_content,
false, $lalign,
false, 2,
'',
'',
true, 0,
true);
11978 $this->lasth = $prevLastH;
11979 $this->cMargin = $oldmargin;
11980 $dom[$trid][
'cellpos'][($cellid - 1)][
'endx'] = $this->x;
11982 if ($rowspan <= 1) {
11983 if (isset($dom[$trid][
'endy'])) {
11984 if ($this->page == $dom[$trid][
'endpage']) {
11985 $dom[$trid][
'endy'] = max($this->y, $dom[$trid][
'endy']);
11986 }
elseif ($this->page > $dom[$trid][
'endpage']) {
11992 if (isset($dom[$trid][
'endpage'])) {
11993 $dom[$trid][
'endpage'] = max($this->page, $dom[$trid][
'endpage']);
11995 $dom[$trid][
'endpage'] = $this->page;
11999 $dom[$table_el][
'rowspans'][($trsid - 1)][
'endx'] = $this->x;
12000 $dom[$table_el][
'rowspans'][($trsid - 1)][
'endy'] = $this->y;
12001 $dom[$table_el][
'rowspans'][($trsid - 1)][
'endpage'] = $this->page;
12003 if (isset($dom[$table_el][
'rowspans'])) {
12005 foreach ($dom[$table_el][
'rowspans'] as $k => $trwsp) {
12006 if ($trwsp[
'rowspan'] > 0) {
12007 if (isset($dom[$trid][
'endpage'])) {
12008 if ($trwsp[
'endpage'] == $dom[$trid][
'endpage']) {
12009 $dom[$table_el][
'rowspans'][$k][
'endy'] = max($dom[$trid][
'endy'], $trwsp[
'endy']);
12010 }
elseif ($trwsp[
'endpage'] < $dom[$trid][
'endpage']) {
12011 $dom[$table_el][
'rowspans'][$k][
'endy'] = $dom[$trid][
'endy'];
12012 $dom[$table_el][
'rowspans'][$k][
'endpage'] = $dom[$trid][
'endpage'];
12014 $dom[$trid][
'endy'] = $this->pagedim[$dom[$trid][
'endpage']][
'hk'] - $this->pagedim[$dom[$trid][
'endpage']][
'bm'];
12020 $this->x += ($cellspacingx / 2);
12023 if (!isset($opentagpos)) {
12024 if (!$this->InFooter) {
12025 if (isset($this->footerlen[$this->page])) {
12026 $this->footerpos[$this->page] = $this->pagelen[$this->page] - $this->footerlen[$this->page];
12028 $this->footerpos[$this->page] = $this->pagelen[$this->page];
12030 $opentagpos = $this->footerpos[$this->page];
12033 $this->openHTMLTagHandler($dom, $key, $cell);
12037 $this->closeHTMLTagHandler($dom, $key, $cell);
12039 }
elseif (strlen($dom[$key][
'value']) > 0) {
12041 if (!$this->empty_string($this->lispacer)) {
12042 $this->SetFont($pfontname, $pfontstyle, $pfontsize);
12043 $this->lasth = $this->FontSize * $this->cell_height_ratio;
12045 $this->putHtmlListBullet($this->listnum, $this->lispacer, $pfontsize);
12046 $this->SetFont($curfontname, $curfontstyle, $curfontsize);
12047 $this->lasth = $this->FontSize * $this->cell_height_ratio;
12048 if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
12049 $this->y += (($pfontsize - $curfontsize) / $this->k);
12050 $minstartliney = min($this->y, $minstartliney);
12054 $this->htmlvspace = 0;
12055 if ((!$this->premode) AND ($this->rtl OR $this->tmprtl)) {
12057 $len1 = strlen($dom[$key][
'value']);
12058 $lsp = $len1 - strlen(ltrim($dom[$key][
'value']));
12059 $rsp = $len1 - strlen(rtrim($dom[$key][
'value']));
12062 $tmpstr .= substr($dom[$key][
'value'], -$rsp);
12064 $tmpstr .= trim($dom[$key][
'value']);
12066 $tmpstr .= substr($dom[$key][
'value'], 0, $lsp);
12068 $dom[
$key][
'value'] = $tmpstr;
12071 if (!$this->premode) {
12072 if (($this->rtl OR $this->tmprtl)) {
12073 $dom[
$key][
'value'] = rtrim($dom[$key][
'value']);
12075 $dom[
$key][
'value'] = ltrim($dom[$key][
'value']);
12079 $firstblock =
true;
12081 $firstblock =
false;
12084 if (!empty($this->HREF) AND (isset($this->HREF[
'url']))) {
12086 $strrest = $this->addHtmlLink($this->HREF[
'url'], $dom[$key][
'value'], $wfill,
true, $this->HREF[
'color'], $this->HREF[
'style']);
12088 $ctmpmargin = $this->cMargin;
12089 $this->cMargin = 0;
12091 $strrest = $this->Write($this->lasth, $dom[$key][
'value'],
'', $wfill,
'',
false, 0,
true, $firstblock);
12092 $this->cMargin = $ctmpmargin;
12094 if (strlen($strrest) > 0) {
12096 $this->newline =
true;
12099 $this->x -= $this->cMargin;
12101 $this->x += $this->cMargin;
12104 if ($strrest == $dom[$key][
'value']) {
12110 $dom[
$key][
'value'] = ltrim($strrest);
12121 if (isset($startlinex)) {
12122 $yshift = $minstartliney - $startliney;
12123 if (($yshift > 0) OR ($this->page > $startlinepage)) {
12126 if ((isset($plalign) AND ((($plalign ==
'C') OR ($plalign ==
'J') OR (($plalign ==
'R') AND (!$this->rtl)) OR (($plalign ==
'L') AND ($this->rtl))))) OR ($yshift < 0)) {
12128 $linew = abs($this->endlinex - $startlinex);
12129 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
12130 if (isset($opentagpos) AND isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
12131 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
12132 $midpos = min($opentagpos, $this->footerpos[$startlinepage]);
12133 }
elseif (isset($opentagpos)) {
12134 $midpos = $opentagpos;
12135 }
elseif (isset($this->footerlen[$startlinepage]) AND (!$this->InFooter)) {
12136 $this->footerpos[$startlinepage] = $this->pagelen[$startlinepage] - $this->footerlen[$startlinepage];
12137 $midpos = $this->footerpos[$startlinepage];
12142 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
12143 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
12145 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
12150 if ($this->lMargin != $prevlMargin) {
12151 $tw += ($prevlMargin - $this->lMargin);
12153 if ($this->rMargin != $prevrMargin) {
12154 $tw += ($prevrMargin - $this->rMargin);
12156 $mdiff = abs($tw - $linew);
12157 if ($plalign ==
'C') {
12159 $t_x = -($mdiff / 2);
12161 $t_x = ($mdiff / 2);
12163 }
elseif (($plalign ==
'R') AND (!$this->rtl)) {
12166 }
elseif (($plalign ==
'L') AND ($this->rtl)) {
12172 if (($t_x != 0) OR ($yshift < 0)) {
12174 $trx = sprintf(
'1 0 0 1 %.3F %.3F cm', ($t_x * $this->k), ($yshift * $this->k));
12175 $this->setPageBuffer($startlinepage, $pstart.
"\nq\n".$trx.
"\n".$pmid.
"\nQ\n".$pend);
12176 $endlinepos = strlen($pstart.
"\nq\n".$trx.
"\n".$pmid.
"\nQ\n");
12178 if (isset($this->PageAnnots[$this->page])) {
12179 foreach ($this->PageAnnots[$this->page] as $pak => $pac) {
12180 if ($pak >= $pask) {
12181 $this->PageAnnots[$this->page][$pak][
'x'] += $t_x;
12182 $this->PageAnnots[$this->page][$pak][
'y'] -= $yshift;
12186 $this->y -= $yshift;
12190 if ($ln AND (!($cell AND ($dom[$key-1][
'value'] ==
'table')))) {
12191 $this->Ln($this->lasth);
12194 $this->setGraphicVars($gvars);
12195 if ($this->page > $prevPage) {
12196 $this->lMargin = $this->pagedim[$this->page][
'olm'];
12197 $this->rMargin = $this->pagedim[$this->page][
'orm'];
12209 protected function openHTMLTagHandler(&$dom, $key, $cell=
false) {
12211 $parent = $dom[($dom[
$key][
'parent'])];
12212 $firstorlast = ($key == 1);
12214 if (isset($tag[
'attribute'][
'dir'])) {
12215 $this->tmprtl = $tag[
'attribute'][
'dir'] ==
'rtl' ?
'R' :
'L';
12217 $this->tmprtl =
false;
12220 switch($tag[
'value']) {
12224 $dom[
$key][
'rowspans'] = array();
12225 if (!$this->empty_string($dom[$key][
'thead'])) {
12227 $this->thead = $dom[
$key][
'thead'];
12228 if (!isset($this->theadMargins) OR (empty($this->theadMargins))) {
12229 $this->theadMargins = array();
12230 $this->theadMargins[
'cmargin'] = $this->cMargin;
12233 if (isset($tag[
'attribute'][
'cellpadding'])) {
12234 $cp = $this->getHTMLUnitToUnits($tag[
'attribute'][
'cellpadding'], 1,
'px');
12235 $this->oldcMargin = $this->cMargin;
12236 $this->cMargin = $cp;
12238 if (isset($tag[
'attribute'][
'cellspacing'])) {
12239 $cs = $this->getHTMLUnitToUnits($tag[
'attribute'][
'cellspacing'], 1,
'px');
12241 $this->checkPageBreak((2 * $cp) + (2 * $cs) + $this->lasth);
12246 $dom[
$key][
'cellpos'] = array();
12250 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
false);
12251 $this->htmlvspace = 0;
12252 $wtmp = $this->w - $this->lMargin - $this->rMargin;
12253 if ((isset($tag[
'attribute'][
'width'])) AND ($tag[
'attribute'][
'width'] !=
'')) {
12254 $hrWidth = $this->getHTMLUnitToUnits($tag[
'attribute'][
'width'], $wtmp,
'px');
12258 $x = $this->GetX();
12259 $y = $this->GetY();
12260 $prevlinewidth = $this->GetLineWidth();
12261 $this->Line(
$x,
$y,
$x + $hrWidth,
$y);
12262 $this->SetLineWidth($prevlinewidth);
12263 $this->addHTMLVertSpace(1, $cell,
'', !isset($dom[($key + 1)]), $tag[
'value'],
false);
12267 if (array_key_exists(
'href', $tag[
'attribute'])) {
12268 $this->HREF[
'url'] = $tag[
'attribute'][
'href'];
12270 $this->HREF[
'color'] = $this->htmlLinkColorArray;
12271 $this->HREF[
'style'] = $this->htmlLinkFontStyle;
12272 if (array_key_exists(
'style', $tag[
'attribute'])) {
12274 preg_match_all(
'/([^;:\s]*):([^;]*)/', $tag[
'attribute'][
'style'], $style_array, PREG_PATTERN_ORDER);
12276 while (list($id, $name) = each($style_array[1])) {
12277 $name = strtolower($name);
12278 $astyle[
$name] = trim($style_array[2][$id]);
12280 if (isset($astyle[
'color'])) {
12281 $this->HREF[
'color'] = $this->convertHTMLColorToDec($astyle[
'color']);
12283 if (isset($astyle[
'text-decoration'])) {
12284 $this->HREF[
'style'] =
'';
12285 $decors = explode(
' ', strtolower($astyle[
'text-decoration']));
12286 foreach ($decors as $dec) {
12288 if (!$this->empty_string($dec)) {
12289 if ($dec{0} ==
'u') {
12290 $this->HREF[
'style'] .=
'U';
12291 }
elseif ($dec{0} ==
'l') {
12292 $this->HREF[
'style'] .=
'D';
12301 if (isset($tag[
'attribute'][
'src'])) {
12303 if ($tag[
'attribute'][
'src'][0] ==
'/') {
12304 $tag[
'attribute'][
'src'] = $_SERVER[
'DOCUMENT_ROOT'].$tag[
'attribute'][
'src'];
12306 $tag[
'attribute'][
'src'] = urldecode($tag[
'attribute'][
'src']);
12307 $tag[
'attribute'][
'src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag[
'attribute'][
'src']);
12308 if (!isset($tag[
'attribute'][
'width'])) {
12309 $tag[
'attribute'][
'width'] = 0;
12311 if (!isset($tag[
'attribute'][
'height'])) {
12312 $tag[
'attribute'][
'height'] = 0;
12317 $tag[
'attribute'][
'align'] =
'bottom';
12319 switch($tag[
'attribute'][
'align']) {
12337 $fileinfo = pathinfo($tag[
'attribute'][
'src']);
12338 if (isset($fileinfo[
'extension']) AND (!$this->empty_string($fileinfo[
'extension']))) {
12339 $type = strtolower($fileinfo[
'extension']);
12342 $xpos = $this->GetX();
12343 if (isset($dom[($key - 1)]) AND ($dom[($key - 1)][
'value'] ==
' ')) {
12345 $xpos += $this->GetStringWidth(
' ');
12347 $xpos -= $this->GetStringWidth(
' ');
12351 if (isset($this->HREF[
'url']) AND !$this->empty_string($this->HREF[
'url'])) {
12352 $imglink = $this->HREF[
'url'];
12353 if ($imglink{0} ==
'#') {
12355 $page = intval(substr($imglink, 1));
12356 $imglink = $this->AddLink();
12357 $this->SetLink($imglink, 0, $page);
12361 if (isset($tag[
'attribute'][
'border']) AND !empty($tag[
'attribute'][
'border'])) {
12363 $border = $tag[
'attribute'][
'border'];
12366 if (isset($tag[
'attribute'][
'width'])) {
12367 $iw = $this->getHTMLUnitToUnits($tag[
'attribute'][
'width'], 1,
'px',
false);
12370 if (isset($tag[
'attribute'][
'height'])) {
12371 $ih = $this->getHTMLUnitToUnits($tag[
'attribute'][
'height'], 1,
'px',
false);
12374 $this->ImageEps($tag[
'attribute'][
'src'], $xpos, $this->GetY(), $iw, $ih, $imglink,
true, $align,
'', $border);
12376 $this->Image($tag[
'attribute'][
'src'], $xpos, $this->GetY(), $iw, $ih,
'', $imglink, $align,
false, 300,
'',
false,
false, $border);
12384 $this->y = (($this->img_rb_y + $prevy - ($tag[
'fontsize'] / $this->k)) / 2) ;
12388 $this->y = $this->img_rb_y - ($tag[
'fontsize'] / $this->k);
12397 $this->addHTMLVertSpace(0, $cell,
'', $firstorlast, $tag[
'value'],
false);
12401 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
false);
12406 $this->rMargin += $this->listindent;
12408 $this->lMargin += $this->listindent;
12410 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
false);
12415 $this->addHTMLVertSpace(0, $cell,
'', $firstorlast, $tag[
'value'],
false);
12416 $this->htmlvspace = 0;
12418 if ($tag[
'value'] ==
'ol') {
12419 $this->listordered[$this->listnum] =
true;
12421 $this->listordered[$this->listnum] =
false;
12423 if (isset($tag[
'attribute'][
'start'])) {
12424 $this->listcount[$this->listnum] = intval($tag[
'attribute'][
'start']) - 1;
12426 $this->listcount[$this->listnum] = 0;
12429 $this->rMargin += $this->listindent;
12431 $this->lMargin += $this->listindent;
12433 $this->addHTMLVertSpace(0, $cell,
'', $firstorlast, $tag[
'value'],
false);
12434 $this->htmlvspace = 0;
12438 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
false);
12439 if ($this->listordered[$this->listnum]) {
12441 if (isset($parent[
'attribute'][
'type']) AND !$this->empty_string($parent[
'attribute'][
'type'])) {
12442 $this->lispacer = $parent[
'attribute'][
'type'];
12443 }
elseif (isset($parent[
'listtype']) AND !$this->empty_string($parent[
'listtype'])) {
12444 $this->lispacer = $parent[
'listtype'];
12445 }
elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
12446 $this->lispacer = $this->lisymbol;
12448 $this->lispacer =
'#';
12450 ++$this->listcount[$this->listnum];
12451 if (isset($tag[
'attribute'][
'value'])) {
12452 $this->listcount[$this->listnum] = intval($tag[
'attribute'][
'value']);
12456 if (isset($parent[
'attribute'][
'type']) AND !$this->empty_string($parent[
'attribute'][
'type'])) {
12457 $this->lispacer = $parent[
'attribute'][
'type'];
12458 }
elseif (isset($parent[
'listtype']) AND !$this->empty_string($parent[
'listtype'])) {
12459 $this->lispacer = $parent[
'listtype'];
12460 }
elseif (isset($this->lisymbol) AND !$this->empty_string($this->lisymbol)) {
12461 $this->lispacer = $this->lisymbol;
12463 $this->lispacer =
'!';
12468 case 'blockquote': {
12470 $this->rMargin += $this->listindent;
12472 $this->lMargin += $this->listindent;
12474 $this->addHTMLVertSpace(2, $cell,
'', $firstorlast, $tag[
'value'],
false);
12478 $this->Ln(
'', $cell);
12482 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
false);
12486 $this->addHTMLVertSpace(2, $cell,
'', $firstorlast, $tag[
'value'],
false);
12490 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
false);
12491 $this->premode =
true;
12495 $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt) / $this->k));
12499 $this->SetXY($this->GetX(), $this->GetY() + ((0.3 * $this->FontSizePt) / $this->k));
12508 $this->addHTMLVertSpace(1, $cell, ($tag[
'fontsize'] * 1.5) / $this->k, $firstorlast, $tag[
'value'],
false);
12513 if (isset($tag[
'attribute'][
'method'])) {
12514 $tcpdf_method = $tag[
'attribute'][
'method'];
12515 if (method_exists($this, $tcpdf_method)) {
12516 if (isset($tag[
'attribute'][
'params']) AND (!empty($tag[
'attribute'][
'params']))) {
12517 eval(
'$params = array('.$tag[
'attribute'][
'params'].
');');
12518 call_user_func_array(array($this, $tcpdf_method),
$params);
12520 $this->$tcpdf_method();
12522 $this->newline =
true;
12539 protected function closeHTMLTagHandler(&$dom, $key, $cell=
false) {
12541 $parent = $dom[($dom[
$key][
'parent'])];
12542 $firstorlast = ((!isset($dom[($key + 1)])) OR ((!isset($dom[($key + 2)])) AND ($dom[($key + 1)][
'value'] ==
'marker')));
12543 $in_table_head =
false;
12545 switch($tag[
'value']) {
12547 $table_el = $dom[($dom[
$key][
'parent'])][
'parent'];
12548 if(!isset($parent[
'endy'])) {
12549 $dom[($dom[
$key][
'parent'])][
'endy'] = $this->y;
12552 if(!isset($parent[
'endpage'])) {
12553 $dom[($dom[
$key][
'parent'])][
'endpage'] = $this->page;
12554 $parent[
'endpage'] = $this->page;
12557 if (isset($dom[$table_el][
'rowspans'])) {
12558 foreach ($dom[$table_el][
'rowspans'] as $k => $trwsp) {
12559 $dom[$table_el][
'rowspans'][$k][
'rowspan'] -= 1;
12560 if ($dom[$table_el][
'rowspans'][$k][
'rowspan'] == 0) {
12561 if ($dom[$table_el][
'rowspans'][$k][
'endpage'] == $parent[
'endpage']) {
12562 $dom[($dom[
$key][
'parent'])][
'endy'] = max($dom[$table_el][
'rowspans'][$k][
'endy'], $parent[
'endy']);
12563 }
elseif ($dom[$table_el][
'rowspans'][$k][
'endpage'] > $parent[
'endpage']) {
12564 $dom[($dom[
$key][
'parent'])][
'endy'] = $dom[$table_el][
'rowspans'][$k][
'endy'];
12565 $dom[($dom[
$key][
'parent'])][
'endpage'] = $dom[$table_el][
'rowspans'][$k][
'endpage'];
12570 foreach ($dom[$table_el][
'rowspans'] as $k => $trwsp) {
12571 if ($dom[$table_el][
'rowspans'][$k][
'rowspan'] == 0) {
12572 $dom[$table_el][
'rowspans'][$k][
'endpage'] = max($dom[$table_el][
'rowspans'][$k][
'endpage'], $dom[($dom[$key][
'parent'])][
'endpage']);
12573 $dom[($dom[
$key][
'parent'])][
'endpage'] = $dom[$table_el][
'rowspans'][$k][
'endpage'];
12574 $dom[$table_el][
'rowspans'][$k][
'endy'] = max($dom[$table_el][
'rowspans'][$k][
'endy'], $dom[($dom[$key][
'parent'])][
'endy']);
12575 $dom[($dom[
$key][
'parent'])][
'endy'] = $dom[$table_el][
'rowspans'][$k][
'endy'];
12579 foreach ($dom[$table_el][
'rowspans'] as $k => $trwsp) {
12580 if ($dom[$table_el][
'rowspans'][$k][
'rowspan'] == 0) {
12581 $dom[$table_el][
'rowspans'][$k][
'endpage'] = $dom[($dom[
$key][
'parent'])][
'endpage'];
12582 $dom[$table_el][
'rowspans'][$k][
'endy'] = $dom[($dom[
$key][
'parent'])][
'endy'];
12586 $this->setPage($dom[($dom[$key][
'parent'])][
'endpage']);
12587 $this->y = $dom[($dom[
$key][
'parent'])][
'endy'];
12588 if (isset($dom[$table_el][
'attribute'][
'cellspacing'])) {
12589 $cellspacing = $this->getHTMLUnitToUnits($dom[$table_el][
'attribute'][
'cellspacing'], 1,
'px');
12590 $this->y += $cellspacing;
12592 $this->Ln(0, $cell);
12593 $this->x = $parent[
'startx'];
12595 if ($this->page > $parent[
'startpage']) {
12596 if (($this->rtl) AND ($this->pagedim[$this->page][
'orm'] != $this->pagedim[$parent[
'startpage']][
'orm'])) {
12597 $this->x += ($this->pagedim[$this->page][
'orm'] - $this->pagedim[$parent[
'startpage']][
'orm']);
12598 }
elseif ((!$this->rtl) AND ($this->pagedim[$this->page][
'olm'] != $this->pagedim[$parent[
'startpage']][
'olm'])) {
12599 $this->x += ($this->pagedim[$this->page][
'olm'] - $this->pagedim[$parent[
'startpage']][
'olm']);
12606 $in_table_head =
true;
12609 $table_el = $parent;
12610 if ((isset($table_el[
'attribute'][
'border']) AND ($table_el[
'attribute'][
'border'] > 0))
12611 OR (isset($table_el[
'style'][
'border']) AND ($table_el[
'style'][
'border'] > 0))) {
12617 foreach ($dom[($dom[$key][
'parent'])][
'trids'] as $j => $trkey) {
12619 if (isset($dom[($dom[$key][
'parent'])][
'rowspans'])) {
12620 foreach ($dom[($dom[$key][
'parent'])][
'rowspans'] as $k => $trwsp) {
12621 if ($trwsp[
'trid'] == $trkey) {
12622 $dom[($dom[
$key][
'parent'])][
'rowspans'][$k][
'mrowspan'] -= 1;
12624 if (isset($prevtrkey) AND ($trwsp[
'trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0)) {
12625 $dom[($dom[
$key][
'parent'])][
'rowspans'][$k][
'trid'] = $trkey;
12629 if (isset($prevtrkey) AND ($dom[$trkey][
'startpage'] > $dom[$prevtrkey][
'endpage'])) {
12630 $pgendy = $this->pagedim[$dom[$prevtrkey][
'endpage']][
'hk'] - $this->pagedim[$dom[$prevtrkey][
'endpage']][
'bm'];
12631 $dom[$prevtrkey][
'endy'] = $pgendy;
12633 if (isset($dom[($dom[$key][
'parent'])][
'rowspans'])) {
12634 foreach ($dom[($dom[$key][
'parent'])][
'rowspans'] as $k => $trwsp) {
12635 if (($trwsp[
'trid'] == $trkey) AND ($trwsp[
'mrowspan'] == 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
12636 $dom[($dom[
$key][
'parent'])][
'rowspans'][$k][
'endy'] = $pgendy;
12637 $dom[($dom[
$key][
'parent'])][
'rowspans'][$k][
'mrowspan'] = -1;
12642 $prevtrkey = $trkey;
12643 $table_el = $dom[($dom[
$key][
'parent'])];
12646 foreach ($table_el[
'trids'] as $j => $trkey) {
12647 $parent = $dom[$trkey];
12649 foreach ($parent[
'cellpos'] as $k => $cellpos) {
12650 if (isset($cellpos[
'rowspanid']) AND ($cellpos[
'rowspanid'] >= 0)) {
12651 $cellpos[
'startx'] = $table_el[
'rowspans'][($cellpos[
'rowspanid'])][
'startx'];
12652 $cellpos[
'endx'] = $table_el[
'rowspans'][($cellpos[
'rowspanid'])][
'endx'];
12653 $endy = $table_el[
'rowspans'][($cellpos[
'rowspanid'])][
'endy'];
12654 $startpage = $table_el[
'rowspans'][($cellpos[
'rowspanid'])][
'startpage'];
12655 $endpage = $table_el[
'rowspans'][($cellpos[
'rowspanid'])][
'endpage'];
12657 $endy = $parent[
'endy'];
12658 $startpage = $parent[
'startpage'];
12659 $endpage = $parent[
'endpage'];
12661 if ($endpage > $startpage) {
12663 for ($page=$startpage; $page <= $endpage; ++$page) {
12664 $this->setPage($page);
12665 if ($page == $startpage) {
12666 $this->y = $parent[
'starty'];
12667 $ch = $this->getPageHeight() - $parent[
'starty'] - $this->getBreakMargin();
12668 $cborder = $this->getBorderMode($border, $position=
'start');
12669 }
elseif ($page == $endpage) {
12670 $this->y = $this->tMargin;
12671 $ch = $endy - $this->tMargin;
12672 $cborder = $this->getBorderMode($border, $position=
'end');
12674 $this->y = $this->tMargin;
12675 $ch = $this->getPageHeight() - $this->tMargin - $this->getBreakMargin();
12676 $cborder = $this->getBorderMode($border, $position=
'middle');
12678 if (isset($cellpos[
'bgcolor']) AND ($cellpos[
'bgcolor']) !==
false) {
12679 $this->SetFillColorArray($cellpos[
'bgcolor']);
12684 $cw = abs($cellpos[
'endx'] - $cellpos[
'startx']);
12685 $this->x = $cellpos[
'startx'];
12687 if ($page > $startpage) {
12688 if (($this->rtl) AND ($this->pagedim[$page][
'orm'] != $this->pagedim[$startpage][
'orm'])) {
12689 $this->x -= ($this->pagedim[$page][
'orm'] - $this->pagedim[$startpage][
'orm']);
12690 }
elseif ((!$this->rtl) AND ($this->pagedim[$page][
'lm'] != $this->pagedim[$startpage][
'olm'])) {
12691 $this->x += ($this->pagedim[$page][
'olm'] - $this->pagedim[$startpage][
'olm']);
12695 $ccode = $this->FillColor.
"\n".$this->getCellCode(
$cw, $ch,
'', $cborder, 1,
'', $fill,
'', 0,
true);
12696 if ($cborder OR $fill) {
12697 $pagebuff = $this->getPageBuffer($this->page);
12698 $pstart = substr($pagebuff, 0, $this->intmrk[$this->page]);
12699 $pend = substr($pagebuff, $this->intmrk[$this->page]);
12700 $this->setPageBuffer($this->page, $pstart.$ccode.
"\n".$pend);
12701 $this->intmrk[$this->page] += strlen($ccode.
"\n");
12705 $this->setPage($startpage);
12706 if (isset($cellpos[
'bgcolor']) AND ($cellpos[
'bgcolor']) !==
false) {
12707 $this->SetFillColorArray($cellpos[
'bgcolor']);
12712 $this->x = $cellpos[
'startx'];
12713 $this->y = $parent[
'starty'];
12714 $cw = abs($cellpos[
'endx'] - $cellpos[
'startx']);
12715 $ch = $endy - $parent[
'starty'];
12717 $ccode = $this->FillColor.
"\n".$this->getCellCode(
$cw, $ch,
'', $border, 1,
'', $fill,
'', 0,
true);
12718 if ($border OR $fill) {
12719 if (end($this->transfmrk[$this->page]) !==
false) {
12720 $pagemarkkey = key($this->transfmrk[$this->page]);
12721 $pagemark = &$this->transfmrk[$this->page][$pagemarkkey];
12722 }
elseif ($this->InFooter) {
12723 $pagemark = &$this->footerpos[$this->page];
12725 $pagemark = &$this->intmrk[$this->page];
12727 $pagebuff = $this->getPageBuffer($this->page);
12728 $pstart = substr($pagebuff, 0, $pagemark);
12729 $pend = substr($pagebuff, $pagemark);
12730 $this->setPageBuffer($this->page, $pstart.$ccode.
"\n".$pend);
12731 $pagemark += strlen($ccode.
"\n");
12735 if (isset($table_el[
'attribute'][
'cellspacing'])) {
12736 $cellspacing = $this->getHTMLUnitToUnits($table_el[
'attribute'][
'cellspacing'], 1,
'px');
12737 $this->y += $cellspacing;
12739 $this->Ln(0, $cell);
12740 $this->x = $parent[
'startx'];
12741 if ($endpage > $startpage) {
12742 if (($this->rtl) AND ($this->pagedim[$endpage][
'orm'] != $this->pagedim[$startpage][
'orm'])) {
12743 $this->x += ($this->pagedim[$endpage][
'orm'] - $this->pagedim[$startpage][
'orm']);
12744 }
elseif ((!$this->rtl) AND ($this->pagedim[$endpage][
'olm'] != $this->pagedim[$startpage][
'olm'])) {
12745 $this->x += ($this->pagedim[$endpage][
'olm'] - $this->pagedim[$startpage][
'olm']);
12749 if (!$in_table_head) {
12751 if (isset($parent[
'cellpadding'])) {
12752 $this->cMargin = $this->oldcMargin;
12754 $this->lasth = $this->FontSize * $this->cell_height_ratio;
12755 if (isset($this->theadMargins[
'top'])) {
12757 $this->tMargin = $this->theadMargins[
'top'];
12758 $this->pagedim[$this->page][
'tm'] = $this->tMargin;
12762 $this->theadMargins = array();
12771 $this->SetXY($this->GetX(), $this->GetY() + ((0.7 * $parent[
'fontsize']) / $this->k));
12775 $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent[
'fontsize'])/$this->k));
12779 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
true);
12782 case 'blockquote': {
12784 $this->rMargin -= $this->listindent;
12786 $this->lMargin -= $this->listindent;
12788 $this->addHTMLVertSpace(2, $cell,
'', $firstorlast, $tag[
'value'],
true);
12792 $this->addHTMLVertSpace(2, $cell,
'', $firstorlast, $tag[
'value'],
true);
12796 $this->addHTMLVertSpace(1, $cell,
'', $firstorlast, $tag[
'value'],
true);
12797 $this->premode =
false;
12802 if ($this->listnum <= 0) {
12803 $this->listnum = 0;
12804 $this->addHTMLVertSpace(2, $cell,
'', $firstorlast, $tag[
'value'],
true);
12809 $this->lispacer =
'';
12810 $this->addHTMLVertSpace(0, $cell,
'', $firstorlast, $tag[
'value'],
true);
12814 $this->lispacer =
'';
12816 $this->rMargin -= $this->listindent;
12818 $this->lMargin -= $this->listindent;
12820 $this->addHTMLVertSpace(0, $cell,
'', $firstorlast, $tag[
'value'],
true);
12826 $this->lispacer =
'';
12828 $this->rMargin -= $this->listindent;
12830 $this->lMargin -= $this->listindent;
12832 if ($this->listnum <= 0) {
12833 $this->listnum = 0;
12834 $this->addHTMLVertSpace(2, $cell,
'', $firstorlast, $tag[
'value'],
true);
12836 $this->lasth = $this->FontSize * $this->cell_height_ratio;
12840 $this->lispacer =
'';
12841 $this->addHTMLVertSpace(0, $cell,
'', $firstorlast, $tag[
'value'],
true);
12850 $this->addHTMLVertSpace(1, $cell, ($parent[
'fontsize'] * 1.5) / $this->k, $firstorlast, $tag[
'value'],
true);
12857 $this->tmprtl =
false;
12870 protected function addHTMLVertSpace($n, $cell=
false, $h=
'', $firstorlast=
false, $tag=
'', $closing=
false) {
12871 if ($firstorlast) {
12872 $this->Ln(0, $cell);
12873 $this->htmlvspace = 0;
12876 if (isset($this->tagvspaces[$tag][intval($closing)][
'n'])) {
12877 $n = $this->tagvspaces[$tag][intval($closing)][
'n'];
12879 if (isset($this->tagvspaces[$tag][intval($closing)][
'h'])) {
12880 $h = $this->tagvspaces[$tag][intval($closing)][
'h'];
12882 if (is_string($h)) {
12883 $vsize = $n * $this->lasth;
12887 if ($vsize > $this->htmlvspace) {
12888 $this->Ln(($vsize - $this->htmlvspace), $cell);
12889 $this->htmlvspace = $vsize;
12899 public function setLIsymbol($symbol=
'!') {
12900 $symbol = strtolower($symbol);
12910 case 'decimal-leading-zero':
12912 case 'lower-roman':
12914 case 'upper-roman':
12916 case 'lower-alpha':
12917 case 'lower-latin':
12919 case 'upper-alpha':
12920 case 'upper-latin':
12921 case 'lower-greek': {
12922 $this->lisymbol = $symbol;
12926 $this->lisymbol =
'';
12939 public function SetBooklet($booklet=
true, $inner=-1, $outer=-1) {
12940 $this->booklet = $booklet;
12942 $this->lMargin = $inner;
12945 $this->rMargin = $outer;
12955 protected function swapMargins($reverse=
true) {
12958 $mtemp = $this->original_lMargin;
12959 $this->original_lMargin = $this->original_rMargin;
12960 $this->original_rMargin = $mtemp;
12961 $deltam = $this->original_lMargin - $this->original_rMargin;
12962 $this->lMargin += $deltam;
12963 $this->rMargin -= $deltam;
12979 public function setHtmlVSpace($tagvs) {
12980 $this->tagvspaces = $tagvs;
12989 public function setListIndentWidth($width) {
12990 return $this->customlistindent = floatval($width);
12999 public function setOpenCell($isopen) {
13000 $this->opencell = $isopen;
13010 public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle=
'U') {
13011 $this->htmlLinkColorArray = $color;
13012 $this->htmlLinkFontStyle = $fontstyle;
13025 public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit=
'px',
$points=
false) {
13026 $supportedunits = array(
'%',
'em',
'ex',
'px',
'in',
'cm',
'mm',
'pc',
'pt');
13034 if (in_array($defaultunit, $supportedunits)) {
13035 $unit = $defaultunit;
13037 if (is_numeric($htmlval)) {
13038 $value = floatval($htmlval);
13039 }
elseif (preg_match(
'/([0-9\.]+)/', $htmlval, $mnum)) {
13040 $value = floatval($mnum[1]);
13041 if (preg_match(
'/([a-z%]+)/', $htmlval, $munit)) {
13042 if (in_array($munit[1], $supportedunits)) {
13050 $retval = (($value * $refsize) / 100);
13055 $retval = ($value * $refsize);
13059 $retval = $value * ($refsize / 2);
13064 $retval = ($value * $this->dpi) / $k;
13068 $retval = ($value / 2.54 * $this->dpi) / $k;
13072 $retval = ($value / 25.4 * $this->dpi) / $k;
13077 $retval = ($value * 12) / $k;
13081 $retval = $value / $k;
13085 $retval = $this->pixelsToUnits($value);
13099 public function intToRoman($number) {
13101 while ($number >= 1000) {
13105 while ($number >= 900) {
13109 while ($number >= 500) {
13113 while ($number >= 400) {
13117 while ($number >= 100) {
13121 while ($number >= 90) {
13125 while ($number >= 50) {
13129 while ($number >= 40) {
13133 while ($number >= 10) {
13137 while ($number >= 9) {
13141 while ($number >= 5) {
13145 while ($number >= 4) {
13149 while ($number >= 1) {
13164 protected function putHtmlListBullet($listdepth, $listtype=
'',
$size=10) {
13167 $color = $this->fgcolor;
13171 $lspace = $this->GetStringWidth(
' ');
13172 if ($listtype ==
'!') {
13174 $deftypes = array(
'disc',
'circle',
'square');
13175 $listtype = $deftypes[($listdepth - 1) % 3];
13176 }
elseif ($listtype ==
'#') {
13178 $listtype =
'decimal';
13180 switch ($listtype) {
13191 $lspace += (2 * $r);
13193 $this->x = $this->w - $this->x - $lspace;
13195 $this->x -= $lspace;
13197 $this->Circle(($this->x + $r), ($this->y + ($this->lasth / 2)), $r, 0, 360, $fill, array(
'color'=>$color), $color, 8);
13204 $this->x = $this->w - $this->x - $lspace;
13206 $this->x -= $lspace;
13208 $this->Rect($this->x, ($this->y + (($this->lasth -
$l)/ 2)),
$l,
$l,
'F', array(), $color);
13217 $textitem = $this->listcount[$this->listnum];
13220 case 'decimal-leading-zero': {
13221 $textitem = sprintf(
"%02d", $this->listcount[$this->listnum]);
13225 case 'lower-roman': {
13226 $textitem = strtolower($this->intToRoman($this->listcount[$this->listnum]));
13230 case 'upper-roman': {
13231 $textitem = $this->intToRoman($this->listcount[$this->listnum]);
13235 case 'lower-alpha':
13236 case 'lower-latin': {
13237 $textitem = chr(97 + $this->listcount[$this->listnum] - 1);
13241 case 'upper-alpha':
13242 case 'upper-latin': {
13243 $textitem = chr(65 + $this->listcount[$this->listnum] - 1);
13246 case 'lower-greek': {
13247 $textitem = $this->unichr(945 + $this->listcount[$this->listnum] - 1);
13278 $textitem = $this->listcount[$this->listnum];
13281 if (!$this->empty_string($textitem)) {
13284 $textitem =
'.'.$textitem;
13286 $textitem = $textitem.
'.';
13288 $lspace += $this->GetStringWidth($textitem);
13290 $this->x += $lspace;
13292 $this->x -= $lspace;
13294 $this->Write($this->lasth, $textitem,
'',
false,
'',
false, 0,
false);
13297 $this->lispacer =
'';
13306 protected function getGraphicVars() {
13308 'FontFamily' => $this->FontFamily,
13309 'FontStyle' => $this->FontStyle,
13310 'FontSizePt' => $this->FontSizePt,
13311 'rMargin' => $this->rMargin,
13312 'lMargin' => $this->lMargin,
13313 'cMargin' => $this->cMargin,
13314 'LineWidth' => $this->LineWidth,
13315 'linestyleWidth' => $this->linestyleWidth,
13316 'linestyleCap' => $this->linestyleCap,
13317 'linestyleJoin' => $this->linestyleJoin,
13318 'linestyleDash' => $this->linestyleDash,
13319 'DrawColor' => $this->DrawColor,
13320 'FillColor' => $this->FillColor,
13321 'TextColor' => $this->TextColor,
13322 'ColorFlag' => $this->ColorFlag,
13323 'bgcolor' => $this->bgcolor,
13324 'fgcolor' => $this->fgcolor,
13325 'htmlvspace' => $this->htmlvspace,
13326 'lasth' => $this->lasth
13337 protected function setGraphicVars($gvars) {
13338 $this->FontFamily = $gvars[
'FontFamily'];
13339 $this->FontStyle = $gvars[
'FontStyle'];
13340 $this->FontSizePt = $gvars[
'FontSizePt'];
13341 $this->rMargin = $gvars[
'rMargin'];
13342 $this->lMargin = $gvars[
'lMargin'];
13343 $this->cMargin = $gvars[
'cMargin'];
13344 $this->LineWidth = $gvars[
'LineWidth'];
13345 $this->linestyleWidth = $gvars[
'linestyleWidth'];
13346 $this->linestyleCap = $gvars[
'linestyleCap'];
13347 $this->linestyleJoin = $gvars[
'linestyleJoin'];
13348 $this->linestyleDash = $gvars[
'linestyleDash'];
13349 $this->DrawColor = $gvars[
'DrawColor'];
13350 $this->FillColor = $gvars[
'FillColor'];
13351 $this->TextColor = $gvars[
'TextColor'];
13352 $this->ColorFlag = $gvars[
'ColorFlag'];
13353 $this->bgcolor = $gvars[
'bgcolor'];
13354 $this->fgcolor = $gvars[
'fgcolor'];
13355 $this->htmlvspace = $gvars[
'htmlvspace'];
13357 $this->_out(
''.$this->linestyleWidth.
' '.$this->linestyleCap.
' '.$this->linestyleJoin.
' '.$this->linestyleDash.
' '.$this->DrawColor.
' '.$this->FillColor.
'');
13358 if (!$this->empty_string($this->FontFamily)) {
13359 $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
13370 protected function getObjFilename($name) {
13371 return tempnam(K_PATH_CACHE, $name.
'_');
13382 protected function writeDiskCache($filename,
$data, $append=
false) {
13388 $f = @fopen($filename, $fmode);
13390 $this->Error(
'Unable to write cache file: '.$filename);
13396 if (!isset($this->cache_file_lenght[
'_'.$filename])) {
13397 $this->cache_file_lenght[
'_'.$filename] = strlen(
$data);
13399 $this->cache_file_lenght[
'_'.$filename] += strlen(
$data);
13410 protected function readDiskCache($filename) {
13411 return file_get_contents($filename);
13420 protected function setBuffer(
$data) {
13421 $this->bufferlen += strlen(
$data);
13422 if ($this->diskcache) {
13423 if (!isset($this->buffer) OR $this->empty_string($this->buffer)) {
13424 $this->buffer = $this->getObjFilename(
'buffer');
13426 $this->writeDiskCache($this->buffer,
$data,
true);
13428 $this->buffer .=
$data;
13438 protected function getBuffer() {
13439 if ($this->diskcache) {
13440 return $this->readDiskCache($this->buffer);
13442 return $this->buffer;
13454 protected function setPageBuffer($page,
$data, $append=
false) {
13455 if ($this->diskcache) {
13456 if (!isset($this->pages[$page])) {
13457 $this->pages[$page] = $this->getObjFilename(
'page'.$page);
13459 $this->writeDiskCache($this->pages[$page],
$data, $append);
13462 $this->pages[$page] .=
$data;
13464 $this->pages[$page] =
$data;
13467 if ($append AND isset($this->pagelen[$page])) {
13468 $this->pagelen[$page] += strlen(
$data);
13470 $this->pagelen[$page] = strlen(
$data);
13481 protected function getPageBuffer($page) {
13482 if ($this->diskcache) {
13483 return $this->readDiskCache($this->pages[$page]);
13484 }
elseif (isset($this->pages[$page])) {
13485 return $this->pages[$page];
13497 protected function setImageBuffer($image,
$data) {
13498 if ($this->diskcache) {
13499 if (!isset($this->images[$image])) {
13500 $this->images[$image] = $this->getObjFilename(
'image'.$image);
13502 $this->writeDiskCache($this->images[$image], serialize(
$data));
13504 $this->images[$image] =
$data;
13506 if (!in_array($image, $this->imagekeys)) {
13507 $this->imagekeys[] = $image;
13509 ++$this->numimages;
13520 protected function setImageSubBuffer($image, $key,
$data) {
13521 if (!isset($this->images[$image])) {
13522 $this->setImageBuffer($image, array());
13524 if ($this->diskcache) {
13525 $tmpimg = $this->getImageBuffer($image);
13527 $this->writeDiskCache($this->images[$image], serialize($tmpimg));
13540 protected function getImageBuffer($image) {
13541 if ($this->diskcache AND isset($this->images[$image])) {
13542 return unserialize($this->readDiskCache($this->images[$image]));
13543 }
elseif (isset($this->images[$image])) {
13544 return $this->images[$image];
13556 protected function setFontBuffer($font,
$data) {
13557 if ($this->diskcache) {
13558 if (!isset($this->fonts[$font])) {
13559 $this->fonts[$font] = $this->getObjFilename(
'font');
13561 $this->writeDiskCache($this->fonts[$font], serialize(
$data));
13563 $this->fonts[$font] =
$data;
13565 if (!in_array($font, $this->fontkeys)) {
13566 $this->fontkeys[] = $font;
13578 protected function setFontSubBuffer($font, $key,
$data) {
13579 if (!isset($this->fonts[$font])) {
13580 $this->setFontBuffer($font, array());
13582 if ($this->diskcache) {
13583 $tmpfont = $this->getFontBuffer($font);
13585 $this->writeDiskCache($this->fonts[$font], serialize($tmpfont));
13598 protected function getFontBuffer($font) {
13599 if ($this->diskcache AND isset($this->fonts[$font])) {
13600 return unserialize($this->readDiskCache($this->fonts[$font]));
13601 }
elseif (isset($this->fonts[$font])) {
13602 return $this->fonts[$font];
13615 public function movePage($frompage, $topage) {
13616 if (($frompage > $this->numpages) OR ($frompage <= $topage)) {
13619 if ($frompage == $this->page) {
13624 $tmppage = $this->pages[$frompage];
13625 $tmppagedim = $this->pagedim[$frompage];
13626 $tmppagelen = $this->pagelen[$frompage];
13627 $tmpintmrk = $this->intmrk[$frompage];
13628 if (isset($this->footerpos[$frompage])) {
13629 $tmpfooterpos = $this->footerpos[$frompage];
13631 if (isset($this->footerlen[$frompage])) {
13632 $tmpfooterlen = $this->footerlen[$frompage];
13634 if (isset($this->transfmrk[$frompage])) {
13635 $tmptransfmrk = $this->transfmrk[$frompage];
13637 if (isset($this->PageAnnots[$frompage])) {
13638 $tmpannots = $this->PageAnnots[$frompage];
13640 if (isset($this->newpagegroup[$frompage])) {
13641 $tmpnewpagegroup = $this->newpagegroup[$frompage];
13643 for ($i = $frompage; $i > $topage; --$i) {
13646 $this->pages[$i] = $this->pages[$j];
13647 $this->pagedim[$i] = $this->pagedim[$j];
13648 $this->pagelen[$i] = $this->pagelen[$j];
13649 $this->intmrk[$i] = $this->intmrk[$j];
13650 if (isset($this->footerpos[$j])) {
13651 $this->footerpos[$i] = $this->footerpos[$j];
13652 }
elseif (isset($this->footerpos[$i])) {
13653 unset($this->footerpos[$i]);
13655 if (isset($this->footerlen[$j])) {
13656 $this->footerlen[$i] = $this->footerlen[$j];
13657 }
elseif (isset($this->footerlen[$i])) {
13658 unset($this->footerlen[$i]);
13660 if (isset($this->transfmrk[$j])) {
13661 $this->transfmrk[$i] = $this->transfmrk[$j];
13662 }
elseif (isset($this->transfmrk[$i])) {
13663 unset($this->transfmrk[$i]);
13665 if (isset($this->PageAnnots[$j])) {
13666 $this->PageAnnots[$i] = $this->PageAnnots[$j];
13667 }
elseif (isset($this->PageAnnots[$i])) {
13668 unset($this->PageAnnots[$i]);
13670 if (isset($this->newpagegroup[$j])) {
13671 $this->newpagegroup[$i] = $this->newpagegroup[$j];
13672 }
elseif (isset($this->newpagegroup[$i])) {
13673 unset($this->newpagegroup[$i]);
13676 $this->pages[$topage] = $tmppage;
13677 $this->pagedim[$topage] = $tmppagedim;
13678 $this->pagelen[$topage] = $tmppagelen;
13679 $this->intmrk[$topage] = $tmpintmrk;
13680 if (isset($tmpfooterpos)) {
13681 $this->footerpos[$topage] = $tmpfooterpos;
13682 }
elseif (isset($this->footerpos[$topage])) {
13683 unset($this->footerpos[$topage]);
13685 if (isset($tmpfooterlen)) {
13686 $this->footerlen[$topage] = $tmpfooterlen;
13687 }
elseif (isset($this->footerlen[$topage])) {
13688 unset($this->footerlen[$topage]);
13690 if (isset($tmptransfmrk)) {
13691 $this->transfmrk[$topage] = $tmptransfmrk;
13692 }
elseif (isset($this->transfmrk[$topage])) {
13693 unset($this->transfmrk[$topage]);
13695 if (isset($tmpannots)) {
13696 $this->PageAnnots[$topage] = $tmpannots;
13697 }
elseif (isset($this->PageAnnots[$topage])) {
13698 unset($this->PageAnnots[$topage]);
13700 if (isset($tmpnewpagegroup)) {
13701 $this->newpagegroup[$topage] = $tmpnewpagegroup;
13702 }
elseif (isset($this->newpagegroup[$topage])) {
13703 unset($this->newpagegroup[$topage]);
13706 $tmpoutlines = $this->outlines;
13707 foreach ($tmpoutlines as $key => $outline) {
13708 if (($outline[
'p'] >= $topage) AND ($outline[
'p'] < $frompage)) {
13709 $this->outlines[
$key][
'p'] = $outline[
'p'] + 1;
13710 }
elseif ($outline[
'p'] == $frompage) {
13711 $this->outlines[
$key][
'p'] = $topage;
13715 $tmplinks = $this->links;
13716 foreach ($tmplinks as $key => $link) {
13717 if (($link[0] >= $topage) AND ($link[0] < $frompage)) {
13718 $this->links[
$key][0] = $link[0] + 1;
13719 }
elseif ($link[0] == $frompage) {
13720 $this->links[
$key][0] = $topage;
13724 $tmpjavascript = $this->javascript;
13725 global $jfrompage, $jtopage;
13726 $jfrompage = $frompage;
13727 $jtopage = $topage;
13728 $this->javascript = preg_replace_callback(
'/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
13729 create_function(
'$matches',
'global $jfrompage, $jtopage;
13730 $pagenum = intval($matches[3]) + 1;
13731 if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
13732 $newpage = ($pagenum + 1);
13733 } elseif ($pagenum == $jfrompage) {
13734 $newpage = $jtopage;
13736 $newpage = $pagenum;
13739 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
13741 $this->lastPage(
true);
13752 public function deletePage($page) {
13753 if ($page > $this->numpages) {
13757 unset($this->pages[$page]);
13758 unset($this->pagedim[$page]);
13759 unset($this->pagelen[$page]);
13760 unset($this->intmrk[$page]);
13761 if (isset($this->footerpos[$page])) {
13762 unset($this->footerpos[$page]);
13764 if (isset($this->footerlen[$page])) {
13765 unset($this->footerlen[$page]);
13767 if (isset($this->transfmrk[$page])) {
13768 unset($this->transfmrk[$page]);
13770 if (isset($this->PageAnnots[$page])) {
13771 unset($this->PageAnnots[$page]);
13773 if (isset($this->newpagegroup[$page])) {
13774 unset($this->newpagegroup[$page]);
13776 if (isset($this->pageopen[$page])) {
13777 unset($this->pageopen[$page]);
13780 for ($i = $page; $i < $this->numpages; ++$i) {
13783 $this->pages[$i] = $this->pages[$j];
13784 $this->pagedim[$i] = $this->pagedim[$j];
13785 $this->pagelen[$i] = $this->pagelen[$j];
13786 $this->intmrk[$i] = $this->intmrk[$j];
13787 if (isset($this->footerpos[$j])) {
13788 $this->footerpos[$i] = $this->footerpos[$j];
13789 }
elseif (isset($this->footerpos[$i])) {
13790 unset($this->footerpos[$i]);
13792 if (isset($this->footerlen[$j])) {
13793 $this->footerlen[$i] = $this->footerlen[$j];
13794 }
elseif (isset($this->footerlen[$i])) {
13795 unset($this->footerlen[$i]);
13797 if (isset($this->transfmrk[$j])) {
13798 $this->transfmrk[$i] = $this->transfmrk[$j];
13799 }
elseif (isset($this->transfmrk[$i])) {
13800 unset($this->transfmrk[$i]);
13802 if (isset($this->PageAnnots[$j])) {
13803 $this->PageAnnots[$i] = $this->PageAnnots[$j];
13804 }
elseif (isset($this->PageAnnots[$i])) {
13805 unset($this->PageAnnots[$i]);
13807 if (isset($this->newpagegroup[$j])) {
13808 $this->newpagegroup[$i] = $this->newpagegroup[$j];
13809 }
elseif (isset($this->newpagegroup[$i])) {
13810 unset($this->newpagegroup[$i]);
13812 if (isset($this->pageopen[$j])) {
13813 $this->pageopen[$i] = $this->pageopen[$j];
13814 }
elseif (isset($this->pageopen[$i])) {
13815 unset($this->pageopen[$i]);
13819 unset($this->pages[$this->numpages]);
13820 unset($this->pagedim[$this->numpages]);
13821 unset($this->pagelen[$this->numpages]);
13822 unset($this->intmrk[$this->numpages]);
13823 if (isset($this->footerpos[$this->numpages])) {
13824 unset($this->footerpos[$this->numpages]);
13826 if (isset($this->footerlen[$this->numpages])) {
13827 unset($this->footerlen[$this->numpages]);
13829 if (isset($this->transfmrk[$this->numpages])) {
13830 unset($this->transfmrk[$this->numpages]);
13832 if (isset($this->PageAnnots[$this->numpages])) {
13833 unset($this->PageAnnots[$this->numpages]);
13835 if (isset($this->newpagegroup[$this->numpages])) {
13836 unset($this->newpagegroup[$this->numpages]);
13838 if (isset($this->pageopen[$this->numpages])) {
13839 unset($this->pageopen[$this->numpages]);
13842 $this->page = $this->numpages;
13844 $tmpoutlines = $this->outlines;
13845 foreach ($tmpoutlines as $key => $outline) {
13846 if ($outline[
'p'] > $page) {
13847 $this->outlines[
$key][
'p'] = $outline[
'p'] - 1;
13848 }
elseif ($outline[
'p'] == $page) {
13849 unset($this->outlines[$key]);
13853 $tmplinks = $this->links;
13854 foreach ($tmplinks as $key => $link) {
13855 if ($link[0] > $page) {
13856 $this->links[
$key][0] = $link[0] - 1;
13857 }
elseif ($link[0] == $page) {
13858 unset($this->links[$key]);
13862 $tmpjavascript = $this->javascript;
13865 $this->javascript = preg_replace_callback(
'/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
13866 create_function(
'$matches',
'global $jpage;
13867 $pagenum = intval($matches[3]) + 1;
13868 if ($pagenum >= $jpage) {
13869 $newpage = ($pagenum - 1);
13870 } elseif ($pagenum == $jpage) {
13873 $newpage = $pagenum;
13876 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
13878 $this->lastPage(
true);
13892 public function addTOC($page=
'', $numbersfont=
'', $filler=
'.') {
13893 $fontsize = $this->FontSizePt;
13894 $fontfamily = $this->FontFamily;
13895 $fontstyle = $this->FontStyle;
13896 $w = $this->w - $this->lMargin - $this->rMargin;
13897 $spacer = $this->GetStringWidth(
' ') * 4;
13898 $page_first = $this->getPage();
13899 $lmargin = $this->lMargin;
13900 $rmargin = $this->rMargin;
13901 $x_start = $this->GetX();
13902 if ($this->empty_string($numbersfont)) {
13903 $numbersfont = $this->default_monospaced_font;
13905 if ($this->empty_string($filler)) {
13908 if ($this->empty_string($page)) {
13913 foreach ($this->outlines as $key => $outline) {
13921 if ($outline[
'l'] == 0) {
13922 $this->SetFont($fontfamily, $fontstyle.
'B', $fontsize);
13924 $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline[
'l']);
13926 $indent = ($spacer * $outline[
'l']);
13928 $this->rMargin += $indent;
13929 $this->x -= $indent;
13931 $this->lMargin += $indent;
13932 $this->x += $indent;
13934 $link = $this->AddLink();
13935 $this->SetLink($link, 0, $outline[
'p']);
13937 $this->Write(0, $outline[
't'], $link, 0, $aligntext,
false, 0,
false,
false, 0);
13938 $this->SetFont($numbersfont, $fontstyle, $fontsize);
13939 if ($this->empty_string($page)) {
13940 $pagenum = $outline[
'p'];
13943 $pagenum =
'{#'.($outline[
'p']).
'}';
13944 if (($this->CurrentFont[
'type'] ==
'TrueTypeUnicode') OR ($this->CurrentFont[
'type'] ==
'cidfont0')) {
13945 $pagenum =
'{'.$pagenum.
'}';
13948 $numwidth = $this->GetStringWidth($pagenum);
13950 $tw = $this->x - $this->lMargin;
13952 $tw = $this->w - $this->rMargin -
$this->x;
13954 $fw = $tw - $numwidth - $this->GetStringWidth(
' ');
13955 $numfills = floor($fw / $this->GetStringWidth($filler));
13956 if ($numfills > 0) {
13957 $rowfill = str_repeat($filler, $numfills);
13962 $pagenum = $pagenum.$gap.$rowfill.
' ';
13964 $pagenum =
' '.$rowfill.$gap.$pagenum;
13968 $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
13969 $this->SetX($x_start);
13970 $this->lMargin = $lmargin;
13971 $this->rMargin = $rmargin;
13973 $page_last = $this->getPage();
13974 $numpages = $page_last - $page_first + 1;
13975 if (!$this->empty_string($page)) {
13976 for ($p = $page_first; $p <= $page_last; ++$p) {
13978 $temppage = $this->getPageBuffer($p);
13979 for ($n = 1; $n <= $this->numpages; ++
$n) {
13983 $alias_a = $this->_escape($k);
13984 $alias_au = $this->_escape(
'{'.$k.
'}');
13985 if ($this->isunicode) {
13986 $alias_b = $this->_escape($this->UTF8ToLatin1($k));
13987 $alias_bu = $this->_escape($this->UTF8ToLatin1($ku));
13988 $alias_c = $this->_escape($this->utf8StrRev($k,
false, $this->tmprtl));
13989 $alias_cu = $this->_escape($this->utf8StrRev($ku,
false, $this->tmprtl));
13992 $np = $n + $numpages;
13996 $ns = $this->formatTOCPageNumber($np);
13998 $sdiff = strlen($k) - strlen($ns) - 1;
13999 $sdiffu = strlen($ku) - strlen($ns) - 1;
14000 $sfill = str_repeat($filler, $sdiff);
14001 $sfillu = str_repeat($filler, $sdiffu);
14003 $ns = $ns.
' '.$sfill;
14004 $nu = $nu.
' '.$sfillu;
14006 $ns = $sfill.
' '.$ns;
14007 $nu = $sfillu.
' '.$nu;
14009 $nu = $this->UTF8ToUTF16BE($nu,
false);
14010 $temppage = str_replace($alias_au, $nu, $temppage);
14011 if ($this->isunicode) {
14012 $temppage = str_replace($alias_bu, $nu, $temppage);
14013 $temppage = str_replace($alias_cu, $nu, $temppage);
14014 $temppage = str_replace($alias_b, $ns, $temppage);
14015 $temppage = str_replace($alias_c, $ns, $temppage);
14017 $temppage = str_replace($alias_a, $ns, $temppage);
14020 $this->setPageBuffer($p, $temppage);
14023 for ($i = 0; $i < $numpages; ++$i) {
14024 $this->movePage($page_last, $page);
14027 $this->SetFont($fontfamily, $fontstyle, $fontsize);
14035 public function startTransaction() {
14036 if (isset($this->objcopy)) {
14038 $this->commitTransaction();
14041 $this->objcopy = $this->objclone($this);
14049 public function commitTransaction() {
14050 if (isset($this->objcopy)) {
14051 $this->objcopy->_destroy(
true,
true);
14052 unset($this->objcopy);
14062 public function rollbackTransaction() {
14063 if (isset($this->objcopy)) {
14064 if (isset($this->objcopy->diskcache) AND $this->objcopy->diskcache) {
14066 foreach ($this->objcopy->cache_file_lenght as $file => $lenght) {
14067 $file = substr($file, 1);
14068 $handle = fopen($file,
'r+');
14069 ftruncate($handle, $lenght);
14072 $this->_destroy(
true,
true);
14073 return $this->objcopy;
14085 public function objclone($object) {
14086 return @clone($object);
14096 public function empty_string($str) {
14097 return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));