2 //============================================================+
3 // File name : tcpdf.php
6 // Last Update : 2019-09-20
7 // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
8 // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
9 // -------------------------------------------------------------------
10 // Copyright (C) 2002-2019 Nicola Asuni - Tecnick.com LTD
12 // This file is part of TCPDF software library.
14 // TCPDF is free software: you can redistribute it and/or modify it
15 // under the terms of the GNU Lesser General Public License as
16 // published by the Free Software Foundation, either version 3 of the
17 // License, or (at your option) any later version.
19 // TCPDF is distributed in the hope that it will be useful, but
20 // WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 // See the GNU Lesser General Public License for more details.
24 // You should have received a copy of the License
25 // along with TCPDF. If not, see
26 // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
28 // See LICENSE.TXT file for more information.
29 // -------------------------------------------------------------------
32 // This is a PHP class for generating PDF documents without requiring external extensions.
35 // This class was originally derived in 2002 from the Public
36 // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
37 // but now is almost entirely rewritten and contains thousands of
38 // new lines of code and hundreds new features.
41 // * no external libraries are required for the basic functions;
42 // * all standard page formats, custom page formats, custom margins and units of measure;
43 // * UTF-8 Unicode and Right-To-Left languages;
44 // * TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;
46 // * methods to publish some XHTML + CSS code, Javascript and Forms;
47 // * images, graphic (geometric figures) and transformation methods;
48 // * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImageMagick (http://www.imagemagick.org/www/formats.html)
49 // * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
50 // * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
51 // * automatic page header and footer management;
52 // * document encryption up to 256 bit and digital signature certifications;
53 // * transactions to UNDO commands;
54 // * PDF annotations, including links, text and file attachments;
55 // * text rendering modes (fill, stroke and clipping);
56 // * multiple columns mode;
57 // * no-write page regions;
58 // * bookmarks, named destinations and table of content;
59 // * text hyphenation;
60 // * text stretching and spacing (tracking);
61 // * automatic page break, line break and text alignments including justification;
62 // * automatic page numbering and page groups;
63 // * move and delete pages;
64 // * page compression (requires php-zlib extension);
65 // * XOBject Templates;
66 // * Layers and object visibility.
68 //============================================================+
72 * This is a PHP class for generating PDF documents without requiring external extensions.<br>
73 * TCPDF project (http://www.tcpdf.org) was originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
74 * <h3>TCPDF main features are:</h3>
76 * <li>no external libraries are required for the basic functions;</li>
77 * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
78 * <li>UTF-8 Unicode and Right-To-Left languages;</li>
79 * <li>TrueTypeUnicode, TrueType, Type1 and CID-0 fonts;</li>
80 * <li>font subsetting;</li>
81 * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
82 * <li>images, graphic (geometric figures) and transformation methods;
83 * <li>supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImageMagick (http://www.imagemagick.org/www/formats.html)</li>
84 * <li>1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;</li>
85 * <li>JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
86 * <li>automatic page header and footer management;</li>
87 * <li>document encryption up to 256 bit and digital signature certifications;</li>
88 * <li>transactions to UNDO commands;</li>
89 * <li>PDF annotations, including links, text and file attachments;</li>
90 * <li>text rendering modes (fill, stroke and clipping);</li>
91 * <li>multiple columns mode;</li>
92 * <li>no-write page regions;</li>
93 * <li>bookmarks, named destinations and table of content;</li>
94 * <li>text hyphenation;</li>
95 * <li>text stretching and spacing (tracking);</li>
96 * <li>automatic page break, line break and text alignments including justification;</li>
97 * <li>automatic page numbering and page groups;</li>
98 * <li>move and delete pages;</li>
99 * <li>page compression (requires php-zlib extension);</li>
100 * <li>XOBject Templates;</li>
101 * <li>Layers and object visibility;</li>
102 * <li>PDF/A-1b support.</li>
104 * Tools to encode your unicode fonts are on fonts/utils directory.</p>
105 * @package com.tecnick.tcpdf
106 * @author Nicola Asuni
110 // TCPDF configuration
111 require_once(dirname(__FILE__
).'/tcpdf_autoconfig.php');
112 // TCPDF static font methods and data
113 require_once(dirname(__FILE__
).'/include/tcpdf_font_data.php');
114 // TCPDF static font methods and data
115 require_once(dirname(__FILE__
).'/include/tcpdf_fonts.php');
116 // TCPDF static color methods and data
117 require_once(dirname(__FILE__
).'/include/tcpdf_colors.php');
118 // TCPDF static image methods and data
119 require_once(dirname(__FILE__
).'/include/tcpdf_images.php');
120 // TCPDF static methods and data
121 require_once(dirname(__FILE__
).'/include/tcpdf_static.php');
123 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127 * PHP class for generating PDF documents without requiring external extensions.
128 * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
129 * @package com.tecnick.tcpdf
130 * @brief PHP class for generating PDF documents without requiring external extensions.
132 * @author Nicola Asuni - info@tecnick.com
133 * @IgnoreAnnotation("protected")
134 * @IgnoreAnnotation("public")
135 * @IgnoreAnnotation("pre")
139 // Protected properties
142 * Current page number.
148 * Current object number.
154 * Array of object offsets.
157 protected $offsets = array();
160 * Array of object IDs for each page.
163 protected $pageobjects = array();
166 * Buffer holding in-memory PDF.
172 * Array containing pages.
175 protected $pages = array();
178 * Current document state.
190 * Current page orientation (P = Portrait, L = Landscape).
193 protected $CurOrientation;
199 protected $pagedim = array();
202 * Scale factor (number of points in user unit).
208 * Width of page format in points.
214 * Height of page format in points.
220 * Current width of page in points.
226 * Current height of page in points.
232 * Current width of page in user unit.
238 * Current height of page in user unit.
256 * Cell left margin (used by regions).
262 * Cell right margin (used by regions).
280 * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
281 * @since 5.9.000 (2010-10-03)
284 protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
287 * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
288 * @since 5.9.000 (2010-10-04)
291 protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
294 * Current horizontal position in user unit for cell positioning.
300 * Current vertical position in user unit for cell positioning.
306 * Height of last cell printed.
312 * Line width in user unit.
315 protected $LineWidth;
318 * Array of standard font names.
321 protected $CoreFonts;
324 * Array of used fonts.
327 protected $fonts = array();
330 * Array of font files.
333 protected $FontFiles = array();
336 * Array of encoding differences.
339 protected $diffs = array();
342 * Array of used images.
345 protected $images = array();
348 * Depth of the svg tag, to keep track if the svg tag is a subtag or the root tag.
351 protected $svg_tag_depth = 0;
354 * Array of Annotations in pages.
357 protected $PageAnnots = array();
360 * Array of internal links.
363 protected $links = array();
366 * Current font family.
369 protected $FontFamily;
372 * Current font style.
375 protected $FontStyle;
378 * Current font ascent (distance between font top and baseline).
380 * @since 2.8.000 (2007-03-29)
382 protected $FontAscent;
385 * Current font descent (distance between font bottom and baseline).
387 * @since 2.8.000 (2007-03-29)
389 protected $FontDescent;
395 protected $underline;
407 protected $CurrentFont;
410 * Current font size in points.
413 protected $FontSizePt;
416 * Current font size in user unit.
422 * Commands for drawing color.
425 protected $DrawColor;
428 * Commands for filling color.
431 protected $FillColor;
434 * Commands for text color.
437 protected $TextColor;
440 * Indicates whether fill and text colors are different.
443 protected $ColorFlag;
446 * Automatic page breaking.
449 protected $AutoPageBreak;
452 * Threshold used to trigger page breaks.
455 protected $PageBreakTrigger;
458 * Flag set when processing page header.
461 protected $InHeader = false;
464 * Flag set when processing page footer.
467 protected $InFooter = false;
476 * Layout display mode.
479 protected $LayoutMode;
482 * If true set the document information dictionary in Unicode.
485 protected $docinfounicode = true;
491 protected $title = '';
497 protected $subject = '';
503 protected $author = '';
509 protected $keywords = '';
515 protected $creator = '';
518 * Starting page number.
521 protected $starting_page_number = 1;
524 * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
526 * @author Nicola Asuni
532 * The right-bottom corner Y coordinate of last inserted image.
534 * @author Nicola Asuni
540 * Adjusting factor to convert pixels to user units.
542 * @author Nicola Asuni
545 protected $imgscale = 1;
548 * Boolean flag set to true when the input text is unicode (require unicode fonts).
550 * @author Nicola Asuni
553 protected $isunicode = false;
560 protected $PDFVersion = '1.7';
563 * ID of the stored default header template (-1 = not set).
566 protected $header_xobjid = false;
569 * If true reset the Header Xobject template at each page
572 protected $header_xobj_autoreset = false;
575 * Minimum distance between header and top page margin.
578 protected $header_margin;
581 * Minimum distance between footer and bottom page margin.
584 protected $footer_margin;
587 * Original left margin value.
589 * @since 1.53.0.TC013
591 protected $original_lMargin;
594 * Original right margin value.
596 * @since 1.53.0.TC013
598 protected $original_rMargin;
601 * Default font used on page header.
604 protected $header_font;
607 * Default font used on page footer.
610 protected $footer_font;
613 * Language templates.
619 * Barcode to print on page footer (only if set).
622 protected $barcode = false;
625 * Boolean flag to print/hide page header.
628 protected $print_header = true;
631 * Boolean flag to print/hide page footer.
634 protected $print_footer = true;
640 protected $header_logo = '';
643 * Width of header image logo in user units.
646 protected $header_logo_width = 30;
649 * Title to be printed on default page header.
652 protected $header_title = '';
655 * String to pring on page header after title.
658 protected $header_string = '';
661 * Color for header text (RGB array).
662 * @since 5.9.174 (2012-07-25)
665 protected $header_text_color = array(0,0,0);
668 * Color for header line (RGB array).
669 * @since 5.9.174 (2012-07-25)
672 protected $header_line_color = array(0,0,0);
675 * Color for footer text (RGB array).
676 * @since 5.9.174 (2012-07-25)
679 protected $footer_text_color = array(0,0,0);
682 * Color for footer line (RGB array).
683 * @since 5.9.174 (2012-07-25)
686 protected $footer_line_color = array(0,0,0);
689 * Text shadow data array.
690 * @since 5.9.174 (2012-07-25)
693 protected $txtshadow = array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal');
696 * Default number of columns for html table.
699 protected $default_table_columns = 4;
701 // variables for html parser
704 * HTML PARSER: array to store current link and rendering styles.
707 protected $HREF = array();
710 * List of available fonts on filesystem.
713 protected $fontlist = array();
716 * Current foreground color.
722 * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
725 protected $listordered = array();
728 * HTML PARSER: array count list items on nested lists.
731 protected $listcount = array();
734 * HTML PARSER: current list nesting level.
737 protected $listnum = 0;
740 * HTML PARSER: indent amount for lists.
743 protected $listindent = 0;
746 * HTML PARSER: current list indententation level.
749 protected $listindentlevel = 0;
752 * Current background color.
758 * Temporary font size in points.
761 protected $tempfontsize = 10;
764 * Spacer string for LI tags.
767 protected $lispacer = '';
772 * @since 1.53.0.TC010
774 protected $encoding = 'UTF-8';
777 * Boolean flag to indicate if the document language is Right-To-Left.
781 protected $rtl = false;
784 * Boolean flag used to force RTL or LTR string direction.
788 protected $tmprtl = false;
790 // --- Variables used for document encryption:
793 * IBoolean flag indicating whether document is protected.
795 * @since 2.0.000 (2008-01-02)
797 protected $encrypted;
800 * Array containing encryption settings.
802 * @since 5.0.005 (2010-05-11)
804 protected $encryptdata = array();
807 * Last RC4 key encrypted (cached for optimisation).
809 * @since 2.0.000 (2008-01-02)
811 protected $last_enc_key;
814 * Last RC4 computed key.
816 * @since 2.0.000 (2008-01-02)
818 protected $last_enc_key_c;
821 * File ID (used on document trailer).
823 * @since 5.0.005 (2010-05-12)
830 * Outlines for bookmark.
832 * @since 2.1.002 (2008-02-12)
834 protected $outlines = array();
837 * Outline root for bookmark.
839 * @since 2.1.002 (2008-02-12)
841 protected $OutlineRoot;
843 // --- javascript and form ---
848 * @since 2.1.002 (2008-02-12)
850 protected $javascript = '';
853 * Javascript counter.
855 * @since 2.1.002 (2008-02-12)
862 * @since 2.8.000 (2008-03-19)
864 protected $linethrough;
867 * Array with additional document-wide usage rights for the document.
869 * @since 5.8.014 (2010-08-23)
871 protected $ur = array();
874 * DPI (Dot Per Inch) Document Resolution (do not change).
876 * @since 3.0.000 (2008-03-27)
881 * Array of page numbers were a new page group was started (the page numbers are the keys of the array).
883 * @since 3.0.000 (2008-03-27)
885 protected $newpagegroup = array();
888 * Array that contains the number of pages in each page group.
890 * @since 3.0.000 (2008-03-27)
892 protected $pagegroups = array();
895 * Current page group number.
897 * @since 3.0.000 (2008-03-27)
899 protected $currpagegroup = 0;
902 * Array of transparency objects and parameters.
904 * @since 3.0.000 (2008-03-27)
906 protected $extgstates;
909 * Set the default JPEG compression quality (1-100).
911 * @since 3.0.000 (2008-03-27)
913 protected $jpeg_quality;
916 * Default cell height ratio.
918 * @since 3.0.014 (2008-05-23)
920 protected $cell_height_ratio = K_CELL_HEIGHT_RATIO
;
923 * PDF viewer preferences.
925 * @since 3.1.000 (2008-06-09)
927 protected $viewer_preferences;
930 * A name object specifying how the document should be displayed when opened.
932 * @since 3.1.000 (2008-06-09)
937 * Array for storing gradient information.
939 * @since 3.1.000 (2008-06-09)
941 protected $gradients = array();
944 * Array used to store positions inside the pages buffer (keys are the page numbers).
946 * @since 3.2.000 (2008-06-26)
948 protected $intmrk = array();
951 * Array used to store positions inside the pages buffer (keys are the page numbers).
953 * @since 5.7.000 (2010-08-03)
955 protected $bordermrk = array();
958 * Array used to store page positions to track empty pages (keys are the page numbers).
960 * @since 5.8.007 (2010-08-18)
962 protected $emptypagemrk = array();
965 * Array used to store content positions inside the pages buffer (keys are the page numbers).
967 * @since 4.6.021 (2009-07-20)
969 protected $cntmrk = array();
972 * Array used to store footer positions of each page.
974 * @since 3.2.000 (2008-07-01)
976 protected $footerpos = array();
979 * Array used to store footer length of each page.
981 * @since 4.0.014 (2008-07-29)
983 protected $footerlen = array();
986 * Boolean flag to indicate if a new line is created.
988 * @since 3.2.000 (2008-07-01)
990 protected $newline = true;
993 * End position of the latest inserted line.
995 * @since 3.2.000 (2008-07-01)
997 protected $endlinex = 0;
1000 * PDF string for width value of the last line.
1002 * @since 4.0.006 (2008-07-16)
1004 protected $linestyleWidth = '';
1007 * PDF string for CAP value of the last line.
1009 * @since 4.0.006 (2008-07-16)
1011 protected $linestyleCap = '0 J';
1014 * PDF string for join value of the last line.
1016 * @since 4.0.006 (2008-07-16)
1018 protected $linestyleJoin = '0 j';
1021 * PDF string for dash value of the last line.
1023 * @since 4.0.006 (2008-07-16)
1025 protected $linestyleDash = '[] 0 d';
1028 * Boolean flag to indicate if marked-content sequence is open.
1030 * @since 4.0.013 (2008-07-28)
1032 protected $openMarkedContent = false;
1035 * Count the latest inserted vertical spaces on HTML.
1037 * @since 4.0.021 (2008-08-24)
1039 protected $htmlvspace = 0;
1042 * Array of Spot colors.
1044 * @since 4.0.024 (2008-09-12)
1046 protected $spot_colors = array();
1049 * Symbol used for HTML unordered list items.
1051 * @since 4.0.028 (2008-09-26)
1053 protected $lisymbol = '';
1056 * String used to mark the beginning and end of EPS image blocks.
1058 * @since 4.1.000 (2008-10-18)
1060 protected $epsmarker = 'x#!#EPS#!#x';
1063 * Array of transformation matrix.
1065 * @since 4.2.000 (2008-10-29)
1067 protected $transfmatrix = array();
1070 * Current key for transformation matrix.
1072 * @since 4.8.005 (2009-09-17)
1074 protected $transfmatrix_key = 0;
1077 * Booklet mode for double-sided pages.
1079 * @since 4.2.000 (2008-10-29)
1081 protected $booklet = false;
1084 * Epsilon value used for float calculations.
1086 * @since 4.2.000 (2008-10-29)
1088 protected $feps = 0.005;
1091 * Array used for custom vertical spaces for HTML tags.
1093 * @since 4.2.001 (2008-10-30)
1095 protected $tagvspaces = array();
1098 * HTML PARSER: custom indent amount for lists. Negative value means disabled.
1100 * @since 4.2.007 (2008-11-12)
1102 protected $customlistindent = -1;
1105 * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
1107 * @since 4.2.010 (2008-11-14)
1109 protected $opencell = true;
1112 * Array of files to embedd.
1114 * @since 4.4.000 (2008-12-07)
1116 protected $embeddedfiles = array();
1119 * Boolean flag to indicate if we are inside a PRE tag.
1121 * @since 4.4.001 (2008-12-08)
1123 protected $premode = false;
1126 * Array used to store positions of graphics transformation blocks inside the page buffer.
1127 * keys are the page numbers
1129 * @since 4.4.002 (2008-12-09)
1131 protected $transfmrk = array();
1134 * Default color for html links.
1136 * @since 4.4.003 (2008-12-09)
1138 protected $htmlLinkColorArray = array(0, 0, 255);
1141 * Default font style to add to html links.
1143 * @since 4.4.003 (2008-12-09)
1145 protected $htmlLinkFontStyle = 'U';
1148 * Counts the number of pages.
1150 * @since 4.5.000 (2008-12-31)
1152 protected $numpages = 0;
1155 * Array containing page lengths in bytes.
1157 * @since 4.5.000 (2008-12-31)
1159 protected $pagelen = array();
1162 * Counts the number of pages.
1164 * @since 4.5.000 (2008-12-31)
1166 protected $numimages = 0;
1169 * Store the image keys.
1171 * @since 4.5.000 (2008-12-31)
1173 protected $imagekeys = array();
1176 * Length of the buffer in bytes.
1178 * @since 4.5.000 (2008-12-31)
1180 protected $bufferlen = 0;
1183 * Counts the number of fonts.
1185 * @since 4.5.000 (2009-01-02)
1187 protected $numfonts = 0;
1190 * Store the font keys.
1192 * @since 4.5.000 (2009-01-02)
1194 protected $fontkeys = array();
1197 * Store the font object IDs.
1199 * @since 4.8.001 (2009-09-09)
1201 protected $font_obj_ids = array();
1204 * Store the fage status (true when opened, false when closed).
1206 * @since 4.5.000 (2009-01-02)
1208 protected $pageopen = array();
1211 * Default monospace font.
1213 * @since 4.5.025 (2009-03-10)
1215 protected $default_monospaced_font = 'courier';
1218 * Cloned copy of the current class object.
1220 * @since 4.5.029 (2009-03-19)
1225 * Array used to store the lengths of cache files.
1227 * @since 4.5.029 (2009-03-19)
1229 protected $cache_file_length = array();
1232 * Table header content to be repeated on each new page.
1234 * @since 4.5.030 (2009-03-20)
1236 protected $thead = '';
1239 * Margins used for table header.
1241 * @since 4.5.030 (2009-03-20)
1243 protected $theadMargins = array();
1246 * Boolean flag to enable document digital signature.
1248 * @since 4.6.005 (2009-04-24)
1250 protected $sign = false;
1253 * Digital signature data.
1255 * @since 4.6.005 (2009-04-24)
1257 protected $signature_data = array();
1260 * Digital signature max length.
1262 * @since 4.6.005 (2009-04-24)
1264 protected $signature_max_length = 11742;
1267 * Data for digital signature appearance.
1269 * @since 5.3.011 (2010-06-16)
1271 protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
1274 * Array of empty digital signature appearances.
1276 * @since 5.9.101 (2011-07-06)
1278 protected $empty_signature_appearance = array();
1281 * Boolean flag to enable document timestamping with TSA.
1283 * @since 6.0.085 (2014-06-19)
1285 protected $tsa_timestamp = false;
1288 * Timestamping data.
1290 * @since 6.0.085 (2014-06-19)
1292 protected $tsa_data = array();
1295 * Regular expression used to find blank characters (required for word-wrapping).
1297 * @since 4.6.006 (2009-04-28)
1299 protected $re_spaces = '/[^\S\xa0]/';
1302 * Array of $re_spaces parts.
1304 * @since 5.5.011 (2010-07-09)
1306 protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
1309 * Digital signature object ID.
1311 * @since 4.6.022 (2009-06-23)
1313 protected $sig_obj_id = 0;
1316 * ID of page objects.
1318 * @since 4.7.000 (2009-08-29)
1320 protected $page_obj_id = array();
1323 * List of form annotations IDs.
1325 * @since 4.8.000 (2009-09-07)
1327 protected $form_obj_id = array();
1330 * Deafult Javascript field properties. Possible values are described on official Javascript for Acrobat API reference. Annotation options can be directly specified using the 'aopt' entry.
1332 * @since 4.8.000 (2009-09-07)
1334 protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
1337 * Javascript objects array.
1339 * @since 4.8.000 (2009-09-07)
1341 protected $js_objects = array();
1344 * Current form action (used during XHTML rendering).
1346 * @since 4.8.000 (2009-09-07)
1348 protected $form_action = '';
1351 * Current form encryption type (used during XHTML rendering).
1353 * @since 4.8.000 (2009-09-07)
1355 protected $form_enctype = 'application/x-www-form-urlencoded';
1358 * Current method to submit forms.
1360 * @since 4.8.000 (2009-09-07)
1362 protected $form_mode = 'post';
1365 * List of fonts used on form fields (fontname => fontkey).
1367 * @since 4.8.001 (2009-09-09)
1369 protected $annotation_fonts = array();
1372 * List of radio buttons parent objects.
1374 * @since 4.8.001 (2009-09-09)
1376 protected $radiobutton_groups = array();
1379 * List of radio group objects IDs.
1381 * @since 4.8.001 (2009-09-09)
1383 protected $radio_groups = array();
1386 * Text indentation value (used for text-indent CSS attribute).
1388 * @since 4.8.006 (2009-09-23)
1390 protected $textindent = 0;
1393 * Store page number when startTransaction() is called.
1395 * @since 4.8.006 (2009-09-23)
1397 protected $start_transaction_page = 0;
1400 * Store Y position when startTransaction() is called.
1402 * @since 4.9.001 (2010-03-28)
1404 protected $start_transaction_y = 0;
1407 * True when we are printing the thead section on a new page.
1409 * @since 4.8.027 (2010-01-25)
1411 protected $inthead = false;
1414 * Array of column measures (width, space, starting Y position).
1416 * @since 4.9.001 (2010-03-28)
1418 protected $columns = array();
1423 * @since 4.9.001 (2010-03-28)
1425 protected $num_columns = 1;
1428 * Current column number.
1430 * @since 4.9.001 (2010-03-28)
1432 protected $current_column = 0;
1435 * Starting page for columns.
1437 * @since 4.9.001 (2010-03-28)
1439 protected $column_start_page = 0;
1442 * Maximum page and column selected.
1444 * @since 5.8.000 (2010-08-11)
1446 protected $maxselcol = array('page' => 0, 'column' => 0);
1449 * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
1451 * @since 5.8.000 (2010-08-11)
1453 protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
1456 * Text rendering mode: 0 = Fill text; 1 = Stroke text; 2 = Fill, then stroke text; 3 = Neither fill nor stroke text (invisible); 4 = Fill text and add to path for clipping; 5 = Stroke text and add to path for clipping; 6 = Fill, then stroke text and add to path for clipping; 7 = Add text to path for clipping.
1458 * @since 4.9.008 (2010-04-03)
1460 protected $textrendermode = 0;
1463 * Text stroke width in doc units.
1465 * @since 4.9.008 (2010-04-03)
1467 protected $textstrokewidth = 0;
1470 * Current stroke color.
1472 * @since 4.9.008 (2010-04-03)
1474 protected $strokecolor;
1477 * Default unit of measure for document.
1479 * @since 5.0.000 (2010-04-22)
1481 protected $pdfunit = 'mm';
1484 * Boolean flag true when we are on TOC (Table Of Content) page.
1487 protected $tocpage = false;
1490 * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
1492 * @since 5.0.000 (2010-04-26)
1494 protected $rasterize_vector_images = false;
1497 * Boolean flag: if true enables font subsetting by default.
1499 * @since 5.3.002 (2010-06-07)
1501 protected $font_subsetting = true;
1504 * Array of default graphic settings.
1506 * @since 5.5.008 (2010-07-02)
1508 protected $default_graphic_vars = array();
1511 * Array of XObjects.
1513 * @since 5.8.014 (2010-08-23)
1515 protected $xobjects = array();
1518 * Boolean value true when we are inside an XObject.
1520 * @since 5.8.017 (2010-08-24)
1522 protected $inxobj = false;
1525 * Current XObject ID.
1527 * @since 5.8.017 (2010-08-24)
1529 protected $xobjid = '';
1532 * Percentage of character stretching.
1534 * @since 5.9.000 (2010-09-29)
1536 protected $font_stretching = 100;
1539 * Increases or decreases the space between characters in a text by the specified amount (tracking).
1541 * @since 5.9.000 (2010-09-29)
1543 protected $font_spacing = 0;
1546 * Array of no-write regions.
1547 * ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right)
1549 * @since 5.9.003 (2010-10-14)
1551 protected $page_regions = array();
1554 * Boolean value true when page region check is active.
1557 protected $check_page_regions = true;
1560 * Array of PDF layers data.
1562 * @since 5.9.102 (2011-07-13)
1564 protected $pdflayers = array();
1567 * A dictionary of names and corresponding destinations (Dests key on document Catalog).
1569 * @since 5.9.097 (2011-06-23)
1571 protected $dests = array();
1574 * Object ID for Named Destinations
1576 * @since 5.9.097 (2011-06-23)
1581 * Embedded Files Names
1583 * @since 5.9.204 (2013-01-23)
1585 protected $efnames = array();
1588 * Directory used for the last SVG image.
1590 * @since 5.0.000 (2010-05-05)
1592 protected $svgdir = '';
1595 * Deafult unit of measure for SVG.
1597 * @since 5.0.000 (2010-05-02)
1599 protected $svgunit = 'px';
1602 * Array of SVG gradients.
1604 * @since 5.0.000 (2010-05-02)
1606 protected $svggradients = array();
1609 * ID of last SVG gradient.
1611 * @since 5.0.000 (2010-05-02)
1613 protected $svggradientid = 0;
1616 * Boolean value true when in SVG defs group.
1618 * @since 5.0.000 (2010-05-02)
1620 protected $svgdefsmode = false;
1623 * Array of SVG defs.
1625 * @since 5.0.000 (2010-05-02)
1627 protected $svgdefs = array();
1630 * Boolean value true when in SVG clipPath tag.
1632 * @since 5.0.000 (2010-04-26)
1634 protected $svgclipmode = false;
1637 * Array of SVG clipPath commands.
1639 * @since 5.0.000 (2010-05-02)
1641 protected $svgclippaths = array();
1644 * Array of SVG clipPath tranformation matrix.
1646 * @since 5.8.022 (2010-08-31)
1648 protected $svgcliptm = array();
1651 * ID of last SVG clipPath.
1653 * @since 5.0.000 (2010-05-02)
1655 protected $svgclipid = 0;
1660 * @since 5.0.000 (2010-05-02)
1662 protected $svgtext = '';
1665 * SVG text properties.
1667 * @since 5.8.013 (2010-08-23)
1669 protected $svgtextmode = array();
1672 * Array of SVG properties.
1674 * @since 5.0.000 (2010-05-02)
1676 protected $svgstyles = array(array(
1677 'alignment-baseline' => 'auto',
1678 'baseline-shift' => 'baseline',
1680 'clip-path' => 'none',
1681 'clip-rule' => 'nonzero',
1683 'color-interpolation' => 'sRGB',
1684 'color-interpolation-filters' => 'linearRGB',
1685 'color-profile' => 'auto',
1686 'color-rendering' => 'auto',
1688 'direction' => 'ltr',
1689 'display' => 'inline',
1690 'dominant-baseline' => 'auto',
1691 'enable-background' => 'accumulate',
1693 'fill-opacity' => 1,
1694 'fill-rule' => 'nonzero',
1696 'flood-color' => 'black',
1697 'flood-opacity' => 1,
1699 'font-family' => 'helvetica',
1700 'font-size' => 'medium',
1701 'font-size-adjust' => 'none',
1702 'font-stretch' => 'normal',
1703 'font-style' => 'normal',
1704 'font-variant' => 'normal',
1705 'font-weight' => 'normal',
1706 'glyph-orientation-horizontal' => '0deg',
1707 'glyph-orientation-vertical' => 'auto',
1708 'image-rendering' => 'auto',
1709 'kerning' => 'auto',
1710 'letter-spacing' => 'normal',
1711 'lighting-color' => 'white',
1713 'marker-end' => 'none',
1714 'marker-mid' => 'none',
1715 'marker-start' => 'none',
1718 'overflow' => 'auto',
1719 'pointer-events' => 'visiblePainted',
1720 'shape-rendering' => 'auto',
1721 'stop-color' => 'black',
1722 'stop-opacity' => 1,
1724 'stroke-dasharray' => 'none',
1725 'stroke-dashoffset' => 0,
1726 'stroke-linecap' => 'butt',
1727 'stroke-linejoin' => 'miter',
1728 'stroke-miterlimit' => 4,
1729 'stroke-opacity' => 1,
1730 'stroke-width' => 1,
1731 'text-anchor' => 'start',
1732 'text-decoration' => 'none',
1733 'text-rendering' => 'auto',
1734 'unicode-bidi' => 'normal',
1735 'visibility' => 'visible',
1736 'word-spacing' => 'normal',
1737 'writing-mode' => 'lr-tb',
1738 'text-color' => 'black',
1739 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
1743 * If true force sRGB color profile for all document.
1745 * @since 5.9.121 (2011-09-28)
1747 protected $force_srgb = false;
1750 * If true set the document to PDF/A mode.
1752 * @since 5.9.121 (2011-09-27)
1754 protected $pdfa_mode = false;
1757 * version of PDF/A mode (1 - 3).
1759 * @since 6.2.26 (2019-03-12)
1761 protected $pdfa_version = 1;
1764 * Document creation date-time
1766 * @since 5.9.152 (2012-03-22)
1768 protected $doc_creation_timestamp;
1771 * Document modification date-time
1773 * @since 5.9.152 (2012-03-22)
1775 protected $doc_modification_timestamp;
1780 * @since 5.9.128 (2011-10-06)
1782 protected $custom_xmp = '';
1785 * Custom XMP RDF data.
1787 * @since 6.3.0 (2019-09-19)
1789 protected $custom_xmp_rdf = '';
1792 * Overprint mode array.
1793 * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
1795 * @since 5.9.152 (2012-03-23)
1797 protected $overprint = array('OP' => false, 'op' => false, 'OPM' => 0);
1801 * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
1803 * @since 5.9.152 (2012-03-23)
1805 protected $alpha = array('CA' => 1, 'ca' => 1, 'BM' => '/Normal', 'AIS' => false);
1808 * Define the page boundaries boxes to be set on document.
1810 * @since 5.9.152 (2012-03-23)
1812 protected $page_boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
1815 * If true print TCPDF meta link.
1817 * @since 5.9.152 (2012-03-23)
1819 protected $tcpdflink = true;
1822 * Cache array for computed GD gamma values.
1824 * @since 5.9.1632 (2012-06-05)
1826 protected $gdgammacache = array();
1829 * Cache array for file content
1832 * @sinde 6.3.5 (2020-09-28)
1834 protected $fileContentCache = array();
1837 * Whether to allow local file path in image html tags, when prefixed with file://
1841 * @since 6.4 (2020-07-23)
1843 protected $allowLocalFiles = false;
1845 //------------------------------------------------------------
1847 //------------------------------------------------------------
1850 * This is the class constructor.
1851 * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
1853 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
1854 * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
1855 * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
1856 * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
1857 * @param $encoding (string) Charset encoding (used only when converting back html entities); default is UTF-8.
1858 * @param $diskcache (boolean) DEPRECATED FEATURE
1859 * @param $pdfa (integer) If not false, set the document to PDF/A mode and the good version (1 or 3).
1861 * @see getPageSizeFromFormat(), setPageFormat()
1863 public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) {
1864 // set file ID for trailer
1865 $serformat = (is_array($format) ?
json_encode($format) : $format);
1866 $this->file_id
= md5(TCPDF_STATIC
::getRandomSeed('TCPDF'.$orientation.$unit.$serformat.$encoding));
1867 $this->font_obj_ids
= array();
1868 $this->page_obj_id
= array();
1869 $this->form_obj_id
= array();
1872 if ($pdfa != false) {
1873 $this->pdfa_mode
= true;
1874 $this->pdfa_version
= $pdfa; // 1 or 3
1876 $this->pdfa_mode
= false;
1878 $this->force_srgb
= false;
1879 // set language direction
1881 $this->tmprtl
= false;
1884 // initialization of properties
1885 $this->isunicode
= $unicode;
1887 $this->transfmrk
[0] = array();
1888 $this->pagedim
= array();
1891 $this->pages
= array();
1893 $this->fonts
= array();
1894 $this->FontFiles
= array();
1895 $this->diffs
= array();
1896 $this->images
= array();
1897 $this->links
= array();
1898 $this->gradients
= array();
1899 $this->InFooter
= false;
1901 $this->FontFamily
= defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN
:'helvetica';
1902 $this->FontStyle
= '';
1903 $this->FontSizePt
= 12;
1904 $this->underline
= false;
1905 $this->overline
= false;
1906 $this->linethrough
= false;
1907 $this->DrawColor
= '0 G';
1908 $this->FillColor
= '0 g';
1909 $this->TextColor
= '0 g';
1910 $this->ColorFlag
= false;
1911 $this->pdflayers
= array();
1912 // encryption values
1913 $this->encrypted
= false;
1914 $this->last_enc_key
= '';
1915 // standard Unicode fonts
1916 $this->CoreFonts
= array(
1917 'courier'=>'Courier',
1918 'courierB'=>'Courier-Bold',
1919 'courierI'=>'Courier-Oblique',
1920 'courierBI'=>'Courier-BoldOblique',
1921 'helvetica'=>'Helvetica',
1922 'helveticaB'=>'Helvetica-Bold',
1923 'helveticaI'=>'Helvetica-Oblique',
1924 'helveticaBI'=>'Helvetica-BoldOblique',
1925 'times'=>'Times-Roman',
1926 'timesB'=>'Times-Bold',
1927 'timesI'=>'Times-Italic',
1928 'timesBI'=>'Times-BoldItalic',
1930 'zapfdingbats'=>'ZapfDingbats'
1933 $this->setPageUnit($unit);
1934 // set page format and orientation
1935 $this->setPageFormat($format, $orientation);
1936 // page margins (1 cm)
1937 $margin = 28.35 / $this->k
;
1938 $this->SetMargins($margin, $margin);
1939 $this->clMargin
= $this->lMargin
;
1940 $this->crMargin
= $this->rMargin
;
1941 // internal cell padding
1942 $cpadding = $margin / 10;
1943 $this->setCellPaddings($cpadding, 0, $cpadding, 0);
1945 $this->setCellMargins(0, 0, 0, 0);
1946 // line width (0.2 mm)
1947 $this->LineWidth
= 0.57 / $this->k
;
1948 $this->linestyleWidth
= sprintf('%F w', ($this->LineWidth
* $this->k
));
1949 $this->linestyleCap
= '0 J';
1950 $this->linestyleJoin
= '0 j';
1951 $this->linestyleDash
= '[] 0 d';
1952 // automatic page break
1953 $this->SetAutoPageBreak(true, (2 * $margin));
1954 // full width display mode
1955 $this->SetDisplayMode('fullwidth');
1957 $this->SetCompression();
1958 // set default PDF version number
1959 $this->setPDFVersion();
1960 $this->tcpdflink
= true;
1961 $this->encoding
= $encoding;
1962 $this->HREF
= array();
1963 $this->getFontsList();
1964 $this->fgcolor
= array('R' => 0, 'G' => 0, 'B' => 0);
1965 $this->strokecolor
= array('R' => 0, 'G' => 0, 'B' => 0);
1966 $this->bgcolor
= array('R' => 255, 'G' => 255, 'B' => 255);
1967 $this->extgstates
= array();
1968 $this->setTextShadow();
1970 $this->sign
= false;
1971 $this->tsa_timestamp
= false;
1972 $this->tsa_data
= array();
1973 $this->signature_appearance
= array('page' => 1, 'rect' => '0 0 0 0', 'name' => 'Signature');
1974 $this->empty_signature_appearance
= array();
1976 $this->ur
['enabled'] = false;
1977 $this->ur
['document'] = '/FullSave';
1978 $this->ur
['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
1979 $this->ur
['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
1980 $this->ur
['signature'] = '/Modify';
1981 $this->ur
['ef'] = '/Create/Delete/Modify/Import';
1982 $this->ur
['formex'] = '';
1983 // set default JPEG quality
1984 $this->jpeg_quality
= 75;
1985 // initialize some settings
1986 TCPDF_FONTS
::utf8Bidi(array(), '', false, $this->isunicode
, $this->CurrentFont
);
1988 $this->SetFont($this->FontFamily
, $this->FontStyle
, $this->FontSizePt
);
1989 $this->setHeaderFont(array($this->FontFamily
, $this->FontStyle
, $this->FontSizePt
));
1990 $this->setFooterFont(array($this->FontFamily
, $this->FontStyle
, $this->FontSizePt
));
1991 // check if PCRE Unicode support is enabled
1992 if ($this->isunicode
AND (@preg_match
('/\pL/u', 'a') == 1)) {
1993 // PCRE unicode support is turned ON
1994 // \s : any whitespace character
1995 // \p{Z} : any separator
1996 // \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
1997 // \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
1998 //$this->setSpacesRE('/(?!\xa0)[\s\p{Z}\p{Lo}]/u');
1999 $this->setSpacesRE('/(?!\xa0)[\s\p{Z}]/u');
2001 // PCRE unicode support is turned OFF
2002 $this->setSpacesRE('/[^\S\xa0]/');
2004 $this->default_form_prop
= array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
2005 // set document creation and modification timestamp
2006 $this->doc_creation_timestamp
= time();
2007 $this->doc_modification_timestamp
= $this->doc_creation_timestamp
;
2008 // get default graphic vars
2009 $this->default_graphic_vars
= $this->getGraphicVars();
2010 $this->header_xobj_autoreset
= false;
2011 $this->custom_xmp
= '';
2012 $this->custom_xmp_rdf
= '';
2013 // Call cleanup method after script execution finishes or exit() is called.
2014 // NOTE: This will not be executed if the process is killed with a SIGTERM or SIGKILL signal.
2015 register_shutdown_function(array($this, '_destroy'), true);
2019 * Default destructor.
2021 * @since 1.53.0.TC016
2023 public function __destruct() {
2025 $this->_destroy(true);
2029 * Set the units of measure for the document.
2030 * @param $unit (string) User measure unit. Possible values are:<ul><li>pt: point</li><li>mm: millimeter (default)</li><li>cm: centimeter</li><li>in: inch</li></ul><br />A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.
2032 * @since 3.0.015 (2008-06-06)
2034 public function setPageUnit($unit) {
2035 $unit = strtolower($unit);
2046 $this->k
= $this->dpi
/ 25.4;
2051 $this->k
= $this->dpi
/ 2.54;
2056 $this->k
= $this->dpi
;
2061 $this->Error('Incorrect unit: '.$unit);
2065 $this->pdfunit
= $unit;
2066 if (isset($this->CurOrientation
)) {
2067 $this->setPageOrientation($this->CurOrientation
);
2072 * Change the format of the current page
2073 * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() documentation or an array of two numbers (width, height) or an array containing the following measures and options:<ul>
2074 * <li>['format'] = page format name (one of the above);</li>
2075 * <li>['Rotate'] : The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li>
2076 * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
2077 * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
2078 * <li>['MediaBox']['llx'] : lower-left x coordinate</li>
2079 * <li>['MediaBox']['lly'] : lower-left y coordinate</li>
2080 * <li>['MediaBox']['urx'] : upper-right x coordinate</li>
2081 * <li>['MediaBox']['ury'] : upper-right y coordinate</li>
2082 * <li>['CropBox'] : the visible region of default user space:</li>
2083 * <li>['CropBox']['llx'] : lower-left x coordinate</li>
2084 * <li>['CropBox']['lly'] : lower-left y coordinate</li>
2085 * <li>['CropBox']['urx'] : upper-right x coordinate</li>
2086 * <li>['CropBox']['ury'] : upper-right y coordinate</li>
2087 * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
2088 * <li>['BleedBox']['llx'] : lower-left x coordinate</li>
2089 * <li>['BleedBox']['lly'] : lower-left y coordinate</li>
2090 * <li>['BleedBox']['urx'] : upper-right x coordinate</li>
2091 * <li>['BleedBox']['ury'] : upper-right y coordinate</li>
2092 * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
2093 * <li>['TrimBox']['llx'] : lower-left x coordinate</li>
2094 * <li>['TrimBox']['lly'] : lower-left y coordinate</li>
2095 * <li>['TrimBox']['urx'] : upper-right x coordinate</li>
2096 * <li>['TrimBox']['ury'] : upper-right y coordinate</li>
2097 * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
2098 * <li>['ArtBox']['llx'] : lower-left x coordinate</li>
2099 * <li>['ArtBox']['lly'] : lower-left y coordinate</li>
2100 * <li>['ArtBox']['urx'] : upper-right x coordinate</li>
2101 * <li>['ArtBox']['ury'] : upper-right y coordinate</li>
2102 * <li>['BoxColorInfo'] :specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for each of the possible page boundaries other than the MediaBox:</li>
2103 * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
2104 * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
2105 * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
2106 * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
2107 * <li>['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation</li>
2108 * <li>['trans']['Dur'] : The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li>
2109 * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
2110 * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
2111 * <li>['trans']['Dm'] : (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li>
2112 * <li>['trans']['M'] : (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li>
2113 * <li>['trans']['Di'] : (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li>
2114 * <li>['trans']['SS'] : (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0.</li>
2115 * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
2117 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
2118 * <li>P or Portrait (default)</li>
2119 * <li>L or Landscape</li>
2120 * <li>'' (empty string) for automatic orientation</li>
2123 * @since 3.0.015 (2008-06-06)
2124 * @see getPageSizeFromFormat()
2126 protected function setPageFormat($format, $orientation='P') {
2127 if (!empty($format) AND isset($this->pagedim
[$this->page
])) {
2128 // remove inherited values
2129 unset($this->pagedim
[$this->page
]);
2131 if (is_string($format)) {
2132 // get page measures from format name
2133 $pf = TCPDF_STATIC
::getPageSizeFromFormat($format);
2134 $this->fwPt
= $pf[0];
2135 $this->fhPt
= $pf[1];
2137 // the boundaries of the physical medium on which the page shall be displayed or printed
2138 if (isset($format['MediaBox'])) {
2139 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false, $this->k
, $this->pagedim
);
2140 $this->fwPt
= (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k
);
2141 $this->fhPt
= (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k
);
2143 if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
2144 $pf = array(($format[0] * $this->k
), ($format[1] * $this->k
));
2146 if (!isset($format['format'])) {
2148 $format['format'] = 'A4';
2150 $pf = TCPDF_STATIC
::getPageSizeFromFormat($format['format']);
2152 $this->fwPt
= $pf[0];
2153 $this->fhPt
= $pf[1];
2154 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'MediaBox', 0, 0, $this->fwPt
, $this->fhPt
, true, $this->k
, $this->pagedim
);
2156 // the visible region of default user space
2157 if (isset($format['CropBox'])) {
2158 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false, $this->k
, $this->pagedim
);
2160 // the region to which the contents of the page shall be clipped when output in a production environment
2161 if (isset($format['BleedBox'])) {
2162 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false, $this->k
, $this->pagedim
);
2164 // the intended dimensions of the finished page after trimming
2165 if (isset($format['TrimBox'])) {
2166 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false, $this->k
, $this->pagedim
);
2168 // the page's meaningful content (including potential white space)
2169 if (isset($format['ArtBox'])) {
2170 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false, $this->k
, $this->pagedim
);
2172 // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
2173 if (isset($format['BoxColorInfo'])) {
2174 $this->pagedim
[$this->page
]['BoxColorInfo'] = $format['BoxColorInfo'];
2176 if (isset($format['Rotate']) AND (($format['Rotate'] %
90) == 0)) {
2177 // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
2178 $this->pagedim
[$this->page
]['Rotate'] = intval($format['Rotate']);
2180 if (isset($format['PZ'])) {
2181 // The page's preferred zoom (magnification) factor
2182 $this->pagedim
[$this->page
]['PZ'] = floatval($format['PZ']);
2184 if (isset($format['trans'])) {
2185 // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
2186 if (isset($format['trans']['Dur'])) {
2187 // The page's display duration
2188 $this->pagedim
[$this->page
]['trans']['Dur'] = floatval($format['trans']['Dur']);
2190 $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
2191 if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
2192 // The transition style that shall be used when moving to this page from another during a presentation
2193 $this->pagedim
[$this->page
]['trans']['S'] = $format['trans']['S'];
2194 $valid_effect = array('Split', 'Blinds');
2195 $valid_vals = array('H', 'V');
2196 if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
2197 $this->pagedim
[$this->page
]['trans']['Dm'] = $format['trans']['Dm'];
2199 $valid_effect = array('Split', 'Box', 'Fly');
2200 $valid_vals = array('I', 'O');
2201 if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
2202 $this->pagedim
[$this->page
]['trans']['M'] = $format['trans']['M'];
2204 $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
2205 if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
2206 if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
2207 OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
2208 OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
2209 $this->pagedim
[$this->page
]['trans']['Di'] = intval($format['trans']['Di']);
2212 if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
2213 $this->pagedim
[$this->page
]['trans']['SS'] = floatval($format['trans']['SS']);
2215 if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
2216 $this->pagedim
[$this->page
]['trans']['B'] = 'true';
2219 $this->pagedim
[$this->page
]['trans']['S'] = 'R';
2221 if (isset($format['trans']['D'])) {
2222 // The duration of the transition effect, in seconds
2223 $this->pagedim
[$this->page
]['trans']['D'] = floatval($format['trans']['D']);
2225 $this->pagedim
[$this->page
]['trans']['D'] = 1;
2229 $this->setPageOrientation($orientation);
2233 * Set page orientation.
2234 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li><li>'' (empty string) for automatic orientation</li></ul>
2235 * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
2236 * @param $bottommargin (float) bottom margin of the page.
2238 * @since 3.0.015 (2008-06-06)
2240 public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
2241 if (!isset($this->pagedim
[$this->page
]['MediaBox'])) {
2242 // the boundaries of the physical medium on which the page shall be displayed or printed
2243 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'MediaBox', 0, 0, $this->fwPt
, $this->fhPt
, true, $this->k
, $this->pagedim
);
2245 if (!isset($this->pagedim
[$this->page
]['CropBox'])) {
2246 // the visible region of default user space
2247 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'CropBox', $this->pagedim
[$this->page
]['MediaBox']['llx'], $this->pagedim
[$this->page
]['MediaBox']['lly'], $this->pagedim
[$this->page
]['MediaBox']['urx'], $this->pagedim
[$this->page
]['MediaBox']['ury'], true, $this->k
, $this->pagedim
);
2249 if (!isset($this->pagedim
[$this->page
]['BleedBox'])) {
2250 // the region to which the contents of the page shall be clipped when output in a production environment
2251 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'BleedBox', $this->pagedim
[$this->page
]['CropBox']['llx'], $this->pagedim
[$this->page
]['CropBox']['lly'], $this->pagedim
[$this->page
]['CropBox']['urx'], $this->pagedim
[$this->page
]['CropBox']['ury'], true, $this->k
, $this->pagedim
);
2253 if (!isset($this->pagedim
[$this->page
]['TrimBox'])) {
2254 // the intended dimensions of the finished page after trimming
2255 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'TrimBox', $this->pagedim
[$this->page
]['CropBox']['llx'], $this->pagedim
[$this->page
]['CropBox']['lly'], $this->pagedim
[$this->page
]['CropBox']['urx'], $this->pagedim
[$this->page
]['CropBox']['ury'], true, $this->k
, $this->pagedim
);
2257 if (!isset($this->pagedim
[$this->page
]['ArtBox'])) {
2258 // the page's meaningful content (including potential white space)
2259 $this->pagedim
= TCPDF_STATIC
::setPageBoxes($this->page
, 'ArtBox', $this->pagedim
[$this->page
]['CropBox']['llx'], $this->pagedim
[$this->page
]['CropBox']['lly'], $this->pagedim
[$this->page
]['CropBox']['urx'], $this->pagedim
[$this->page
]['CropBox']['ury'], true, $this->k
, $this->pagedim
);
2261 if (!isset($this->pagedim
[$this->page
]['Rotate'])) {
2262 // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
2263 $this->pagedim
[$this->page
]['Rotate'] = 0;
2265 if (!isset($this->pagedim
[$this->page
]['PZ'])) {
2266 // The page's preferred zoom (magnification) factor
2267 $this->pagedim
[$this->page
]['PZ'] = 1;
2269 if ($this->fwPt
> $this->fhPt
) {
2271 $default_orientation = 'L';
2274 $default_orientation = 'P';
2276 $valid_orientations = array('P', 'L');
2277 if (empty($orientation)) {
2278 $orientation = $default_orientation;
2280 $orientation = strtoupper($orientation[0]);
2282 if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
2283 $this->CurOrientation
= $orientation;
2284 $this->wPt
= $this->fhPt
;
2285 $this->hPt
= $this->fwPt
;
2287 $this->CurOrientation
= $default_orientation;
2288 $this->wPt
= $this->fwPt
;
2289 $this->hPt
= $this->fhPt
;
2291 if ((abs($this->pagedim
[$this->page
]['MediaBox']['urx'] - $this->hPt
) < $this->feps
) AND (abs($this->pagedim
[$this->page
]['MediaBox']['ury'] - $this->wPt
) < $this->feps
)){
2292 // swap X and Y coordinates (change page orientation)
2293 $this->pagedim
= TCPDF_STATIC
::swapPageBoxCoordinates($this->page
, $this->pagedim
);
2295 $this->w
= ($this->wPt
/ $this->k
);
2296 $this->h
= ($this->hPt
/ $this->k
);
2297 if (TCPDF_STATIC
::empty_string($autopagebreak)) {
2298 if (isset($this->AutoPageBreak
)) {
2299 $autopagebreak = $this->AutoPageBreak
;
2301 $autopagebreak = true;
2304 if (TCPDF_STATIC
::empty_string($bottommargin)) {
2305 if (isset($this->bMargin
)) {
2306 $bottommargin = $this->bMargin
;
2308 // default value = 2 cm
2309 $bottommargin = 2 * 28.35 / $this->k
;
2312 $this->SetAutoPageBreak($autopagebreak, $bottommargin);
2313 // store page dimensions
2314 $this->pagedim
[$this->page
]['w'] = $this->wPt
;
2315 $this->pagedim
[$this->page
]['h'] = $this->hPt
;
2316 $this->pagedim
[$this->page
]['wk'] = $this->w
;
2317 $this->pagedim
[$this->page
]['hk'] = $this->h
;
2318 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
2319 $this->pagedim
[$this->page
]['bm'] = $bottommargin;
2320 $this->pagedim
[$this->page
]['lm'] = $this->lMargin
;
2321 $this->pagedim
[$this->page
]['rm'] = $this->rMargin
;
2322 $this->pagedim
[$this->page
]['pb'] = $autopagebreak;
2323 $this->pagedim
[$this->page
]['or'] = $this->CurOrientation
;
2324 $this->pagedim
[$this->page
]['olm'] = $this->original_lMargin
;
2325 $this->pagedim
[$this->page
]['orm'] = $this->original_rMargin
;
2329 * Set regular expression to detect withespaces or word separators.
2330 * The pattern delimiter must be the forward-slash character "/".
2331 * Some example patterns are:
2333 * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
2334 * Unicode and PCRE unicode support: "/(?!\xa0)[\s\p{Z}]/u"
2335 * Unicode and PCRE unicode support in Chinese mode: "/(?!\xa0)[\s\p{Z}\p{Lo}]/u"
2336 * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
2337 * \s : any whitespace character
2338 * \p{Z} : any separator
2339 * \p{Lo} : Unicode letter or ideograph that does not have lowercase and uppercase variants. Is used to chunk chinese words.
2340 * \xa0 : Unicode Character 'NO-BREAK SPACE' (U+00A0)
2342 * @param $re (string) regular expression (leave empty for default).
2344 * @since 4.6.016 (2009-06-15)
2346 public function setSpacesRE($re='/[^\S\xa0]/') {
2347 $this->re_spaces
= $re;
2348 $re_parts = explode('/', $re);
2349 // get pattern parts
2350 $this->re_space
= array();
2351 if (isset($re_parts[1]) AND !empty($re_parts[1])) {
2352 $this->re_space
['p'] = $re_parts[1];
2354 $this->re_space
['p'] = '[\s]';
2356 // set pattern modifiers
2357 if (isset($re_parts[2]) AND !empty($re_parts[2])) {
2358 $this->re_space
['m'] = $re_parts[2];
2360 $this->re_space
['m'] = '';
2365 * Enable or disable Right-To-Left language mode
2366 * @param $enable (Boolean) if true enable Right-To-Left language mode.
2367 * @param $resetx (Boolean) if true reset the X position on direction change.
2369 * @since 2.0.000 (2008-01-03)
2371 public function setRTL($enable, $resetx=true) {
2372 $enable = $enable ?
true : false;
2373 $resetx = ($resetx AND ($enable != $this->rtl
));
2374 $this->rtl
= $enable;
2375 $this->tmprtl
= false;
2382 * Return the RTL status
2385 * @since 4.0.012 (2008-07-24)
2387 public function getRTL() {
2392 * Force temporary RTL language direction
2393 * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
2395 * @since 2.1.000 (2008-01-09)
2397 public function setTempRTL($mode) {
2399 switch (strtoupper($mode)) {
2420 $this->tmprtl
= $newmode;
2424 * Return the current temporary RTL status
2427 * @since 4.8.014 (2009-11-04)
2429 public function isRTLTextDir() {
2430 return ($this->rtl
OR ($this->tmprtl
== 'R'));
2434 * Set the last cell height.
2435 * @param $h (float) cell height.
2436 * @author Nicola Asuni
2438 * @since 1.53.0.TC034
2440 public function setLastH($h) {
2445 * Return the cell height
2446 * @param $fontsize (int) Font size in internal units
2447 * @param $padding (boolean) If true add cell padding
2450 public function getCellHeight($fontsize, $padding=TRUE) {
2451 $height = ($fontsize * $this->cell_height_ratio
);
2453 $height +
= ($this->cell_padding
['T'] +
$this->cell_padding
['B']);
2455 return round($height, 6);
2459 * Reset the last cell height.
2461 * @since 5.9.000 (2010-10-03)
2463 public function resetLastH() {
2464 $this->lasth
= $this->getCellHeight($this->FontSize
);
2468 * Get the last cell height.
2469 * @return last cell height
2471 * @since 4.0.017 (2008-08-05)
2473 public function getLastH() {
2474 return $this->lasth
;
2478 * Set the adjusting factor to convert pixels to user units.
2479 * @param $scale (float) adjusting factor to convert pixels to user units.
2480 * @author Nicola Asuni
2484 public function setImageScale($scale) {
2485 $this->imgscale
= $scale;
2489 * Returns the adjusting factor to convert pixels to user units.
2490 * @return float adjusting factor to convert pixels to user units.
2491 * @author Nicola Asuni
2495 public function getImageScale() {
2496 return $this->imgscale
;
2500 * Returns an array of page dimensions:
2501 * <ul><li>$this->pagedim[$this->page]['w'] = page width in points</li><li>$this->pagedim[$this->page]['h'] = height in points</li><li>$this->pagedim[$this->page]['wk'] = page width in user units</li><li>$this->pagedim[$this->page]['hk'] = page height in user units</li><li>$this->pagedim[$this->page]['tm'] = top margin</li><li>$this->pagedim[$this->page]['bm'] = bottom margin</li><li>$this->pagedim[$this->page]['lm'] = left margin</li><li>$this->pagedim[$this->page]['rm'] = right margin</li><li>$this->pagedim[$this->page]['pb'] = auto page break</li><li>$this->pagedim[$this->page]['or'] = page orientation</li><li>$this->pagedim[$this->page]['olm'] = original left margin</li><li>$this->pagedim[$this->page]['orm'] = original right margin</li><li>$this->pagedim[$this->page]['Rotate'] = The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.</li><li>$this->pagedim[$this->page]['PZ'] = The page's preferred zoom (magnification) factor.</li><li>$this->pagedim[$this->page]['trans'] : the style and duration of the visual transition to use when moving from another page to the given page during a presentation<ul><li>$this->pagedim[$this->page]['trans']['Dur'] = The page's display duration (also called its advance timing): the maximum length of time, in seconds, that the page shall be displayed during presentations before the viewer application shall automatically advance to the next page.</li><li>$this->pagedim[$this->page]['trans']['S'] = transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li><li>$this->pagedim[$this->page]['trans']['D'] = The duration of the transition effect, in seconds.</li><li>$this->pagedim[$this->page]['trans']['Dm'] = (Split and Blinds transition styles only) The dimension in which the specified transition effect shall occur: H = Horizontal, V = Vertical. Default value: H.</li><li>$this->pagedim[$this->page]['trans']['M'] = (Split, Box and Fly transition styles only) The direction of motion for the specified transition effect: I = Inward from the edges of the page, O = Outward from the center of the pageDefault value: I.</li><li>$this->pagedim[$this->page]['trans']['Di'] = (Wipe, Glitter, Fly, Cover, Uncover and Push transition styles only) The direction in which the specified transition effect shall moves, expressed in degrees counterclockwise starting from a left-to-right direction. If the value is a number, it shall be one of: 0 = Left to right, 90 = Bottom to top (Wipe only), 180 = Right to left (Wipe only), 270 = Top to bottom, 315 = Top-left to bottom-right (Glitter only). If the value is a name, it shall be None, which is relevant only for the Fly transition when the value of SS is not 1.0. Default value: 0.</li><li>$this->pagedim[$this->page]['trans']['SS'] = (Fly transition style only) The starting or ending scale at which the changes shall be drawn. If M specifies an inward transition, the scale of the changes drawn shall progress from SS to 1.0 over the course of the transition. If M specifies an outward transition, the scale of the changes drawn shall progress from 1.0 to SS over the course of the transition. Default: 1.0. </li><li>$this->pagedim[$this->page]['trans']['B'] = (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li></ul></li><li>$this->pagedim[$this->page]['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed<ul><li>$this->pagedim[$this->page]['MediaBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['MediaBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['CropBox'] : the visible region of default user space<ul><li>$this->pagedim[$this->page]['CropBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['CropBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment<ul><li>$this->pagedim[$this->page]['BleedBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['BleedBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['TrimBox'] : the intended dimensions of the finished page after trimming<ul><li>$this->pagedim[$this->page]['TrimBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['TrimBox']['ury'] = upper-right y coordinate in points</li></ul></li><li>$this->pagedim[$this->page]['ArtBox'] : the extent of the page's meaningful content<ul><li>$this->pagedim[$this->page]['ArtBox']['llx'] = lower-left x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['lly'] = lower-left y coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['urx'] = upper-right x coordinate in points</li><li>$this->pagedim[$this->page]['ArtBox']['ury'] = upper-right y coordinate in points</li></ul></li></ul>
2502 * @param $pagenum (int) page number (empty = current page)
2503 * @return array of page dimensions.
2504 * @author Nicola Asuni
2506 * @since 4.5.027 (2009-03-16)
2508 public function getPageDimensions($pagenum='') {
2509 if (empty($pagenum)) {
2510 $pagenum = $this->page
;
2512 return $this->pagedim
[$pagenum];
2516 * Returns the page width in units.
2517 * @param $pagenum (int) page number (empty = current page)
2518 * @return int page width.
2519 * @author Nicola Asuni
2522 * @see getPageDimensions()
2524 public function getPageWidth($pagenum='') {
2525 if (empty($pagenum)) {
2528 return $this->pagedim
[$pagenum]['w'];
2532 * Returns the page height in units.
2533 * @param $pagenum (int) page number (empty = current page)
2534 * @return int page height.
2535 * @author Nicola Asuni
2538 * @see getPageDimensions()
2540 public function getPageHeight($pagenum='') {
2541 if (empty($pagenum)) {
2544 return $this->pagedim
[$pagenum]['h'];
2548 * Returns the page break margin.
2549 * @param $pagenum (int) page number (empty = current page)
2550 * @return int page break margin.
2551 * @author Nicola Asuni
2554 * @see getPageDimensions()
2556 public function getBreakMargin($pagenum='') {
2557 if (empty($pagenum)) {
2558 return $this->bMargin
;
2560 return $this->pagedim
[$pagenum]['bm'];
2564 * Returns the scale factor (number of points in user unit).
2565 * @return int scale factor.
2566 * @author Nicola Asuni
2570 public function getScaleFactor() {
2575 * Defines the left, top and right margins.
2576 * @param $left (float) Left margin.
2577 * @param $top (float) Top margin.
2578 * @param $right (float) Right margin. Default value is the left one.
2579 * @param $keepmargins (boolean) if true overwrites the default page margins
2582 * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
2584 public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
2585 //Set left, top and right margins
2586 $this->lMargin
= $left;
2587 $this->tMargin
= $top;
2591 $this->rMargin
= $right;
2593 // overwrite original values
2594 $this->original_lMargin
= $this->lMargin
;
2595 $this->original_rMargin
= $this->rMargin
;
2600 * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
2601 * @param $margin (float) The margin.
2604 * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
2606 public function SetLeftMargin($margin) {
2608 $this->lMargin
= $margin;
2609 if (($this->page
> 0) AND ($this->x
< $margin)) {
2615 * Defines the top margin. The method can be called before creating the first page.
2616 * @param $margin (float) The margin.
2619 * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
2621 public function SetTopMargin($margin) {
2623 $this->tMargin
= $margin;
2624 if (($this->page
> 0) AND ($this->y
< $margin)) {
2630 * Defines the right margin. The method can be called before creating the first page.
2631 * @param $margin (float) The margin.
2634 * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
2636 public function SetRightMargin($margin) {
2637 $this->rMargin
= $margin;
2638 if (($this->page
> 0) AND ($this->x
> ($this->w
- $margin))) {
2639 $this->x
= $this->w
- $margin;
2644 * Set the same internal Cell padding for top, right, bottom, left-
2645 * @param $pad (float) internal padding.
2647 * @since 2.1.000 (2008-01-09)
2648 * @see getCellPaddings(), setCellPaddings()
2650 public function SetCellPadding($pad) {
2652 $this->cell_padding
['L'] = $pad;
2653 $this->cell_padding
['T'] = $pad;
2654 $this->cell_padding
['R'] = $pad;
2655 $this->cell_padding
['B'] = $pad;
2660 * Set the internal Cell paddings.
2661 * @param $left (float) left padding
2662 * @param $top (float) top padding
2663 * @param $right (float) right padding
2664 * @param $bottom (float) bottom padding
2666 * @since 5.9.000 (2010-10-03)
2667 * @see getCellPaddings(), SetCellPadding()
2669 public function setCellPaddings($left='', $top='', $right='', $bottom='') {
2670 if (($left !== '') AND ($left >= 0)) {
2671 $this->cell_padding
['L'] = $left;
2673 if (($top !== '') AND ($top >= 0)) {
2674 $this->cell_padding
['T'] = $top;
2676 if (($right !== '') AND ($right >= 0)) {
2677 $this->cell_padding
['R'] = $right;
2679 if (($bottom !== '') AND ($bottom >= 0)) {
2680 $this->cell_padding
['B'] = $bottom;
2685 * Get the internal Cell padding array.
2686 * @return array of padding values
2688 * @since 5.9.000 (2010-10-03)
2689 * @see setCellPaddings(), SetCellPadding()
2691 public function getCellPaddings() {
2692 return $this->cell_padding
;
2696 * Set the internal Cell margins.
2697 * @param $left (float) left margin
2698 * @param $top (float) top margin
2699 * @param $right (float) right margin
2700 * @param $bottom (float) bottom margin
2702 * @since 5.9.000 (2010-10-03)
2703 * @see getCellMargins()
2705 public function setCellMargins($left='', $top='', $right='', $bottom='') {
2706 if (($left !== '') AND ($left >= 0)) {
2707 $this->cell_margin
['L'] = $left;
2709 if (($top !== '') AND ($top >= 0)) {
2710 $this->cell_margin
['T'] = $top;
2712 if (($right !== '') AND ($right >= 0)) {
2713 $this->cell_margin
['R'] = $right;
2715 if (($bottom !== '') AND ($bottom >= 0)) {
2716 $this->cell_margin
['B'] = $bottom;
2721 * Get the internal Cell margin array.
2722 * @return array of margin values
2724 * @since 5.9.000 (2010-10-03)
2725 * @see setCellMargins()
2727 public function getCellMargins() {
2728 return $this->cell_margin
;
2732 * Adjust the internal Cell padding array to take account of the line width.
2733 * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
2734 * @return void|array of adjustments
2736 * @since 5.9.000 (2010-10-03)
2738 protected function adjustCellPadding($brd=0) {
2742 if (is_string($brd)) {
2743 // convert string to array
2744 $slen = strlen($brd);
2746 for ($i = 0; $i < $slen; ++
$i) {
2747 $newbrd[$brd[$i]] = true;
2753 ||
(is_numeric($brd) && ((int)$brd > 0))
2755 $brd = array('LRTB' => true);
2757 if (!is_array($brd)) {
2760 // store current cell padding
2761 $cp = $this->cell_padding
;
2762 // select border mode
2763 if (isset($brd['mode'])) {
2764 $mode = $brd['mode'];
2765 unset($brd['mode']);
2770 foreach ($brd as $border => $style) {
2771 $line_width = $this->LineWidth
;
2772 if (is_array($style) && isset($style['width'])) {
2774 $line_width = $style['width'];
2776 $adj = 0; // line width inside the cell
2788 $adj = ($line_width / 2);
2792 // correct internal cell padding if required to avoid overlap between text and lines
2794 is_numeric($this->cell_padding
['T'])
2795 && ($this->cell_padding
['T'] < $adj)
2796 && (strpos($border, 'T') !== false)
2798 $this->cell_padding
['T'] = $adj;
2801 is_numeric($this->cell_padding
['R'])
2802 && ($this->cell_padding
['R'] < $adj)
2803 && (strpos($border, 'R') !== false)
2805 $this->cell_padding
['R'] = $adj;
2808 is_numeric($this->cell_padding
['B'])
2809 && ($this->cell_padding
['B'] < $adj)
2810 && (strpos($border, 'B') !== false)
2812 $this->cell_padding
['B'] = $adj;
2815 is_numeric($this->cell_padding
['L'])
2816 && ($this->cell_padding
['L'] < $adj)
2817 && (strpos($border, 'L') !== false)
2819 $this->cell_padding
['L'] = $adj;
2825 'T' => ($this->cell_padding
['T'] - $cp['T']),
2826 'R' => ($this->cell_padding
['R'] - $cp['R']),
2827 'B' => ($this->cell_padding
['B'] - $cp['B']),
2828 'L' => ($this->cell_padding
['L'] - $cp['L']),
2833 * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
2834 * @param $auto (boolean) Boolean indicating if mode should be on or off.
2835 * @param $margin (float) Distance from the bottom of the page.
2838 * @see Cell(), MultiCell(), AcceptPageBreak()
2840 public function SetAutoPageBreak($auto, $margin=0) {
2841 $this->AutoPageBreak
= $auto ?
true : false;
2842 $this->bMargin
= $margin;
2843 $this->PageBreakTrigger
= $this->h
- $margin;
2847 * Return the auto-page-break mode (true or false).
2848 * @return boolean auto-page-break mode
2852 public function getAutoPageBreak() {
2853 return $this->AutoPageBreak
;
2857 * Defines the way the document is to be displayed by the viewer.
2858 * @param $zoom (mixed) The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
2859 * @param $layout (string) The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
2860 * @param $mode (string) A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
2864 public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
2865 if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
2866 $this->ZoomMode
= $zoom;
2868 $this->Error('Incorrect zoom display mode: '.$zoom);
2870 $this->LayoutMode
= TCPDF_STATIC
::getPageLayoutMode($layout);
2871 $this->PageMode
= TCPDF_STATIC
::getPageMode($mode);
2875 * Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
2876 * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
2877 * @param $compress (boolean) Boolean indicating if compression must be enabled.
2881 public function SetCompression($compress=true) {
2882 $this->compress
= false;
2883 if (function_exists('gzcompress')) {
2885 if ( !$this->pdfa_mode
) {
2886 $this->compress
= true;
2893 * Set flag to force sRGB_IEC61966-2.1 black scaled ICC color profile for the whole document.
2894 * @param $mode (boolean) If true force sRGB output intent.
2896 * @since 5.9.121 (2011-09-28)
2898 public function setSRGBmode($mode=false) {
2899 $this->force_srgb
= $mode ?
true : false;
2903 * Turn on/off Unicode mode for document information dictionary (meta tags).
2904 * This has effect only when unicode mode is set to false.
2905 * @param $unicode (boolean) if true set the meta information in Unicode
2906 * @since 5.9.027 (2010-12-01)
2909 public function SetDocInfoUnicode($unicode=true) {
2910 $this->docinfounicode
= $unicode ?
true : false;
2914 * Defines the title of the document.
2915 * @param $title (string) The title.
2918 * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
2920 public function SetTitle($title) {
2921 $this->title
= $title;
2925 * Defines the subject of the document.
2926 * @param $subject (string) The subject.
2929 * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
2931 public function SetSubject($subject) {
2932 $this->subject
= $subject;
2936 * Defines the author of the document.
2937 * @param $author (string) The name of the author.
2940 * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
2942 public function SetAuthor($author) {
2943 $this->author
= $author;
2947 * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
2948 * @param $keywords (string) The list of keywords.
2951 * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
2953 public function SetKeywords($keywords) {
2954 $this->keywords
= $keywords;
2958 * Defines the creator of the document. This is typically the name of the application that generates the PDF.
2959 * @param $creator (string) The name of the creator.
2962 * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
2964 public function SetCreator($creator) {
2965 $this->creator
= $creator;
2969 * Whether to allow local file path in image html tags, when prefixed with file://
2971 * @param $allowLocalFiles bool true, when local files should be allowed. Otherwise false.
2975 public function SetAllowLocalFiles($allowLocalFiles) {
2976 $this->allowLocalFiles
= (bool) $allowLocalFiles;
2981 * Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
2982 * @param $msg (string) The error message
2986 public function Error($msg) {
2987 // unset all class variables
2988 $this->_destroy(true);
2989 if (defined('K_TCPDF_THROW_EXCEPTION_ERROR') AND !K_TCPDF_THROW_EXCEPTION_ERROR
) {
2990 die('<strong>TCPDF ERROR: </strong>'.$msg);
2992 throw new Exception('TCPDF ERROR: '.$msg);
2997 * This method begins the generation of the PDF document.
2998 * It is not necessary to call it explicitly because AddPage() does it automatically.
2999 * Note: no page is created by this method
3002 * @see AddPage(), Close()
3004 public function Open() {
3009 * Terminates the PDF document.
3010 * It is not necessary to call this method explicitly because Output() does it automatically.
3011 * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
3014 * @see Open(), Output()
3016 public function Close() {
3017 if ($this->state
== 3) {
3020 if ($this->page
== 0) {
3024 if ($this->tcpdflink
) {
3025 // save current graphic settings
3026 $gvars = $this->getGraphicVars();
3027 $this->setEqualColumns();
3028 $this->lastpage(true);
3029 $this->SetAutoPageBreak(false);
3031 $this->y
= $this->h
- (1 / $this->k
);
3033 $this->_outSaveGraphicsState();
3034 $font = defined('PDF_FONT_NAME_MAIN')?PDF_FONT_NAME_MAIN
:'helvetica';
3035 $this->SetFont($font, '', 1);
3036 $this->setTextRenderingMode(0, false, false);
3037 $msg = "\x50\x6f\x77\x65\x72\x65\x64\x20\x62\x79\x20\x54\x43\x50\x44\x46\x20\x28\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
3038 $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
3039 $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
3040 $this->_outRestoreGraphicsState();
3041 // restore graphic settings
3042 $this->setGraphicVars($gvars);
3048 // unset all class variables (except critical ones)
3049 $this->_destroy(false);
3053 * Move pointer at the specified document page and update page dimensions.
3054 * @param $pnum (int) page number (1 ... numpages)
3055 * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
3057 * @since 2.1.000 (2008-01-07)
3058 * @see getPage(), lastpage(), getNumPages()
3060 public function setPage($pnum, $resetmargins=false) {
3061 if (($pnum == $this->page
) AND ($this->state
== 2)) {
3064 if (($pnum > 0) AND ($pnum <= $this->numpages
)) {
3066 // save current graphic settings
3067 //$gvars = $this->getGraphicVars();
3068 $oldpage = $this->page
;
3069 $this->page
= $pnum;
3070 $this->wPt
= $this->pagedim
[$this->page
]['w'];
3071 $this->hPt
= $this->pagedim
[$this->page
]['h'];
3072 $this->w
= $this->pagedim
[$this->page
]['wk'];
3073 $this->h
= $this->pagedim
[$this->page
]['hk'];
3074 $this->tMargin
= $this->pagedim
[$this->page
]['tm'];
3075 $this->bMargin
= $this->pagedim
[$this->page
]['bm'];
3076 $this->original_lMargin
= $this->pagedim
[$this->page
]['olm'];
3077 $this->original_rMargin
= $this->pagedim
[$this->page
]['orm'];
3078 $this->AutoPageBreak
= $this->pagedim
[$this->page
]['pb'];
3079 $this->CurOrientation
= $this->pagedim
[$this->page
]['or'];
3080 $this->SetAutoPageBreak($this->AutoPageBreak
, $this->bMargin
);
3081 // restore graphic settings
3082 //$this->setGraphicVars($gvars);
3083 if ($resetmargins) {
3084 $this->lMargin
= $this->pagedim
[$this->page
]['olm'];
3085 $this->rMargin
= $this->pagedim
[$this->page
]['orm'];
3086 $this->SetY($this->tMargin
);
3088 // account for booklet mode
3089 if ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$oldpage]['olm']) {
3090 $deltam = $this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$this->page
]['orm'];
3091 $this->lMargin +
= $deltam;
3092 $this->rMargin
-= $deltam;
3096 $this->Error('Wrong page number on setPage() function: '.$pnum);
3101 * Reset pointer to the last document page.
3102 * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
3104 * @since 2.0.000 (2008-01-04)
3105 * @see setPage(), getPage(), getNumPages()
3107 public function lastPage($resetmargins=false) {
3108 $this->setPage($this->getNumPages(), $resetmargins);
3112 * Get current document page number.
3113 * @return int page number
3115 * @since 2.1.000 (2008-01-07)
3116 * @see setPage(), lastpage(), getNumPages()
3118 public function getPage() {
3123 * Get the total number of insered pages.
3124 * @return int number of pages
3126 * @since 2.1.000 (2008-01-07)
3127 * @see setPage(), getPage(), lastpage()
3129 public function getNumPages() {
3130 return $this->numpages
;
3134 * Adds a new TOC (Table Of Content) page to the document.
3135 * @param $orientation (string) page orientation.
3136 * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
3137 * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
3139 * @since 5.0.001 (2010-05-06)
3140 * @see AddPage(), startPage(), endPage(), endTOCPage()
3142 public function addTOCPage($orientation='', $format='', $keepmargins=false) {
3143 $this->AddPage($orientation, $format, $keepmargins, true);
3147 * Terminate the current TOC (Table Of Content) page
3149 * @since 5.0.001 (2010-05-06)
3150 * @see AddPage(), startPage(), endPage(), addTOCPage()
3152 public function endTOCPage() {
3153 $this->endPage(true);
3157 * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer (if enabled). Then the page is added, the current position set to the top-left corner according to the left and top margins (or top-right if in RTL mode), and Header() is called to display the header (if enabled).
3158 * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
3159 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
3160 * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
3161 * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
3162 * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
3165 * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
3167 public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
3168 if ($this->inxobj
) {
3169 // we are inside an XObject template
3172 if (!isset($this->original_lMargin
) OR $keepmargins) {
3173 $this->original_lMargin
= $this->lMargin
;
3175 if (!isset($this->original_rMargin
) OR $keepmargins) {
3176 $this->original_rMargin
= $this->rMargin
;
3178 // terminate previous page
3181 $this->startPage($orientation, $format, $tocpage);
3185 * Terminate the current page
3186 * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
3188 * @since 4.2.010 (2008-11-14)
3189 * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
3191 public function endPage($tocpage=false) {
3192 // check if page is already closed
3193 if (($this->page
== 0) OR ($this->numpages
> $this->page
) OR (!$this->pageopen
[$this->page
])) {
3196 // print page footer
3200 // mark page as closed
3201 $this->pageopen
[$this->page
] = false;
3203 $this->tocpage
= false;
3208 * Starts a new page to the document. The page must be closed using the endPage() function.
3209 * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
3210 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
3211 * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
3212 * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
3213 * @since 4.2.010 (2008-11-14)
3214 * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
3217 public function startPage($orientation='', $format='', $tocpage=false) {
3219 $this->tocpage
= true;
3221 // move page numbers of documents to be attached
3222 if ($this->tocpage
) {
3223 // move reference to unexistent pages (used for page attachments)
3225 $tmpoutlines = $this->outlines
;
3226 foreach ($tmpoutlines as $key => $outline) {
3227 if (!$outline['f'] AND ($outline['p'] > $this->numpages
)) {
3228 $this->outlines
[$key]['p'] = ($outline['p'] +
1);
3232 $tmpdests = $this->dests
;
3233 foreach ($tmpdests as $key => $dest) {
3234 if (!$dest['f'] AND ($dest['p'] > $this->numpages
)) {
3235 $this->dests
[$key]['p'] = ($dest['p'] +
1);
3239 $tmplinks = $this->links
;
3240 foreach ($tmplinks as $key => $link) {
3241 if (!$link['f'] AND ($link['p'] > $this->numpages
)) {
3242 $this->links
[$key]['p'] = ($link['p'] +
1);
3246 if ($this->numpages
> $this->page
) {
3247 // this page has been already added
3248 $this->setPage($this->page +
1);
3249 $this->SetY($this->tMargin
);
3253 if ($this->state
== 0) {
3257 $this->swapMargins($this->booklet
);
3258 // save current graphic settings
3259 $gvars = $this->getGraphicVars();
3261 $this->_beginpage($orientation, $format);
3262 // mark page as open
3263 $this->pageopen
[$this->page
] = true;
3264 // restore graphic settings
3265 $this->setGraphicVars($gvars);
3267 $this->setPageMark();
3268 // print page header
3270 // restore graphic settings
3271 $this->setGraphicVars($gvars);
3273 $this->setPageMark();
3274 // print table header (if any)
3275 $this->setTableHeader();
3276 // set mark for empty page check
3277 $this->emptypagemrk
[$this->page
]= $this->pagelen
[$this->page
];
3281 * Set start-writing mark on current page stream used to put borders and fills.
3282 * Borders and fills are always created after content and inserted on the position marked by this method.
3283 * This function must be called after calling Image() function for a background image.
3284 * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
3286 * @since 4.0.016 (2008-07-30)
3288 public function setPageMark() {
3289 $this->intmrk
[$this->page
] = $this->pagelen
[$this->page
];
3290 $this->bordermrk
[$this->page
] = $this->intmrk
[$this->page
];
3291 $this->setContentMark();
3295 * Set start-writing mark on selected page.
3296 * Borders and fills are always created after content and inserted on the position marked by this method.
3297 * @param $page (int) page number (default is the current page)
3299 * @since 4.6.021 (2009-07-20)
3301 protected function setContentMark($page=0) {
3303 $page = $this->page
;
3305 if (isset($this->footerlen
[$page])) {
3306 $this->cntmrk
[$page] = $this->pagelen
[$page] - $this->footerlen
[$page];
3308 $this->cntmrk
[$page] = $this->pagelen
[$page];
3314 * @param $ln (string) header image logo
3315 * @param $lw (string) header image logo width in mm
3316 * @param $ht (string) string to print as title on document header
3317 * @param $hs (string) string to print on document header
3318 * @param $tc (array) RGB array color for text.
3319 * @param $lc (array) RGB array color for line.
3322 public function setHeaderData($ln='', $lw=0, $ht='', $hs='', $tc=array(0,0,0), $lc=array(0,0,0)) {
3323 $this->header_logo
= $ln;
3324 $this->header_logo_width
= $lw;
3325 $this->header_title
= $ht;
3326 $this->header_string
= $hs;
3327 $this->header_text_color
= $tc;
3328 $this->header_line_color
= $lc;
3333 * @param $tc (array) RGB array color for text.
3334 * @param $lc (array) RGB array color for line.
3337 public function setFooterData($tc=array(0,0,0), $lc=array(0,0,0)) {
3338 $this->footer_text_color
= $tc;
3339 $this->footer_line_color
= $lc;
3343 * Returns header data:
3344 * <ul><li>$ret['logo'] = logo image</li><li>$ret['logo_width'] = width of the image logo in user units</li><li>$ret['title'] = header title</li><li>$ret['string'] = header description string</li></ul>
3347 * @since 4.0.012 (2008-07-24)
3349 public function getHeaderData() {
3351 $ret['logo'] = $this->header_logo
;
3352 $ret['logo_width'] = $this->header_logo_width
;
3353 $ret['title'] = $this->header_title
;
3354 $ret['string'] = $this->header_string
;
3355 $ret['text_color'] = $this->header_text_color
;
3356 $ret['line_color'] = $this->header_line_color
;
3361 * Set header margin.
3362 * (minimum distance between header and top page margin)
3363 * @param $hm (int) distance in user units
3366 public function setHeaderMargin($hm=10) {
3367 $this->header_margin
= $hm;
3371 * Returns header margin in user units.
3373 * @since 4.0.012 (2008-07-24)
3376 public function getHeaderMargin() {
3377 return $this->header_margin
;
3381 * Set footer margin.
3382 * (minimum distance between footer and bottom page margin)
3383 * @param $fm (int) distance in user units
3386 public function setFooterMargin($fm=10) {
3387 $this->footer_margin
= $fm;
3391 * Returns footer margin in user units.
3393 * @since 4.0.012 (2008-07-24)
3396 public function getFooterMargin() {
3397 return $this->footer_margin
;
3400 * Set a flag to print page header.
3401 * @param $val (boolean) set to true to print the page header (default), false otherwise.
3404 public function setPrintHeader($val=true) {
3405 $this->print_header
= $val ?
true : false;
3409 * Set a flag to print page footer.
3410 * @param $val (boolean) set to true to print the page footer (default), false otherwise.
3413 public function setPrintFooter($val=true) {
3414 $this->print_footer
= $val ?
true : false;
3418 * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
3422 public function getImageRBX() {
3423 return $this->img_rb_x
;
3427 * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
3431 public function getImageRBY() {
3432 return $this->img_rb_y
;
3436 * Reset the xobject template used by Header() method.
3439 public function resetHeaderTemplate() {
3440 $this->header_xobjid
= false;
3444 * Set a flag to automatically reset the xobject template used by Header() method at each page.
3445 * @param $val (boolean) set to true to reset Header xobject template at each page, false otherwise.
3448 public function setHeaderTemplateAutoreset($val=true) {
3449 $this->header_xobj_autoreset
= $val ?
true : false;
3453 * This method is used to render the page header.
3454 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
3457 public function Header() {
3458 if ($this->header_xobjid
=== false) {
3459 // start a new XObject Template
3460 $this->header_xobjid
= $this->startTemplate($this->w
, $this->tMargin
);
3461 $headerfont = $this->getHeaderFont();
3462 $headerdata = $this->getHeaderData();
3463 $this->y
= $this->header_margin
;
3465 $this->x
= $this->w
- $this->original_rMargin
;
3467 $this->x
= $this->original_lMargin
;
3469 if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE
)) {
3470 $imgtype = TCPDF_IMAGES
::getImageFileType(K_PATH_IMAGES
.$headerdata['logo']);
3471 if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
3472 $this->ImageEps(K_PATH_IMAGES
.$headerdata['logo'], '', '', $headerdata['logo_width']);
3473 } elseif ($imgtype == 'svg') {
3474 $this->ImageSVG(K_PATH_IMAGES
.$headerdata['logo'], '', '', $headerdata['logo_width']);
3476 $this->Image(K_PATH_IMAGES
.$headerdata['logo'], '', '', $headerdata['logo_width']);
3478 $imgy = $this->getImageRBY();
3482 $cell_height = $this->getCellHeight($headerfont[2] / $this->k
);
3483 // set starting margin for text data cell
3484 if ($this->getRTL()) {
3485 $header_x = $this->original_rMargin +
($headerdata['logo_width'] * 1.1);
3487 $header_x = $this->original_lMargin +
($headerdata['logo_width'] * 1.1);
3489 $cw = $this->w
- $this->original_lMargin
- $this->original_rMargin
- ($headerdata['logo_width'] * 1.1);
3490 $this->SetTextColorArray($this->header_text_color
);
3492 $this->SetFont($headerfont[0], 'B', $headerfont[2] +
1);
3493 $this->SetX($header_x);
3494 $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
3496 $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
3497 $this->SetX($header_x);
3498 $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false, true, 0, 'T', false);
3499 // print an ending header line
3500 $this->SetLineStyle(array('width' => 0.85 / $this->k
, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $headerdata['line_color']));
3501 $this->SetY((2.835 / $this->k
) +
max($imgy, $this->y
));
3503 $this->SetX($this->original_rMargin
);
3505 $this->SetX($this->original_lMargin
);
3507 $this->Cell(($this->w
- $this->original_lMargin
- $this->original_rMargin
), 0, '', 'T', 0, 'C');
3508 $this->endTemplate();
3510 // print header template
3513 if (!$this->header_xobj_autoreset
AND $this->booklet
AND (($this->page %
2) == 0)) {
3514 // adjust margins for booklet mode
3515 $dx = ($this->original_lMargin
- $this->original_rMargin
);
3518 $x = $this->w +
$dx;
3522 $this->printTemplate($this->header_xobjid
, $x, 0, 0, 0, '', '', false);
3523 if ($this->header_xobj_autoreset
) {
3524 // reset header xobject template at each page
3525 $this->header_xobjid
= false;
3530 * This method is used to render the page footer.
3531 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
3534 public function Footer() {
3536 $this->SetTextColorArray($this->footer_text_color
);
3537 //set style for cell border
3538 $line_width = (0.85 / $this->k
);
3539 $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->footer_line_color
));
3540 //print document barcode
3541 $barcode = $this->getBarcode();
3542 if (!empty($barcode)) {
3543 $this->Ln($line_width);
3544 $barcode_width = round(($this->w
- $this->original_lMargin
- $this->original_rMargin
) / 3);
3546 'position' => $this->rtl?
'R':'L',
3547 'align' => $this->rtl?
'R':'L',
3550 'cellfitalign' => '',
3553 'fgcolor' => array(0,0,0),
3557 $this->write1DBarcode($barcode, 'C128', '', $cur_y +
$line_width, '', (($this->footer_margin
/ 3) - $line_width), 0.3, $style, '');
3559 $w_page = isset($this->l
['w_page']) ?
$this->l
['w_page'].' ' : '';
3560 if (empty($this->pagegroups
)) {
3561 $pagenumtxt = $w_page.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
3563 $pagenumtxt = $w_page.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
3565 $this->SetY($cur_y);
3567 if ($this->getRTL()) {
3568 $this->SetX($this->original_rMargin
);
3569 $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
3571 $this->SetX($this->original_lMargin
);
3572 $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
3577 * This method is used to render the page header.
3579 * @since 4.0.012 (2008-07-24)
3581 protected function setHeader() {
3582 if (!$this->print_header
OR ($this->state
!= 2)) {
3585 $this->InHeader
= true;
3586 $this->setGraphicVars($this->default_graphic_vars
);
3587 $temp_thead = $this->thead
;
3588 $temp_theadMargins = $this->theadMargins
;
3589 $lasth = $this->lasth
;
3590 $newline = $this->newline
;
3591 $this->_outSaveGraphicsState();
3592 $this->rMargin
= $this->original_rMargin
;
3593 $this->lMargin
= $this->original_lMargin
;
3594 $this->SetCellPadding(0);
3595 //set current position
3597 $this->SetXY($this->original_rMargin
, $this->header_margin
);
3599 $this->SetXY($this->original_lMargin
, $this->header_margin
);
3601 $this->SetFont($this->header_font
[0], $this->header_font
[1], $this->header_font
[2]);
3605 $this->SetXY($this->original_rMargin
, $this->tMargin
);
3607 $this->SetXY($this->original_lMargin
, $this->tMargin
);
3609 $this->_outRestoreGraphicsState();
3610 $this->lasth
= $lasth;
3611 $this->thead
= $temp_thead;
3612 $this->theadMargins
= $temp_theadMargins;
3613 $this->newline
= $newline;
3614 $this->InHeader
= false;
3618 * This method is used to render the page footer.
3620 * @since 4.0.012 (2008-07-24)
3622 protected function setFooter() {
3623 if ($this->state
!= 2) {
3626 $this->InFooter
= true;
3627 // save current graphic settings
3628 $gvars = $this->getGraphicVars();
3630 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
3632 if ($this->print_footer
) {
3633 $this->setGraphicVars($this->default_graphic_vars
);
3634 $this->current_column
= 0;
3635 $this->num_columns
= 1;
3636 $temp_thead = $this->thead
;
3637 $temp_theadMargins = $this->theadMargins
;
3638 $lasth = $this->lasth
;
3639 $this->_outSaveGraphicsState();
3640 $this->rMargin
= $this->original_rMargin
;
3641 $this->lMargin
= $this->original_lMargin
;
3642 $this->SetCellPadding(0);
3643 //set current position
3644 $footer_y = $this->h
- $this->footer_margin
;
3646 $this->SetXY($this->original_rMargin
, $footer_y);
3648 $this->SetXY($this->original_lMargin
, $footer_y);
3650 $this->SetFont($this->footer_font
[0], $this->footer_font
[1], $this->footer_font
[2]);
3654 $this->SetXY($this->original_rMargin
, $this->tMargin
);
3656 $this->SetXY($this->original_lMargin
, $this->tMargin
);
3658 $this->_outRestoreGraphicsState();
3659 $this->lasth
= $lasth;
3660 $this->thead
= $temp_thead;
3661 $this->theadMargins
= $temp_theadMargins;
3663 // restore graphic settings
3664 $this->setGraphicVars($gvars);
3665 $this->current_column
= $gvars['current_column'];
3666 $this->num_columns
= $gvars['num_columns'];
3667 // calculate footer length
3668 $this->footerlen
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerpos
[$this->page
] +
1;
3669 $this->InFooter
= false;
3673 * Check if we are on the page body (excluding page header and footer).
3674 * @return true if we are not in page header nor in page footer, false otherwise.
3676 * @since 5.9.091 (2011-06-15)
3678 protected function inPageBody() {
3679 return (($this->InHeader
=== false) AND ($this->InFooter
=== false));
3683 * This method is used to render the table header on new page (if any).
3685 * @since 4.5.030 (2009-03-25)
3687 protected function setTableHeader() {
3688 if ($this->num_columns
> 1) {
3689 // multi column mode
3692 if (isset($this->theadMargins
['top'])) {
3693 // restore the original top-margin
3694 $this->tMargin
= $this->theadMargins
['top'];
3695 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
3696 $this->y
= $this->tMargin
;
3698 if (!TCPDF_STATIC
::empty_string($this->thead
) AND (!$this->inthead
)) {
3700 $prev_lMargin = $this->lMargin
;
3701 $prev_rMargin = $this->rMargin
;
3702 $prev_cell_padding = $this->cell_padding
;
3703 $this->lMargin
= $this->theadMargins
['lmargin'] +
($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$this->theadMargins
['page']]['olm']);
3704 $this->rMargin
= $this->theadMargins
['rmargin'] +
($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$this->theadMargins
['page']]['orm']);
3705 $this->cell_padding
= $this->theadMargins
['cell_padding'];
3707 $this->x
= $this->w
- $this->rMargin
;
3709 $this->x
= $this->lMargin
;
3711 // account for special "cell" mode
3712 if ($this->theadMargins
['cell']) {
3714 $this->x
-= $this->cell_padding
['R'];
3716 $this->x +
= $this->cell_padding
['L'];
3719 $gvars = $this->getGraphicVars();
3720 if (!empty($this->theadMargins
['gvars'])) {
3721 // set the correct graphic style
3722 $this->setGraphicVars($this->theadMargins
['gvars']);
3723 $this->rMargin
= $gvars['rMargin'];
3724 $this->lMargin
= $gvars['lMargin'];
3726 // print table header
3727 $this->writeHTML($this->thead
, false, false, false, false, '');
3728 $this->setGraphicVars($gvars);
3729 // set new top margin to skip the table headers
3730 if (!isset($this->theadMargins
['top'])) {
3731 $this->theadMargins
['top'] = $this->tMargin
;
3733 // store end of header position
3734 if (!isset($this->columns
[0]['th'])) {
3735 $this->columns
[0]['th'] = array();
3737 $this->columns
[0]['th']['\''.$this->page
.'\''] = $this->y
;
3738 $this->tMargin
= $this->y
;
3739 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
3741 $this->lMargin
= $prev_lMargin;
3742 $this->rMargin
= $prev_rMargin;
3743 $this->cell_padding
= $prev_cell_padding;
3748 * Returns the current page number.
3749 * @return int page number
3752 * @see getAliasNbPages()
3754 public function PageNo() {
3759 * Returns the array of spot colors.
3760 * @return (array) Spot colors array.
3762 * @since 6.0.038 (2013-09-30)
3764 public function getAllSpotColors() {
3765 return $this->spot_colors
;
3769 * Defines a new spot color.
3770 * It can be expressed in RGB components or gray scale.
3771 * The method can be called before the first page is created and the value is retained from page to page.
3772 * @param $name (string) Full name of the spot color.
3773 * @param $c (float) Cyan color for CMYK. Value between 0 and 100.
3774 * @param $m (float) Magenta color for CMYK. Value between 0 and 100.
3775 * @param $y (float) Yellow color for CMYK. Value between 0 and 100.
3776 * @param $k (float) Key (Black) color for CMYK. Value between 0 and 100.
3778 * @since 4.0.024 (2008-09-12)
3779 * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
3781 public function AddSpotColor($name, $c, $m, $y, $k) {
3782 if (!isset($this->spot_colors
[$name])) {
3783 $i = (1 +
count($this->spot_colors
));
3784 $this->spot_colors
[$name] = array('C' => $c, 'M' => $m, 'Y' => $y, 'K' => $k, 'name' => $name, 'i' => $i);
3789 * Set the spot color for the specified type ('draw', 'fill', 'text').
3790 * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
3791 * @param $name (string) Name of the spot color.
3792 * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3793 * @return (string) PDF color command.
3795 * @since 5.9.125 (2011-10-03)
3797 public function setSpotColor($type, $name, $tint=100) {
3798 $spotcolor = TCPDF_COLORS
::getSpotColor($name, $this->spot_colors
);
3799 if ($spotcolor === false) {
3800 $this->Error('Undefined spot color: '.$name.', you must add it using the AddSpotColor() method.');
3802 $tint = (max(0, min(100, $tint)) / 100);
3803 $pdfcolor = sprintf('/CS%d ', $this->spot_colors
[$name]['i']);
3806 $pdfcolor .= sprintf('CS %F SCN', $tint);
3807 $this->DrawColor
= $pdfcolor;
3808 $this->strokecolor
= $spotcolor;
3812 $pdfcolor .= sprintf('cs %F scn', $tint);
3813 $this->FillColor
= $pdfcolor;
3814 $this->bgcolor
= $spotcolor;
3818 $pdfcolor .= sprintf('cs %F scn', $tint);
3819 $this->TextColor
= $pdfcolor;
3820 $this->fgcolor
= $spotcolor;
3824 $this->ColorFlag
= ($this->FillColor
!= $this->TextColor
);
3825 if ($this->state
== 2) {
3826 $this->_out($pdfcolor);
3828 if ($this->inxobj
) {
3829 // we are inside an XObject template
3830 $this->xobjects
[$this->xobjid
]['spot_colors'][$name] = $this->spot_colors
[$name];
3836 * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
3837 * @param $name (string) Name of the spot color.
3838 * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3840 * @since 4.0.024 (2008-09-12)
3841 * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
3843 public function SetDrawSpotColor($name, $tint=100) {
3844 $this->setSpotColor('draw', $name, $tint);
3848 * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
3849 * @param $name (string) Name of the spot color.
3850 * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3852 * @since 4.0.024 (2008-09-12)
3853 * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
3855 public function SetFillSpotColor($name, $tint=100) {
3856 $this->setSpotColor('fill', $name, $tint);
3860 * Defines the spot color used for text.
3861 * @param $name (string) Name of the spot color.
3862 * @param $tint (int) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
3864 * @since 4.0.024 (2008-09-12)
3865 * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
3867 public function SetTextSpotColor($name, $tint=100) {
3868 $this->setSpotColor('text', $name, $tint);
3872 * Set the color array for the specified type ('draw', 'fill', 'text').
3873 * It can be expressed in RGB, CMYK or GRAY SCALE components.
3874 * The method can be called before the first page is created and the value is retained from page to page.
3875 * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
3876 * @param $color (array) Array of colors (1=gray, 3=RGB, 4=CMYK or 5=spotcolor=CMYK+name values).
3877 * @param $ret (boolean) If true do not send the PDF command.
3878 * @return (string) The PDF command or empty string.
3880 * @since 3.1.000 (2008-06-11)
3882 public function setColorArray($type, $color, $ret=false) {
3883 if (is_array($color)) {
3884 $color = array_values($color);
3885 // component: grey, RGB red or CMYK cyan
3886 $c = isset($color[0]) ?
$color[0] : -1;
3887 // component: RGB green or CMYK magenta
3888 $m = isset($color[1]) ?
$color[1] : -1;
3889 // component: RGB blue or CMYK yellow
3890 $y = isset($color[2]) ?
$color[2] : -1;
3891 // component: CMYK black
3892 $k = isset($color[3]) ?
$color[3] : -1;
3894 $name = isset($color[4]) ?
$color[4] : '';
3896 return $this->setColor($type, $c, $m, $y, $k, $ret, $name);
3903 * Defines the color used for all drawing operations (lines, rectangles and cell borders).
3904 * It can be expressed in RGB, CMYK or GRAY SCALE components.
3905 * The method can be called before the first page is created and the value is retained from page to page.
3906 * @param $color (array) Array of colors (1, 3 or 4 values).
3907 * @param $ret (boolean) If true do not send the PDF command.
3908 * @return string the PDF command
3910 * @since 3.1.000 (2008-06-11)
3911 * @see SetDrawColor()
3913 public function SetDrawColorArray($color, $ret=false) {
3914 return $this->setColorArray('draw', $color, $ret);
3918 * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
3919 * It can be expressed in RGB, CMYK or GRAY SCALE components.
3920 * The method can be called before the first page is created and the value is retained from page to page.
3921 * @param $color (array) Array of colors (1, 3 or 4 values).
3922 * @param $ret (boolean) If true do not send the PDF command.
3924 * @since 3.1.000 (2008-6-11)
3925 * @see SetFillColor()
3927 public function SetFillColorArray($color, $ret=false) {
3928 return $this->setColorArray('fill', $color, $ret);
3932 * Defines the color used for text. It can be expressed in RGB components or gray scale.
3933 * The method can be called before the first page is created and the value is retained from page to page.
3934 * @param $color (array) Array of colors (1, 3 or 4 values).
3935 * @param $ret (boolean) If true do not send the PDF command.
3937 * @since 3.1.000 (2008-6-11)
3938 * @see SetFillColor()
3940 public function SetTextColorArray($color, $ret=false) {
3941 return $this->setColorArray('text', $color, $ret);
3945 * Defines the color used by the specified type ('draw', 'fill', 'text').
3946 * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
3947 * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
3948 * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
3949 * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
3950 * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
3951 * @param $ret (boolean) If true do not send the command.
3952 * @param $name (string) spot color name (if any)
3953 * @return (string) The PDF command or empty string.
3955 * @since 5.9.125 (2011-10-03)
3957 public function setColor($type, $col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
3958 // set default values
3959 if (!is_numeric($col1)) {
3962 if (!is_numeric($col2)) {
3965 if (!is_numeric($col3)) {
3968 if (!is_numeric($col4)) {
3971 // set color by case
3973 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
3975 $col1 = max(0, min(255, $col1));
3976 $intcolor = array('G' => $col1);
3977 $pdfcolor = sprintf('%F ', ($col1 / 255));
3979 } elseif ($col4 == -1) {
3981 $col1 = max(0, min(255, $col1));
3982 $col2 = max(0, min(255, $col2));
3983 $col3 = max(0, min(255, $col3));
3984 $intcolor = array('R' => $col1, 'G' => $col2, 'B' => $col3);
3985 $pdfcolor = sprintf('%F %F %F ', ($col1 / 255), ($col2 / 255), ($col3 / 255));
3988 $col1 = max(0, min(100, $col1));
3989 $col2 = max(0, min(100, $col2));
3990 $col3 = max(0, min(100, $col3));
3991 $col4 = max(0, min(100, $col4));
3994 $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
3995 $pdfcolor = sprintf('%F %F %F %F ', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
3999 $intcolor = array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
4000 $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
4001 $pdfcolor = $this->setSpotColor($type, $name, 100);
4006 $pdfcolor .= strtoupper($suffix);
4007 $this->DrawColor
= $pdfcolor;
4008 $this->strokecolor
= $intcolor;
4012 $pdfcolor .= $suffix;
4013 $this->FillColor
= $pdfcolor;
4014 $this->bgcolor
= $intcolor;
4018 $pdfcolor .= $suffix;
4019 $this->TextColor
= $pdfcolor;
4020 $this->fgcolor
= $intcolor;
4024 $this->ColorFlag
= ($this->FillColor
!= $this->TextColor
);
4025 if (($type != 'text') AND ($this->state
== 2)) {
4027 $this->_out($pdfcolor);
4035 * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
4036 * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4037 * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4038 * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4039 * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
4040 * @param $ret (boolean) If true do not send the command.
4041 * @param $name (string) spot color name (if any)
4042 * @return string the PDF command
4045 * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
4047 public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4048 return $this->setColor('draw', $col1, $col2, $col3, $col4, $ret, $name);
4052 * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
4053 * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4054 * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4055 * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4056 * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
4057 * @param $ret (boolean) If true do not send the command.
4058 * @param $name (string) Spot color name (if any).
4059 * @return (string) The PDF command.
4062 * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
4064 public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4065 return $this->setColor('fill', $col1, $col2, $col3, $col4, $ret, $name);
4069 * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
4070 * @param $col1 (float) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4071 * @param $col2 (float) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4072 * @param $col3 (float) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4073 * @param $col4 (float) KEY (BLACK) color for CMYK (0-100).
4074 * @param $ret (boolean) If true do not send the command.
4075 * @param $name (string) Spot color name (if any).
4076 * @return (string) Empty string.
4079 * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
4081 public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4082 return $this->setColor('text', $col1, $col2, $col3, $col4, $ret, $name);
4086 * Returns the length of a string in user unit. A font must be selected.<br>
4087 * @param $s (string) The string whose length is to be computed
4088 * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
4089 * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line-through</li><li>O: overline</li></ul> or any combination. The default value is regular.
4090 * @param $fontsize (float) Font size in points. The default value is the current size.
4091 * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
4092 * @return mixed int total string length or array of characted widths
4093 * @author Nicola Asuni
4097 public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
4098 return $this->GetArrStringWidth(TCPDF_FONTS
::utf8Bidi(TCPDF_FONTS
::UTF8StringToArray($s, $this->isunicode
, $this->CurrentFont
), $s, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
), $fontname, $fontstyle, $fontsize, $getarray);
4102 * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
4103 * @param $sa (string) The array of chars whose total length is to be computed
4104 * @param $fontname (string) Family font. It can be either a name defined by AddFont() or one of the standard families. It is also possible to pass an empty string, in that case, the current family is retained.
4105 * @param $fontstyle (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line through</li><li>O: overline</li></ul> or any combination. The default value is regular.
4106 * @param $fontsize (float) Font size in points. The default value is the current size.
4107 * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
4108 * @return mixed int total string length or array of characted widths
4109 * @author Nicola Asuni
4111 * @since 2.4.000 (2008-03-06)
4113 public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
4114 // store current values
4115 if (!TCPDF_STATIC
::empty_string($fontname)) {
4116 $prev_FontFamily = $this->FontFamily
;
4117 $prev_FontStyle = $this->FontStyle
;
4118 $prev_FontSizePt = $this->FontSizePt
;
4119 $this->SetFont($fontname, $fontstyle, $fontsize, '', 'default', false);
4121 // convert UTF-8 array to Latin1 if required
4122 if ($this->isunicode
AND (!$this->isUnicodeFont())) {
4123 $sa = TCPDF_FONTS
::UTF8ArrToLatin1Arr($sa);
4125 $w = 0; // total width
4126 $wa = array(); // array of characters widths
4127 foreach ($sa as $ck => $char) {
4129 $cw = $this->GetCharWidth($char, isset($sa[($ck +
1)]));
4133 // restore previous values
4134 if (!TCPDF_STATIC
::empty_string($fontname)) {
4135 $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt, '', 'default', false);
4144 * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking).
4145 * @param $char (int) The char code whose length is to be returned
4146 * @param $notlast (boolean) If false ignore the font-spacing.
4147 * @return float char width
4148 * @author Nicola Asuni
4150 * @since 2.4.000 (2008-03-06)
4152 public function GetCharWidth($char, $notlast=true) {
4154 $chw = $this->getRawCharWidth($char);
4155 if (($this->font_spacing
< 0) OR (($this->font_spacing
> 0) AND $notlast)) {
4156 // increase/decrease font spacing
4157 $chw +
= $this->font_spacing
;
4159 if ($this->font_stretching
!= 100) {
4160 // fixed stretching mode
4161 $chw *= ($this->font_stretching
/ 100);
4167 * Returns the length of the char in user unit for the current font.
4168 * @param $char (int) The char code whose length is to be returned
4169 * @return float char width
4170 * @author Nicola Asuni
4172 * @since 5.9.000 (2010-09-28)
4174 public function getRawCharWidth($char) {
4176 // SHY character will not be printed
4179 if (isset($this->CurrentFont
['cw'][$char])) {
4180 $w = $this->CurrentFont
['cw'][$char];
4181 } elseif (isset($this->CurrentFont
['dw'])) {
4183 $w = $this->CurrentFont
['dw'];
4184 } elseif (isset($this->CurrentFont
['cw'][32])) {
4186 $w = $this->CurrentFont
['cw'][32];
4190 return $this->getAbsFontMeasure($w);
4194 * Returns the numbero of characters in a string.
4195 * @param $s (string) The input string.
4196 * @return int number of characters
4198 * @since 2.0.0001 (2008-01-07)
4200 public function GetNumChars($s) {
4201 if ($this->isUnicodeFont()) {
4202 return count(TCPDF_FONTS
::UTF8StringToArray($s, $this->isunicode
, $this->CurrentFont
));
4208 * Fill the list of available fonts ($this->fontlist).
4210 * @since 4.0.013 (2008-07-28)
4212 protected function getFontsList() {
4213 if (($fontsdir = opendir(TCPDF_FONTS
::_getfontpath())) !== false) {
4214 while (($file = readdir($fontsdir)) !== false) {
4215 if (substr($file, -4) == '.php') {
4216 array_push($this->fontlist
, strtolower(basename($file, '.php')));
4219 closedir($fontsdir);
4224 * Imports a TrueType, Type1, core, or CID0 font and makes it available.
4225 * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
4226 * The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
4227 * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
4228 * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
4229 * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
4230 * @return array containing the font data, or false in case of error.
4231 * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
4234 * @see SetFont(), setFontSubsetting()
4236 public function AddFont($family, $style='', $fontfile='', $subset='default') {
4237 if ($subset === 'default') {
4238 $subset = $this->font_subsetting
;
4240 if ($this->pdfa_mode
) {
4243 if (TCPDF_STATIC
::empty_string($family)) {
4244 if (!TCPDF_STATIC
::empty_string($this->FontFamily
)) {
4245 $family = $this->FontFamily
;
4247 $this->Error('Empty font family');
4250 // move embedded styles on $style
4251 if (substr($family, -1) == 'I') {
4253 $family = substr($family, 0, -1);
4255 if (substr($family, -1) == 'B') {
4257 $family = substr($family, 0, -1);
4259 // normalize family name
4260 $family = strtolower($family);
4261 if ((!$this->isunicode
) AND ($family == 'arial')) {
4262 $family = 'helvetica';
4264 if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
4267 if ($this->pdfa_mode
AND (isset($this->CoreFonts
[$family]))) {
4268 // all fonts must be embedded
4269 $family = 'pdfa'.$family;
4271 $tempstyle = strtoupper($style);
4274 if (strpos($tempstyle, 'U') !== false) {
4275 $this->underline
= true;
4277 $this->underline
= false;
4279 // line-through (deleted)
4280 if (strpos($tempstyle, 'D') !== false) {
4281 $this->linethrough
= true;
4283 $this->linethrough
= false;
4286 if (strpos($tempstyle, 'O') !== false) {
4287 $this->overline
= true;
4289 $this->overline
= false;
4292 if (strpos($tempstyle, 'B') !== false) {
4296 if (strpos($tempstyle, 'I') !== false) {
4300 $fontkey = $family.$style;
4301 $font_style = $style.($this->underline ?
'U' : '').($this->linethrough ?
'D' : '').($this->overline ?
'O' : '');
4302 $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
4303 // check if the font has been already added
4304 $fb = $this->getFontBuffer($fontkey);
4305 if ($fb !== false) {
4306 if ($this->inxobj
) {
4307 // we are inside an XObject template
4308 $this->xobjects
[$this->xobjid
]['fonts'][$fontkey] = $fb['i'];
4312 // get specified font directory (if any)
4314 if (!TCPDF_STATIC
::empty_string($fontfile)) {
4315 $fontdir = dirname($fontfile);
4316 if (TCPDF_STATIC
::empty_string($fontdir) OR ($fontdir == '.')) {
4322 // true when the font style variation is missing
4323 $missing_style = false;
4324 // search and include font file
4325 if (TCPDF_STATIC
::empty_string($fontfile) OR (!@TCPDF_STATIC
::file_exists($fontfile))) {
4326 // build a standard filenames for specified font
4327 $tmp_fontfile = str_replace(' ', '', $family).strtolower($style).'.php';
4328 $fontfile = TCPDF_FONTS
::getFontFullPath($tmp_fontfile, $fontdir);
4329 if (TCPDF_STATIC
::empty_string($fontfile)) {
4330 $missing_style = true;
4331 // try to remove the style part
4332 $tmp_fontfile = str_replace(' ', '', $family).'.php';
4333 $fontfile = TCPDF_FONTS
::getFontFullPath($tmp_fontfile, $fontdir);
4336 // include font file
4337 if (!TCPDF_STATIC
::empty_string($fontfile) AND (@TCPDF_STATIC
::file_exists($fontfile))) {
4340 $this->Error('Could not include font definition file: '.$family.'');
4342 // check font parameters
4343 if ((!isset($type)) OR (!isset($cw))) {
4344 $this->Error('The font definition file has a bad format: '.$fontfile.'');
4346 // SET default parameters
4347 if (!isset($file) OR TCPDF_STATIC
::empty_string($file)) {
4350 if (!isset($enc) OR TCPDF_STATIC
::empty_string($enc)) {
4353 if (!isset($cidinfo) OR TCPDF_STATIC
::empty_string($cidinfo)) {
4354 $cidinfo = array('Registry'=>'Adobe', 'Ordering'=>'Identity', 'Supplement'=>0);
4355 $cidinfo['uni2cid'] = array();
4357 if (!isset($ctg) OR TCPDF_STATIC
::empty_string($ctg)) {
4360 if (!isset($desc) OR TCPDF_STATIC
::empty_string($desc)) {
4363 if (!isset($up) OR TCPDF_STATIC
::empty_string($up)) {
4366 if (!isset($ut) OR TCPDF_STATIC
::empty_string($ut)) {
4369 if (!isset($cw) OR TCPDF_STATIC
::empty_string($cw)) {
4372 if (!isset($dw) OR TCPDF_STATIC
::empty_string($dw)) {
4373 // set default width
4374 if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
4375 $dw = $desc['MissingWidth'];
4376 } elseif (isset($cw[32])) {
4383 if ($type == 'core') {
4384 $name = $this->CoreFonts
[$fontkey];
4386 } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
4388 } elseif ($type == 'TrueTypeUnicode') {
4389 $enc = 'Identity-H';
4390 } elseif ($type == 'cidfont0') {
4391 if ($this->pdfa_mode
) {
4392 $this->Error('All fonts must be embedded in PDF/A mode!');
4395 $this->Error('Unknow font type: '.$type.'');
4397 // set name if unset
4398 if (!isset($name) OR empty($name)) {
4401 // create artificial font style variations if missing (only works with non-embedded fonts)
4402 if (($type != 'core') AND $missing_style) {
4404 $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
4405 $name .= $styles[$bistyle];
4407 if (strpos($bistyle, 'B') !== false) {
4408 if (isset($desc['StemV'])) {
4409 // from normal to bold
4410 $desc['StemV'] = round($desc['StemV'] * 1.75);
4413 $desc['StemV'] = 123;
4416 // artificial italic
4417 if (strpos($bistyle, 'I') !== false) {
4418 if (isset($desc['ItalicAngle'])) {
4419 $desc['ItalicAngle'] -= 11;
4421 $desc['ItalicAngle'] = -11;
4423 if (isset($desc['Flags'])) {
4424 $desc['Flags'] |
= 64; //bit 7
4426 $desc['Flags'] = 64;
4430 // check if the array of characters bounding boxes is defined
4431 if (!isset($cbbox)) {
4434 // initialize subsetchars
4435 $subsetchars = array_fill(0, 255, true);
4436 $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts
, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'cbbox' => $cbbox, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
4437 if ($this->inxobj
) {
4438 // we are inside an XObject template
4439 $this->xobjects
[$this->xobjid
]['fonts'][$fontkey] = $this->numfonts
;
4441 if (isset($diff) AND (!empty($diff))) {
4442 //Search existing encodings
4444 $nb = count($this->diffs
);
4445 for ($i=1; $i <= $nb; ++
$i) {
4446 if ($this->diffs
[$i] == $diff) {
4453 $this->diffs
[$d] = $diff;
4455 $this->setFontSubBuffer($fontkey, 'diff', $d);
4457 if (!TCPDF_STATIC
::empty_string($file)) {
4458 if (!isset($this->FontFiles
[$file])) {
4459 if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
4460 $this->FontFiles
[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
4461 } elseif ($type != 'core') {
4462 $this->FontFiles
[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
4465 // update fontkeys that are sharing this font file
4466 $this->FontFiles
[$file]['subset'] = ($this->FontFiles
[$file]['subset'] AND $subset);
4467 if (!in_array($fontkey, $this->FontFiles
[$file]['fontkeys'])) {
4468 $this->FontFiles
[$file]['fontkeys'][] = $fontkey;
4476 * Sets the font used to print character strings.
4477 * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
4478 * The method can be called before the first page is created and the font is retained from page to page.
4479 * If you just wish to change the current font size, it is simpler to call SetFontSize().
4480 * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the K_PATH_FONTS constant</li></ul><br />
4481 * @param $family (string) Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
4482 * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line through</li><li>O: overline</li></ul> or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
4483 * @param $size (float) Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
4484 * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
4485 * @param $subset (mixed) if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
4486 * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
4487 * @author Nicola Asuni
4490 * @see AddFont(), SetFontSize()
4492 public function SetFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true) {
4493 //Select a font; size given in points
4494 if ($size === null) {
4495 $size = $this->FontSizePt
;
4500 // try to add font (if not already added)
4501 $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
4502 $this->FontFamily
= $fontdata['family'];
4503 $this->FontStyle
= $fontdata['style'];
4504 if (isset($this->CurrentFont
['fontkey']) AND isset($this->CurrentFont
['subsetchars'])) {
4505 // save subset chars of the previous font
4506 $this->setFontSubBuffer($this->CurrentFont
['fontkey'], 'subsetchars', $this->CurrentFont
['subsetchars']);
4508 $this->CurrentFont
= $this->getFontBuffer($fontdata['fontkey']);
4509 $this->SetFontSize($size, $out);
4513 * Defines the size of the current font.
4514 * @param $size (float) The font size in points.
4515 * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
4520 public function SetFontSize($size, $out=true) {
4521 $size = (float)$size;
4522 // font size in points
4523 $this->FontSizePt
= $size;
4524 // font size in user units
4525 $this->FontSize
= $size / $this->k
;
4526 // calculate some font metrics
4527 if (isset($this->CurrentFont
['desc']['FontBBox'])) {
4528 $bbox = explode(' ', substr($this->CurrentFont
['desc']['FontBBox'], 1, -1));
4529 $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
4531 $font_height = $size * 1.219;
4533 if (isset($this->CurrentFont
['desc']['Ascent']) AND ($this->CurrentFont
['desc']['Ascent'] > 0)) {
4534 $font_ascent = ($this->CurrentFont
['desc']['Ascent'] * $size / 1000);
4536 if (isset($this->CurrentFont
['desc']['Descent']) AND ($this->CurrentFont
['desc']['Descent'] <= 0)) {
4537 $font_descent = (- $this->CurrentFont
['desc']['Descent'] * $size / 1000);
4539 if (!isset($font_ascent) AND !isset($font_descent)) {
4541 $font_ascent = 0.76 * $font_height;
4542 $font_descent = $font_height - $font_ascent;
4543 } elseif (!isset($font_descent)) {
4544 $font_descent = $font_height - $font_ascent;
4545 } elseif (!isset($font_ascent)) {
4546 $font_ascent = $font_height - $font_descent;
4548 $this->FontAscent
= ($font_ascent / $this->k
);
4549 $this->FontDescent
= ($font_descent / $this->k
);
4550 if ($out AND ($this->page
> 0) AND (isset($this->CurrentFont
['i'])) AND ($this->state
== 2)) {
4551 $this->_out(sprintf('BT /F%d %F Tf ET', $this->CurrentFont
['i'], $this->FontSizePt
));
4556 * Returns the bounding box of the current font in user units.
4559 * @since 5.9.152 (2012-03-23)
4561 public function getFontBBox() {
4563 if (isset($this->CurrentFont
['desc']['FontBBox'])) {
4564 $tmpbbox = explode(' ', substr($this->CurrentFont
['desc']['FontBBox'], 1, -1));
4565 $fbbox = array_map(array($this,'getAbsFontMeasure'), $tmpbbox);
4568 if (isset($this->CurrentFont
['desc']['MaxWidth'])) {
4569 $maxw = $this->getAbsFontMeasure(intval($this->CurrentFont
['desc']['MaxWidth']));
4572 if (isset($this->CurrentFont
['desc']['MissingWidth'])) {
4573 $maxw = max($maxw, $this->CurrentFont
['desc']['MissingWidth']);
4575 if (isset($this->CurrentFont
['desc']['AvgWidth'])) {
4576 $maxw = max($maxw, $this->CurrentFont
['desc']['AvgWidth']);
4578 if (isset($this->CurrentFont
['dw'])) {
4579 $maxw = max($maxw, $this->CurrentFont
['dw']);
4581 foreach ($this->CurrentFont
['cw'] as $char => $w) {
4582 $maxw = max($maxw, $w);
4587 $maxw = $this->getAbsFontMeasure($maxw);
4589 $fbbox = array(0, (0 - $this->FontDescent
), $maxw, $this->FontAscent
);
4595 * Convert a relative font measure into absolute value.
4596 * @param $s (int) Font measure.
4597 * @return float Absolute measure.
4598 * @since 5.9.186 (2012-09-13)
4600 public function getAbsFontMeasure($s) {
4601 return ($s * $this->FontSize
/ 1000);
4605 * Returns the glyph bounding box of the specified character in the current font in user units.
4606 * @param $char (int) Input character code.
4607 * @return mixed array(xMin, yMin, xMax, yMax) or FALSE if not defined.
4608 * @since 5.9.186 (2012-09-13)
4610 public function getCharBBox($char) {
4612 if (isset($this->CurrentFont
['cw'][$c])) {
4613 // glyph is defined ... use zero width & height for glyphs without outlines
4614 $result = array(0,0,0,0);
4615 if (isset($this->CurrentFont
['cbbox'][$c])) {
4616 $result = $this->CurrentFont
['cbbox'][$c];
4618 return array_map(array($this,'getAbsFontMeasure'), $result);
4624 * Return the font descent value
4625 * @param $font (string) font name
4626 * @param $style (string) font style
4627 * @param $size (float) The size (in points)
4628 * @return int font descent
4630 * @author Nicola Asuni
4631 * @since 4.9.003 (2010-03-30)
4633 public function getFontDescent($font, $style='', $size=0) {
4634 $fontdata = $this->AddFont($font, $style);
4635 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4636 if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
4637 $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
4639 $descent = (1.219 * 0.24 * $size);
4641 return ($descent / $this->k
);
4645 * Return the font ascent value.
4646 * @param $font (string) font name
4647 * @param $style (string) font style
4648 * @param $size (float) The size (in points)
4649 * @return int font ascent
4651 * @author Nicola Asuni
4652 * @since 4.9.003 (2010-03-30)
4654 public function getFontAscent($font, $style='', $size=0) {
4655 $fontdata = $this->AddFont($font, $style);
4656 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4657 if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
4658 $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
4660 $ascent = 1.219 * 0.76 * $size;
4662 return ($ascent / $this->k
);
4666 * Return true in the character is present in the specified font.
4667 * @param $char (mixed) Character to check (integer value or string)
4668 * @param $font (string) Font name (family name).
4669 * @param $style (string) Font style.
4670 * @return (boolean) true if the char is defined, false otherwise.
4672 * @since 5.9.153 (2012-03-28)
4674 public function isCharDefined($char, $font='', $style='') {
4675 if (is_string($char)) {
4676 // get character code
4677 $char = TCPDF_FONTS
::UTF8StringToArray($char, $this->isunicode
, $this->CurrentFont
);
4680 if (TCPDF_STATIC
::empty_string($font)) {
4681 if (TCPDF_STATIC
::empty_string($style)) {
4682 return (isset($this->CurrentFont
['cw'][intval($char)]));
4684 $font = $this->FontFamily
;
4686 $fontdata = $this->AddFont($font, $style);
4687 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4688 return (isset($fontinfo['cw'][intval($char)]));
4692 * Replace missing font characters on selected font with specified substitutions.
4693 * @param $text (string) Text to process.
4694 * @param $font (string) Font name (family name).
4695 * @param $style (string) Font style.
4696 * @param $subs (array) Array of possible character substitutions. The key is the character to check (integer value) and the value is a single intege value or an array of possible substitutes.
4697 * @return (string) Processed text.
4699 * @since 5.9.153 (2012-03-28)
4701 public function replaceMissingChars($text, $font='', $style='', $subs=array()) {
4705 if (TCPDF_STATIC
::empty_string($font)) {
4706 $font = $this->FontFamily
;
4708 $fontdata = $this->AddFont($font, $style);
4709 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
4710 $uniarr = TCPDF_FONTS
::UTF8StringToArray($text, $this->isunicode
, $this->CurrentFont
);
4711 foreach ($uniarr as $k => $chr) {
4712 if (!isset($fontinfo['cw'][$chr])) {
4713 // this character is missing on the selected font
4714 if (isset($subs[$chr])) {
4715 // we have available substitutions
4716 if (is_array($subs[$chr])) {
4717 foreach($subs[$chr] as $s) {
4718 if (isset($fontinfo['cw'][$s])) {
4723 } elseif (isset($fontinfo['cw'][$subs[$chr]])) {
4724 $uniarr[$k] = $subs[$chr];
4729 return TCPDF_FONTS
::UniArrSubString(TCPDF_FONTS
::UTF8ArrayToUniArray($uniarr, $this->isunicode
));
4733 * Defines the default monospaced font.
4734 * @param $font (string) Font name.
4738 public function SetDefaultMonospacedFont($font) {
4739 $this->default_monospaced_font
= $font;
4743 * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
4744 * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
4747 * @see Cell(), Write(), Image(), Link(), SetLink()
4749 public function AddLink() {
4750 // create a new internal link
4751 $n = count($this->links
) +
1;
4752 $this->links
[$n] = array('p' => 0, 'y' => 0, 'f' => false);
4757 * Defines the page and position a link points to.
4758 * @param $link (int) The link identifier returned by AddLink()
4759 * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
4760 * @param $page (int|string) Number of target page; -1 indicates the current page (default value). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
4765 public function SetLink($link, $y=0, $page=-1) {
4767 if (!empty($page) AND (substr($page, 0, 1) == '*')) {
4768 $page = intval(substr($page, 1));
4769 // this page number will not be changed when moving/add/deleting pages
4773 $page = $this->page
;
4778 $this->links
[$link] = array('p' => $page, 'y' => $y, 'f' => $fixed);
4782 * Puts a link on a rectangular area of the page.
4783 * Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.
4784 * @param $x (float) Abscissa of the upper-left corner of the rectangle
4785 * @param $y (float) Ordinate of the upper-left corner of the rectangle
4786 * @param $w (float) Width of the rectangle
4787 * @param $h (float) Height of the rectangle
4788 * @param $link (mixed) URL or identifier returned by AddLink()
4789 * @param $spaces (int) number of spaces on the text to link
4792 * @see AddLink(), Annotation(), Cell(), Write(), Image()
4794 public function Link($x, $y, $w, $h, $link, $spaces=0) {
4795 $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
4799 * Puts a markup annotation on a rectangular area of the page.
4800 * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
4801 * @param $x (float) Abscissa of the upper-left corner of the rectangle
4802 * @param $y (float) Ordinate of the upper-left corner of the rectangle
4803 * @param $w (float) Width of the rectangle
4804 * @param $h (float) Height of the rectangle
4805 * @param $text (string) annotation text or alternate content
4806 * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
4807 * @param $spaces (int) number of spaces on the text to link
4809 * @since 4.0.018 (2008-08-06)
4811 public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
4812 if ($this->inxobj
) {
4813 // store parameters for later use on template
4814 $this->xobjects
[$this->xobjid
]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
4823 // check page for no-write regions and adapt page margins if necessary
4824 list($x, $y) = $this->checkPageRegions($h, $x, $y);
4825 // recalculate coordinates to account for graphic transformations
4826 if (isset($this->transfmatrix
) AND !empty($this->transfmatrix
)) {
4827 for ($i=$this->transfmatrix_key
; $i > 0; --$i) {
4828 $maxid = count($this->transfmatrix
[$i]) - 1;
4829 for ($j=$maxid; $j >= 0; --$j) {
4830 $ctm = $this->transfmatrix
[$i][$j];
4831 if (isset($ctm['a'])) {
4833 $y = ($this->h
- $y) * $this->k
;
4839 $x1 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
4840 $y1 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
4844 $x2 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
4845 $y2 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
4849 $x3 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
4850 $y3 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
4854 $x4 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
4855 $y4 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
4856 // new coordinates (rectangle area)
4857 $x = min($x1, $x2, $x3, $x4);
4858 $y = max($y1, $y2, $y3, $y4);
4859 $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k
;
4860 $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k
;
4862 $y = $this->h
- ($y / $this->k
);
4867 if ($this->page
<= 0) {
4870 $page = $this->page
;
4872 if (!isset($this->PageAnnots
[$page])) {
4873 $this->PageAnnots
[$page] = array();
4875 $this->PageAnnots
[$page][] = array('n' => ++
$this->n
, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
4876 if (!$this->pdfa_mode ||
($this->pdfa_mode
&& $this->pdfa_version
== 3)) {
4877 if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!TCPDF_STATIC
::empty_string($opt['FS']))
4878 AND (@TCPDF_STATIC
::file_exists($opt['FS']) OR TCPDF_STATIC
::isValidURL($opt['FS']))
4879 AND (!isset($this->embeddedfiles
[basename($opt['FS'])]))) {
4880 $this->embeddedfiles
[basename($opt['FS'])] = array('f' => ++
$this->n
, 'n' => ++
$this->n
, 'file' => $opt['FS']);
4883 // Add widgets annotation's icons
4884 if (isset($opt['mk']['i']) AND @TCPDF_STATIC
::file_exists($opt['mk']['i'])) {
4885 $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
4887 if (isset($opt['mk']['ri']) AND @TCPDF_STATIC
::file_exists($opt['mk']['ri'])) {
4888 $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
4890 if (isset($opt['mk']['ix']) AND @TCPDF_STATIC
::file_exists($opt['mk']['ix'])) {
4891 $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
4896 * Embedd the attached files.
4897 * @since 4.4.000 (2008-12-07)
4901 protected function _putEmbeddedFiles() {
4902 if ($this->pdfa_mode
&& $this->pdfa_version
!= 3) {
4903 // embedded files are not allowed in PDF/A mode version 1 and 2
4906 reset($this->embeddedfiles
);
4907 foreach ($this->embeddedfiles
as $filename => $filedata) {
4908 $data = $this->getCachedFileContents($filedata['file']);
4909 if ($data !== FALSE) {
4910 $rawsize = strlen($data);
4913 $this->efnames
[$filename] = $filedata['f'].' 0 R';
4914 // embedded file specification object
4915 $out = $this->_getobj($filedata['f'])."\n";
4916 $out .= '<</Type /Filespec /F '.$this->_datastring($filename, $filedata['f']);
4917 $out .= ' /UF '.$this->_datastring($filename, $filedata['f']);
4918 $out .= ' /AFRelationship /Source';
4919 $out .= ' /EF <</F '.$filedata['n'].' 0 R>> >>';
4920 $out .= "\n".'endobj';
4922 // embedded file object
4924 if ($this->compress
) {
4925 $data = gzcompress($data);
4926 $filter = ' /Filter /FlateDecode';
4929 if ($this->pdfa_version
== 3) {
4930 $filter = ' /Subtype /text#2Fxml';
4933 $stream = $this->_getrawstream($data, $filedata['n']);
4934 $out = $this->_getobj($filedata['n'])."\n";
4935 $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' /Params <</Size '.$rawsize.'>> >>';
4936 $out .= ' stream'."\n".$stream."\n".'endstream';
4937 $out .= "\n".'endobj';
4945 * Prints a text cell at the specified position.
4946 * This method allows to place a string precisely on the page.
4947 * @param $x (float) Abscissa of the cell origin
4948 * @param $y (float) Ordinate of the cell origin
4949 * @param $txt (string) String to print
4950 * @param $fstroke (int) outline size in user units (false = disable)
4951 * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
4952 * @param $ffill (boolean) if true fills the text
4953 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
4954 * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
4955 * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
4956 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
4957 * @param $link (mixed) URL or identifier returned by AddLink().
4958 * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
4959 * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
4960 * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li><li>B : cell bottom</li></ul>
4961 * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
4962 * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
4965 * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
4967 public function Text($x, $y, $txt, $fstroke=false, $fclip=false, $ffill=true, $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M', $rtloff=false) {
4968 $textrendermode = $this->textrendermode
;
4969 $textstrokewidth = $this->textstrokewidth
;
4970 $this->setTextRenderingMode($fstroke, $ffill, $fclip);
4971 $this->SetXY($x, $y, $rtloff);
4972 $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
4973 // restore previous rendering mode
4974 $this->textrendermode
= $textrendermode;
4975 $this->textstrokewidth
= $textstrokewidth;
4979 * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
4980 * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
4981 * This method is called automatically and should not be called directly by the application.
4985 * @see SetAutoPageBreak()
4987 public function AcceptPageBreak() {
4988 if ($this->num_columns
> 1) {
4989 // multi column mode
4990 if ($this->current_column
< ($this->num_columns
- 1)) {
4991 // go to next column
4992 $this->selectColumn($this->current_column +
1);
4993 } elseif ($this->AutoPageBreak
) {
4997 $this->selectColumn(0);
4999 // avoid page breaking from checkPageBreak()
5002 return $this->AutoPageBreak
;
5006 * Add page if needed.
5007 * @param $h (float) Cell height. Default value: 0.
5008 * @param $y (mixed) starting y position, leave empty for current position.
5009 * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
5010 * @return boolean true in case of page break, false otherwise.
5011 * @since 3.2.000 (2008-07-01)
5014 protected function checkPageBreak($h=0, $y='', $addpage=true) {
5015 if (TCPDF_STATIC
::empty_string($y)) {
5018 $current_page = $this->page
;
5019 if ((($y +
$h) > $this->PageBreakTrigger
) AND ($this->inPageBody()) AND ($this->AcceptPageBreak())) {
5021 //Automatic page break
5023 $this->AddPage($this->CurOrientation
);
5024 $this->y
= $this->tMargin
;
5025 $oldpage = $this->page
- 1;
5027 if ($this->pagedim
[$this->page
]['orm'] != $this->pagedim
[$oldpage]['orm']) {
5028 $this->x
= $x - ($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$oldpage]['orm']);
5033 if ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$oldpage]['olm']) {
5034 $this->x
= $x +
($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$oldpage]['olm']);
5042 if ($current_page != $this->page
) {
5043 // account for columns mode
5050 * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
5051 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
5052 * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
5053 * @param $h (float) Cell height. Default value: 0.
5054 * @param $txt (string) String to print. Default value: empty string.
5055 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
5056 * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
5057 * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
5058 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
5059 * @param $link (mixed) URL or identifier returned by AddLink().
5060 * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
5061 * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
5062 * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
5063 * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>C : center</li><li>B : bottom</li></ul>
5066 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
5068 public function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
5069 $prev_cell_margin = $this->cell_margin
;
5070 $prev_cell_padding = $this->cell_padding
;
5071 $this->adjustCellPadding($border);
5072 if (!$ignore_min_height) {
5073 $min_cell_height = $this->getCellHeight($this->FontSize
);
5074 if ($h < $min_cell_height) {
5075 $h = $min_cell_height;
5078 $this->checkPageBreak($h +
$this->cell_margin
['T'] +
$this->cell_margin
['B']);
5079 // apply text shadow if enabled
5080 if ($this->txtshadow
['enabled']) {
5084 $bc = $this->bgcolor
;
5085 $fc = $this->fgcolor
;
5086 $sc = $this->strokecolor
;
5087 $alpha = $this->alpha
;
5089 $this->x +
= $this->txtshadow
['depth_w'];
5090 $this->y +
= $this->txtshadow
['depth_h'];
5091 $this->SetFillColorArray($this->txtshadow
['color']);
5092 $this->SetTextColorArray($this->txtshadow
['color']);
5093 $this->SetDrawColorArray($this->txtshadow
['color']);
5094 if ($this->txtshadow
['opacity'] != $alpha['CA']) {
5095 $this->setAlpha($this->txtshadow
['opacity'], $this->txtshadow
['blend_mode']);
5097 if ($this->state
== 2) {
5098 $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
5103 $this->SetFillColorArray($bc);
5104 $this->SetTextColorArray($fc);
5105 $this->SetDrawColorArray($sc);
5106 if ($this->txtshadow
['opacity'] != $alpha['CA']) {
5107 $this->setAlpha($alpha['CA'], $alpha['BM'], $alpha['ca'], $alpha['AIS']);
5110 if ($this->state
== 2) {
5111 $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
5113 $this->cell_padding
= $prev_cell_padding;
5114 $this->cell_margin
= $prev_cell_margin;
5118 * Returns the PDF string code to print a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
5119 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
5120 * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
5121 * @param $h (float) Cell height. Default value: 0.
5122 * @param $txt (string) String to print. Default value: empty string.
5123 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
5124 * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL languages)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
5125 * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
5126 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
5127 * @param $link (mixed) URL or identifier returned by AddLink().
5128 * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
5129 * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
5130 * @param $calign (string) cell vertical alignment relative to the specified Y value. Possible values are:<ul><li>T : cell top</li><li>C : center</li><li>B : cell bottom</li><li>A : font top</li><li>L : font baseline</li><li>D : font bottom</li></ul>
5131 * @param $valign (string) text vertical alignment inside the cell. Possible values are:<ul><li>T : top</li><li>M : middle</li><li>B : bottom</li></ul>
5132 * @return string containing cell code
5137 protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
5138 // replace 'NO-BREAK SPACE' (U+00A0) character with a simple space
5139 $txt = str_replace(TCPDF_FONTS
::unichr(160, $this->isunicode
), ' ', $txt);
5140 $prev_cell_margin = $this->cell_margin
;
5141 $prev_cell_padding = $this->cell_padding
;
5142 $txt = TCPDF_STATIC
::removeSHY($txt, $this->isunicode
);
5143 $rs = ''; //string to be returned
5144 $this->adjustCellPadding($border);
5145 if (!$ignore_min_height) {
5146 $min_cell_height = $this->getCellHeight($this->FontSize
);
5147 if ($h < $min_cell_height) {
5148 $h = $min_cell_height;
5152 // check page for no-write regions and adapt page margins if necessary
5153 list($this->x
, $this->y
) = $this->checkPageRegions($h, $this->x
, $this->y
);
5155 $x = $this->x
- $this->cell_margin
['R'];
5157 $x = $this->x +
$this->cell_margin
['L'];
5159 $y = $this->y +
$this->cell_margin
['T'];
5160 $prev_font_stretching = $this->font_stretching
;
5161 $prev_font_spacing = $this->font_spacing
;
5162 // cell vertical alignment
5169 $y -= $this->cell_padding
['T'];
5174 $y -= ($h - $this->cell_padding
['B'] - $this->FontAscent
- $this->FontDescent
);
5181 $y -= (($h - $this->FontAscent
- $this->FontDescent
) / 2);
5192 $y -= ($this->cell_padding
['T'] +
$this->FontAscent
);
5197 $y -= ($h - $this->cell_padding
['B'] - $this->FontDescent
);
5204 $y -= (($h +
$this->FontAscent
- $this->FontDescent
) / 2);
5215 $y -= ($this->cell_padding
['T'] +
$this->FontAscent +
$this->FontDescent
);
5220 $y -= ($h - $this->cell_padding
['B']);
5227 $y -= (($h +
$this->FontAscent +
$this->FontDescent
) / 2);
5250 // text vertical alignment
5254 $yt = $y +
$this->cell_padding
['T'];
5259 $yt = $y +
$h - $this->cell_padding
['B'] - $this->FontAscent
- $this->FontDescent
;
5266 $yt = $y +
(($h - $this->FontAscent
- $this->FontDescent
) / 2);
5270 $basefonty = $yt +
$this->FontAscent
;
5271 if (TCPDF_STATIC
::empty_string($w) OR ($w <= 0)) {
5273 $w = $x - $this->lMargin
;
5275 $w = $this->w
- $this->rMargin
- $x;
5280 if (is_string($border) AND (strlen($border) == 4)) {
5284 if ($fill OR ($border == 1)) {
5286 $op = ($border == 1) ?
'B' : 'f';
5291 $xk = (($x - $w) * $k);
5295 $s .= sprintf('%F %F %F %F re %s ', $xk, (($this->h
- $y) * $k), ($w * $k), (-$h * $k), $op);
5298 $s .= $this->getCellBorder($x, $y, $w, $h, $border);
5301 if ($this->isunicode
) {
5302 if (($this->CurrentFont
['type'] == 'core') OR ($this->CurrentFont
['type'] == 'TrueType') OR ($this->CurrentFont
['type'] == 'Type1')) {
5303 $txt2 = TCPDF_FONTS
::UTF8ToLatin1($txt2, $this->isunicode
, $this->CurrentFont
);
5305 $unicode = TCPDF_FONTS
::UTF8StringToArray($txt, $this->isunicode
, $this->CurrentFont
); // array of UTF-8 unicode values
5306 $unicode = TCPDF_FONTS
::utf8Bidi($unicode, '', $this->tmprtl
, $this->isunicode
, $this->CurrentFont
);
5307 // replace thai chars (if any)
5308 if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS
== true)) {
5310 $numchars = count($unicode);
5311 // po pla, for far, for fan
5312 $longtail = array(0x0e1b, 0x0e1d, 0x0e1f);
5313 // do chada, to patak
5314 $lowtail = array(0x0e0e, 0x0e0f);
5315 // mai hun arkad, sara i, sara ii, sara ue, sara uee
5316 $upvowel = array(0x0e31, 0x0e34, 0x0e35, 0x0e36, 0x0e37);
5317 // mai ek, mai tho, mai tri, mai chattawa, karan
5318 $tonemark = array(0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c);
5319 // sara u, sara uu, pinthu
5320 $lowvowel = array(0x0e38, 0x0e39, 0x0e3a);
5322 for ($i = 0; $i < $numchars; $i++
) {
5323 if (($unicode[$i] >= 0x0e00) && ($unicode[$i] <= 0x0e5b)) {
5324 $ch0 = $unicode[$i];
5325 $ch1 = ($i > 0) ?
$unicode[($i - 1)] : 0;
5326 $ch2 = ($i > 1) ?
$unicode[($i - 2)] : 0;
5327 $chn = ($i < ($numchars - 1)) ?
$unicode[($i +
1)] : 0;
5328 if (in_array($ch0, $tonemark)) {
5329 if ($chn == 0x0e33) {
5331 if (in_array($ch1, $longtail)) {
5332 // tonemark at upper left
5333 $output[] = $this->replaceChar($ch0, (0xf713 +
$ch0 - 0x0e48));
5335 // tonemark at upper right (normal position)
5338 } elseif (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $lowvowel))) {
5339 // tonemark at lower left
5340 $output[] = $this->replaceChar($ch0, (0xf705 +
$ch0 - 0x0e48));
5341 } elseif (in_array($ch1, $upvowel)) {
5342 if (in_array($ch2, $longtail)) {
5343 // tonemark at upper left
5344 $output[] = $this->replaceChar($ch0, (0xf713 +
$ch0 - 0x0e48));
5346 // tonemark at upper right (normal position)
5350 // tonemark at lower right
5351 $output[] = $this->replaceChar($ch0, (0xf70a +
$ch0 - 0x0e48));
5353 } elseif (($ch0 == 0x0e33) AND (in_array($ch1, $longtail) OR (in_array($ch2, $longtail) AND in_array($ch1, $tonemark)))) {
5354 // add lower left nikhahit and sara aa
5355 if ($this->isCharDefined(0xf711) AND $this->isCharDefined(0x0e32)) {
5357 $this->CurrentFont
['subsetchars'][0xf711] = true;
5359 $this->CurrentFont
['subsetchars'][0x0e32] = true;
5363 } elseif (in_array($ch1, $longtail)) {
5364 if ($ch0 == 0x0e31) {
5365 // lower left mai hun arkad
5366 $output[] = $this->replaceChar($ch0, 0xf710);
5367 } elseif (in_array($ch0, $upvowel)) {
5369 $output[] = $this->replaceChar($ch0, (0xf701 +
$ch0 - 0x0e34));
5370 } elseif ($ch0 == 0x0e47) {
5371 // lower left mai tai koo
5372 $output[] = $this->replaceChar($ch0, 0xf712);
5377 } elseif (in_array($ch1, $lowtail) AND in_array($ch0, $lowvowel)) {
5379 $output[] = $this->replaceChar($ch0, (0xf718 +
$ch0 - 0x0e38));
5380 } elseif (($ch0 == 0x0e0d) AND in_array($chn, $lowvowel)) {
5381 // yo ying without lower part
5382 $output[] = $this->replaceChar($ch0, 0xf70f);
5383 } elseif (($ch0 == 0x0e10) AND in_array($chn, $lowvowel)) {
5384 // tho santan without lower part
5385 $output[] = $this->replaceChar($ch0, 0xf700);
5390 // non-thai character
5391 $output[] = $unicode[$i];
5395 // update font subsetchars
5396 $this->setFontSubBuffer($this->CurrentFont
['fontkey'], 'subsetchars', $this->CurrentFont
['subsetchars']);
5397 } // end of K_THAI_TOPCHARS
5398 $txt2 = TCPDF_FONTS
::arrUTF8ToUTF16BE($unicode, false);
5401 $txt2 = TCPDF_STATIC
::_escape($txt2);
5402 // get current text width (considering general font stretching and spacing)
5403 $txwidth = $this->GetStringWidth($txt);
5405 // check for stretch mode
5407 // calculate ratio between cell width and text width
5411 $ratio = (($w - $this->cell_padding
['L'] - $this->cell_padding
['R']) / $width);
5413 // check if stretching is required
5414 if (($ratio < 1) OR (($ratio > 1) AND (($stretch %
2) == 0))) {
5415 // the text will be stretched to fit cell width
5417 // set new character spacing
5418 $this->font_spacing +
= ($w - $this->cell_padding
['L'] - $this->cell_padding
['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching
/ 100));
5420 // set new horizontal stretching
5421 $this->font_stretching
*= $ratio;
5423 // recalculate text width (the text fills the entire cell)
5424 $width = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
5429 if ($this->font_stretching
!= 100) {
5430 // apply font stretching
5431 $rs .= sprintf('BT %F Tz ET ', $this->font_stretching
);
5433 if ($this->font_spacing
!= 0) {
5434 // increase/decrease font spacing
5435 $rs .= sprintf('BT %F Tc ET ', ($this->font_spacing
* $this->k
));
5437 if ($this->ColorFlag
AND ($this->textrendermode
< 4)) {
5438 $s .= 'q '.$this->TextColor
.' ';
5441 $s .= sprintf('BT %d Tr %F w ET ', $this->textrendermode
, ($this->textstrokewidth
* $this->k
));
5442 // count number of spaces
5443 $ns = substr_count($txt, chr(32));
5446 if (($align == 'J') AND ($ns > 0)) {
5447 if ($this->isUnicodeFont()) {
5448 // get string width without spaces
5449 $width = $this->GetStringWidth(str_replace(' ', '', $txt));
5450 // calculate average space width
5451 $spacewidth = -1000 * ($w - $width - $this->cell_padding
['L'] - $this->cell_padding
['R']) / ($ns?
$ns:1) / ($this->FontSize?
$this->FontSize
:1);
5452 if ($this->font_stretching
!= 100) {
5453 // word spacing is affected by stretching
5454 $spacewidth /= ($this->font_stretching
/ 100);
5456 // set word position to be used with TJ operator
5457 $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacewidth).' (', $txt2);
5458 $unicode_justification = true;
5463 $spacewidth = (($w - $width - $this->cell_padding
['L'] - $this->cell_padding
['R']) / ($ns?
$ns:1)) * $this->k
;
5464 if ($this->font_stretching
!= 100) {
5465 // word spacing (Tw) is affected by stretching
5466 $spacewidth /= ($this->font_stretching
/ 100);
5469 $rs .= sprintf('BT %F Tw ET ', $spacewidth);
5471 $width = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
5473 // replace carriage return characters
5474 $txt2 = str_replace("\r", ' ', $txt2);
5477 $dx = ($w - $width) / 2;
5482 $dx = $this->cell_padding
['R'];
5484 $dx = $w - $width - $this->cell_padding
['R'];
5490 $dx = $w - $width - $this->cell_padding
['L'];
5492 $dx = $this->cell_padding
['L'];
5499 $dx = $this->cell_padding
['R'];
5501 $dx = $this->cell_padding
['L'];
5507 $xdx = $x - $dx - $width;
5513 $s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h
- $basefonty) * $k), $txt2);
5514 if (isset($uniblock)) {
5515 // print overlapping characters as separate string
5516 $xshift = 0; // horizontal shift
5517 $ty = (($this->h
- $basefonty +
(0.2 * $this->FontSize
)) * $k);
5518 $spw = (($w - $txwidth - $this->cell_padding
['L'] - $this->cell_padding
['R']) / ($ns?
$ns:1));
5519 foreach ($uniblock as $uk => $uniarr) {
5520 if (($uk %
2) == 0) {
5522 if ($spacewidth != 0) {
5523 // justification shift
5524 $xshift +
= (count(array_keys($uniarr, 32)) * $spw);
5526 $xshift +
= $this->GetArrStringWidth($uniarr); // + shift justification
5528 // character to print
5529 $topchr = TCPDF_FONTS
::arrUTF8ToUTF16BE($uniarr, false);
5530 $topchr = TCPDF_STATIC
::_escape($topchr);
5531 $s .= sprintf(' BT %F %F Td [(%s)] TJ ET', ($xdk +
($xshift * $k)), $ty, $topchr);
5535 if ($this->underline
) {
5536 $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
5538 if ($this->linethrough
) {
5539 $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
5541 if ($this->overline
) {
5542 $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
5544 if ($this->ColorFlag
AND ($this->textrendermode
< 4)) {
5548 $this->Link($xdx, $yt, $width, ($this->FontAscent +
$this->FontDescent
), $link, $ns);
5555 if ($this->font_spacing
!= 0) {
5556 // reset font spacing mode
5557 $rs .= ' BT 0 Tc ET';
5559 if ($this->font_stretching
!= 100) {
5560 // reset font stretching mode
5561 $rs .= ' BT 100 Tz ET';
5564 // reset word spacing
5565 if (!$this->isUnicodeFont() AND ($align == 'J')) {
5566 $rs .= ' BT 0 Tw ET';
5568 // reset stretching and spacing
5569 $this->font_stretching
= $prev_font_stretching;
5570 $this->font_spacing
= $prev_font_spacing;
5573 //Go to the beginning of the next line
5574 $this->y
= $y +
$h +
$this->cell_margin
['B'];
5577 $this->x
= $this->w
- $this->rMargin
;
5579 $this->x
= $this->lMargin
;
5583 // go left or right by case
5585 $this->x
= $x - $w - $this->cell_margin
['L'];
5587 $this->x
= $x +
$w +
$this->cell_margin
['R'];
5590 $gstyles = ''.$this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
.' '.$this->FillColor
."\n";
5592 $this->cell_padding
= $prev_cell_padding;
5593 $this->cell_margin
= $prev_cell_margin;
5598 * Replace a char if is defined on the current font.
5599 * @param $oldchar (int) Integer code (unicode) of the character to replace.
5600 * @param $newchar (int) Integer code (unicode) of the new character.
5601 * @return int the replaced char or the old char in case the new char i not defined
5603 * @since 5.9.167 (2012-06-22)
5605 protected function replaceChar($oldchar, $newchar) {
5606 if ($this->isCharDefined($newchar)) {
5607 // add the new char on the subset list
5608 $this->CurrentFont
['subsetchars'][$newchar] = true;
5609 // return the new character
5612 // return the old char
5617 * Returns the code to draw the cell border
5618 * @param $x (float) X coordinate.
5619 * @param $y (float) Y coordinate.
5620 * @param $w (float) Cell width.
5621 * @param $h (float) Cell height.
5622 * @param $brd (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
5623 * @return string containing cell border code
5625 * @see SetLineStyle()
5626 * @since 5.7.000 (2010-08-02)
5628 protected function getCellBorder($x, $y, $w, $h, $brd) {
5629 $s = ''; // string to be returned
5634 $brd = array('LRTB' => true);
5636 // calculate coordinates for border
5639 $xeL = ($x - $w) * $k;
5643 $xeR = ($x +
$w) * $k;
5645 $yeL = (($this->h
- ($y +
$h)) * $k);
5646 $yeT = (($this->h
- $y) * $k);
5651 if (is_string($brd)) {
5652 // convert string to array
5653 $slen = strlen($brd);
5655 for ($i = 0; $i < $slen; ++
$i) {
5656 $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
5660 if (isset($brd['mode'])) {
5661 $mode = $brd['mode'];
5662 unset($brd['mode']);
5666 foreach ($brd as $border => $style) {
5667 if (is_array($style) AND !empty($style)) {
5668 // apply border style
5669 $prev_style = $this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
.' ';
5670 $s .= $this->SetLineStyle($style, true)."\n";
5674 $off = (($this->LineWidth
/ 2) * $k);
5683 $w +
= $this->LineWidth
;
5684 $h +
= $this->LineWidth
;
5688 $off = ($this->LineWidth
/ 2) * $k;
5697 $w -= $this->LineWidth
;
5698 $h -= $this->LineWidth
;
5714 // draw borders by case
5715 if (strlen($border) == 4) {
5716 $s .= sprintf('%F %F %F %F re S ', $xT, $yT, ($w * $k), (-$h * $k));
5717 } elseif (strlen($border) == 3) {
5718 if (strpos($border,'B') === false) { // LTR
5719 $s .= sprintf('%F %F m ', $xL, $yL);
5720 $s .= sprintf('%F %F l ', $xT, $yT);
5721 $s .= sprintf('%F %F l ', $xR, $yR);
5722 $s .= sprintf('%F %F l ', $xB, $yB);
5724 } elseif (strpos($border,'L') === false) { // TRB
5725 $s .= sprintf('%F %F m ', $xT, $yT);
5726 $s .= sprintf('%F %F l ', $xR, $yR);
5727 $s .= sprintf('%F %F l ', $xB, $yB);
5728 $s .= sprintf('%F %F l ', $xL, $yL);
5730 } elseif (strpos($border,'T') === false) { // RBL
5731 $s .= sprintf('%F %F m ', $xR, $yR);
5732 $s .= sprintf('%F %F l ', $xB, $yB);
5733 $s .= sprintf('%F %F l ', $xL, $yL);
5734 $s .= sprintf('%F %F l ', $xT, $yT);
5736 } elseif (strpos($border,'R') === false) { // BLT
5737 $s .= sprintf('%F %F m ', $xB, $yB);
5738 $s .= sprintf('%F %F l ', $xL, $yL);
5739 $s .= sprintf('%F %F l ', $xT, $yT);
5740 $s .= sprintf('%F %F l ', $xR, $yR);
5743 } elseif (strlen($border) == 2) {
5744 if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
5745 $s .= sprintf('%F %F m ', $xL, $yL);
5746 $s .= sprintf('%F %F l ', $xT, $yT);
5747 $s .= sprintf('%F %F l ', $xR, $yR);
5749 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
5750 $s .= sprintf('%F %F m ', $xT, $yT);
5751 $s .= sprintf('%F %F l ', $xR, $yR);
5752 $s .= sprintf('%F %F l ', $xB, $yB);
5754 } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
5755 $s .= sprintf('%F %F m ', $xR, $yR);
5756 $s .= sprintf('%F %F l ', $xB, $yB);
5757 $s .= sprintf('%F %F l ', $xL, $yL);
5759 } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
5760 $s .= sprintf('%F %F m ', $xB, $yB);
5761 $s .= sprintf('%F %F l ', $xL, $yL);
5762 $s .= sprintf('%F %F l ', $xT, $yT);
5764 } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
5765 $s .= sprintf('%F %F m ', $xL, $yL);
5766 $s .= sprintf('%F %F l ', $xT, $yT);
5768 $s .= sprintf('%F %F m ', $xR, $yR);
5769 $s .= sprintf('%F %F l ', $xB, $yB);
5771 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
5772 $s .= sprintf('%F %F m ', $xT, $yT);
5773 $s .= sprintf('%F %F l ', $xR, $yR);
5775 $s .= sprintf('%F %F m ', $xB, $yB);
5776 $s .= sprintf('%F %F l ', $xL, $yL);
5779 } else { // strlen($border) == 1
5780 if (strpos($border,'L') !== false) { // L
5781 $s .= sprintf('%F %F m ', $xL, $yL);
5782 $s .= sprintf('%F %F l ', $xT, $yT);
5784 } elseif (strpos($border,'T') !== false) { // T
5785 $s .= sprintf('%F %F m ', $xT, $yT);
5786 $s .= sprintf('%F %F l ', $xR, $yR);
5788 } elseif (strpos($border,'R') !== false) { // R
5789 $s .= sprintf('%F %F m ', $xR, $yR);
5790 $s .= sprintf('%F %F l ', $xB, $yB);
5792 } elseif (strpos($border,'B') !== false) { // B
5793 $s .= sprintf('%F %F m ', $xB, $yB);
5794 $s .= sprintf('%F %F l ', $xL, $yL);
5798 if (is_array($style) AND !empty($style)) {
5799 // reset border style to previous value
5800 $s .= "\n".$this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
."\n";
5807 * This method allows printing text with line breaks.
5808 * They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />
5809 * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
5810 * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
5811 * @param $h (float) Cell minimum height. The cell extends automatically if needed.
5812 * @param $txt (string) String to print
5813 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
5814 * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value when $ishtml=false)</li></ul>
5815 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
5816 * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
5817 * @param $x (float) x position in user units
5818 * @param $y (float) y position in user units
5819 * @param $reseth (boolean) if true reset the last cell height (default true).
5820 * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
5821 * @param $ishtml (boolean) INTERNAL USE ONLY -- set to true if $txt is HTML content (default = false). Never set this parameter to true, use instead writeHTMLCell() or writeHTML() methods.
5822 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
5823 * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature. This feature works only when $ishtml=false.
5824 * @param $valign (string) Vertical alignment of text (requires $maxh = $h > 0). Possible values are:<ul><li>T: TOP</li><li>M: middle</li><li>B: bottom</li></ul>. This feature works only when $ishtml=false and the cell must fit in a single page.
5825 * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size (do not work in HTML mode). $maxh must be greater than 0 and equal to $h.
5826 * @return int Return the number of cells or 1 for html mode.
5829 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
5831 public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false) {
5832 $prev_cell_margin = $this->cell_margin
;
5833 $prev_cell_padding = $this->cell_padding
;
5834 // adjust internal padding
5835 $this->adjustCellPadding($border);
5836 $mc_padding = $this->cell_padding
;
5837 $mc_margin = $this->cell_margin
;
5838 $this->cell_padding
['T'] = 0;
5839 $this->cell_padding
['B'] = 0;
5840 $this->setCellMargins(0, 0, 0, 0);
5841 if (TCPDF_STATIC
::empty_string($this->lasth
) OR $reseth) {
5843 $this->resetLastH();
5845 if (!TCPDF_STATIC
::empty_string($y)) {
5846 $this->SetY($y); // set y in order to convert negative y values to positive ones
5850 if (($h > 0) AND $this->inPageBody() AND (($y +
$h +
$mc_margin['T'] +
$mc_margin['B']) > $this->PageBreakTrigger
)) {
5851 // spit cell in more pages/columns
5852 $newh = ($this->PageBreakTrigger
- $y);
5853 $resth = ($h - $newh); // cell to be printed on the next page/column
5856 // get current page number
5857 $startpage = $this->page
;
5858 // get current column
5859 $startcolumn = $this->current_column
;
5860 if (!TCPDF_STATIC
::empty_string($x)) {
5865 // check page for no-write regions and adapt page margins if necessary
5866 list($x, $y) = $this->checkPageRegions(0, $x, $y);
5868 $oy = $y +
$mc_margin['T'];
5870 $ox = ($this->w
- $x - $mc_margin['R']);
5872 $ox = ($x +
$mc_margin['L']);
5877 if (TCPDF_STATIC
::empty_string($w) OR ($w <= 0)) {
5879 $w = ($this->x
- $this->lMargin
- $mc_margin['L']);
5881 $w = ($this->w
- $this->x
- $this->rMargin
- $mc_margin['R']);
5884 // store original margin values
5885 $lMargin = $this->lMargin
;
5886 $rMargin = $this->rMargin
;
5888 $this->rMargin
= ($this->w
- $this->x
);
5889 $this->lMargin
= ($this->x
- $w);
5891 $this->lMargin
= ($this->x
);
5892 $this->rMargin
= ($this->w
- $this->x
- $w);
5894 $this->clMargin
= $this->lMargin
;
5895 $this->crMargin
= $this->rMargin
;
5898 $this->y +
= $mc_padding['T'];
5900 if ($ishtml) { // ******* Write HTML text
5901 $this->writeHTML($txt, true, false, $reseth, true, $align);
5903 } else { // ******* Write simple text
5904 $prev_FontSizePt = $this->FontSizePt
;
5906 // ajust height values
5907 $tobottom = ($this->h
- $this->y
- $this->bMargin
- $this->cell_padding
['T'] - $this->cell_padding
['B']);
5908 $h = $maxh = max(min($h, $tobottom), min($maxh, $tobottom));
5910 // vertical alignment
5913 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
5914 if ($fitcell AND ($text_height > $maxh) AND ($this->FontSizePt
> 1)) {
5915 // try to reduce font size to fit text on cell (use a quick search algorithm)
5917 $fmax = $this->FontSizePt
;
5918 $diff_epsilon = (1 / $this->k
); // one point (min resolution)
5919 $maxit = (2 * min(100, max(10, intval($fmax)))); // max number of iterations
5920 while ($maxit >= 0) {
5921 $fmid = (($fmax +
$fmin) / 2);
5922 $this->SetFontSize($fmid, false);
5923 $this->resetLastH();
5924 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
5925 $diff = ($maxh - $text_height);
5927 if ($diff <= $diff_epsilon) {
5937 // premature exit, we get the minimum font value to fit the cell
5938 $this->SetFontSize($fmin);
5939 $this->resetLastH();
5940 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
5942 $this->SetFontSize($fmid);
5943 $this->resetLastH();
5946 if ($text_height < $maxh) {
5947 if ($valign == 'M') {
5948 // text vertically centered
5949 $this->y +
= (($maxh - $text_height) / 2);
5950 } elseif ($valign == 'B') {
5951 // text vertically aligned on bottom
5952 $this->y +
= ($maxh - $text_height);
5956 $nl = $this->Write($this->lasth
, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
5958 // restore font size
5959 $this->SetFontSize($prev_FontSizePt);
5963 // add bottom padding
5964 $this->y +
= $mc_padding['B'];
5966 // Get end-of-text Y position
5967 $currentY = $this->y
;
5968 // get latest page number
5969 $endpage = $this->page
;
5971 $skip = ($endpage - $startpage);
5973 while ($tmpresth > 0) {
5975 // add a page (or trig AcceptPageBreak() for multicolumn mode)
5976 $this->checkPageBreak($this->PageBreakTrigger +
1);
5978 if ($this->num_columns
> 1) {
5979 $tmpresth -= ($this->h
- $this->y
- $this->bMargin
);
5981 $tmpresth -= ($this->h
- $this->tMargin
- $this->bMargin
);
5985 $currentY = $this->y
;
5986 $endpage = $this->page
;
5988 // get latest column
5989 $endcolumn = $this->current_column
;
5990 if ($this->num_columns
== 0) {
5991 $this->num_columns
= 1;
5993 // disable page regions check
5994 $check_page_regions = $this->check_page_regions
;
5995 $this->check_page_regions
= false;
5997 $border_start = TCPDF_STATIC
::getBorderMode($border, $position='start', $this->opencell
);
5998 $border_end = TCPDF_STATIC
::getBorderMode($border, $position='end', $this->opencell
);
5999 $border_middle = TCPDF_STATIC
::getBorderMode($border, $position='middle', $this->opencell
);
6000 // design borders around HTML cells.
6001 for ($page = $startpage; $page <= $endpage; ++
$page) { // for each page
6003 $this->setPage($page);
6004 if ($this->num_columns
< 2) {
6005 // single-column mode
6007 $this->y
= $this->tMargin
;
6009 // account for margin changes
6010 if ($page > $startpage) {
6011 if (($this->rtl
) AND ($this->pagedim
[$page]['orm'] != $this->pagedim
[$startpage]['orm'])) {
6012 $this->x
-= ($this->pagedim
[$page]['orm'] - $this->pagedim
[$startpage]['orm']);
6013 } elseif ((!$this->rtl
) AND ($this->pagedim
[$page]['olm'] != $this->pagedim
[$startpage]['olm'])) {
6014 $this->x +
= ($this->pagedim
[$page]['olm'] - $this->pagedim
[$startpage]['olm']);
6017 if ($startpage == $endpage) {
6019 for ($column = $startcolumn; $column <= $endcolumn; ++
$column) { // for each column
6020 if ($column != $this->current_column
) {
6021 $this->selectColumn($column);
6024 $this->x
-= $mc_margin['R'];
6026 $this->x +
= $mc_margin['L'];
6028 if ($startcolumn == $endcolumn) { // single column
6030 $h = max($h, ($currentY - $oy));
6032 } elseif ($column == $startcolumn) { // first column
6033 $cborder = $border_start;
6035 $h = $this->h
- $this->y
- $this->bMargin
;
6036 } elseif ($column == $endcolumn) { // end column
6037 $cborder = $border_end;
6038 $h = $currentY - $this->y
;
6042 } else { // middle column
6043 $cborder = $border_middle;
6044 $h = $this->h
- $this->y
- $this->bMargin
;
6047 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6048 } // end for each column
6049 } elseif ($page == $startpage) { // first page
6050 for ($column = $startcolumn; $column < $this->num_columns
; ++
$column) { // for each column
6051 if ($column != $this->current_column
) {
6052 $this->selectColumn($column);
6055 $this->x
-= $mc_margin['R'];
6057 $this->x +
= $mc_margin['L'];
6059 if ($column == $startcolumn) { // first column
6060 $cborder = $border_start;
6062 $h = $this->h
- $this->y
- $this->bMargin
;
6063 } else { // middle column
6064 $cborder = $border_middle;
6065 $h = $this->h
- $this->y
- $this->bMargin
;
6068 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6069 } // end for each column
6070 } elseif ($page == $endpage) { // last page
6071 for ($column = 0; $column <= $endcolumn; ++
$column) { // for each column
6072 if ($column != $this->current_column
) {
6073 $this->selectColumn($column);
6076 $this->x
-= $mc_margin['R'];
6078 $this->x +
= $mc_margin['L'];
6080 if ($column == $endcolumn) {
6082 $cborder = $border_end;
6083 $h = $currentY - $this->y
;
6089 $cborder = $border_middle;
6090 $h = $this->h
- $this->y
- $this->bMargin
;
6093 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6094 } // end for each column
6095 } else { // middle page
6096 for ($column = 0; $column < $this->num_columns
; ++
$column) { // for each column
6097 $this->selectColumn($column);
6099 $this->x
-= $mc_margin['R'];
6101 $this->x +
= $mc_margin['L'];
6103 $cborder = $border_middle;
6104 $h = $this->h
- $this->y
- $this->bMargin
;
6106 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6107 } // end for each column
6109 if ($cborder OR $fill) {
6110 $offsetlen = strlen($ccode);
6111 // draw border and fill
6112 if ($this->inxobj
) {
6113 // we are inside an XObject template
6114 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
6115 $pagemarkkey = key($this->xobjects
[$this->xobjid
]['transfmrk']);
6116 $pagemark = $this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey];
6117 $this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey] +
= $offsetlen;
6119 $pagemark = $this->xobjects
[$this->xobjid
]['intmrk'];
6120 $this->xobjects
[$this->xobjid
]['intmrk'] +
= $offsetlen;
6122 $pagebuff = $this->xobjects
[$this->xobjid
]['outdata'];
6123 $pstart = substr($pagebuff, 0, $pagemark);
6124 $pend = substr($pagebuff, $pagemark);
6125 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$ccode.$pend;
6127 if (end($this->transfmrk
[$this->page
]) !== false) {
6128 $pagemarkkey = key($this->transfmrk
[$this->page
]);
6129 $pagemark = $this->transfmrk
[$this->page
][$pagemarkkey];
6130 $this->transfmrk
[$this->page
][$pagemarkkey] +
= $offsetlen;
6131 } elseif ($this->InFooter
) {
6132 $pagemark = $this->footerpos
[$this->page
];
6133 $this->footerpos
[$this->page
] +
= $offsetlen;
6135 $pagemark = $this->intmrk
[$this->page
];
6136 $this->intmrk
[$this->page
] +
= $offsetlen;
6138 $pagebuff = $this->getPageBuffer($this->page
);
6139 $pstart = substr($pagebuff, 0, $pagemark);
6140 $pend = substr($pagebuff, $pagemark);
6141 $this->setPageBuffer($this->page
, $pstart.$ccode.$pend);
6144 } // end for each page
6145 // restore page regions check
6146 $this->check_page_regions
= $check_page_regions;
6147 // Get end-of-cell Y position
6148 $currentY = $this->GetY();
6149 // restore previous values
6150 if ($this->num_columns
> 1) {
6151 $this->selectColumn();
6153 // restore original margins
6154 $this->lMargin
= $lMargin;
6155 $this->rMargin
= $rMargin;
6156 if ($this->page
> $startpage) {
6157 // check for margin variations between pages (i.e. booklet mode)
6158 $dl = ($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$startpage]['olm']);
6159 $dr = ($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$startpage]['orm']);
6160 if (($dl != 0) OR ($dr != 0)) {
6161 $this->lMargin +
= $dl;
6162 $this->rMargin +
= $dr;
6167 //Go to the beginning of the next line
6168 $this->SetY($currentY +
$mc_margin['B']);
6170 $this->SetX($x +
$w +
$mc_margin['L'] +
$mc_margin['R']);
6173 // go left or right by case
6174 $this->setPage($startpage);
6176 $this->SetX($x +
$w +
$mc_margin['L'] +
$mc_margin['R']);
6178 $this->setContentMark();
6179 $this->cell_padding
= $prev_cell_padding;
6180 $this->cell_margin
= $prev_cell_margin;
6181 $this->clMargin
= $this->lMargin
;
6182 $this->crMargin
= $this->rMargin
;
6187 * This method return the estimated number of lines for print a simple text string using Multicell() method.
6188 * @param $txt (string) String for calculating his height
6189 * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
6190 * @param $reseth (boolean) if true reset the last cell height (default false).
6191 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
6192 * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
6193 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
6194 * @return float Return the minimal height needed for multicell method for printing the $txt param.
6195 * @author Alexander Escalona Fern\E1ndez, Nicola Asuni
6199 public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
6200 if ($txt === NULL) {
6207 // adjust internal padding
6208 $prev_cell_padding = $this->cell_padding
;
6209 $prev_lasth = $this->lasth
;
6210 if (is_array($cellpadding)) {
6211 $this->cell_padding
= $cellpadding;
6213 $this->adjustCellPadding($border);
6214 if (TCPDF_STATIC
::empty_string($w) OR ($w <= 0)) {
6216 $w = $this->x
- $this->lMargin
;
6218 $w = $this->w
- $this->rMargin
- $this->x
;
6221 $wmax = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
6224 $this->resetLastH();
6228 $chars = TCPDF_FONTS
::utf8Bidi(TCPDF_FONTS
::UTF8StringToArray($txt, $this->isunicode
, $this->CurrentFont
), $txt, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
);
6229 $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
6230 $length = count($chars);
6231 $lastSeparator = -1;
6232 for ($i = 0; $i < $length; ++
$i) {
6234 $charWidth = $charsWidth[$i];
6237 OR preg_match($this->re_spaces
, TCPDF_FONTS
::unichr($c, $this->isunicode
))
6239 AND ($i > 0) AND ($i < ($length - 1))
6240 AND @preg_match
('/[\p{L}]/'.$this->re_space
['m'], TCPDF_FONTS
::unichr($chars[($i - 1)], $this->isunicode
))
6241 AND @preg_match
('/[\p{L}]/'.$this->re_space
['m'], TCPDF_FONTS
::unichr($chars[($i +
1)], $this->isunicode
))
6245 $lastSeparator = $i;
6247 if ((($sum +
$charWidth) > $wmax) OR ($c == 10)) {
6250 $lastSeparator = -1;
6252 } elseif ($lastSeparator != -1) {
6253 $i = $lastSeparator;
6254 $lastSeparator = -1;
6263 if ($chars[($length - 1)] == 10) {
6266 $this->cell_padding
= $prev_cell_padding;
6267 $this->lasth
= $prev_lasth;
6272 * This method return the estimated height needed for printing a simple text string using the Multicell() method.
6273 * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
6275 * // store current object
6276 * $pdf->startTransaction();
6277 * // store starting values
6278 * $start_y = $pdf->GetY();
6279 * $start_page = $pdf->getPage();
6280 * // call your printing functions with your parameters
6281 * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6282 * $pdf->MultiCell($w=0, $h=0, $txt, $border=1, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
6283 * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6285 * $end_y = $pdf->GetY();
6286 * $end_page = $pdf->getPage();
6287 * // calculate height
6289 * if ($end_page == $start_page) {
6290 * $height = $end_y - $start_y;
6292 * for ($page=$start_page; $page <= $end_page; ++$page) {
6293 * $this->setPage($page);
6294 * if ($page == $start_page) {
6296 * $height += $this->h - $start_y - $this->bMargin;
6297 * } elseif ($page == $end_page) {
6299 * $height += $end_y - $this->tMargin;
6301 * $height += $this->h - $this->tMargin - $this->bMargin;
6305 * // restore previous object
6306 * $pdf = $pdf->rollbackTransaction();
6308 * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
6309 * @param $txt (string) String for calculating his height
6310 * @param $reseth (boolean) if true reset the last cell height (default false).
6311 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
6312 * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
6313 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
6314 * @return float Return the minimal height needed for multicell method for printing the $txt param.
6315 * @author Nicola Asuni, Alexander Escalona Fern\E1ndez
6318 public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
6319 // adjust internal padding
6320 $prev_cell_padding = $this->cell_padding
;
6321 $prev_lasth = $this->lasth
;
6322 if (is_array($cellpadding)) {
6323 $this->cell_padding
= $cellpadding;
6325 $this->adjustCellPadding($border);
6326 $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
6327 $height = $this->getCellHeight(($lines * $this->FontSize
), $autopadding);
6328 $this->cell_padding
= $prev_cell_padding;
6329 $this->lasth
= $prev_lasth;
6334 * This method prints text from the current position.<br />
6335 * @param $h (float) Line height
6336 * @param $txt (string) String to print
6337 * @param $link (mixed) URL or identifier returned by AddLink()
6338 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
6339 * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li><li>J: justify</li></ul>
6340 * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
6341 * @param $stretch (int) font stretch mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if text is larger than cell width</li><li>2 = forced horizontal scaling to fit cell width</li><li>3 = character spacing only if text is larger than cell width</li><li>4 = forced character spacing to fit cell width</li></ul> General font stretching and scaling values will be preserved when possible.
6342 * @param $firstline (boolean) if true prints only the first line and return the remaining string.
6343 * @param $firstblock (boolean) if true the string is the starting of a line.
6344 * @param $maxh (float) maximum height. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
6345 * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
6346 * @param $margin (array) margin array of the parent container
6347 * @return mixed Return the number of cells or the remaining string if $firstline = true.
6351 public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
6352 // check page for no-write regions and adapt page margins if necessary
6353 list($this->x
, $this->y
) = $this->checkPageRegions($h, $this->x
, $this->y
);
6354 if (strlen($txt) == 0) {
6358 if ($margin === '') {
6359 // set default margins
6360 $margin = $this->cell_margin
;
6362 // remove carriage returns
6363 $s = str_replace("\r", '', $txt);
6364 // check if string contains arabic text
6365 if (preg_match(TCPDF_FONT_DATA
::$uni_RE_PATTERN_ARABIC, $s)) {
6370 // check if string contains RTL text
6371 if ($arabic OR ($this->tmprtl
== 'R') OR preg_match(TCPDF_FONT_DATA
::$uni_RE_PATTERN_RTL, $s)) {
6377 $chrwidth = $this->GetCharWidth(46); // dot character
6378 // get array of unicode values
6379 $chars = TCPDF_FONTS
::UTF8StringToArray($s, $this->isunicode
, $this->CurrentFont
);
6380 // calculate maximum width for a single character on string
6381 $chrw = $this->GetArrStringWidth($chars, '', '', 0, true);
6382 array_walk($chrw, array($this, 'getRawCharWidth'));
6383 $maxchwidth = max($chrw);
6384 // get array of chars
6385 $uchars = TCPDF_FONTS
::UTF8ArrayToUniArray($chars, $this->isunicode
);
6386 // get the number of characters
6387 $nb = count($chars);
6388 // replacement for SHY character (minus symbol)
6389 $shy_replacement = 45;
6390 $shy_replacement_char = TCPDF_FONTS
::unichr($shy_replacement, $this->isunicode
);
6391 // widht for SHY replacement
6392 $shy_replacement_width = $this->GetCharWidth($shy_replacement);
6394 $pw = $w = $this->w
- $this->lMargin
- $this->rMargin
;
6395 // calculate remaining line width ($w)
6397 $w = $this->x
- $this->lMargin
;
6399 $w = $this->w
- $this->rMargin
- $this->x
;
6402 $wmax = ($w - $wadj);
6404 $wmax -= ($this->cell_padding
['L'] +
$this->cell_padding
['R']);
6406 if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
6407 // the maximum width character do not fit on column
6410 // minimum row height
6411 $row_height = max($h, $this->getCellHeight($this->FontSize
));
6413 $maxy = $this->y +
$maxh - max($row_height, $h);
6414 $start_page = $this->page
;
6415 $i = 0; // character position
6416 $j = 0; // current starting position
6417 $sep = -1; // position of the last blank space
6418 $prevsep = $sep; // previous separator
6419 $shy = false; // true if the last blank is a soft hypen (SHY)
6420 $prevshy = $shy; // previous shy mode
6421 $l = 0; // current string length
6422 $nl = 0; //number of lines
6424 $pc = 0; // previous character
6425 // for each character
6427 if (($maxh > 0) AND ($this->y
> $maxy) ) {
6430 //Get the current character
6432 if ($c == 10) { // 10 = "\n" = new line
6433 //Explicit line break
6434 if ($align == 'J') {
6443 $tmpstr = TCPDF_FONTS
::UniArrSubString($uchars, $j, $i);
6446 $tmparr = array_slice($chars, $j, ($i - $j));
6448 $tmparr = TCPDF_FONTS
::utf8Bidi($tmparr, $tmpstr, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
);
6450 $linew = $this->GetArrStringWidth($tmparr);
6453 $this->endlinex
= $startx - $linew;
6455 $this->endlinex
= $startx +
$linew;
6458 $tmpcellpadding = $this->cell_padding
;
6460 $this->SetCellPadding(0);
6463 if ($firstblock AND $this->isRTLTextDir()) {
6464 $tmpstr = $this->stringRightTrim($tmpstr);
6466 // Skip newlines at the beginning of a page or column
6467 if (!empty($tmpstr) OR ($this->y
< ($this->PageBreakTrigger
- $row_height))) {
6468 $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
6472 $this->cell_padding
= $tmpcellpadding;
6473 return (TCPDF_FONTS
::UniArrSubString($uchars, $i));
6481 // account for margin changes
6482 if ((($this->y +
$this->lasth
) > $this->PageBreakTrigger
) AND ($this->inPageBody())) {
6483 $this->AcceptPageBreak();
6485 $this->x
-= $margin['R'];
6487 $this->x +
= $margin['L'];
6489 $this->lMargin +
= $margin['L'];
6490 $this->rMargin +
= $margin['R'];
6492 $w = $this->getRemainingWidth();
6493 $wmax = ($w - $this->cell_padding
['L'] - $this->cell_padding
['R']);
6495 // 160 is the non-breaking space.
6496 // 173 is SHY (Soft Hypen).
6497 // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
6498 // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
6499 // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
6502 OR preg_match($this->re_spaces
, TCPDF_FONTS
::unichr($c, $this->isunicode
))
6504 AND ($i < ($nb - 1))
6505 AND @preg_match
('/[\p{L}]/'.$this->re_space
['m'], TCPDF_FONTS
::unichr($pc, $this->isunicode
))
6506 AND @preg_match
('/[\p{L}]/'.$this->re_space
['m'], TCPDF_FONTS
::unichr($chars[($i +
1)], $this->isunicode
))
6510 // update last blank space position
6513 // check if is a SHY
6514 if (($c == 173) OR ($c == 45)) {
6518 $tmp_shy_replacement_width = 0;
6519 $tmp_shy_replacement_char = '';
6521 $tmp_shy_replacement_width = $shy_replacement_width;
6522 $tmp_shy_replacement_char = $shy_replacement_char;
6528 // update string length
6529 if ($this->isUnicodeFont() AND ($arabic)) {
6530 // with bidirectional algorithm some chars may be changed affecting the line length
6531 // *** very slow ***
6532 $l = $this->GetArrStringWidth(TCPDF_FONTS
::utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl
, $this->isunicode
, $this->CurrentFont
));
6534 $l +
= $this->GetCharWidth($c, ($i+
1 < $nb));
6536 if (($l > $wmax) OR (($c == 173) AND (($l +
$tmp_shy_replacement_width) >= $wmax))) {
6537 if (($c == 173) AND (($l +
$tmp_shy_replacement_width) > $wmax)) {
6541 // we have reached the end of column
6543 // check if the line was already started
6544 if (($this->rtl
AND ($this->x
<= ($this->w
- $this->rMargin
- $this->cell_padding
['R'] - $margin['R'] - $chrwidth)))
6545 OR ((!$this->rtl
) AND ($this->x
>= ($this->lMargin +
$this->cell_padding
['L'] +
$margin['L'] +
$chrwidth)))) {
6546 // print a void cell and go to next line
6547 $this->Cell($w, $h, '', 0, 1);
6550 return (TCPDF_FONTS
::UniArrSubString($uchars, $j));
6553 // truncate the word because do not fit on column
6554 $tmpstr = TCPDF_FONTS
::UniArrSubString($uchars, $j, $i);
6557 $tmparr = array_slice($chars, $j, ($i - $j));
6559 $tmparr = TCPDF_FONTS
::utf8Bidi($tmparr, $tmpstr, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
);
6561 $linew = $this->GetArrStringWidth($tmparr);
6564 $this->endlinex
= $startx - $linew;
6566 $this->endlinex
= $startx +
$linew;
6569 $tmpcellpadding = $this->cell_padding
;
6571 $this->SetCellPadding(0);
6574 if ($firstblock AND $this->isRTLTextDir()) {
6575 $tmpstr = $this->stringRightTrim($tmpstr);
6577 $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
6580 $this->cell_padding
= $tmpcellpadding;
6581 return (TCPDF_FONTS
::UniArrSubString($uchars, $i));
6588 if ($this->rtl
AND (!$firstblock) AND ($sep < $i)) {
6593 // check the length of the next string
6594 $strrest = TCPDF_FONTS
::UniArrSubString($uchars, ($sep +
$endspace));
6595 $nextstr = TCPDF_STATIC
::pregSplit('/'.$this->re_space
['p'].'/', $this->re_space
['m'], $this->stringTrim($strrest));
6596 if (isset($nextstr[0]) AND ($this->GetStringWidth($nextstr[0]) > $pw)) {
6597 // truncate the word because do not fit on a full page width
6598 $tmpstr = TCPDF_FONTS
::UniArrSubString($uchars, $j, $i);
6601 $tmparr = array_slice($chars, $j, ($i - $j));
6603 $tmparr = TCPDF_FONTS
::utf8Bidi($tmparr, $tmpstr, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
);
6605 $linew = $this->GetArrStringWidth($tmparr);
6608 $this->endlinex
= ($startx - $linew);
6610 $this->endlinex
= ($startx +
$linew);
6613 $tmpcellpadding = $this->cell_padding
;
6615 $this->SetCellPadding(0);
6618 if ($firstblock AND $this->isRTLTextDir()) {
6619 $tmpstr = $this->stringRightTrim($tmpstr);
6621 $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
6624 $this->cell_padding
= $tmpcellpadding;
6625 return (TCPDF_FONTS
::UniArrSubString($uchars, $i));
6632 // add hypen (minus symbol) at the end of the line
6633 $shy_width = $tmp_shy_replacement_width;
6635 $shy_char_left = $tmp_shy_replacement_char;
6636 $shy_char_right = '';
6638 $shy_char_left = '';
6639 $shy_char_right = $tmp_shy_replacement_char;
6643 $shy_char_left = '';
6644 $shy_char_right = '';
6646 $tmpstr = TCPDF_FONTS
::UniArrSubString($uchars, $j, ($sep +
$endspace));
6649 $tmparr = array_slice($chars, $j, (($sep +
$endspace) - $j));
6651 $tmparr = TCPDF_FONTS
::utf8Bidi($tmparr, $tmpstr, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
);
6653 $linew = $this->GetArrStringWidth($tmparr);
6656 $this->endlinex
= $startx - $linew - $shy_width;
6658 $this->endlinex
= $startx +
$linew +
$shy_width;
6661 $tmpcellpadding = $this->cell_padding
;
6663 $this->SetCellPadding(0);
6667 if ($firstblock AND $this->isRTLTextDir()) {
6668 $tmpstr = $this->stringRightTrim($tmpstr);
6670 $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
6673 if ($chars[$sep] == 45) {
6676 // return the remaining text
6677 $this->cell_padding
= $tmpcellpadding;
6678 return (TCPDF_FONTS
::UniArrSubString($uchars, ($sep +
$endspace)));
6686 // account for margin changes
6687 if ((($this->y +
$this->lasth
) > $this->PageBreakTrigger
) AND ($this->inPageBody())) {
6688 $this->AcceptPageBreak();
6690 $this->x
-= $margin['R'];
6692 $this->x +
= $margin['L'];
6694 $this->lMargin +
= $margin['L'];
6695 $this->rMargin +
= $margin['R'];
6697 $w = $this->getRemainingWidth();
6698 $wmax = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
6707 // save last character
6710 } // end while i < nb
6711 // print last substring (if any)
6740 $tmpstr = TCPDF_FONTS
::UniArrSubString($uchars, $j, $nb);
6743 $tmparr = array_slice($chars, $j, ($nb - $j));
6745 $tmparr = TCPDF_FONTS
::utf8Bidi($tmparr, $tmpstr, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
);
6747 $linew = $this->GetArrStringWidth($tmparr);
6750 $this->endlinex
= $startx - $linew;
6752 $this->endlinex
= $startx +
$linew;
6755 $tmpcellpadding = $this->cell_padding
;
6757 $this->SetCellPadding(0);
6760 if ($firstblock AND $this->isRTLTextDir()) {
6761 $tmpstr = $this->stringRightTrim($tmpstr);
6763 $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
6766 $this->cell_padding
= $tmpcellpadding;
6767 return (TCPDF_FONTS
::UniArrSubString($uchars, $nb));
6778 * Returns the remaining width between the current position and margins.
6779 * @return int Return the remaining width
6782 protected function getRemainingWidth() {
6783 list($this->x
, $this->y
) = $this->checkPageRegions(0, $this->x
, $this->y
);
6785 return ($this->x
- $this->lMargin
);
6787 return ($this->w
- $this->rMargin
- $this->x
);
6792 * Set the block dimensions accounting for page breaks and page/column fitting
6793 * @param $w (float) width
6794 * @param $h (float) height
6795 * @param $x (float) X coordinate
6796 * @param $y (float) Y coodiante
6797 * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
6798 * @return array($w, $h, $x, $y)
6800 * @since 5.5.009 (2010-07-05)
6802 protected function fitBlock($w, $h, $x, $y, $fitonpage=false) {
6804 // set maximum width
6805 $w = ($this->w
- $this->lMargin
- $this->rMargin
);
6811 // set maximum height
6812 $h = ($this->PageBreakTrigger
- $this->tMargin
);
6817 // resize the block to be vertically contained on a single page or single column
6818 if ($fitonpage OR $this->AutoPageBreak
) {
6819 $ratio_wh = ($w / $h);
6820 if ($h > ($this->PageBreakTrigger
- $this->tMargin
)) {
6821 $h = $this->PageBreakTrigger
- $this->tMargin
;
6822 $w = ($h * $ratio_wh);
6824 // resize the block to be horizontally contained on a single page or single column
6826 $maxw = ($this->w
- $this->lMargin
- $this->rMargin
);
6829 $h = ($w / $ratio_wh);
6833 // Check whether we need a new page or new column first as this does not fit
6836 if ($this->checkPageBreak($h, $y) OR ($this->y
< $prev_y)) {
6839 $x +
= ($prev_x - $this->x
);
6841 $x +
= ($this->x
- $prev_x);
6843 $this->newline
= true;
6845 // resize the block to be contained on the remaining available page or column space
6847 $ratio_wh = ($w / $h);
6848 if (($y +
$h) > $this->PageBreakTrigger
) {
6849 $h = $this->PageBreakTrigger
- $y;
6850 $w = ($h * $ratio_wh);
6852 if ((!$this->rtl
) AND (($x +
$w) > ($this->w
- $this->rMargin
))) {
6853 $w = $this->w
- $this->rMargin
- $x;
6854 $h = ($w / $ratio_wh);
6855 } elseif (($this->rtl
) AND (($x - $w) < ($this->lMargin
))) {
6856 $w = $x - $this->lMargin
;
6857 $h = ($w / $ratio_wh);
6860 return array($w, $h, $x, $y);
6864 * Puts an image in the page.
6865 * The upper-left corner must be given.
6866 * The dimensions can be specified in different ways:<ul>
6867 * <li>explicit width and height (expressed in user unit)</li>
6868 * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
6869 * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
6870 * Supported formats are JPEG and PNG images whitout GD library and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;
6871 * The format can be specified explicitly or inferred from the file extension.<br />
6872 * It is possible to put a link on the image.<br />
6873 * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
6874 * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string. To link an image without embedding it on the document, set an asterisk character before the URL (i.e.: '*http://www.example.com/image.jpg').
6875 * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
6876 * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
6877 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
6878 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
6879 * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
6880 * @param $link (mixed) URL or identifier returned by AddLink().
6881 * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
6882 * @param $resize (mixed) If true resize (reduce) the image to fit $w and $h (requires GD or ImageMagick library); if false do not resize; if 2 force resize in all cases (upscaling and downscaling).
6883 * @param $dpi (int) dot-per-inch resolution used on resize
6884 * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
6885 * @param $ismask (boolean) true if this image is a mask, false otherwise
6886 * @param $imgmask (mixed) image object returned by this function or false
6887 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
6888 * @param $fitbox (mixed) If not false scale image dimensions proportionally to fit within the ($w, $h) box. $fitbox can be true or a 2 characters string indicating the image alignment inside the box. The first character indicate the horizontal alignment (L = left, C = center, R = right) the second character indicate the vertical algnment (T = top, M = middle, B = bottom).
6889 * @param $hidden (boolean) If true do not display the image.
6890 * @param $fitonpage (boolean) If true the image is resized to not exceed page dimensions.
6891 * @param $alt (boolean) If true the image will be added as alternative and not directly printed (the ID of the image will be returned).
6892 * @param $altimgs (array) Array of alternate images IDs. Each alternative image must be an array with two values: an integer representing the image ID (the value returned by the Image method) and a boolean value to indicate if the image is the default for printing.
6893 * @return image information
6897 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, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array()) {
6898 if ($this->state
!= 2) {
6901 if (strcmp($x, '') === 0) {
6904 if (strcmp($y, '') === 0) {
6907 // check page for no-write regions and adapt page margins if necessary
6908 list($x, $y) = $this->checkPageRegions($h, $x, $y);
6909 $exurl = ''; // external streams
6912 // Make sure the file variable is not empty or null because accessing $file[0] later
6913 // results in error when running PHP 7.4
6917 // check if we are passing an image as file or string
6918 if ($file[0] === '@') {
6919 // image from string
6920 $imgdata = substr($file, 1);
6921 } else { // image file
6922 if ($file[0] === '*') {
6923 // image as external stream
6924 $file = substr($file, 1);
6927 // check if file exist and it is valid
6928 if (!@$this->fileExists($file)) {
6931 if (false !== $info = $this->getImageBuffer($file)) {
6932 $imsize = array($info['w'], $info['h']);
6933 } elseif (($imsize = @getimagesize
($file)) === FALSE && strpos($file, '__tcpdf_'.$this->file_id
.'_img') === FALSE){
6934 $imgdata = $this->getCachedFileContents($file);
6937 if (!empty($imgdata)) {
6938 // copy image to cache
6939 $original_file = $file;
6940 $file = TCPDF_STATIC
::getObjFilename('img', $this->file_id
);
6941 $fp = TCPDF_STATIC
::fopenLocal($file, 'w');
6943 $this->Error('Unable to write file: '.$file);
6945 fwrite($fp, $imgdata);
6948 $imsize = @getimagesize
($file);
6949 if ($imsize === FALSE) {
6951 $file = $original_file;
6954 if ($imsize === FALSE) {
6955 if (($w > 0) AND ($h > 0)) {
6956 // get measures from specified data
6957 $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit
, true) * $this->imgscale
* $this->k
;
6958 $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit
, true) * $this->imgscale
* $this->k
;
6959 $imsize = array($pw, $ph);
6961 $this->Error('[Image] Unable to get the size of the image: '.$file);
6965 $filehash = md5($file);
6966 // get original image width and height in pixels
6967 list($pixw, $pixh) = $imsize;
6968 // calculate image width and height on document
6969 if (($w <= 0) AND ($h <= 0)) {
6970 // convert image size to document unit
6971 $w = $this->pixelsToUnits($pixw);
6972 $h = $this->pixelsToUnits($pixh);
6973 } elseif ($w <= 0) {
6974 $w = $h * $pixw / $pixh;
6975 } elseif ($h <= 0) {
6976 $h = $w * $pixh / $pixw;
6977 } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
6978 if (strlen($fitbox) !== 2) {
6979 // set default alignment
6982 // scale image dimensions proportionally to fit within the ($w, $h) box
6983 if ((($w * $pixh) / ($h * $pixw)) < 1) {
6984 // store current height
6986 // calculate new height
6987 $h = $w * $pixh / $pixw;
6988 // height difference
6989 $hdiff = ($oldh - $h);
6990 // vertical alignment
6991 switch (strtoupper($fitbox[1])) {
7005 // store current width
7007 // calculate new width
7008 $w = $h * $pixw / $pixh;
7010 $wdiff = ($oldw - $w);
7011 // horizontal alignment
7012 switch (strtoupper($fitbox[0])) {
7036 // fit the image on available space
7037 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
7038 // calculate new minimum dimensions in pixels
7039 $neww = round($w * $this->k
* $dpi / $this->dpi
);
7040 $newh = round($h * $this->k
* $dpi / $this->dpi
);
7041 // check if resize is necessary (resize is used only to reduce the image)
7042 $newsize = ($neww * $newh);
7043 $pixsize = ($pixw * $pixh);
7044 if (intval($resize) == 2) {
7046 } elseif ($newsize >= $pixsize) {
7049 // check if image has been already added on document
7051 if (in_array($file, $this->imagekeys
)) {
7053 // get existing image data
7054 $info = $this->getImageBuffer($file);
7055 if (strpos($file, '__tcpdf_'.$this->file_id
.'_imgmask_') === FALSE) {
7056 // check if the newer image is larger
7057 $oldsize = ($info['w'] * $info['h']);
7058 if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
7062 } elseif (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id
.'_imgmask_') === FALSE)) {
7063 // create temp image file (without alpha channel)
7064 $tempfile_plain = K_PATH_CACHE
.'__tcpdf_'.$this->file_id
.'_imgmask_plain_'.$filehash;
7065 // create temp alpha file
7066 $tempfile_alpha = K_PATH_CACHE
.'__tcpdf_'.$this->file_id
.'_imgmask_alpha_'.$filehash;
7067 // check for cached images
7068 if (in_array($tempfile_plain, $this->imagekeys
)) {
7069 // get existing image data
7070 $info = $this->getImageBuffer($tempfile_plain);
7071 // check if the newer image is larger
7072 $oldsize = ($info['w'] * $info['h']);
7073 if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
7078 $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
7079 // embed image, masked with previously embedded mask
7080 return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
7085 //First use of image, get info
7086 $type = strtolower($type);
7088 $type = TCPDF_IMAGES
::getImageFileType($file, $imsize);
7089 } elseif ($type == 'jpg') {
7092 $mqr = TCPDF_STATIC
::get_mqr();
7093 TCPDF_STATIC
::set_mqr(false);
7094 // Specific image handlers (defined on TCPDF_IMAGES CLASS)
7095 $mtd = '_parse'.$type;
7096 // GD image handler function
7097 $gdfunction = 'imagecreatefrom'.$type;
7099 if ((method_exists('TCPDF_IMAGES', $mtd)) AND (!($resize AND (function_exists($gdfunction) OR extension_loaded('imagick'))))) {
7100 // TCPDF image functions
7101 $info = TCPDF_IMAGES
::$mtd($file);
7102 if (($ismask === false) AND ($imgmask === false) AND (strpos($file, '__tcpdf_'.$this->file_id
.'_imgmask_') === FALSE)
7103 AND (($info === 'pngalpha') OR (isset($info['trns']) AND !empty($info['trns'])))) {
7104 return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
7107 if (($info === false) AND function_exists($gdfunction)) {
7110 $img = $gdfunction($file);
7111 if ($img !== false) {
7113 $imgr = imagecreatetruecolor($neww, $newh);
7114 if (($type == 'gif') OR ($type == 'png')) {
7115 $imgr = TCPDF_IMAGES
::setGDImageTransparency($imgr, $img);
7117 imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
7120 if (($type == 'gif') OR ($type == 'png')) {
7121 $info = TCPDF_IMAGES
::_toPNG($img, TCPDF_STATIC
::getObjFilename('img', $this->file_id
));
7123 $info = TCPDF_IMAGES
::_toJPEG($img, $this->jpeg_quality
, TCPDF_STATIC
::getObjFilename('img', $this->file_id
));
7126 } catch(Exception
$e) {
7130 if (($info === false) AND extension_loaded('imagick')) {
7132 // ImageMagick library
7133 $img = new Imagick();
7134 if ($type == 'svg') {
7135 if ($file[0] === '@') {
7136 // image from string
7137 $svgimg = substr($file, 1);
7139 // get SVG file content
7140 $svgimg = $this->getCachedFileContents($file);
7142 if ($svgimg !== FALSE) {
7143 // get width and height
7145 if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
7148 if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
7149 $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
7150 $owu = sprintf('%F', ($ow * $dpi / 72)).$this->pdfunit
;
7151 $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
7156 if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
7157 $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
7158 $ohu = sprintf('%F', ($oh * $dpi / 72)).$this->pdfunit
;
7159 $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
7164 if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
7165 $vbw = ($ow * $this->imgscale
* $this->k
);
7166 $vbh = ($oh * $this->imgscale
* $this->k
);
7167 $vbox = sprintf(' viewBox="0 0 %F %F" ', $vbw, $vbh);
7168 $svgtag = $vbox.$svgtag;
7170 $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
7172 $img->readImageBlob($svgimg);
7175 $img->readImage($file);
7178 $img->resizeImage($neww, $newh, 10, 1, false);
7180 $img->setCompressionQuality($this->jpeg_quality
);
7181 $img->setImageFormat('jpeg');
7182 $tempname = TCPDF_STATIC
::getObjFilename('img', $this->file_id
);
7183 $img->writeImage($tempname);
7184 $info = TCPDF_IMAGES
::_parsejpeg($tempname);
7187 } catch(Exception
$e) {
7191 if ($info === false) {
7192 // unable to process image
7195 TCPDF_STATIC
::set_mqr($mqr);
7198 $info['cs'] = 'DeviceGray';
7200 if ($imgmask !== false) {
7201 $info['masked'] = $imgmask;
7203 if (!empty($exurl)) {
7204 $info['exurl'] = $exurl;
7206 // array of alternative images
7207 $info['altimgs'] = $altimgs;
7208 // add image to document
7209 $info['i'] = $this->setImageBuffer($file, $info);
7212 $this->img_rb_x
= $x +
$w;
7213 $this->img_rb_y
= $y +
$h;
7216 if ($palign == 'L') {
7217 $ximg = $this->lMargin
;
7218 } elseif ($palign == 'C') {
7219 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
7220 } elseif ($palign == 'R') {
7221 $ximg = $this->w
- $this->rMargin
- $w;
7226 if ($ismask OR $hidden) {
7227 // image is not displayed
7230 $xkimg = $ximg * $this->k
;
7232 // only non-alternative immages will be set
7233 $this->_out(sprintf('q %F 0 0 %F %F %F cm /I%u Do Q', ($w * $this->k
), ($h * $this->k
), $xkimg, (($this->h
- ($y +
$h)) * $this->k
), $info['i']));
7235 if (!empty($border)) {
7243 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
7248 $this->Link($ximg, $y, $w, $h, $link, 0);
7250 // set pointer to align the next text/objects
7254 $this->x
= $this->img_rb_x
;
7258 $this->y
= $y +
round($h/2);
7259 $this->x
= $this->img_rb_x
;
7263 $this->y
= $this->img_rb_y
;
7264 $this->x
= $this->img_rb_x
;
7268 $this->SetY($this->img_rb_y
);
7275 $this->endlinex
= $this->img_rb_x
;
7276 if ($this->inxobj
) {
7277 // we are inside an XObject template
7278 $this->xobjects
[$this->xobjid
]['images'][] = $info['i'];
7284 * Extract info from a PNG image with alpha channel using the Imagick or GD library.
7285 * @param $file (string) Name of the file containing the image.
7286 * @param $x (float) Abscissa of the upper-left corner.
7287 * @param $y (float) Ordinate of the upper-left corner.
7288 * @param $wpx (float) Original width of the image in pixels.
7289 * @param $hpx (float) original height of the image in pixels.
7290 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
7291 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
7292 * @param $type (string) Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
7293 * @param $link (mixed) URL or identifier returned by AddLink().
7294 * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
7295 * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
7296 * @param $dpi (int) dot-per-inch resolution used on resize
7297 * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
7298 * @param $filehash (string) File hash used to build unique file names.
7299 * @author Nicola Asuni
7301 * @since 4.3.007 (2008-12-04)
7304 protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') {
7305 // create temp images
7306 if (empty($filehash)) {
7307 $filehash = md5($file);
7309 // create temp image file (without alpha channel)
7310 $tempfile_plain = K_PATH_CACHE
.'__tcpdf_'.$this->file_id
.'_imgmask_plain_'.$filehash;
7311 // create temp alpha file
7312 $tempfile_alpha = K_PATH_CACHE
.'__tcpdf_'.$this->file_id
.'_imgmask_alpha_'.$filehash;
7315 // ImageMagick extension
7316 if (($parsed === false) AND extension_loaded('imagick')) {
7318 // ImageMagick library
7319 $img = new Imagick();
7320 $img->readImage($file);
7321 // clone image object
7322 $imga = TCPDF_STATIC
::objclone($img);
7323 // extract alpha channel
7324 if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
7325 $img->setImageAlphaChannel(Imagick
::ALPHACHANNEL_EXTRACT
);
7327 $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
7328 $img->negateImage(true);
7330 $img->setImageFormat('png');
7331 $img->writeImage($tempfile_alpha);
7332 // remove alpha channel
7333 if (method_exists($imga, 'setImageMatte')) {
7334 $imga->setImageMatte(false);
7336 $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
7338 $imga->setImageFormat('png');
7339 $imga->writeImage($tempfile_plain);
7341 } catch (Exception
$e) {
7342 // Imagemagick fails, try with GD
7343 $parse_error = 'Imagick library error: '.$e->getMessage();
7347 if (($parsed === false) AND function_exists('imagecreatefrompng')) {
7350 $img = imagecreatefrompng($file);
7351 $imgalpha = imagecreate($wpx, $hpx);
7352 // generate gray scale palette (0 -> 255)
7353 for ($c = 0; $c < 256; ++
$c) {
7354 ImageColorAllocate($imgalpha, $c, $c, $c);
7356 // extract alpha channel
7357 for ($xpx = 0; $xpx < $wpx; ++
$xpx) {
7358 for ($ypx = 0; $ypx < $hpx; ++
$ypx) {
7359 $color = imagecolorat($img, $xpx, $ypx);
7360 // get and correct gamma color
7361 $alpha = $this->getGDgamma($img, $color);
7362 imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
7365 imagepng($imgalpha, $tempfile_alpha);
7366 imagedestroy($imgalpha);
7367 // extract image without alpha channel
7368 $imgplain = imagecreatetruecolor($wpx, $hpx);
7369 imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
7370 imagepng($imgplain, $tempfile_plain);
7371 imagedestroy($imgplain);
7373 } catch (Exception
$e) {
7375 $parse_error = 'GD library error: '.$e->getMessage();
7378 if ($parsed === false) {
7379 if (empty($parse_error)) {
7380 $this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
7382 $this->Error($parse_error);
7386 $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
7387 // embed image, masked with previously embedded mask
7388 $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
7392 * Get the GD-corrected PNG gamma value from alpha color
7393 * @param $img (int) GD image Resource ID.
7394 * @param $c (int) alpha color
7396 * @since 4.3.007 (2008-12-04)
7398 protected function getGDgamma($img, $c) {
7399 if (!isset($this->gdgammacache
['#'.$c])) {
7400 $colors = imagecolorsforindex($img, $c);
7401 // GD alpha is only 7 bit (0 -> 127)
7402 $this->gdgammacache
['#'.$c] = (((127 - $colors['alpha']) / 127) * 255);
7404 $this->gdgammacache
['#'.$c] = (pow(($this->gdgammacache
['#'.$c] / 255), 2.2) * 255);
7405 // store the latest values on cache to improve performances
7406 if (count($this->gdgammacache
) > 8) {
7407 // remove one element from the cache array
7408 array_shift($this->gdgammacache
);
7411 return $this->gdgammacache
['#'.$c];
7415 * Performs a line break.
7416 * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
7417 * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
7418 * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
7423 public function Ln($h='', $cell=false) {
7424 if (($this->num_columns
> 1) AND ($this->y
== $this->columns
[$this->current_column
]['y']) AND isset($this->columns
[$this->current_column
]['x']) AND ($this->x
== $this->columns
[$this->current_column
]['x'])) {
7425 // revove vertical space from the top of the column
7430 $cellpadding = $this->cell_padding
['R'];
7432 $cellpadding = $this->cell_padding
['L'];
7438 $this->x
= $this->w
- $this->rMargin
- $cellpadding;
7440 $this->x
= $this->lMargin +
$cellpadding;
7442 if (is_string($h)) {
7446 $this->newline
= true;
7450 * Returns the relative X value of current position.
7451 * The value is relative to the left border for LTR languages and to the right border for RTL languages.
7455 * @see SetX(), GetY(), SetY()
7457 public function GetX() {
7460 return ($this->w
- $this->x
);
7467 * Returns the absolute X value of current position.
7471 * @see SetX(), GetY(), SetY()
7473 public function GetAbsX() {
7478 * Returns the ordinate of the current position.
7482 * @see SetY(), GetX(), SetX()
7484 public function GetY() {
7489 * Defines the abscissa of the current position.
7490 * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
7491 * @param $x (float) The value of the abscissa in user units.
7492 * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
7495 * @see GetX(), GetY(), SetY(), SetXY()
7497 public function SetX($x, $rtloff=false) {
7499 if (!$rtloff AND $this->rtl
) {
7501 $this->x
= $this->w
- $x;
7509 $this->x
= $this->w +
$x;
7515 if ($this->x
> $this->w
) {
7516 $this->x
= $this->w
;
7521 * Moves the current abscissa back to the left margin and sets the ordinate.
7522 * If the passed value is negative, it is relative to the bottom of the page.
7523 * @param $y (float) The value of the ordinate in user units.
7524 * @param $resetx (bool) if true (default) reset the X position.
7525 * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
7528 * @see GetX(), GetY(), SetY(), SetXY()
7530 public function SetY($y, $resetx=true, $rtloff=false) {
7534 if (!$rtloff AND $this->rtl
) {
7535 $this->x
= $this->w
- $this->rMargin
;
7537 $this->x
= $this->lMargin
;
7543 $this->y
= $this->h +
$y;
7548 if ($this->y
> $this->h
) {
7549 $this->y
= $this->h
;
7554 * Defines the abscissa and ordinate of the current position.
7555 * If the passed values are negative, they are relative respectively to the right and bottom of the page.
7556 * @param $x (float) The value of the abscissa.
7557 * @param $y (float) The value of the ordinate.
7558 * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
7561 * @see SetX(), SetY()
7563 public function SetXY($x, $y, $rtloff=false) {
7564 $this->SetY($y, false, $rtloff);
7565 $this->SetX($x, $rtloff);
7569 * Set the absolute X coordinate of the current pointer.
7570 * @param $x (float) The value of the abscissa in user units.
7572 * @since 5.9.186 (2012-09-13)
7573 * @see setAbsX(), setAbsY(), SetAbsXY()
7575 public function SetAbsX($x) {
7576 $this->x
= floatval($x);
7580 * Set the absolute Y coordinate of the current pointer.
7581 * @param $y (float) (float) The value of the ordinate in user units.
7583 * @since 5.9.186 (2012-09-13)
7584 * @see setAbsX(), setAbsY(), SetAbsXY()
7586 public function SetAbsY($y) {
7587 $this->y
= floatval($y);
7591 * Set the absolute X and Y coordinates of the current pointer.
7592 * @param $x (float) The value of the abscissa in user units.
7593 * @param $y (float) (float) The value of the ordinate in user units.
7595 * @since 5.9.186 (2012-09-13)
7596 * @see setAbsX(), setAbsY(), SetAbsXY()
7598 public function SetAbsXY($x, $y) {
7604 * Send the document to a given destination: string, local file or browser.
7605 * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
7606 * The method first calls Close() if necessary to terminate the document.
7607 * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
7608 * @param $dest (string) Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string (name is ignored).</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li><li>E: return the document as base64 mime multi-part email attachment (RFC 2045)</li></ul>
7614 public function Output($name='doc.pdf', $dest='I') {
7615 //Output PDF to some destination
7616 //Finish document if necessary
7617 if ($this->state
< 3) {
7620 //Normalize parameters
7621 if (is_bool($dest)) {
7622 $dest = $dest ?
'D' : 'F';
7624 $dest = strtoupper($dest);
7625 if ($dest[0] != 'F') {
7626 $name = preg_replace('/[\s]+/', '_', $name);
7627 $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
7630 // *** apply digital signature to the document ***
7631 // get the document content
7632 $pdfdoc = $this->getBuffer();
7633 // remove last newline
7634 $pdfdoc = substr($pdfdoc, 0, -1);
7635 // remove filler space
7636 $byterange_string_len = strlen(TCPDF_STATIC
::$byterange_string);
7637 // define the ByteRange
7638 $byte_range = array();
7640 $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC
::$byterange_string) +
$byterange_string_len +
10;
7641 $byte_range[2] = $byte_range[1] +
$this->signature_max_length +
2;
7642 $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
7643 $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
7644 // replace the ByteRange
7645 $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
7646 $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
7647 $pdfdoc = str_replace(TCPDF_STATIC
::$byterange_string, $byterange, $pdfdoc);
7648 // write the document to a temporary folder
7649 $tempdoc = TCPDF_STATIC
::getObjFilename('doc', $this->file_id
);
7650 $f = TCPDF_STATIC
::fopenLocal($tempdoc, 'wb');
7652 $this->Error('Unable to create temporary file: '.$tempdoc);
7654 $pdfdoc_length = strlen($pdfdoc);
7655 fwrite($f, $pdfdoc, $pdfdoc_length);
7657 // get digital signature via openssl library
7658 $tempsign = TCPDF_STATIC
::getObjFilename('sig', $this->file_id
);
7659 if (empty($this->signature_data
['extracerts'])) {
7660 openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data
['signcert'], array($this->signature_data
['privkey'], $this->signature_data
['password']), array(), PKCS7_BINARY | PKCS7_DETACHED
);
7662 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']);
7665 $signature = file_get_contents($tempsign);
7666 // extract signature
7667 $signature = substr($signature, $pdfdoc_length);
7668 $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") +
13));
7669 $tmparr = explode("\n\n", $signature);
7670 $signature = $tmparr[1];
7672 $signature = base64_decode(trim($signature));
7673 // add TSA timestamp to signature
7674 $signature = $this->applyTSA($signature);
7675 // convert signature to hex
7676 $signature = current(unpack('H*', $signature));
7677 $signature = str_pad($signature, $this->signature_max_length
, '0');
7678 // Add signature to the document
7679 $this->buffer
= substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
7680 $this->bufferlen
= strlen($this->buffer
);
7684 // Send PDF to the standard output
7685 if (ob_get_contents()) {
7686 $this->Error('Some data has already been output, can\'t send PDF file');
7688 if (php_sapi_name() != 'cli') {
7689 // send output to a browser
7690 header('Content-Type: application/pdf');
7691 if (headers_sent()) {
7692 $this->Error('Some data has already been output to browser, can\'t send PDF file');
7694 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7695 //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
7696 header('Pragma: public');
7697 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7698 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7699 header('Content-Disposition: inline; filename="'.basename($name).'"');
7700 TCPDF_STATIC
::sendOutputData($this->getBuffer(), $this->bufferlen
);
7702 echo $this->getBuffer();
7707 // download PDF as file
7708 if (ob_get_contents()) {
7709 $this->Error('Some data has already been output, can\'t send PDF file');
7711 header('Content-Description: File Transfer');
7712 if (headers_sent()) {
7713 $this->Error('Some data has already been output to browser, can\'t send PDF file');
7715 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7716 //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
7717 header('Pragma: public');
7718 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7719 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7720 // force download dialog
7721 if (strpos(php_sapi_name(), 'cgi') === false) {
7722 header('Content-Type: application/force-download');
7723 header('Content-Type: application/octet-stream', false);
7724 header('Content-Type: application/download', false);
7725 header('Content-Type: application/pdf', false);
7727 header('Content-Type: application/pdf');
7729 // use the Content-Disposition header to supply a recommended filename
7730 header('Content-Disposition: attachment; filename="'.basename($name).'"');
7731 header('Content-Transfer-Encoding: binary');
7732 TCPDF_STATIC
::sendOutputData($this->getBuffer(), $this->bufferlen
);
7738 // save PDF to a local file
7739 $f = TCPDF_STATIC
::fopenLocal($name, 'wb');
7741 $this->Error('Unable to create output file: '.$name);
7743 fwrite($f, $this->getBuffer(), $this->bufferlen
);
7745 if ($dest == 'FI') {
7746 // send headers to browser
7747 header('Content-Type: application/pdf');
7748 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7749 //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
7750 header('Pragma: public');
7751 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7752 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7753 header('Content-Disposition: inline; filename="'.basename($name).'"');
7754 TCPDF_STATIC
::sendOutputData(file_get_contents($name), filesize($name));
7755 } elseif ($dest == 'FD') {
7756 // send headers to browser
7757 if (ob_get_contents()) {
7758 $this->Error('Some data has already been output, can\'t send PDF file');
7760 header('Content-Description: File Transfer');
7761 if (headers_sent()) {
7762 $this->Error('Some data has already been output to browser, can\'t send PDF file');
7764 header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
7765 header('Pragma: public');
7766 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
7767 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
7768 // force download dialog
7769 if (strpos(php_sapi_name(), 'cgi') === false) {
7770 header('Content-Type: application/force-download');
7771 header('Content-Type: application/octet-stream', false);
7772 header('Content-Type: application/download', false);
7773 header('Content-Type: application/pdf', false);
7775 header('Content-Type: application/pdf');
7777 // use the Content-Disposition header to supply a recommended filename
7778 header('Content-Disposition: attachment; filename="'.basename($name).'"');
7779 header('Content-Transfer-Encoding: binary');
7780 TCPDF_STATIC
::sendOutputData(file_get_contents($name), filesize($name));
7785 // return PDF as base64 mime multi-part email attachment (RFC 2045)
7786 $retval = 'Content-Type: application/pdf;'."\r\n";
7787 $retval .= ' name="'.$name.'"'."\r\n";
7788 $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
7789 $retval .= 'Content-Disposition: attachment;'."\r\n";
7790 $retval .= ' filename="'.$name.'"'."\r\n\r\n";
7791 $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
7795 // returns PDF as a string
7796 return $this->getBuffer();
7799 $this->Error('Incorrect output destination: '.$dest);
7805 protected static $cleaned_ids = array();
7807 * Unset all class variables except the following critical variables.
7808 * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
7809 * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
7811 * @since 4.5.016 (2009-02-24)
7813 public function _destroy($destroyall=false, $preserve_objcopy=false) {
7814 if (isset(self
::$cleaned_ids[$this->file_id
])) {
7815 $destroyall = false;
7817 if ($destroyall AND !$preserve_objcopy && isset($this->file_id
)) {
7818 self
::$cleaned_ids[$this->file_id
] = true;
7819 // remove all temporary files
7820 if ($handle = @opendir
(K_PATH_CACHE
)) {
7821 while ( false !== ( $file_name = readdir( $handle ) ) ) {
7822 if (strpos($file_name, '__tcpdf_'.$this->file_id
.'_') === 0) {
7823 unlink(K_PATH_CACHE
.$file_name);
7828 if (isset($this->imagekeys
)) {
7829 foreach($this->imagekeys
as $file) {
7830 if (strpos($file, K_PATH_CACHE
) === 0 && TCPDF_STATIC
::file_exists($file)) {
7845 'signature_max_length',
7850 foreach (array_keys(get_object_vars($this)) as $val) {
7851 if ($destroyall OR !in_array($val, $preserve)) {
7852 if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
7860 * Check for locale-related bug
7863 protected function _dochecks() {
7864 //Check for locale-related bug
7866 $this->Error('Don\'t alter the locale before including class file');
7868 //Check for decimal separator
7869 if (sprintf('%.1F', 1.0) != '1.0') {
7870 setlocale(LC_NUMERIC
, 'C');
7875 * Return an array containing variations for the basic page number alias.
7876 * @param $a (string) Base alias.
7877 * @return array of page number aliases
7880 protected function getInternalPageNumberAliases($a= '') {
7882 // build array of Unicode + ASCII variants (the order is important)
7883 $alias = array('u' => array(), 'a' => array());
7885 $alias['u'][] = TCPDF_STATIC
::_escape($u);
7886 if ($this->isunicode
) {
7887 $alias['u'][] = TCPDF_STATIC
::_escape(TCPDF_FONTS
::UTF8ToLatin1($u, $this->isunicode
, $this->CurrentFont
));
7888 $alias['u'][] = TCPDF_STATIC
::_escape(TCPDF_FONTS
::utf8StrRev($u, false, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
));
7889 $alias['a'][] = TCPDF_STATIC
::_escape(TCPDF_FONTS
::UTF8ToLatin1($a, $this->isunicode
, $this->CurrentFont
));
7890 $alias['a'][] = TCPDF_STATIC
::_escape(TCPDF_FONTS
::utf8StrRev($a, false, $this->tmprtl
, $this->isunicode
, $this->CurrentFont
));
7892 $alias['a'][] = TCPDF_STATIC
::_escape($a);
7897 * Return an array containing all internal page aliases.
7898 * @return array of page number aliases
7901 protected function getAllInternalPageNumberAliases() {
7902 $basic_alias = array(TCPDF_STATIC
::$alias_tot_pages, TCPDF_STATIC
::$alias_num_page, TCPDF_STATIC
::$alias_group_tot_pages, TCPDF_STATIC
::$alias_group_num_page, TCPDF_STATIC
::$alias_right_shift);
7904 foreach($basic_alias as $k => $a) {
7905 $pnalias[$k] = $this->getInternalPageNumberAliases($a);
7911 * Replace right shift page number aliases with spaces to correct right alignment.
7912 * This works perfectly only when using monospaced fonts.
7913 * @param $page (string) Page content.
7914 * @param $aliases (array) Array of page aliases.
7915 * @param $diff (int) initial difference to add.
7916 * @return replaced page content.
7919 protected function replaceRightShiftPageNumAliases($page, $aliases, $diff) {
7920 foreach ($aliases as $type => $alias) {
7921 foreach ($alias as $a) {
7922 // find position of compensation factor
7923 $startnum = (strpos($a, ':') +
1);
7924 $a = substr($a, 0, $startnum);
7925 if (($pos = strpos($page, $a)) !== false) {
7927 $endnum = strpos($page, '}', $pos);
7928 // string to be replaced
7929 $aa = substr($page, $pos, ($endnum - $pos +
1));
7930 // get compensation factor
7931 $ratio = substr($page, ($pos +
$startnum), ($endnum - $pos - $startnum));
7932 $ratio = preg_replace('/[^0-9\.]/', '', $ratio);
7933 $ratio = floatval($ratio);
7935 $chrdiff = floor(($diff +
12) * $ratio);
7936 $shift = str_repeat(' ', $chrdiff);
7937 $shift = TCPDF_FONTS
::UTF8ToUTF16BE($shift, false, $this->isunicode
, $this->CurrentFont
);
7939 $chrdiff = floor(($diff +
11) * $ratio);
7940 $shift = str_repeat(' ', $chrdiff);
7942 $page = str_replace($aa, $shift, $page);
7950 * Set page boxes to be included on page descriptions.
7951 * @param $boxes (array) Array of page boxes to set on document: ('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox').
7954 protected function setPageBoxTypes($boxes) {
7955 $this->page_boxes
= array();
7956 foreach ($boxes as $box) {
7957 if (in_array($box, TCPDF_STATIC
::$pageboxes)) {
7958 $this->page_boxes
[] = $box;
7964 * Output pages (and replace page number aliases).
7967 protected function _putpages() {
7968 $filter = ($this->compress
) ?
'/Filter /FlateDecode ' : '';
7969 // get internal aliases for page numbers
7970 $pnalias = $this->getAllInternalPageNumberAliases();
7971 $num_pages = $this->numpages
;
7972 $ptpa = TCPDF_STATIC
::formatPageNumber(($this->starting_page_number +
$num_pages - 1));
7973 $ptpu = TCPDF_FONTS
::UTF8ToUTF16BE($ptpa, false, $this->isunicode
, $this->CurrentFont
);
7974 $ptp_num_chars = $this->GetNumChars($ptpa);
7980 for ($n = 1; $n <= $num_pages; ++
$n) {
7982 $temppage = $this->getPageBuffer($n);
7983 $pagelen = strlen($temppage);
7984 // set replacements for total pages number
7985 $pnpa = TCPDF_STATIC
::formatPageNumber(($this->starting_page_number +
$n - 1));
7986 $pnpu = TCPDF_FONTS
::UTF8ToUTF16BE($pnpa, false, $this->isunicode
, $this->CurrentFont
);
7987 $pnp_num_chars = $this->GetNumChars($pnpa);
7988 $pdiff = 0; // difference used for right shift alignment of page numbers
7989 $gdiff = 0; // difference used for right shift alignment of page group numbers
7990 if (!empty($this->pagegroups
)) {
7991 if (isset($this->newpagegroup
[$n])) {
7994 $ptga = TCPDF_STATIC
::formatPageNumber($this->pagegroups
[$groupnum]);
7995 $ptgu = TCPDF_FONTS
::UTF8ToUTF16BE($ptga, false, $this->isunicode
, $this->CurrentFont
);
7996 $ptg_num_chars = $this->GetNumChars($ptga);
7999 $pnga = TCPDF_STATIC
::formatPageNumber($pagegroupnum);
8000 $pngu = TCPDF_FONTS
::UTF8ToUTF16BE($pnga, false, $this->isunicode
, $this->CurrentFont
);
8001 $png_num_chars = $this->GetNumChars($pnga);
8002 // replace page numbers
8004 $replace[] = array($ptgu, $ptg_num_chars, 9, $pnalias[2]['u']);
8005 $replace[] = array($ptga, $ptg_num_chars, 7, $pnalias[2]['a']);
8006 $replace[] = array($pngu, $png_num_chars, 9, $pnalias[3]['u']);
8007 $replace[] = array($pnga, $png_num_chars, 7, $pnalias[3]['a']);
8008 list($temppage, $gdiff) = TCPDF_STATIC
::replacePageNumAliases($temppage, $replace, $gdiff);
8010 // replace page numbers
8012 $replace[] = array($ptpu, $ptp_num_chars, 9, $pnalias[0]['u']);
8013 $replace[] = array($ptpa, $ptp_num_chars, 7, $pnalias[0]['a']);
8014 $replace[] = array($pnpu, $pnp_num_chars, 9, $pnalias[1]['u']);
8015 $replace[] = array($pnpa, $pnp_num_chars, 7, $pnalias[1]['a']);
8016 list($temppage, $pdiff) = TCPDF_STATIC
::replacePageNumAliases($temppage, $replace, $pdiff);
8017 // replace right shift alias
8018 $temppage = $this->replaceRightShiftPageNumAliases($temppage, $pnalias[4], max($pdiff, $gdiff));
8019 // replace EPS marker
8020 $temppage = str_replace($this->epsmarker
, '', $temppage);
8022 $this->page_obj_id
[$n] = $this->_newobj();
8024 $out .= ' /Type /Page';
8025 $out .= ' /Parent 1 0 R';
8026 if (empty($this->signature_data
['approval']) OR ($this->signature_data
['approval'] != 'A')) {
8027 $out .= ' /LastModified '.$this->_datestring(0, $this->doc_modification_timestamp
);
8029 $out .= ' /Resources 2 0 R';
8030 foreach ($this->page_boxes
as $box) {
8032 $out .= sprintf(' [%F %F %F %F]', $this->pagedim
[$n][$box]['llx'], $this->pagedim
[$n][$box]['lly'], $this->pagedim
[$n][$box]['urx'], $this->pagedim
[$n][$box]['ury']);
8034 if (isset($this->pagedim
[$n]['BoxColorInfo']) AND !empty($this->pagedim
[$n]['BoxColorInfo'])) {
8035 $out .= ' /BoxColorInfo <<';
8036 foreach ($this->page_boxes
as $box) {
8037 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box])) {
8038 $out .= ' /'.$box.' <<';
8039 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['C'])) {
8040 $color = $this->pagedim
[$n]['BoxColorInfo'][$box]['C'];
8042 $out .= sprintf(' %F %F %F', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
8045 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['W'])) {
8046 $out .= ' /W '.($this->pagedim
[$n]['BoxColorInfo'][$box]['W'] * $this->k
);
8048 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['S'])) {
8049 $out .= ' /S /'.$this->pagedim
[$n]['BoxColorInfo'][$box]['S'];
8051 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['D'])) {
8052 $dashes = $this->pagedim
[$n]['BoxColorInfo'][$box]['D'];
8054 foreach ($dashes as $dash) {
8055 $out .= sprintf(' %F', ($dash * $this->k
));
8064 $out .= ' /Contents '.($this->n +
1).' 0 R';
8065 $out .= ' /Rotate '.$this->pagedim
[$n]['Rotate'];
8066 if (!$this->pdfa_mode
) {
8067 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
8069 if (isset($this->pagedim
[$n]['trans']) AND !empty($this->pagedim
[$n]['trans'])) {
8071 if (isset($this->pagedim
[$n]['trans']['Dur'])) {
8072 $out .= ' /Dur '.$this->pagedim
[$n]['trans']['Dur'];
8074 $out .= ' /Trans <<';
8075 $out .= ' /Type /Trans';
8076 if (isset($this->pagedim
[$n]['trans']['S'])) {
8077 $out .= ' /S /'.$this->pagedim
[$n]['trans']['S'];
8079 if (isset($this->pagedim
[$n]['trans']['D'])) {
8080 $out .= ' /D '.$this->pagedim
[$n]['trans']['D'];
8082 if (isset($this->pagedim
[$n]['trans']['Dm'])) {
8083 $out .= ' /Dm /'.$this->pagedim
[$n]['trans']['Dm'];
8085 if (isset($this->pagedim
[$n]['trans']['M'])) {
8086 $out .= ' /M /'.$this->pagedim
[$n]['trans']['M'];
8088 if (isset($this->pagedim
[$n]['trans']['Di'])) {
8089 $out .= ' /Di '.$this->pagedim
[$n]['trans']['Di'];
8091 if (isset($this->pagedim
[$n]['trans']['SS'])) {
8092 $out .= ' /SS '.$this->pagedim
[$n]['trans']['SS'];
8094 if (isset($this->pagedim
[$n]['trans']['B'])) {
8095 $out .= ' /B '.$this->pagedim
[$n]['trans']['B'];
8099 $out .= $this->_getannotsrefs($n);
8100 $out .= ' /PZ '.$this->pagedim
[$n]['PZ'];
8102 $out .= "\n".'endobj';
8105 $p = ($this->compress
) ?
gzcompress($temppage) : $temppage;
8107 $p = $this->_getrawstream($p);
8108 $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
8111 $out = $this->_getobj(1)."\n";
8112 $out .= '<< /Type /Pages /Kids [';
8113 foreach($this->page_obj_id
as $page_obj) {
8114 $out .= ' '.$page_obj.' 0 R';
8116 $out .= ' ] /Count '.$num_pages.' >>';
8117 $out .= "\n".'endobj';
8122 * Get references to page annotations.
8123 * @param $n (int) page number
8126 * @author Nicola Asuni
8127 * @since 5.0.010 (2010-05-17)
8129 protected function _getannotsrefs($n) {
8130 if (!(isset($this->PageAnnots
[$n]) OR ($this->sign
AND isset($this->signature_data
['cert_type'])))) {
8133 $out = ' /Annots [';
8134 if (isset($this->PageAnnots
[$n])) {
8135 foreach ($this->PageAnnots
[$n] as $key => $val) {
8136 if (!in_array($val['n'], $this->radio_groups
)) {
8137 $out .= ' '.$val['n'].' 0 R';
8140 // add radiobutton groups
8141 if (isset($this->radiobutton_groups
[$n])) {
8142 foreach ($this->radiobutton_groups
[$n] as $key => $data) {
8143 if (isset($data['n'])) {
8144 $out .= ' '.$data['n'].' 0 R';
8149 if ($this->sign
AND ($n == $this->signature_appearance
['page']) AND isset($this->signature_data
['cert_type'])) {
8150 // set reference for signature object
8151 $out .= ' '.$this->sig_obj_id
.' 0 R';
8153 if (!empty($this->empty_signature_appearance
)) {
8154 foreach ($this->empty_signature_appearance
as $esa) {
8155 if ($esa['page'] == $n) {
8156 // set reference for empty signature objects
8157 $out .= ' '.$esa['objid'].' 0 R';
8166 * Output annotations objects for all pages.
8167 * !!! THIS METHOD IS NOT YET COMPLETED !!!
8168 * See section 12.5 of PDF 32000_2008 reference.
8170 * @author Nicola Asuni
8171 * @since 4.0.018 (2008-08-06)
8173 protected function _putannotsobjs() {
8174 // reset object counter
8175 for ($n=1; $n <= $this->numpages
; ++
$n) {
8176 if (isset($this->PageAnnots
[$n])) {
8177 // set page annotations
8178 foreach ($this->PageAnnots
[$n] as $key => $pl) {
8179 $annot_obj_id = $this->PageAnnots
[$n][$key]['n'];
8180 // create annotation object for grouping radiobuttons
8181 if (isset($this->radiobutton_groups
[$n][$pl['txt']]) AND is_array($this->radiobutton_groups
[$n][$pl['txt']])) {
8182 $radio_button_obj_id = $this->radiobutton_groups
[$n][$pl['txt']]['n'];
8184 $annots .= ' /Type /Annot';
8185 $annots .= ' /Subtype /Widget';
8186 $annots .= ' /Rect [0 0 0 0]';
8187 if ($this->radiobutton_groups
[$n][$pl['txt']]['#readonly#']) {
8189 $annots .= ' /F 68';
8190 $annots .= ' /Ff 49153';
8192 $annots .= ' /F 4'; // default print for PDF/A
8193 $annots .= ' /Ff 49152';
8195 $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
8196 if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
8197 $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $radio_button_obj_id);
8199 $annots .= ' /FT /Btn';
8200 $annots .= ' /Kids [';
8202 foreach ($this->radiobutton_groups
[$n][$pl['txt']] as $key => $data) {
8203 if (isset($data['kid'])) {
8204 $annots .= ' '.$data['kid'].' 0 R';
8205 if ($data['def'] !== 'Off') {
8206 $defval = $data['def'];
8211 if (!empty($defval)) {
8212 $annots .= ' /V /'.$defval;
8215 $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
8216 $this->form_obj_id
[] = $radio_button_obj_id;
8217 // store object id to be used on Parent entry of Kids
8218 $this->radiobutton_groups
[$n][$pl['txt']] = $radio_button_obj_id;
8221 $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER
);
8222 $a = $pl['x'] * $this->k
;
8223 $b = $this->pagedim
[$n]['h'] - (($pl['y'] +
$pl['h']) * $this->k
);
8224 $c = $pl['w'] * $this->k
;
8225 $d = $pl['h'] * $this->k
;
8226 $rect = sprintf('%F %F %F %F', $a, $b, $a+
$c, $b+
$d);
8227 // create new annotation object
8228 $annots = '<</Type /Annot';
8229 $annots .= ' /Subtype /'.$pl['opt']['subtype'];
8230 $annots .= ' /Rect ['.$rect.']';
8231 $ft = array('Btn', 'Tx', 'Ch', 'Sig');
8232 if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
8233 $annots .= ' /FT /'.$pl['opt']['ft'];
8236 if ($pl['opt']['subtype'] !== 'Link') {
8237 $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
8239 $annots .= ' /P '.$this->page_obj_id
[$n].' 0 R';
8240 $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
8241 $annots .= ' /M '.$this->_datestring($annot_obj_id, $this->doc_modification_timestamp
);
8242 if (isset($pl['opt']['f'])) {
8244 if (is_array($pl['opt']['f'])) {
8245 foreach ($pl['opt']['f'] as $f) {
8246 switch (strtolower($f)) {
8279 case 'togglenoview': {
8283 case 'lockedcontents': {
8293 $fval = intval($pl['opt']['f']);
8298 if ($this->pdfa_mode
) {
8299 // force print flag for PDF/A mode
8302 $annots .= ' /F '.intval($fval);
8303 if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
8304 $annots .= ' /AS /'.$pl['opt']['as'];
8306 if (isset($pl['opt']['ap'])) {
8307 // appearance stream
8308 $annots .= ' /AP <<';
8309 if (is_array($pl['opt']['ap'])) {
8310 foreach ($pl['opt']['ap'] as $apmode => $apdef) {
8311 // $apmode can be: n = normal; r = rollover; d = down;
8312 $annots .= ' /'.strtoupper($apmode);
8313 if (is_array($apdef)) {
8315 foreach ($apdef as $apstate => $stream) {
8316 // reference to XObject that define the appearance for this mode-state
8317 $apsobjid = $this->_putAPXObject($c, $d, $stream);
8318 $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
8322 // reference to XObject that define the appearance for this mode
8323 $apsobjid = $this->_putAPXObject($c, $d, $apdef);
8324 $annots .= ' '.$apsobjid.' 0 R';
8328 $annots .= $pl['opt']['ap'];
8332 if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
8333 $annots .= ' /BS <<';
8334 $annots .= ' /Type /Border';
8335 if (isset($pl['opt']['bs']['w'])) {
8336 $annots .= ' /W '.intval($pl['opt']['bs']['w']);
8338 $bstyles = array('S', 'D', 'B', 'I', 'U');
8339 if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
8340 $annots .= ' /S /'.$pl['opt']['bs']['s'];
8342 if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
8344 foreach ($pl['opt']['bs']['d'] as $cord) {
8345 $annots .= ' '.intval($cord);
8351 $annots .= ' /Border [';
8352 if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
8353 $annots .= intval($pl['opt']['border'][0]).' ';
8354 $annots .= intval($pl['opt']['border'][1]).' ';
8355 $annots .= intval($pl['opt']['border'][2]);
8356 if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
8358 foreach ($pl['opt']['border'][3] as $dash) {
8359 $annots .= intval($dash).' ';
8368 if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
8369 $annots .= ' /BE <<';
8370 $bstyles = array('S', 'C');
8371 if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $bstyles)) {
8372 $annots .= ' /S /'.$pl['opt']['bs']['s'];
8374 $annots .= ' /S /S';
8376 if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
8377 $annots .= ' /I '.sprintf(' %F', $pl['opt']['be']['i']);
8381 if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
8382 $annots .= ' /C '.TCPDF_COLORS
::getColorStringFromArray($pl['opt']['c']);
8384 //$annots .= ' /StructParent ';
8385 //$annots .= ' /OC ';
8386 $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
8387 if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
8388 // this is a markup type
8389 if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
8390 $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
8392 //$annots .= ' /Popup ';
8393 if (isset($pl['opt']['ca'])) {
8394 $annots .= ' /CA '.sprintf('%F', floatval($pl['opt']['ca']));
8396 if (isset($pl['opt']['rc'])) {
8397 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
8399 $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id, $this->doc_creation_timestamp
);
8400 //$annots .= ' /IRT ';
8401 if (isset($pl['opt']['subj'])) {
8402 $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
8404 //$annots .= ' /RT ';
8405 //$annots .= ' /IT ';
8406 //$annots .= ' /ExData ';
8408 $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
8410 switch (strtolower($pl['opt']['subtype'])) {
8412 if (isset($pl['opt']['open'])) {
8413 $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ?
'true' : 'false');
8415 $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
8416 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8417 $annots .= ' /Name /'.$pl['opt']['name'];
8419 $annots .= ' /Name /Note';
8421 $statemodels = array('Marked', 'Review');
8422 if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
8423 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
8425 $pl['opt']['statemodel'] = 'Marked';
8426 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
8428 if ($pl['opt']['statemodel'] == 'Marked') {
8429 $states = array('Accepted', 'Unmarked');
8431 $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
8433 if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
8434 $annots .= ' /State /'.$pl['opt']['state'];
8436 if ($pl['opt']['statemodel'] == 'Marked') {
8437 $annots .= ' /State /Unmarked';
8439 $annots .= ' /State /None';
8445 if (is_string($pl['txt']) && !empty($pl['txt'])) {
8446 if ($pl['txt'][0] == '#') {
8447 // internal destination
8448 $annots .= ' /A <</S /GoTo /D '.TCPDF_STATIC
::encodeNameObject(substr($pl['txt'], 1)).'>>';
8449 } elseif ($pl['txt'][0] == '%') {
8450 // embedded PDF file
8451 $filename = basename(substr($pl['txt'], 1));
8452 $annots .= ' /A << /S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($n - 1).' /A '.$this->embeddedfiles
[$filename]['a'].' >> >>';
8453 } elseif ($pl['txt'][0] == '*') {
8454 // embedded generic file
8455 $filename = basename(substr($pl['txt'], 1));
8456 $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
8457 $annots .= ' /A << /S /JavaScript /JS '.$this->_textstring($jsa, $annot_obj_id).'>>';
8459 $parsedUrl = parse_url($pl['txt']);
8460 if (empty($parsedUrl['scheme']) AND (!empty($parsedUrl['path']) && strtolower(substr($parsedUrl['path'], -4)) == '.pdf')) {
8461 // relative link to a PDF file
8462 $dest = '[0 /Fit]'; // default page 0
8463 if (!empty($parsedUrl['fragment'])) {
8464 // check for named destination
8465 $tmp = explode('=', $parsedUrl['fragment']);
8466 $dest = '('.((count($tmp) == 2) ?
$tmp[1] : $tmp[0]).')';
8468 $annots .= ' /A <</S /GoToR /D '.$dest.' /F '.$this->_datastring($this->unhtmlentities($parsedUrl['path']), $annot_obj_id).' /NewWindow true>>';
8470 // external URI link
8471 $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
8474 } elseif (isset($this->links
[$pl['txt']])) {
8476 $l = $this->links
[$pl['txt']];
8477 if (isset($this->page_obj_id
[($l['p'])])) {
8478 $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id
[($l['p'])], ($this->pagedim
[$l['p']]['h'] - ($l['y'] * $this->k
)));
8481 $hmodes = array('N', 'I', 'O', 'P');
8482 if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
8483 $annots .= ' /H /'.$pl['opt']['h'];
8485 $annots .= ' /H /I';
8487 //$annots .= ' /PA ';
8488 //$annots .= ' /Quadpoints ';
8492 if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
8493 $annots .= ' /DA ('.$pl['opt']['da'].')';
8495 if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
8496 $annots .= ' /Q '.intval($pl['opt']['q']);
8498 if (isset($pl['opt']['rc'])) {
8499 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
8501 if (isset($pl['opt']['ds'])) {
8502 $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
8504 if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
8505 $annots .= ' /CL [';
8506 foreach ($pl['opt']['cl'] as $cl) {
8507 $annots .= sprintf('%F ', $cl * $this->k
);
8511 $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
8512 if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
8513 $annots .= ' /IT /'.$pl['opt']['it'];
8515 if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
8516 $l = $pl['opt']['rd'][0] * $this->k
;
8517 $r = $pl['opt']['rd'][1] * $this->k
;
8518 $t = $pl['opt']['rd'][2] * $this->k
;
8519 $b = $pl['opt']['rd'][3] * $this->k
;
8520 $annots .= ' /RD ['.sprintf('%F %F %F %F', $l, $r, $t, $b).']';
8522 if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
8523 $annots .= ' /LE /'.$pl['opt']['le'];
8566 case 'fileattachment': {
8567 if ($this->pdfa_mode
&& $this->pdfa_version
!= 3) {
8568 // embedded files are not allowed in PDF/A mode version 1 and 2
8571 if (!isset($pl['opt']['fs'])) {
8574 $filename = basename($pl['opt']['fs']);
8575 if (isset($this->embeddedfiles
[$filename]['f'])) {
8576 $annots .= ' /FS '.$this->embeddedfiles
[$filename]['f'].' 0 R';
8577 $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
8578 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8579 $annots .= ' /Name /'.$pl['opt']['name'];
8581 $annots .= ' /Name /PushPin';
8583 // index (zero-based) of the annotation in the Annots array of this page
8584 $this->embeddedfiles
[$filename]['a'] = $key;
8589 if (!isset($pl['opt']['fs'])) {
8592 $filename = basename($pl['opt']['fs']);
8593 if (isset($this->embeddedfiles
[$filename]['f'])) {
8594 // ... TO BE COMPLETED ...
8595 // /R /C /B /E /CO /CP
8596 $annots .= ' /Sound '.$this->embeddedfiles
[$filename]['f'].' 0 R';
8597 $iconsapp = array('Speaker', 'Mic');
8598 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8599 $annots .= ' /Name /'.$pl['opt']['name'];
8601 $annots .= ' /Name /Speaker';
8610 $hmode = array('N', 'I', 'O', 'P', 'T');
8611 if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
8612 $annots .= ' /H /'.$pl['opt']['h'];
8614 if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
8615 $annots .= ' /MK <<';
8616 if (isset($pl['opt']['mk']['r'])) {
8617 $annots .= ' /R '.$pl['opt']['mk']['r'];
8619 if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
8620 $annots .= ' /BC '.TCPDF_COLORS
::getColorStringFromArray($pl['opt']['mk']['bc']);
8622 if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
8623 $annots .= ' /BG '.TCPDF_COLORS
::getColorStringFromArray($pl['opt']['mk']['bg']);
8625 if (isset($pl['opt']['mk']['ca'])) {
8626 $annots .= ' /CA '.$pl['opt']['mk']['ca'];
8628 if (isset($pl['opt']['mk']['rc'])) {
8629 $annots .= ' /RC '.$pl['opt']['mk']['rc'];
8631 if (isset($pl['opt']['mk']['ac'])) {
8632 $annots .= ' /AC '.$pl['opt']['mk']['ac'];
8634 if (isset($pl['opt']['mk']['i'])) {
8635 $info = $this->getImageBuffer($pl['opt']['mk']['i']);
8636 if ($info !== false) {
8637 $annots .= ' /I '.$info['n'].' 0 R';
8640 if (isset($pl['opt']['mk']['ri'])) {
8641 $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
8642 if ($info !== false) {
8643 $annots .= ' /RI '.$info['n'].' 0 R';
8646 if (isset($pl['opt']['mk']['ix'])) {
8647 $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
8648 if ($info !== false) {
8649 $annots .= ' /IX '.$info['n'].' 0 R';
8652 if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
8653 $annots .= ' /IF <<';
8654 $if_sw = array('A', 'B', 'S', 'N');
8655 if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
8656 $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
8658 $if_s = array('A', 'P');
8659 if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
8660 $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
8662 if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
8663 $annots .= sprintf(' /A [%F %F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
8665 if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
8666 $annots .= ' /FB true';
8670 if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
8671 $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
8675 // --- Entries for field dictionaries ---
8676 if (isset($this->radiobutton_groups
[$n][$pl['txt']])) {
8678 $annots .= ' /Parent '.$this->radiobutton_groups
[$n][$pl['txt']].' 0 R';
8680 if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
8681 $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
8683 if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
8684 $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
8686 if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
8687 $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
8689 if (isset($pl['opt']['ff'])) {
8690 if (is_array($pl['opt']['ff'])) {
8691 // array of bit settings
8693 foreach($pl['opt']['ff'] as $val) {
8694 $flag +
= 1 << ($val - 1);
8697 $flag = intval($pl['opt']['ff']);
8699 $annots .= ' /Ff '.$flag;
8701 if (isset($pl['opt']['maxlen'])) {
8702 $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
8704 if (isset($pl['opt']['v'])) {
8706 if (is_array($pl['opt']['v'])) {
8707 foreach ($pl['opt']['v'] AS $optval) {
8708 if (is_float($optval)) {
8709 $optval = sprintf('%F', $optval);
8711 $annots .= ' '.$optval;
8714 $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
8717 if (isset($pl['opt']['dv'])) {
8719 if (is_array($pl['opt']['dv'])) {
8720 foreach ($pl['opt']['dv'] AS $optval) {
8721 if (is_float($optval)) {
8722 $optval = sprintf('%F', $optval);
8724 $annots .= ' '.$optval;
8727 $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
8730 if (isset($pl['opt']['rv'])) {
8732 if (is_array($pl['opt']['rv'])) {
8733 foreach ($pl['opt']['rv'] AS $optval) {
8734 if (is_float($optval)) {
8735 $optval = sprintf('%F', $optval);
8737 $annots .= ' '.$optval;
8740 $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
8743 if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
8744 $annots .= ' /A << '.$pl['opt']['a'].' >>';
8746 if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
8747 $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
8749 if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
8750 $annots .= ' /DA ('.$pl['opt']['da'].')';
8752 if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
8753 $annots .= ' /Q '.intval($pl['opt']['q']);
8755 if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
8756 $annots .= ' /Opt [';
8757 foreach($pl['opt']['opt'] AS $copt) {
8758 if (is_array($copt)) {
8759 $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
8761 $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
8766 if (isset($pl['opt']['ti'])) {
8767 $annots .= ' /TI '.intval($pl['opt']['ti']);
8769 if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
8771 foreach($pl['opt']['i'] AS $copt) {
8772 $annots .= intval($copt).' ';
8781 case 'printermark': {
8798 // create new annotation object
8799 $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
8800 if ($formfield AND !isset($this->radiobutton_groups
[$n][$pl['txt']])) {
8801 // store reference of form object
8802 $this->form_obj_id
[] = $annot_obj_id;
8806 } // end for each page
8810 * Put appearance streams XObject used to define annotation's appearance states.
8811 * @param $w (int) annotation width
8812 * @param $h (int) annotation height
8813 * @param $stream (string) appearance stream
8814 * @return int object ID
8816 * @since 4.8.001 (2009-09-09)
8818 protected function _putAPXObject($w=0, $h=0, $stream='') {
8819 $stream = trim($stream);
8820 $out = $this->_getobj()."\n";
8821 $this->xobjects
['AX'.$this->n
] = array('n' => $this->n
);
8823 $out .= ' /Type /XObject';
8824 $out .= ' /Subtype /Form';
8825 $out .= ' /FormType 1';
8826 if ($this->compress
) {
8827 $stream = gzcompress($stream);
8828 $out .= ' /Filter /FlateDecode';
8830 $rect = sprintf('%F %F', $w, $h);
8831 $out .= ' /BBox [0 0 '.$rect.']';
8832 $out .= ' /Matrix [1 0 0 1 0 0]';
8833 $out .= ' /Resources 2 0 R';
8834 $stream = $this->_getrawstream($stream);
8835 $out .= ' /Length '.strlen($stream);
8837 $out .= ' stream'."\n".$stream."\n".'endstream';
8838 $out .= "\n".'endobj';
8845 * @author Nicola Asuni
8848 protected function _putfonts() {
8850 foreach ($this->diffs
as $diff) {
8853 $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
8855 $mqr = TCPDF_STATIC
::get_mqr();
8856 TCPDF_STATIC
::set_mqr(false);
8857 foreach ($this->FontFiles
as $file => $info) {
8858 // search and get font file to embedd
8859 $fontfile = TCPDF_FONTS
::getFontFullPath($file, $info['fontdir']);
8860 if (!TCPDF_STATIC
::empty_string($fontfile)) {
8861 $font = file_get_contents($fontfile);
8862 $compressed = (substr($file, -2) == '.z');
8863 if ((!$compressed) AND (isset($info['length2']))) {
8864 $header = (ord($font[0]) == 128);
8866 // strip first binary header
8867 $font = substr($font, 6);
8869 if ($header AND (ord($font[$info['length1']]) == 128)) {
8870 // strip second binary header
8871 $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] +
6));
8873 } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
8876 $font = gzuncompress($font);
8878 // merge subset characters
8879 $subsetchars = array(); // used chars
8880 foreach ($info['fontkeys'] as $fontkey) {
8881 $fontinfo = $this->getFontBuffer($fontkey);
8882 $subsetchars +
= $fontinfo['subsetchars'];
8884 // rebuild a font subset
8885 $font = TCPDF_FONTS
::_getTrueTypeFontSubset($font, $subsetchars);
8886 // calculate new font length
8887 $info['length1'] = strlen($font);
8890 $font = gzcompress($font);
8894 $this->FontFiles
[$file]['n'] = $this->n
;
8895 $stream = $this->_getrawstream($font);
8896 $out = '<< /Length '.strlen($stream);
8898 $out .= ' /Filter /FlateDecode';
8900 $out .= ' /Length1 '.$info['length1'];
8901 if (isset($info['length2'])) {
8902 $out .= ' /Length2 '.$info['length2'].' /Length3 0';
8905 $out .= ' stream'."\n".$stream."\n".'endstream';
8906 $out .= "\n".'endobj';
8910 TCPDF_STATIC
::set_mqr($mqr);
8911 foreach ($this->fontkeys
as $k) {
8913 $font = $this->getFontBuffer($k);
8914 $type = $font['type'];
8915 $name = $font['name'];
8916 if ($type == 'core') {
8917 // standard core font
8918 $out = $this->_getobj($this->font_obj_ids
[$k])."\n";
8919 $out .= '<</Type /Font';
8920 $out .= ' /Subtype /Type1';
8921 $out .= ' /BaseFont /'.$name;
8922 $out .= ' /Name /F'.$font['i'];
8923 if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
8924 $out .= ' /Encoding /WinAnsiEncoding';
8926 if ($k == 'helvetica') {
8927 // add default font for annotations
8928 $this->annotation_fonts
[$k] = $font['i'];
8931 $out .= "\n".'endobj';
8933 } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
8934 // additional Type1 or TrueType font
8935 $out = $this->_getobj($this->font_obj_ids
[$k])."\n";
8936 $out .= '<</Type /Font';
8937 $out .= ' /Subtype /'.$type;
8938 $out .= ' /BaseFont /'.$name;
8939 $out .= ' /Name /F'.$font['i'];
8940 $out .= ' /FirstChar 32 /LastChar 255';
8941 $out .= ' /Widths '.($this->n +
1).' 0 R';
8942 $out .= ' /FontDescriptor '.($this->n +
2).' 0 R';
8944 if (isset($font['diff'])) {
8945 $out .= ' /Encoding '.($nf +
$font['diff']).' 0 R';
8947 $out .= ' /Encoding /WinAnsiEncoding';
8951 $out .= "\n".'endobj';
8956 for ($i = 32; $i < 256; ++
$i) {
8957 if (isset($font['cw'][$i])) {
8958 $s .= $font['cw'][$i].' ';
8960 $s .= $font['dw'].' ';
8964 $s .= "\n".'endobj';
8968 $s = '<</Type /FontDescriptor /FontName /'.$name;
8969 foreach ($font['desc'] as $fdk => $fdv) {
8970 if (is_float($fdv)) {
8971 $fdv = sprintf('%F', $fdv);
8973 $s .= ' /'.$fdk.' '.$fdv.'';
8975 if (!TCPDF_STATIC
::empty_string($font['file'])) {
8976 $s .= ' /FontFile'.($type == 'Type1' ?
'' : '2').' '.$this->FontFiles
[$font['file']]['n'].' 0 R';
8979 $s .= "\n".'endobj';
8983 $mtd = '_put'.strtolower($type);
8984 if (!method_exists($this, $mtd)) {
8985 $this->Error('Unsupported font type: '.$type);
8993 * Adds unicode fonts.<br>
8994 * Based on PDF Reference 1.3 (section 5)
8995 * @param $font (array) font data
8997 * @author Nicola Asuni
8998 * @since 1.52.0.TC005 (2005-01-05)
9000 protected function _puttruetypeunicode($font) {
9002 if ($font['subset']) {
9003 // change name for font subsetting
9004 $subtag = sprintf('%06u', $font['i']);
9005 $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
9006 $fontname .= $subtag.'+';
9008 $fontname .= $font['name'];
9010 // A composite font composed of other fonts, organized hierarchically
9011 $out = $this->_getobj($this->font_obj_ids
[$font['fontkey']])."\n";
9012 $out .= '<< /Type /Font';
9013 $out .= ' /Subtype /Type0';
9014 $out .= ' /BaseFont /'.$fontname;
9015 $out .= ' /Name /F'.$font['i'];
9016 $out .= ' /Encoding /'.$font['enc'];
9017 $out .= ' /ToUnicode '.($this->n +
1).' 0 R';
9018 $out .= ' /DescendantFonts ['.($this->n +
2).' 0 R]';
9020 $out .= "\n".'endobj';
9022 // ToUnicode map for Identity-H
9023 $stream = TCPDF_FONT_DATA
::$uni_identity_h;
9026 $stream = ($this->compress
) ?
gzcompress($stream) : $stream;
9027 $filter = ($this->compress
) ?
'/Filter /FlateDecode ' : '';
9028 $stream = $this->_getrawstream($stream);
9029 $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
9031 // A CIDFont whose glyph descriptions are based on TrueType font technology
9032 $oid = $this->_newobj();
9033 $out = '<< /Type /Font';
9034 $out .= ' /Subtype /CIDFontType2';
9035 $out .= ' /BaseFont /'.$fontname;
9036 // A dictionary containing entries that define the character collection of the CIDFont.
9037 $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
9038 $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
9039 $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
9040 $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
9041 $out .= ' /FontDescriptor '.($this->n +
1).' 0 R';
9042 $out .= ' /DW '.$font['dw']; // default width
9043 $out .= "\n".TCPDF_FONTS
::_putfontwidths($font, 0);
9044 if (isset($font['ctg']) AND (!TCPDF_STATIC
::empty_string($font['ctg']))) {
9045 $out .= "\n".'/CIDToGIDMap '.($this->n +
2).' 0 R';
9048 $out .= "\n".'endobj';
9051 // A font descriptor describing the CIDFont default metrics other than its glyph widths
9053 $out = '<< /Type /FontDescriptor';
9054 $out .= ' /FontName /'.$fontname;
9055 foreach ($font['desc'] as $key => $value) {
9056 if (is_float($value)) {
9057 $value = sprintf('%F', $value);
9059 $out .= ' /'.$key.' '.$value;
9062 if (!TCPDF_STATIC
::empty_string($font['file'])) {
9063 // A stream containing a TrueType font
9064 $out .= ' /FontFile2 '.$this->FontFiles
[$font['file']]['n'].' 0 R';
9065 $fontdir = $this->FontFiles
[$font['file']]['fontdir'];
9068 $out .= "\n".'endobj';
9070 if (isset($font['ctg']) AND (!TCPDF_STATIC
::empty_string($font['ctg']))) {
9072 // Embed CIDToGIDMap
9073 // A specification of the mapping from CIDs to glyph indices
9074 // search and get CTG font file to embedd
9075 $ctgfile = strtolower($font['ctg']);
9076 // search and get ctg font file to embedd
9077 $fontfile = TCPDF_FONTS
::getFontFullPath($ctgfile, $fontdir);
9078 if (TCPDF_STATIC
::empty_string($fontfile)) {
9079 $this->Error('Font file not found: '.$ctgfile);
9081 $stream = $this->_getrawstream(file_get_contents($fontfile));
9082 $out = '<< /Length '.strlen($stream).'';
9083 if (substr($fontfile, -2) == '.z') { // check file extension
9084 // Decompresses data encoded using the public-domain
9085 // zlib/deflate compression method, reproducing the
9086 // original text or binary data
9087 $out .= ' /Filter /FlateDecode';
9090 $out .= ' stream'."\n".$stream."\n".'endstream';
9091 $out .= "\n".'endobj';
9097 * Output CID-0 fonts.
9098 * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
9099 * @param $font (array) font data
9101 * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
9102 * @since 3.2.000 (2008-06-23)
9104 protected function _putcidfont0($font) {
9106 if (!isset($font['cw'][1])) {
9109 if (isset($font['cidinfo']['uni2cid'])) {
9110 // convert unicode to cid.
9111 $uni2cid = $font['cidinfo']['uni2cid'];
9113 foreach ($font['cw'] as $uni => $width) {
9114 if (isset($uni2cid[$uni])) {
9115 $cw[($uni2cid[$uni] +
$cidoffset)] = $width;
9116 } elseif ($uni < 256) {
9118 } // else unknown character
9120 $font = array_merge($font, array('cw' => $cw));
9122 $name = $font['name'];
9123 $enc = $font['enc'];
9125 $longname = $name.'-'.$enc;
9129 $out = $this->_getobj($this->font_obj_ids
[$font['fontkey']])."\n";
9130 $out .= '<</Type /Font';
9131 $out .= ' /Subtype /Type0';
9132 $out .= ' /BaseFont /'.$longname;
9133 $out .= ' /Name /F'.$font['i'];
9135 $out .= ' /Encoding /'.$enc;
9137 $out .= ' /DescendantFonts ['.($this->n +
1).' 0 R]';
9139 $out .= "\n".'endobj';
9141 $oid = $this->_newobj();
9142 $out = '<</Type /Font';
9143 $out .= ' /Subtype /CIDFontType0';
9144 $out .= ' /BaseFont /'.$name;
9145 $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
9146 $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
9147 $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
9148 $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
9149 $out .= ' /FontDescriptor '.($this->n +
1).' 0 R';
9150 $out .= ' /DW '.$font['dw'];
9151 $out .= "\n".TCPDF_FONTS
::_putfontwidths($font, $cidoffset);
9153 $out .= "\n".'endobj';
9156 $s = '<</Type /FontDescriptor /FontName /'.$name;
9157 foreach ($font['desc'] as $k => $v) {
9158 if ($k != 'Style') {
9160 $v = sprintf('%F', $v);
9162 $s .= ' /'.$k.' '.$v.'';
9166 $s .= "\n".'endobj';
9174 protected function _putimages() {
9175 $filter = ($this->compress
) ?
'/Filter /FlateDecode ' : '';
9176 foreach ($this->imagekeys
as $file) {
9177 $info = $this->getImageBuffer($file);
9178 // set object for alternate images array
9179 if ((!$this->pdfa_mode
) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
9180 $altoid = $this->_newobj();
9182 foreach ($info['altimgs'] as $altimage) {
9183 if (isset($this->xobjects
['I'.$altimage[0]]['n'])) {
9184 $out .= ' << /Image '.$this->xobjects
['I'.$altimage[0]]['n'].' 0 R';
9185 $out .= ' /DefaultForPrinting';
9186 if ($altimage[1] === true) {
9195 $out .= "\n".'endobj';
9199 $oid = $this->_newobj();
9200 $this->xobjects
['I'.$info['i']] = array('n' => $oid);
9201 $this->setImageSubBuffer($file, 'n', $this->n
);
9202 $out = '<</Type /XObject';
9203 $out .= ' /Subtype /Image';
9204 $out .= ' /Width '.$info['w'];
9205 $out .= ' /Height '.$info['h'];
9206 if (array_key_exists('masked', $info)) {
9207 $out .= ' /SMask '.($this->n
- 1).' 0 R';
9211 if (isset($info['icc']) AND ($info['icc'] !== false)) {
9214 $out .= ' /ColorSpace [/ICCBased '.($this->n +
1).' 0 R]';
9215 } elseif ($info['cs'] == 'Indexed') {
9216 // Indexed Colour Space
9217 $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n +
1).' 0 R]';
9219 // Device Colour Space
9220 $out .= ' /ColorSpace /'.$info['cs'];
9222 if ($info['cs'] == 'DeviceCMYK') {
9223 $out .= ' /Decode [1 0 1 0 1 0 1 0]';
9225 $out .= ' /BitsPerComponent '.$info['bpc'];
9226 if (isset($altoid) AND ($altoid > 0)) {
9227 // reference to alternate images dictionary
9228 $out .= ' /Alternates '.$altoid.' 0 R';
9230 if (isset($info['exurl']) AND !empty($info['exurl'])) {
9232 $out .= ' /Length 0';
9233 $out .= ' /F << /FS /URL /F '.$this->_datastring($info['exurl'], $oid).' >>';
9234 if (isset($info['f'])) {
9235 $out .= ' /FFilter /'.$info['f'];
9238 $out .= ' stream'."\n".'endstream';
9240 if (isset($info['f'])) {
9241 $out .= ' /Filter /'.$info['f'];
9243 if (isset($info['parms'])) {
9244 $out .= ' '.$info['parms'];
9246 if (isset($info['trns']) AND is_array($info['trns'])) {
9248 $count_info = count($info['trns']);
9249 if ($info['cs'] == 'Indexed') {
9250 $maxval =(pow(2, $info['bpc']) - 1);
9251 for ($i = 0; $i < $count_info; ++
$i) {
9252 if (($info['trns'][$i] != 0) AND ($info['trns'][$i] != $maxval)) {
9253 // this is not a binary type mask @TODO: create a SMask
9256 } elseif (empty($trns) AND ($info['trns'][$i] == 0)) {
9257 // store the first fully transparent value
9258 $trns .= $i.' '.$i.' ';
9263 for ($i = 0; $i < $count_info; ++
$i) {
9264 if ($info['trns'][$i] == 0) {
9265 $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
9269 // Colour Key Masking
9270 if (!empty($trns)) {
9271 $out .= ' /Mask ['.$trns.']';
9274 $stream = $this->_getrawstream($info['data']);
9275 $out .= ' /Length '.strlen($stream).' >>';
9276 $out .= ' stream'."\n".$stream."\n".'endstream';
9278 $out .= "\n".'endobj';
9281 // ICC colour profile
9283 $icc = ($this->compress
) ?
gzcompress($info['icc']) : $info['icc'];
9284 $icc = $this->_getrawstream($icc);
9285 $this->_out('<</N '.$info['ch'].' /Alternate /'.$info['cs'].' '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
9286 } elseif ($info['cs'] == 'Indexed') {
9289 $pal = ($this->compress
) ?
gzcompress($info['pal']) : $info['pal'];
9290 $pal = $this->_getrawstream($pal);
9291 $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
9297 * Output Form XObjects Templates.
9298 * @author Nicola Asuni
9299 * @since 5.8.017 (2010-08-24)
9301 * @see startTemplate(), endTemplate(), printTemplate()
9303 protected function _putxobjects() {
9304 foreach ($this->xobjects
as $key => $data) {
9305 if (isset($data['outdata'])) {
9306 $stream = str_replace($this->epsmarker
, '', trim($data['outdata']));
9307 $out = $this->_getobj($data['n'])."\n";
9309 $out .= ' /Type /XObject';
9310 $out .= ' /Subtype /Form';
9311 $out .= ' /FormType 1';
9312 if ($this->compress
) {
9313 $stream = gzcompress($stream);
9314 $out .= ' /Filter /FlateDecode';
9316 $out .= sprintf(' /BBox [%F %F %F %F]', ($data['x'] * $this->k
), (-$data['y'] * $this->k
), (($data['w'] +
$data['x']) * $this->k
), (($data['h'] - $data['y']) * $this->k
));
9317 $out .= ' /Matrix [1 0 0 1 0 0]';
9318 $out .= ' /Resources <<';
9319 $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
9320 if (!$this->pdfa_mode
) {
9322 if (isset($data['extgstates']) AND !empty($data['extgstates'])) {
9323 $out .= ' /ExtGState <<';
9324 foreach ($data['extgstates'] as $k => $extgstate) {
9325 if (isset($this->extgstates
[$k]['name'])) {
9326 $out .= ' /'.$this->extgstates
[$k]['name'];
9330 $out .= ' '.$this->extgstates
[$k]['n'].' 0 R';
9334 if (isset($data['gradients']) AND !empty($data['gradients'])) {
9337 foreach ($data['gradients'] as $id => $grad) {
9338 // gradient patterns
9339 $gp .= ' /p'.$id.' '.$this->gradients
[$id]['pattern'].' 0 R';
9340 // gradient shadings
9341 $gs .= ' /Sh'.$id.' '.$this->gradients
[$id]['id'].' 0 R';
9343 $out .= ' /Pattern <<'.$gp.' >>';
9344 $out .= ' /Shading <<'.$gs.' >>';
9348 if (isset($data['spot_colors']) AND !empty($data['spot_colors'])) {
9349 $out .= ' /ColorSpace <<';
9350 foreach ($data['spot_colors'] as $name => $color) {
9351 $out .= ' /CS'.$color['i'].' '.$this->spot_colors
[$name]['n'].' 0 R';
9356 if (!empty($data['fonts'])) {
9357 $out .= ' /Font <<';
9358 foreach ($data['fonts'] as $fontkey => $fontid) {
9359 $out .= ' /F'.$fontid.' '.$this->font_obj_ids
[$fontkey].' 0 R';
9363 // images or nested xobjects
9364 if (!empty($data['images']) OR !empty($data['xobjects'])) {
9365 $out .= ' /XObject <<';
9366 foreach ($data['images'] as $imgid) {
9367 $out .= ' /I'.$imgid.' '.$this->xobjects
['I'.$imgid]['n'].' 0 R';
9369 foreach ($data['xobjects'] as $sub_id => $sub_objid) {
9370 $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
9374 $out .= ' >>'; //end resources
9375 if (isset($data['group']) AND ($data['group'] !== false)) {
9376 // set transparency group
9377 $out .= ' /Group << /Type /Group /S /Transparency';
9378 if (is_array($data['group'])) {
9379 if (isset($data['group']['CS']) AND !empty($data['group']['CS'])) {
9380 $out .= ' /CS /'.$data['group']['CS'];
9382 if (isset($data['group']['I'])) {
9383 $out .= ' /I /'.($data['group']['I']===true?
'true':'false');
9385 if (isset($data['group']['K'])) {
9386 $out .= ' /K /'.($data['group']['K']===true?
'true':'false');
9391 $stream = $this->_getrawstream($stream, $data['n']);
9392 $out .= ' /Length '.strlen($stream);
9394 $out .= ' stream'."\n".$stream."\n".'endstream';
9395 $out .= "\n".'endobj';
9402 * Output Spot Colors Resources.
9404 * @since 4.0.024 (2008-09-12)
9406 protected function _putspotcolors() {
9407 foreach ($this->spot_colors
as $name => $color) {
9409 $this->spot_colors
[$name]['n'] = $this->n
;
9410 $out = '[/Separation /'.str_replace(' ', '#20', $name);
9411 $out .= ' /DeviceCMYK <<';
9412 $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
9413 $out .= ' '.sprintf('/C1 [%F %F %F %F] ', ($color['C'] / 100), ($color['M'] / 100), ($color['Y'] / 100), ($color['K'] / 100));
9414 $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
9415 $out .= "\n".'endobj';
9421 * Return XObjects Dictionary.
9422 * @return string XObjects dictionary
9424 * @since 5.8.014 (2010-08-23)
9426 protected function _getxobjectdict() {
9428 foreach ($this->xobjects
as $id => $objid) {
9429 $out .= ' /'.$id.' '.$objid['n'].' 0 R';
9435 * Output Resources Dictionary.
9438 protected function _putresourcedict() {
9439 $out = $this->_getobj(2)."\n";
9440 $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
9441 $out .= ' /Font <<';
9442 foreach ($this->fontkeys
as $fontkey) {
9443 $font = $this->getFontBuffer($fontkey);
9444 $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
9447 $out .= ' /XObject <<';
9448 $out .= $this->_getxobjectdict();
9451 if (!empty($this->pdflayers
)) {
9452 $out .= ' /Properties <<';
9453 foreach ($this->pdflayers
as $layer) {
9454 $out .= ' /'.$layer['layer'].' '.$layer['objid'].' 0 R';
9458 if (!$this->pdfa_mode
) {
9460 if (isset($this->extgstates
) AND !empty($this->extgstates
)) {
9461 $out .= ' /ExtGState <<';
9462 foreach ($this->extgstates
as $k => $extgstate) {
9463 if (isset($extgstate['name'])) {
9464 $out .= ' /'.$extgstate['name'];
9468 $out .= ' '.$extgstate['n'].' 0 R';
9472 if (isset($this->gradients
) AND !empty($this->gradients
)) {
9475 foreach ($this->gradients
as $id => $grad) {
9476 // gradient patterns
9477 $gp .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
9478 // gradient shadings
9479 $gs .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
9481 $out .= ' /Pattern <<'.$gp.' >>';
9482 $out .= ' /Shading <<'.$gs.' >>';
9486 if (isset($this->spot_colors
) AND !empty($this->spot_colors
)) {
9487 $out .= ' /ColorSpace <<';
9488 foreach ($this->spot_colors
as $color) {
9489 $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
9494 $out .= "\n".'endobj';
9502 protected function _putresources() {
9503 $this->_putextgstates();
9506 $this->_putimages();
9507 $this->_putspotcolors();
9508 $this->_putshaders();
9509 $this->_putxobjects();
9510 $this->_putresourcedict();
9512 $this->_putEmbeddedFiles();
9513 $this->_putannotsobjs();
9514 $this->_putjavascript();
9515 $this->_putbookmarks();
9516 $this->_putencryption();
9520 * Adds some Metadata information (Document Information Dictionary)
9521 * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
9522 * @return int object id
9525 protected function _putinfo() {
9526 $oid = $this->_newobj();
9528 // store current isunicode value
9529 $prev_isunicode = $this->isunicode
;
9530 if ($this->docinfounicode
) {
9531 $this->isunicode
= true;
9533 if (!TCPDF_STATIC
::empty_string($this->title
)) {
9534 // The document's title.
9535 $out .= ' /Title '.$this->_textstring($this->title
, $oid);
9537 if (!TCPDF_STATIC
::empty_string($this->author
)) {
9538 // The name of the person who created the document.
9539 $out .= ' /Author '.$this->_textstring($this->author
, $oid);
9541 if (!TCPDF_STATIC
::empty_string($this->subject
)) {
9542 // The subject of the document.
9543 $out .= ' /Subject '.$this->_textstring($this->subject
, $oid);
9545 if (!TCPDF_STATIC
::empty_string($this->keywords
)) {
9546 // Keywords associated with the document.
9547 $out .= ' /Keywords '.$this->_textstring($this->keywords
, $oid);
9549 if (!TCPDF_STATIC
::empty_string($this->creator
)) {
9550 // If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted.
9551 $out .= ' /Creator '.$this->_textstring($this->creator
, $oid);
9553 // restore previous isunicode value
9554 $this->isunicode
= $prev_isunicode;
9556 $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC
::getTCPDFProducer(), $oid);
9557 // The date and time the document was created, in human-readable form
9558 $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp
);
9559 // The date and time the document was most recently modified, in human-readable form
9560 $out .= ' /ModDate '.$this->_datestring(0, $this->doc_modification_timestamp
);
9561 // A name object indicating whether the document has been modified to include trapping information
9562 $out .= ' /Trapped /False';
9564 $out .= "\n".'endobj';
9570 * Set additional XMP data to be added on the default XMP data just before the end of "x:xmpmeta" tag.
9571 * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
9572 * @param $xmp (string) Custom XMP data.
9573 * @since 5.9.128 (2011-10-06)
9576 public function setExtraXMP($xmp) {
9577 $this->custom_xmp
= $xmp;
9581 * Set additional XMP data to be added on the default XMP data just before the end of "rdf:RDF" tag.
9582 * IMPORTANT: This data is added as-is without controls, so you have to validate your data before using this method!
9583 * @param $xmp (string) Custom XMP RDF data.
9584 * @since 6.3.0 (2019-09-19)
9587 public function setExtraXMPRDF($xmp) {
9588 $this->custom_xmp_rdf
= $xmp;
9592 * Put XMP data object and return ID.
9593 * @return (int) The object ID.
9594 * @since 5.9.121 (2011-09-28)
9597 protected function _putXMP() {
9598 $oid = $this->_newobj();
9599 // store current isunicode value
9600 $prev_isunicode = $this->isunicode
;
9601 $this->isunicode
= true;
9602 $prev_encrypted = $this->encrypted
;
9603 $this->encrypted
= false;
9605 $xmp = '<?xpacket begin="'.TCPDF_FONTS
::unichr(0xfeff, $this->isunicode
).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n";
9606 $xmp .= '<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04">'."\n";
9607 $xmp .= "\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n";
9608 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
9609 $xmp .= "\t\t\t".'<dc:format>application/pdf</dc:format>'."\n";
9610 $xmp .= "\t\t\t".'<dc:title>'."\n";
9611 $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
9612 $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC
::_escapeXML($this->title
).'</rdf:li>'."\n";
9613 $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
9614 $xmp .= "\t\t\t".'</dc:title>'."\n";
9615 $xmp .= "\t\t\t".'<dc:creator>'."\n";
9616 $xmp .= "\t\t\t\t".'<rdf:Seq>'."\n";
9617 $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC
::_escapeXML($this->author
).'</rdf:li>'."\n";
9618 $xmp .= "\t\t\t\t".'</rdf:Seq>'."\n";
9619 $xmp .= "\t\t\t".'</dc:creator>'."\n";
9620 $xmp .= "\t\t\t".'<dc:description>'."\n";
9621 $xmp .= "\t\t\t\t".'<rdf:Alt>'."\n";
9622 $xmp .= "\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.TCPDF_STATIC
::_escapeXML($this->subject
).'</rdf:li>'."\n";
9623 $xmp .= "\t\t\t\t".'</rdf:Alt>'."\n";
9624 $xmp .= "\t\t\t".'</dc:description>'."\n";
9625 $xmp .= "\t\t\t".'<dc:subject>'."\n";
9626 $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
9627 $xmp .= "\t\t\t\t\t".'<rdf:li>'.TCPDF_STATIC
::_escapeXML($this->keywords
).'</rdf:li>'."\n";
9628 $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
9629 $xmp .= "\t\t\t".'</dc:subject>'."\n";
9630 $xmp .= "\t\t".'</rdf:Description>'."\n";
9631 // convert doc creation date format
9632 $dcdate = TCPDF_STATIC
::getFormattedDate($this->doc_creation_timestamp
);
9633 $doccreationdate = substr($dcdate, 0, 4).'-'.substr($dcdate, 4, 2).'-'.substr($dcdate, 6, 2);
9634 $doccreationdate .= 'T'.substr($dcdate, 8, 2).':'.substr($dcdate, 10, 2).':'.substr($dcdate, 12, 2);
9635 $doccreationdate .= substr($dcdate, 14, 3).':'.substr($dcdate, 18, 2);
9636 $doccreationdate = TCPDF_STATIC
::_escapeXML($doccreationdate);
9637 // convert doc modification date format
9638 $dmdate = TCPDF_STATIC
::getFormattedDate($this->doc_modification_timestamp
);
9639 $docmoddate = substr($dmdate, 0, 4).'-'.substr($dmdate, 4, 2).'-'.substr($dmdate, 6, 2);
9640 $docmoddate .= 'T'.substr($dmdate, 8, 2).':'.substr($dmdate, 10, 2).':'.substr($dmdate, 12, 2);
9641 $docmoddate .= substr($dmdate, 14, 3).':'.substr($dmdate, 18, 2);
9642 $docmoddate = TCPDF_STATIC
::_escapeXML($docmoddate);
9643 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n";
9644 $xmp .= "\t\t\t".'<xmp:CreateDate>'.$doccreationdate.'</xmp:CreateDate>'."\n";
9645 $xmp .= "\t\t\t".'<xmp:CreatorTool>'.$this->creator
.'</xmp:CreatorTool>'."\n";
9646 $xmp .= "\t\t\t".'<xmp:ModifyDate>'.$docmoddate.'</xmp:ModifyDate>'."\n";
9647 $xmp .= "\t\t\t".'<xmp:MetadataDate>'.$doccreationdate.'</xmp:MetadataDate>'."\n";
9648 $xmp .= "\t\t".'</rdf:Description>'."\n";
9649 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n";
9650 $xmp .= "\t\t\t".'<pdf:Keywords>'.TCPDF_STATIC
::_escapeXML($this->keywords
).'</pdf:Keywords>'."\n";
9651 $xmp .= "\t\t\t".'<pdf:Producer>'.TCPDF_STATIC
::_escapeXML(TCPDF_STATIC
::getTCPDFProducer()).'</pdf:Producer>'."\n";
9652 $xmp .= "\t\t".'</rdf:Description>'."\n";
9653 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n";
9654 $uuid = 'uuid:'.substr($this->file_id
, 0, 8).'-'.substr($this->file_id
, 8, 4).'-'.substr($this->file_id
, 12, 4).'-'.substr($this->file_id
, 16, 4).'-'.substr($this->file_id
, 20, 12);
9655 $xmp .= "\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n";
9656 $xmp .= "\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n";
9657 $xmp .= "\t\t".'</rdf:Description>'."\n";
9658 if ($this->pdfa_mode
) {
9659 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n";
9660 $xmp .= "\t\t\t".'<pdfaid:part>'.$this->pdfa_version
.'</pdfaid:part>'."\n";
9661 $xmp .= "\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n";
9662 $xmp .= "\t\t".'</rdf:Description>'."\n";
9664 // XMP extension schemas
9665 $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">'."\n";
9666 $xmp .= "\t\t\t".'<pdfaExtension:schemas>'."\n";
9667 $xmp .= "\t\t\t\t".'<rdf:Bag>'."\n";
9668 $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9669 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n";
9670 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n";
9671 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
9672 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
9673 $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
9674 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9675 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9676 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Adobe PDF Schema</pdfaProperty:description>'."\n";
9677 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
9678 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
9679 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9680 $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
9681 $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
9682 $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
9683 $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9684 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n";
9685 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n";
9686 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n";
9687 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
9688 $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
9689 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9690 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9691 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n";
9692 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n";
9693 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n";
9694 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9695 $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
9696 $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
9697 $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
9698 $xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9699 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n";
9700 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n";
9701 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n";
9702 $xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
9703 $xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
9704 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9705 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9706 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n";
9707 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n";
9708 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n";
9709 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9710 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9711 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9712 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n";
9713 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n";
9714 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
9715 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9716 $xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
9717 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
9718 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n";
9719 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n";
9720 $xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
9721 $xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
9722 $xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
9723 $xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
9724 $xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
9725 $xmp .= "\t\t\t\t".'</rdf:Bag>'."\n";
9726 $xmp .= "\t\t\t".'</pdfaExtension:schemas>'."\n";
9727 $xmp .= "\t\t".'</rdf:Description>'."\n";
9728 $xmp .= $this->custom_xmp_rdf
;
9729 $xmp .= "\t".'</rdf:RDF>'."\n";
9730 $xmp .= $this->custom_xmp
;
9731 $xmp .= '</x:xmpmeta>'."\n";
9732 $xmp .= '<?xpacket end="w"?>';
9733 $out = '<< /Type /Metadata /Subtype /XML /Length '.strlen($xmp).' >> stream'."\n".$xmp."\n".'endstream'."\n".'endobj';
9734 // restore previous isunicode value
9735 $this->isunicode
= $prev_isunicode;
9736 $this->encrypted
= $prev_encrypted;
9743 * @return int object id
9746 protected function _putcatalog() {
9748 $xmpobj = $this->_putXMP();
9749 // if required, add standard sRGB ICC colour profile
9750 if ($this->pdfa_mode
OR $this->force_srgb
) {
9751 $iccobj = $this->_newobj();
9752 $icc = file_get_contents(dirname(__FILE__
).'/include/sRGB.icc');
9754 if ($this->compress
) {
9755 $filter = ' /Filter /FlateDecode';
9756 $icc = gzcompress($icc);
9758 $icc = $this->_getrawstream($icc);
9759 $this->_out('<</N 3 '.$filter.'/Length '.strlen($icc).'>> stream'."\n".$icc."\n".'endstream'."\n".'endobj');
9762 $oid = $this->_newobj();
9763 $out = '<< /Type /Catalog';
9764 $out .= ' /Version /'.$this->PDFVersion
;
9765 //$out .= ' /Extensions <<>>';
9766 $out .= ' /Pages 1 0 R';
9767 //$out .= ' /PageLabels ' //...;
9768 $out .= ' /Names <<';
9769 if ((!$this->pdfa_mode
) AND !empty($this->n_js
)) {
9770 $out .= ' /JavaScript '.$this->n_js
;
9772 if (!empty($this->efnames
)) {
9773 $out .= ' /EmbeddedFiles <</Names [';
9774 foreach ($this->efnames
AS $fn => $fref) {
9775 $out .= ' '.$this->_datastring($fn).' '.$fref;
9780 if (!empty($this->dests
)) {
9781 $out .= ' /Dests '.($this->n_dests
).' 0 R';
9783 $out .= $this->_putviewerpreferences();
9784 if (isset($this->LayoutMode
) AND (!TCPDF_STATIC
::empty_string($this->LayoutMode
))) {
9785 $out .= ' /PageLayout /'.$this->LayoutMode
;
9787 if (isset($this->PageMode
) AND (!TCPDF_STATIC
::empty_string($this->PageMode
))) {
9788 $out .= ' /PageMode /'.$this->PageMode
;
9790 if (count($this->outlines
) > 0) {
9791 $out .= ' /Outlines '.$this->OutlineRoot
.' 0 R';
9792 $out .= ' /PageMode /UseOutlines';
9794 //$out .= ' /Threads []';
9795 if ($this->ZoomMode
== 'fullpage') {
9796 $out .= ' /OpenAction ['.$this->page_obj_id
[1].' 0 R /Fit]';
9797 } elseif ($this->ZoomMode
== 'fullwidth') {
9798 $out .= ' /OpenAction ['.$this->page_obj_id
[1].' 0 R /FitH null]';
9799 } elseif ($this->ZoomMode
== 'real') {
9800 $out .= ' /OpenAction ['.$this->page_obj_id
[1].' 0 R /XYZ null null 1]';
9801 } elseif (!is_string($this->ZoomMode
)) {
9802 $out .= sprintf(' /OpenAction ['.$this->page_obj_id
[1].' 0 R /XYZ null null %F]', ($this->ZoomMode
/ 100));
9804 //$out .= ' /AA <<>>';
9805 //$out .= ' /URI <<>>';
9806 $out .= ' /Metadata '.$xmpobj.' 0 R';
9807 //$out .= ' /StructTreeRoot <<>>';
9808 //$out .= ' /MarkInfo <<>>';
9809 if (isset($this->l
['a_meta_language'])) {
9810 $out .= ' /Lang '.$this->_textstring($this->l
['a_meta_language'], $oid);
9812 //$out .= ' /SpiderInfo <<>>';
9813 // set OutputIntent to sRGB IEC61966-2.1 if required
9814 if ($this->pdfa_mode
OR $this->force_srgb
) {
9815 $out .= ' /OutputIntents [<<';
9816 $out .= ' /Type /OutputIntent';
9817 $out .= ' /S /GTS_PDFA1';
9818 $out .= ' /OutputCondition '.$this->_textstring('sRGB IEC61966-2.1', $oid);
9819 $out .= ' /OutputConditionIdentifier '.$this->_textstring('sRGB IEC61966-2.1', $oid);
9820 $out .= ' /RegistryName '.$this->_textstring('http://www.color.org', $oid);
9821 $out .= ' /Info '.$this->_textstring('sRGB IEC61966-2.1', $oid);
9822 $out .= ' /DestOutputProfile '.$iccobj.' 0 R';
9825 //$out .= ' /PieceInfo <<>>';
9826 if (!empty($this->pdflayers
)) {
9830 foreach ($this->pdflayers
as $layer) {
9831 $layer_obj_ref = ' '.$layer['objid'].' 0 R';
9832 $lyrobjs .= $layer_obj_ref;
9833 if ($layer['view'] === false) {
9834 $lyrobjs_off .= $layer_obj_ref;
9836 if ($layer['lock']) {
9837 $lyrobjs_lock .= $layer_obj_ref;
9840 $out .= ' /OCProperties << /OCGs ['.$lyrobjs.']';
9842 $out .= ' /Name '.$this->_textstring('Layers', $oid);
9843 $out .= ' /Creator '.$this->_textstring('TCPDF', $oid);
9844 $out .= ' /BaseState /ON';
9845 $out .= ' /OFF ['.$lyrobjs_off.']';
9846 $out .= ' /Locked ['.$lyrobjs_lock.']';
9847 $out .= ' /Intent /View';
9849 $out .= ' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>';
9850 $out .= ' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>';
9852 $out .= ' /Order ['.$lyrobjs.']';
9853 $out .= ' /ListMode /AllPages';
9854 //$out .= ' /RBGroups ['..']';
9855 //$out .= ' /Locked ['..']';
9860 if (!empty($this->form_obj_id
)
9861 OR ($this->sign
AND isset($this->signature_data
['cert_type']))
9862 OR !empty($this->empty_signature_appearance
)) {
9863 $out .= ' /AcroForm <<';
9865 if ($this->sign
AND isset($this->signature_data
['cert_type'])) {
9866 // set reference for signature object
9867 $objrefs .= $this->sig_obj_id
.' 0 R';
9869 if (!empty($this->empty_signature_appearance
)) {
9870 foreach ($this->empty_signature_appearance
as $esa) {
9871 // set reference for empty signature objects
9872 $objrefs .= ' '.$esa['objid'].' 0 R';
9875 if (!empty($this->form_obj_id
)) {
9876 foreach($this->form_obj_id
as $objid) {
9877 $objrefs .= ' '.$objid.' 0 R';
9880 $out .= ' /Fields ['.$objrefs.']';
9881 // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
9882 if (empty($this->signature_data
['approval']) OR ($this->signature_data
['approval'] != 'A')) {
9883 $out .= ' /NeedAppearances false';
9885 if ($this->sign
AND isset($this->signature_data
['cert_type'])) {
9886 if ($this->signature_data
['cert_type'] > 0) {
9887 $out .= ' /SigFlags 3';
9889 $out .= ' /SigFlags 1';
9893 if (isset($this->annotation_fonts
) AND !empty($this->annotation_fonts
)) {
9895 $out .= ' /Font <<';
9896 foreach ($this->annotation_fonts
as $fontkey => $fontid) {
9897 $out .= ' /F'.$fontid.' '.$this->font_obj_ids
[$fontkey].' 0 R';
9901 $font = $this->getFontBuffer('helvetica');
9902 $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
9903 $out .= ' /Q '.(($this->rtl
)?
'2':'0');
9907 if ($this->sign
AND isset($this->signature_data
['cert_type'])
9908 AND (empty($this->signature_data
['approval']) OR ($this->signature_data
['approval'] != 'A'))) {
9909 if ($this->signature_data
['cert_type'] > 0) {
9910 $out .= ' /Perms << /DocMDP '.($this->sig_obj_id +
1).' 0 R >>';
9912 $out .= ' /Perms << /UR3 '.($this->sig_obj_id +
1).' 0 R >>';
9916 //$out .= ' /Legal <<>>';
9917 //$out .= ' /Requirements []';
9918 //$out .= ' /Collection <<>>';
9919 //$out .= ' /NeedsRendering true';
9921 $out .= "\n".'endobj';
9927 * Output viewer preferences.
9928 * @return string for viewer preferences
9929 * @author Nicola asuni
9930 * @since 3.1.000 (2008-06-09)
9933 protected function _putviewerpreferences() {
9934 $vp = $this->viewer_preferences
;
9935 $out = ' /ViewerPreferences <<';
9937 $out .= ' /Direction /R2L';
9939 $out .= ' /Direction /L2R';
9941 if (isset($vp['HideToolbar']) AND ($vp['HideToolbar'])) {
9942 $out .= ' /HideToolbar true';
9944 if (isset($vp['HideMenubar']) AND ($vp['HideMenubar'])) {
9945 $out .= ' /HideMenubar true';
9947 if (isset($vp['HideWindowUI']) AND ($vp['HideWindowUI'])) {
9948 $out .= ' /HideWindowUI true';
9950 if (isset($vp['FitWindow']) AND ($vp['FitWindow'])) {
9951 $out .= ' /FitWindow true';
9953 if (isset($vp['CenterWindow']) AND ($vp['CenterWindow'])) {
9954 $out .= ' /CenterWindow true';
9956 if (isset($vp['DisplayDocTitle']) AND ($vp['DisplayDocTitle'])) {
9957 $out .= ' /DisplayDocTitle true';
9959 if (isset($vp['NonFullScreenPageMode'])) {
9960 $out .= ' /NonFullScreenPageMode /'.$vp['NonFullScreenPageMode'];
9962 if (isset($vp['ViewArea'])) {
9963 $out .= ' /ViewArea /'.$vp['ViewArea'];
9965 if (isset($vp['ViewClip'])) {
9966 $out .= ' /ViewClip /'.$vp['ViewClip'];
9968 if (isset($vp['PrintArea'])) {
9969 $out .= ' /PrintArea /'.$vp['PrintArea'];
9971 if (isset($vp['PrintClip'])) {
9972 $out .= ' /PrintClip /'.$vp['PrintClip'];
9974 if (isset($vp['PrintScaling'])) {
9975 $out .= ' /PrintScaling /'.$vp['PrintScaling'];
9977 if (isset($vp['Duplex']) AND (!TCPDF_STATIC
::empty_string($vp['Duplex']))) {
9978 $out .= ' /Duplex /'.$vp['Duplex'];
9980 if (isset($vp['PickTrayByPDFSize'])) {
9981 if ($vp['PickTrayByPDFSize']) {
9982 $out .= ' /PickTrayByPDFSize true';
9984 $out .= ' /PickTrayByPDFSize false';
9987 if (isset($vp['PrintPageRange'])) {
9988 $PrintPageRangeNum = '';
9989 foreach ($vp['PrintPageRange'] as $k => $v) {
9990 $PrintPageRangeNum .= ' '.($v - 1).'';
9992 $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
9994 if (isset($vp['NumCopies'])) {
9995 $out .= ' /NumCopies '.intval($vp['NumCopies']);
10002 * Output PDF File Header (7.5.2).
10005 protected function _putheader() {
10006 $this->_out('%PDF-'.$this->PDFVersion
);
10007 $this->_out('%'.chr(0xe2).chr(0xe3).chr(0xcf).chr(0xd3));
10011 * Output end of document (EOF).
10014 protected function _enddoc() {
10015 if (isset($this->CurrentFont
['fontkey']) AND isset($this->CurrentFont
['subsetchars'])) {
10016 // save subset chars of the previous font
10017 $this->setFontSubBuffer($this->CurrentFont
['fontkey'], 'subsetchars', $this->CurrentFont
['subsetchars']);
10020 $this->_putheader();
10021 $this->_putpages();
10022 $this->_putresources();
10023 // empty signature fields
10024 if (!empty($this->empty_signature_appearance
)) {
10025 foreach ($this->empty_signature_appearance
as $key => $esa) {
10026 // widget annotation for empty signature
10027 $out = $this->_getobj($esa['objid'])."\n";
10028 $out .= '<< /Type /Annot';
10029 $out .= ' /Subtype /Widget';
10030 $out .= ' /Rect ['.$esa['rect'].']';
10031 $out .= ' /P '.$this->page_obj_id
[($esa['page'])].' 0 R'; // link to signature appearance page
10033 $out .= ' /FT /Sig';
10034 $signame = $esa['name'].sprintf(' [%03d]', ($key +
1));
10035 $out .= ' /T '.$this->_textstring($signame, $esa['objid']);
10038 $out .= "\n".'endobj';
10043 if ($this->sign
AND isset($this->signature_data
['cert_type'])) {
10044 // widget annotation for signature
10045 $out = $this->_getobj($this->sig_obj_id
)."\n";
10046 $out .= '<< /Type /Annot';
10047 $out .= ' /Subtype /Widget';
10048 $out .= ' /Rect ['.$this->signature_appearance
['rect'].']';
10049 $out .= ' /P '.$this->page_obj_id
[($this->signature_appearance
['page'])].' 0 R'; // link to signature appearance page
10051 $out .= ' /FT /Sig';
10052 $out .= ' /T '.$this->_textstring($this->signature_appearance
['name'], $this->sig_obj_id
);
10054 $out .= ' /V '.($this->sig_obj_id +
1).' 0 R';
10056 $out .= "\n".'endobj';
10059 $this->_putsignature();
10062 $objid_info = $this->_putinfo();
10064 $objid_catalog = $this->_putcatalog();
10066 $o = $this->bufferlen
;
10068 $this->_out('xref');
10069 $this->_out('0 '.($this->n +
1));
10070 $this->_out('0000000000 65535 f ');
10071 $freegen = ($this->n +
2);
10072 for ($i=1; $i <= $this->n
; ++
$i) {
10073 if (!isset($this->offsets
[$i]) AND ($i > 1)) {
10074 $this->_out(sprintf('0000000000 %05d f ', $freegen));
10077 $this->_out(sprintf('%010d 00000 n ', $this->offsets
[$i]));
10081 $out = 'trailer'."\n";
10083 $out .= ' /Size '.($this->n +
1);
10084 $out .= ' /Root '.$objid_catalog.' 0 R';
10085 $out .= ' /Info '.$objid_info.' 0 R';
10086 if ($this->encrypted
) {
10087 $out .= ' /Encrypt '.$this->encryptdata
['objid'].' 0 R';
10089 $out .= ' /ID [ <'.$this->file_id
.'> <'.$this->file_id
.'> ]';
10092 $this->_out('startxref');
10094 $this->_out('%%EOF');
10095 $this->state
= 3; // end-of-doc
10099 * Initialize a new page.
10100 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
10101 * @param $format (mixed) The format used for pages. It can be either: one of the string values specified at getPageSizeFromFormat() or an array of parameters specified at setPageFormat().
10103 * @see getPageSizeFromFormat(), setPageFormat()
10105 protected function _beginpage($orientation='', $format='') {
10107 $this->pageobjects
[$this->page
] = array();
10108 $this->setPageBuffer($this->page
, '');
10109 // initialize array for graphics tranformation positions inside a page buffer
10110 $this->transfmrk
[$this->page
] = array();
10112 if (TCPDF_STATIC
::empty_string($orientation)) {
10113 if (isset($this->CurOrientation
)) {
10114 $orientation = $this->CurOrientation
;
10115 } elseif ($this->fwPt
> $this->fhPt
) {
10117 $orientation = 'L';
10120 $orientation = 'P';
10123 if (TCPDF_STATIC
::empty_string($format)) {
10124 $this->pagedim
[$this->page
] = $this->pagedim
[($this->page
- 1)];
10125 $this->setPageOrientation($orientation);
10127 $this->setPageFormat($format, $orientation);
10130 $this->x
= $this->w
- $this->rMargin
;
10132 $this->x
= $this->lMargin
;
10134 $this->y
= $this->tMargin
;
10135 if (isset($this->newpagegroup
[$this->page
])) {
10136 // start a new group
10137 $this->currpagegroup
= $this->newpagegroup
[$this->page
];
10138 $this->pagegroups
[$this->currpagegroup
] = 1;
10139 } elseif (isset($this->currpagegroup
) AND ($this->currpagegroup
> 0)) {
10140 ++
$this->pagegroups
[$this->currpagegroup
];
10145 * Mark end of page.
10148 protected function _endpage() {
10149 $this->setVisibility('all');
10154 * Begin a new object and return the object number.
10155 * @return int object number
10158 protected function _newobj() {
10159 $this->_out($this->_getobj());
10164 * Return the starting object string for the selected object ID.
10165 * @param $objid (int) Object ID (leave empty to get a new ID).
10166 * @return string the starting object string
10168 * @since 5.8.009 (2010-08-20)
10170 protected function _getobj($objid='') {
10171 if ($objid === '') {
10175 $this->offsets
[$objid] = $this->bufferlen
;
10176 $this->pageobjects
[$this->page
][] = $objid;
10177 return $objid.' 0 obj';
10182 * @param $x (int) X coordinate
10183 * @param $y (int) Y coordinate
10184 * @param $txt (string) text to underline
10187 protected function _dounderline($x, $y, $txt) {
10188 $w = $this->GetStringWidth($txt);
10189 return $this->_dounderlinew($x, $y, $w);
10193 * Underline for rectangular text area.
10194 * @param $x (int) X coordinate
10195 * @param $y (int) Y coordinate
10196 * @param $w (int) width to underline
10198 * @since 4.8.008 (2009-09-29)
10200 protected function _dounderlinew($x, $y, $w) {
10201 $linew = - $this->CurrentFont
['ut'] / 1000 * $this->FontSizePt
;
10202 return sprintf('%F %F %F %F re f', $x * $this->k
, ((($this->h
- $y) * $this->k
) +
$linew), $w * $this->k
, $linew);
10206 * Line through text.
10207 * @param $x (int) X coordinate
10208 * @param $y (int) Y coordinate
10209 * @param $txt (string) text to linethrough
10212 protected function _dolinethrough($x, $y, $txt) {
10213 $w = $this->GetStringWidth($txt);
10214 return $this->_dolinethroughw($x, $y, $w);
10218 * Line through for rectangular text area.
10219 * @param $x (int) X coordinate
10220 * @param $y (int) Y coordinate
10221 * @param $w (int) line length (width)
10223 * @since 4.9.008 (2009-09-29)
10225 protected function _dolinethroughw($x, $y, $w) {
10226 $linew = - $this->CurrentFont
['ut'] / 1000 * $this->FontSizePt
;
10227 return sprintf('%F %F %F %F re f', $x * $this->k
, ((($this->h
- $y) * $this->k
) +
$linew +
($this->FontSizePt
/ 3)), $w * $this->k
, $linew);
10232 * @param $x (int) X coordinate
10233 * @param $y (int) Y coordinate
10234 * @param $txt (string) text to overline
10236 * @since 4.9.015 (2010-04-19)
10238 protected function _dooverline($x, $y, $txt) {
10239 $w = $this->GetStringWidth($txt);
10240 return $this->_dooverlinew($x, $y, $w);
10244 * Overline for rectangular text area.
10245 * @param $x (int) X coordinate
10246 * @param $y (int) Y coordinate
10247 * @param $w (int) width to overline
10249 * @since 4.9.015 (2010-04-19)
10251 protected function _dooverlinew($x, $y, $w) {
10252 $linew = - $this->CurrentFont
['ut'] / 1000 * $this->FontSizePt
;
10253 return sprintf('%F %F %F %F re f', $x * $this->k
, (($this->h
- $y +
$this->FontAscent
) * $this->k
) - $linew, $w * $this->k
, $linew);
10258 * Format a data string for meta information
10259 * @param $s (string) data string to escape.
10260 * @param $n (int) object ID
10261 * @return string escaped string.
10264 protected function _datastring($s, $n=0) {
10268 $s = $this->_encrypt_data($n, $s);
10269 return '('. TCPDF_STATIC
::_escape($s).')';
10273 * Set the document creation timestamp
10274 * @param $time (mixed) Document creation timestamp in seconds or date-time string.
10276 * @since 5.9.152 (2012-03-23)
10278 public function setDocCreationTimestamp($time) {
10279 if (is_string($time)) {
10280 $time = TCPDF_STATIC
::getTimestamp($time);
10282 $this->doc_creation_timestamp
= intval($time);
10286 * Set the document modification timestamp
10287 * @param $time (mixed) Document modification timestamp in seconds or date-time string.
10289 * @since 5.9.152 (2012-03-23)
10291 public function setDocModificationTimestamp($time) {
10292 if (is_string($time)) {
10293 $time = TCPDF_STATIC
::getTimestamp($time);
10295 $this->doc_modification_timestamp
= intval($time);
10299 * Returns document creation timestamp in seconds.
10300 * @return (int) Creation timestamp in seconds.
10302 * @since 5.9.152 (2012-03-23)
10304 public function getDocCreationTimestamp() {
10305 return $this->doc_creation_timestamp
;
10309 * Returns document modification timestamp in seconds.
10310 * @return (int) Modfication timestamp in seconds.
10312 * @since 5.9.152 (2012-03-23)
10314 public function getDocModificationTimestamp() {
10315 return $this->doc_modification_timestamp
;
10319 * Returns a formatted date for meta information
10320 * @param $n (int) Object ID.
10321 * @param $timestamp (int) Timestamp to convert.
10322 * @return string escaped date string.
10324 * @since 4.6.028 (2009-08-25)
10326 protected function _datestring($n=0, $timestamp=0) {
10327 if ((empty($timestamp)) OR ($timestamp < 0)) {
10328 $timestamp = $this->doc_creation_timestamp
;
10330 return $this->_datastring('D:'.TCPDF_STATIC
::getFormattedDate($timestamp), $n);
10334 * Format a text string for meta information
10335 * @param $s (string) string to escape.
10336 * @param $n (int) object ID
10337 * @return string escaped string.
10340 protected function _textstring($s, $n=0) {
10341 if ($this->isunicode
) {
10342 //Convert string to UTF-16BE
10343 $s = TCPDF_FONTS
::UTF8ToUTF16BE($s, true, $this->isunicode
, $this->CurrentFont
);
10345 return $this->_datastring($s, $n);
10349 * get raw output stream.
10350 * @param $s (string) string to output.
10351 * @param $n (int) object reference for encryption mode
10353 * @author Nicola Asuni
10354 * @since 5.5.000 (2010-06-22)
10356 protected function _getrawstream($s, $n=0) {
10358 // default to current object
10361 return $this->_encrypt_data($n, $s);
10365 * Output a string to the document.
10366 * @param $s (string) string to output.
10369 protected function _out($s) {
10370 if ($this->state
== 2) {
10371 if ($this->inxobj
) {
10372 // we are inside an XObject template
10373 $this->xobjects
[$this->xobjid
]['outdata'] .= $s."\n";
10374 } elseif ((!$this->InFooter
) AND isset($this->footerlen
[$this->page
]) AND ($this->footerlen
[$this->page
] > 0)) {
10375 // puts data before page footer
10376 $pagebuff = $this->getPageBuffer($this->page
);
10377 $page = substr($pagebuff, 0, -$this->footerlen
[$this->page
]);
10378 $footer = substr($pagebuff, -$this->footerlen
[$this->page
]);
10379 $this->setPageBuffer($this->page
, $page.$s."\n".$footer);
10380 // update footer position
10381 $this->footerpos
[$this->page
] +
= strlen($s."\n");
10384 $this->setPageBuffer($this->page
, $s."\n", true);
10386 } elseif ($this->state
> 0) {
10387 // set general data
10388 $this->setBuffer($s."\n");
10394 * @param $font (array) Array describing the basic font parameters: (family, style, size).
10398 public function setHeaderFont($font) {
10399 $this->header_font
= $font;
10404 * @return array() Array describing the basic font parameters: (family, style, size).
10406 * @since 4.0.012 (2008-07-24)
10408 public function getHeaderFont() {
10409 return $this->header_font
;
10414 * @param $font (array) Array describing the basic font parameters: (family, style, size).
10418 public function setFooterFont($font) {
10419 $this->footer_font
= $font;
10424 * @return array() Array describing the basic font parameters: (family, style, size).
10426 * @since 4.0.012 (2008-07-24)
10428 public function getFooterFont() {
10429 return $this->footer_font
;
10433 * Set language array.
10434 * @param $language (array)
10438 public function setLanguageArray($language) {
10439 $this->l
= $language;
10440 if (isset($this->l
['a_meta_dir'])) {
10441 $this->rtl
= $this->l
['a_meta_dir']=='rtl' ?
true : false;
10443 $this->rtl
= false;
10448 * Returns the PDF data.
10451 public function getPDFData() {
10452 if ($this->state
< 3) {
10455 return $this->buffer
;
10459 * Output anchor link.
10460 * @param $url (string) link URL or internal link (i.e.: <a href="#23,4.5">link to page 23 at 4.5 Y position</a>)
10461 * @param $name (string) link name
10462 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
10463 * @param $firstline (boolean) if true prints only the first line and return the remaining string.
10464 * @param $color (array) array of RGB text color
10465 * @param $style (string) font style (U, D, B, I)
10466 * @param $firstblock (boolean) if true the string is the starting of a line.
10467 * @return the number of cells used or the remaining text if $firstline = true;
10470 public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
10471 if (isset($url[1]) AND ($url[0] == '#') AND is_numeric($url[1])) {
10472 // convert url to internal link
10473 $lnkdata = explode(',', $url);
10474 if (isset($lnkdata[0]) ) {
10475 $page = substr($lnkdata[0], 1);
10476 if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
10477 $lnky = floatval($lnkdata[1]);
10481 $url = $this->AddLink();
10482 $this->SetLink($url, $lnky, $page);
10485 // store current settings
10486 $prevcolor = $this->fgcolor
;
10487 $prevstyle = $this->FontStyle
;
10488 if (empty($color)) {
10489 $this->SetTextColorArray($this->htmlLinkColorArray
);
10491 $this->SetTextColorArray($color);
10493 if ($style == -1) {
10494 $this->SetFont('', $this->FontStyle
.$this->htmlLinkFontStyle
);
10496 $this->SetFont('', $this->FontStyle
.$style);
10498 $ret = $this->Write($this->lasth
, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
10499 // restore settings
10500 $this->SetFont('', $prevstyle);
10501 $this->SetTextColorArray($prevcolor);
10506 * Converts pixels to User's Units.
10507 * @param $px (int) pixels
10508 * @return float value in user's unit
10510 * @see setImageScale(), getImageScale()
10512 public function pixelsToUnits($px) {
10513 return ($px / ($this->imgscale
* $this->k
));
10517 * Reverse function for htmlentities.
10518 * Convert entities in UTF-8.
10519 * @param $text_to_convert (string) Text to convert.
10520 * @return string converted text string
10523 public function unhtmlentities($text_to_convert) {
10524 return @html_entity_decode
($text_to_convert, ENT_QUOTES
, $this->encoding
);
10527 // ENCRYPTION METHODS ----------------------------------
10530 * Compute encryption key depending on object number where the encrypted data is stored.
10531 * This is used for all strings and streams without crypt filter specifier.
10532 * @param $n (int) object number
10533 * @return int object key
10535 * @author Nicola Asuni
10536 * @since 2.0.000 (2008-01-02)
10538 protected function _objectkey($n) {
10539 $objkey = $this->encryptdata
['key'].pack('VXxx', $n);
10540 if ($this->encryptdata
['mode'] == 2) { // AES-128
10542 $objkey .= "\x73\x41\x6C\x54"; // sAlT
10544 $objkey = substr(TCPDF_STATIC
::_md5_16($objkey), 0, (($this->encryptdata
['Length'] / 8) +
5));
10545 $objkey = substr($objkey, 0, 16);
10550 * Encrypt the input string.
10551 * @param $n (int) object number
10552 * @param $s (string) data string to encrypt
10553 * @return encrypted string
10555 * @author Nicola Asuni
10556 * @since 5.0.005 (2010-05-11)
10558 protected function _encrypt_data($n, $s) {
10559 if (!$this->encrypted
) {
10562 switch ($this->encryptdata
['mode']) {
10564 case 1: { // RC4-128
10565 $s = TCPDF_STATIC
::_RC4($this->_objectkey($n), $s, $this->last_enc_key
, $this->last_enc_key_c
);
10568 case 2: { // AES-128
10569 $s = TCPDF_STATIC
::_AES($this->_objectkey($n), $s);
10572 case 3: { // AES-256
10573 $s = TCPDF_STATIC
::_AES($this->encryptdata
['key'], $s);
10581 * Put encryption on PDF document.
10583 * @author Nicola Asuni
10584 * @since 2.0.000 (2008-01-02)
10586 protected function _putencryption() {
10587 if (!$this->encrypted
) {
10590 $this->encryptdata
['objid'] = $this->_newobj();
10592 if (!isset($this->encryptdata
['Filter']) OR empty($this->encryptdata
['Filter'])) {
10593 $this->encryptdata
['Filter'] = 'Standard';
10595 $out .= ' /Filter /'.$this->encryptdata
['Filter'];
10596 if (isset($this->encryptdata
['SubFilter']) AND !empty($this->encryptdata
['SubFilter'])) {
10597 $out .= ' /SubFilter /'.$this->encryptdata
['SubFilter'];
10599 if (!isset($this->encryptdata
['V']) OR empty($this->encryptdata
['V'])) {
10600 $this->encryptdata
['V'] = 1;
10602 // V is a code specifying the algorithm to be used in encrypting and decrypting the document
10603 $out .= ' /V '.$this->encryptdata
['V'];
10604 if (isset($this->encryptdata
['Length']) AND !empty($this->encryptdata
['Length'])) {
10605 // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
10606 $out .= ' /Length '.$this->encryptdata
['Length'];
10608 $out .= ' /Length 40';
10610 if ($this->encryptdata
['V'] >= 4) {
10611 if (!isset($this->encryptdata
['StmF']) OR empty($this->encryptdata
['StmF'])) {
10612 $this->encryptdata
['StmF'] = 'Identity';
10614 if (!isset($this->encryptdata
['StrF']) OR empty($this->encryptdata
['StrF'])) {
10615 // The name of the crypt filter that shall be used when decrypting all strings in the document.
10616 $this->encryptdata
['StrF'] = 'Identity';
10618 // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
10619 if (isset($this->encryptdata
['CF']) AND !empty($this->encryptdata
['CF'])) {
10621 $out .= ' /'.$this->encryptdata
['StmF'].' <<';
10622 $out .= ' /Type /CryptFilter';
10623 if (isset($this->encryptdata
['CF']['CFM']) AND !empty($this->encryptdata
['CF']['CFM'])) {
10625 $out .= ' /CFM /'.$this->encryptdata
['CF']['CFM'];
10626 if ($this->encryptdata
['pubkey']) {
10627 $out .= ' /Recipients [';
10628 foreach ($this->encryptdata
['Recipients'] as $rec) {
10629 $out .= ' <'.$rec.'>';
10632 if (isset($this->encryptdata
['CF']['EncryptMetadata']) AND (!$this->encryptdata
['CF']['EncryptMetadata'])) {
10633 $out .= ' /EncryptMetadata false';
10635 $out .= ' /EncryptMetadata true';
10639 $out .= ' /CFM /None';
10641 if (isset($this->encryptdata
['CF']['AuthEvent']) AND !empty($this->encryptdata
['CF']['AuthEvent'])) {
10642 // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
10643 $out .= ' /AuthEvent /'.$this->encryptdata
['CF']['AuthEvent'];
10645 $out .= ' /AuthEvent /DocOpen';
10647 if (isset($this->encryptdata
['CF']['Length']) AND !empty($this->encryptdata
['CF']['Length'])) {
10648 // The bit length of the encryption key.
10649 $out .= ' /Length '.$this->encryptdata
['CF']['Length'];
10653 // The name of the crypt filter that shall be used by default when decrypting streams.
10654 $out .= ' /StmF /'.$this->encryptdata
['StmF'];
10655 // The name of the crypt filter that shall be used when decrypting all strings in the document.
10656 $out .= ' /StrF /'.$this->encryptdata
['StrF'];
10657 if (isset($this->encryptdata
['EFF']) AND !empty($this->encryptdata
['EFF'])) {
10658 // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
10659 $out .= ' /EFF /'.$this->encryptdata
[''];
10662 // Additional encryption dictionary entries for the standard security handler
10663 if ($this->encryptdata
['pubkey']) {
10664 if (($this->encryptdata
['V'] < 4) AND isset($this->encryptdata
['Recipients']) AND !empty($this->encryptdata
['Recipients'])) {
10665 $out .= ' /Recipients [';
10666 foreach ($this->encryptdata
['Recipients'] as $rec) {
10667 $out .= ' <'.$rec.'>';
10673 if ($this->encryptdata
['V'] == 5) { // AES-256
10675 $out .= ' /OE ('.TCPDF_STATIC
::_escape($this->encryptdata
['OE']).')';
10676 $out .= ' /UE ('.TCPDF_STATIC
::_escape($this->encryptdata
['UE']).')';
10677 $out .= ' /Perms ('.TCPDF_STATIC
::_escape($this->encryptdata
['perms']).')';
10678 } elseif ($this->encryptdata
['V'] == 4) { // AES-128
10680 } elseif ($this->encryptdata
['V'] < 2) { // RC-40
10685 $out .= ' /O ('.TCPDF_STATIC
::_escape($this->encryptdata
['O']).')';
10686 $out .= ' /U ('.TCPDF_STATIC
::_escape($this->encryptdata
['U']).')';
10687 $out .= ' /P '.$this->encryptdata
['P'];
10688 if (isset($this->encryptdata
['EncryptMetadata']) AND (!$this->encryptdata
['EncryptMetadata'])) {
10689 $out .= ' /EncryptMetadata false';
10691 $out .= ' /EncryptMetadata true';
10695 $out .= "\n".'endobj';
10700 * Compute U value (used for encryption)
10701 * @return string U value
10703 * @since 2.0.000 (2008-01-02)
10704 * @author Nicola Asuni
10706 protected function _Uvalue() {
10707 if ($this->encryptdata
['mode'] == 0) { // RC4-40
10708 return TCPDF_STATIC
::_RC4($this->encryptdata
['key'], TCPDF_STATIC
::$enc_padding, $this->last_enc_key
, $this->last_enc_key_c
);
10709 } elseif ($this->encryptdata
['mode'] < 3) { // RC4-128, AES-128
10710 $tmp = TCPDF_STATIC
::_md5_16(TCPDF_STATIC
::$enc_padding.$this->encryptdata
['fileid']);
10711 $enc = TCPDF_STATIC
::_RC4($this->encryptdata
['key'], $tmp, $this->last_enc_key
, $this->last_enc_key_c
);
10712 $len = strlen($tmp);
10713 for ($i = 1; $i <= 19; ++
$i) {
10715 for ($j = 0; $j < $len; ++
$j) {
10716 $ek .= chr(ord($this->encryptdata
['key'][$j]) ^
$i);
10718 $enc = TCPDF_STATIC
::_RC4($ek, $enc, $this->last_enc_key
, $this->last_enc_key_c
);
10720 $enc .= str_repeat("\x00", 16);
10721 return substr($enc, 0, 32);
10722 } elseif ($this->encryptdata
['mode'] == 3) { // AES-256
10723 $seed = TCPDF_STATIC
::_md5_16(TCPDF_STATIC
::getRandomSeed());
10724 // User Validation Salt
10725 $this->encryptdata
['UVS'] = substr($seed, 0, 8);
10727 $this->encryptdata
['UKS'] = substr($seed, 8, 16);
10728 return hash('sha256', $this->encryptdata
['user_password'].$this->encryptdata
['UVS'], true).$this->encryptdata
['UVS'].$this->encryptdata
['UKS'];
10733 * Compute UE value (used for encryption)
10734 * @return string UE value
10736 * @since 5.9.006 (2010-10-19)
10737 * @author Nicola Asuni
10739 protected function _UEvalue() {
10740 $hashkey = hash('sha256', $this->encryptdata
['user_password'].$this->encryptdata
['UKS'], true);
10741 return TCPDF_STATIC
::_AESnopad($hashkey, $this->encryptdata
['key']);
10745 * Compute O value (used for encryption)
10746 * @return string O value
10748 * @since 2.0.000 (2008-01-02)
10749 * @author Nicola Asuni
10751 protected function _Ovalue() {
10752 if ($this->encryptdata
['mode'] < 3) { // RC4-40, RC4-128, AES-128
10753 $tmp = TCPDF_STATIC
::_md5_16($this->encryptdata
['owner_password']);
10754 if ($this->encryptdata
['mode'] > 0) {
10755 for ($i = 0; $i < 50; ++
$i) {
10756 $tmp = TCPDF_STATIC
::_md5_16($tmp);
10759 $owner_key = substr($tmp, 0, ($this->encryptdata
['Length'] / 8));
10760 $enc = TCPDF_STATIC
::_RC4($owner_key, $this->encryptdata
['user_password'], $this->last_enc_key
, $this->last_enc_key_c
);
10761 if ($this->encryptdata
['mode'] > 0) {
10762 $len = strlen($owner_key);
10763 for ($i = 1; $i <= 19; ++
$i) {
10765 for ($j = 0; $j < $len; ++
$j) {
10766 $ek .= chr(ord($owner_key[$j]) ^
$i);
10768 $enc = TCPDF_STATIC
::_RC4($ek, $enc, $this->last_enc_key
, $this->last_enc_key_c
);
10772 } elseif ($this->encryptdata
['mode'] == 3) { // AES-256
10773 $seed = TCPDF_STATIC
::_md5_16(TCPDF_STATIC
::getRandomSeed());
10774 // Owner Validation Salt
10775 $this->encryptdata
['OVS'] = substr($seed, 0, 8);
10777 $this->encryptdata
['OKS'] = substr($seed, 8, 16);
10778 return hash('sha256', $this->encryptdata
['owner_password'].$this->encryptdata
['OVS'].$this->encryptdata
['U'], true).$this->encryptdata
['OVS'].$this->encryptdata
['OKS'];
10783 * Compute OE value (used for encryption)
10784 * @return string OE value
10786 * @since 5.9.006 (2010-10-19)
10787 * @author Nicola Asuni
10789 protected function _OEvalue() {
10790 $hashkey = hash('sha256', $this->encryptdata
['owner_password'].$this->encryptdata
['OKS'].$this->encryptdata
['U'], true);
10791 return TCPDF_STATIC
::_AESnopad($hashkey, $this->encryptdata
['key']);
10795 * Convert password for AES-256 encryption mode
10796 * @param $password (string) password
10797 * @return string password
10799 * @since 5.9.006 (2010-10-19)
10800 * @author Nicola Asuni
10802 protected function _fixAES256Password($password) {
10803 $psw = ''; // password to be returned
10804 $psw_array = TCPDF_FONTS
::utf8Bidi(TCPDF_FONTS
::UTF8StringToArray($password, $this->isunicode
, $this->CurrentFont
), $password, $this->rtl
, $this->isunicode
, $this->CurrentFont
);
10805 foreach ($psw_array as $c) {
10806 $psw .= TCPDF_FONTS
::unichr($c, $this->isunicode
);
10808 return substr($psw, 0, 127);
10812 * Compute encryption key
10814 * @since 2.0.000 (2008-01-02)
10815 * @author Nicola Asuni
10817 protected function _generateencryptionkey() {
10818 $keybytelen = ($this->encryptdata
['Length'] / 8);
10819 if (!$this->encryptdata
['pubkey']) { // standard mode
10820 if ($this->encryptdata
['mode'] == 3) { // AES-256
10821 // generate 256 bit random key
10822 $this->encryptdata
['key'] = substr(hash('sha256', TCPDF_STATIC
::getRandomSeed(), true), 0, $keybytelen);
10823 // truncate passwords
10824 $this->encryptdata
['user_password'] = $this->_fixAES256Password($this->encryptdata
['user_password']);
10825 $this->encryptdata
['owner_password'] = $this->_fixAES256Password($this->encryptdata
['owner_password']);
10827 $this->encryptdata
['U'] = $this->_Uvalue();
10828 // Compute UE value
10829 $this->encryptdata
['UE'] = $this->_UEvalue();
10831 $this->encryptdata
['O'] = $this->_Ovalue();
10832 // Compute OE value
10833 $this->encryptdata
['OE'] = $this->_OEvalue();
10835 $this->encryptdata
['P'] = $this->encryptdata
['protection'];
10836 // Computing the encryption dictionary's Perms (permissions) value
10837 $perms = TCPDF_STATIC
::getEncPermissionsString($this->encryptdata
['protection']); // bytes 0-3
10838 $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
10839 if (isset($this->encryptdata
['CF']['EncryptMetadata']) AND (!$this->encryptdata
['CF']['EncryptMetadata'])) { // byte 8
10844 $perms .= 'adb'; // bytes 9-11
10845 $perms .= 'nick'; // bytes 12-15
10846 $this->encryptdata
['perms'] = TCPDF_STATIC
::_AESnopad($this->encryptdata
['key'], $perms);
10847 } else { // RC4-40, RC4-128, AES-128
10849 $this->encryptdata
['user_password'] = substr($this->encryptdata
['user_password'].TCPDF_STATIC
::$enc_padding, 0, 32);
10850 $this->encryptdata
['owner_password'] = substr($this->encryptdata
['owner_password'].TCPDF_STATIC
::$enc_padding, 0, 32);
10852 $this->encryptdata
['O'] = $this->_Ovalue();
10853 // get default permissions (reverse byte order)
10854 $permissions = TCPDF_STATIC
::getEncPermissionsString($this->encryptdata
['protection']);
10855 // Compute encryption key
10856 $tmp = TCPDF_STATIC
::_md5_16($this->encryptdata
['user_password'].$this->encryptdata
['O'].$permissions.$this->encryptdata
['fileid']);
10857 if ($this->encryptdata
['mode'] > 0) {
10858 for ($i = 0; $i < 50; ++
$i) {
10859 $tmp = TCPDF_STATIC
::_md5_16(substr($tmp, 0, $keybytelen));
10862 $this->encryptdata
['key'] = substr($tmp, 0, $keybytelen);
10864 $this->encryptdata
['U'] = $this->_Uvalue();
10866 $this->encryptdata
['P'] = $this->encryptdata
['protection'];
10868 } else { // Public-Key mode
10869 // random 20-byte seed
10870 $seed = sha1(TCPDF_STATIC
::getRandomSeed(), true);
10871 $recipient_bytes = '';
10872 foreach ($this->encryptdata
['pubkeys'] as $pubkey) {
10873 // for each public certificate
10874 if (isset($pubkey['p'])) {
10875 $pkprotection = TCPDF_STATIC
::getUserPermissionCode($pubkey['p'], $this->encryptdata
['mode']);
10877 $pkprotection = $this->encryptdata
['protection'];
10879 // get default permissions (reverse byte order)
10880 $pkpermissions = TCPDF_STATIC
::getEncPermissionsString($pkprotection);
10882 $envelope = $seed.$pkpermissions;
10883 // write the envelope data to a temporary file
10884 $tempkeyfile = TCPDF_STATIC
::getObjFilename('key', $this->file_id
);
10885 $f = TCPDF_STATIC
::fopenLocal($tempkeyfile, 'wb');
10887 $this->Error('Unable to create temporary key file: '.$tempkeyfile);
10889 $envelope_length = strlen($envelope);
10890 fwrite($f, $envelope, $envelope_length);
10892 $tempencfile = TCPDF_STATIC
::getObjFilename('enc', $this->file_id
);
10893 if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_BINARY | PKCS7_DETACHED
)) {
10894 $this->Error('Unable to encrypt the file: '.$tempkeyfile);
10896 // read encryption signature
10897 $signature = file_get_contents($tempencfile, false, null, $envelope_length);
10898 // extract signature
10899 $signature = substr($signature, strpos($signature, 'Content-Disposition'));
10900 $tmparr = explode("\n\n", $signature);
10901 $signature = trim($tmparr[1]);
10903 // decode signature
10904 $signature = base64_decode($signature);
10905 // convert signature to hex
10906 $hexsignature = current(unpack('H*', $signature));
10907 // store signature on recipients array
10908 $this->encryptdata
['Recipients'][] = $hexsignature;
10909 // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
10910 $recipient_bytes .= $signature;
10912 // calculate encryption key
10913 if ($this->encryptdata
['mode'] == 3) { // AES-256
10914 $this->encryptdata
['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
10915 } else { // RC4-40, RC4-128, AES-128
10916 $this->encryptdata
['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
10922 * Set document protection
10923 * Remark: the protection against modification is for people who have the full Acrobat product.
10924 * If you don't set any password, the document will open as usual. If you set a user password, the PDF viewer will ask for it before displaying the document. The master password, if different from the user one, can be used to get full access.
10925 * Note: protecting a document requires to encrypt it, which increases the processing time a lot. This can cause a PHP time-out in some cases, especially if the document contains images or fonts.
10926 * @param $permissions (Array) the set of permissions (specify the ones you want to block):<ul><li>print : Print the document;</li><li>modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';</li><li>copy : Copy or otherwise extract text and graphics from the document;</li><li>annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);</li><li>fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;</li><li>extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);</li><li>assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;</li><li>print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.</li><li>owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.</li></ul>
10927 * @param $user_pass (String) user password. Empty by default.
10928 * @param $owner_pass (String) owner password. If not specified, a random value is used.
10929 * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
10930 * @param $pubkeys (String) array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
10932 * @since 2.0.000 (2008-01-02)
10933 * @author Nicola Asuni
10935 public function SetProtection($permissions=array('print', 'modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-high'), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null) {
10936 if ($this->pdfa_mode
) {
10937 // encryption is not allowed in PDF/A mode
10940 $this->encryptdata
['protection'] = TCPDF_STATIC
::getUserPermissionCode($permissions, $mode);
10941 if (($pubkeys !== null) AND (is_array($pubkeys))) {
10943 $this->encryptdata
['pubkeys'] = $pubkeys;
10945 // public-Key Security requires at least 128 bit
10948 if (!function_exists('openssl_pkcs7_encrypt')) {
10949 $this->Error('Public-Key Security requires openssl library.');
10951 // Set Public-Key filter (available are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
10952 $this->encryptdata
['pubkey'] = true;
10953 $this->encryptdata
['Filter'] = 'Adobe.PubSec';
10954 $this->encryptdata
['StmF'] = 'DefaultCryptFilter';
10955 $this->encryptdata
['StrF'] = 'DefaultCryptFilter';
10957 // standard mode (password mode)
10958 $this->encryptdata
['pubkey'] = false;
10959 $this->encryptdata
['Filter'] = 'Standard';
10960 $this->encryptdata
['StmF'] = 'StdCF';
10961 $this->encryptdata
['StrF'] = 'StdCF';
10963 if ($mode > 1) { // AES
10964 if (!extension_loaded('openssl') && !extension_loaded('mcrypt')) {
10965 $this->Error('AES encryption requires openssl or mcrypt extension (http://www.php.net/manual/en/mcrypt.requirements.php).');
10967 if (extension_loaded('openssl') && !in_array('aes-256-cbc', openssl_get_cipher_methods())) {
10968 $this->Error('AES encryption requires openssl/aes-256-cbc cypher.');
10970 if (extension_loaded('mcrypt') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128
) === false) {
10971 $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
10973 if (($mode == 3) AND !function_exists('hash')) {
10974 // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
10975 $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
10978 if ($owner_pass === null) {
10979 $owner_pass = md5(TCPDF_STATIC
::getRandomSeed());
10981 $this->encryptdata
['user_password'] = $user_pass;
10982 $this->encryptdata
['owner_password'] = $owner_pass;
10983 $this->encryptdata
['mode'] = $mode;
10985 case 0: { // RC4 40 bit
10986 $this->encryptdata
['V'] = 1;
10987 $this->encryptdata
['Length'] = 40;
10988 $this->encryptdata
['CF']['CFM'] = 'V2';
10991 case 1: { // RC4 128 bit
10992 $this->encryptdata
['V'] = 2;
10993 $this->encryptdata
['Length'] = 128;
10994 $this->encryptdata
['CF']['CFM'] = 'V2';
10995 if ($this->encryptdata
['pubkey']) {
10996 $this->encryptdata
['SubFilter'] = 'adbe.pkcs7.s4';
10997 $this->encryptdata
['Recipients'] = array();
11001 case 2: { // AES 128 bit
11002 $this->encryptdata
['V'] = 4;
11003 $this->encryptdata
['Length'] = 128;
11004 $this->encryptdata
['CF']['CFM'] = 'AESV2';
11005 $this->encryptdata
['CF']['Length'] = 128;
11006 if ($this->encryptdata
['pubkey']) {
11007 $this->encryptdata
['SubFilter'] = 'adbe.pkcs7.s5';
11008 $this->encryptdata
['Recipients'] = array();
11012 case 3: { // AES 256 bit
11013 $this->encryptdata
['V'] = 5;
11014 $this->encryptdata
['Length'] = 256;
11015 $this->encryptdata
['CF']['CFM'] = 'AESV3';
11016 $this->encryptdata
['CF']['Length'] = 256;
11017 if ($this->encryptdata
['pubkey']) {
11018 $this->encryptdata
['SubFilter'] = 'adbe.pkcs7.s5';
11019 $this->encryptdata
['Recipients'] = array();
11024 $this->encrypted
= true;
11025 $this->encryptdata
['fileid'] = TCPDF_STATIC
::convertHexStringToString($this->file_id
);
11026 $this->_generateencryptionkey();
11029 // END OF ENCRYPTION FUNCTIONS -------------------------
11031 // START TRANSFORMATIONS SECTION -----------------------
11034 * Starts a 2D tranformation saving current graphic state.
11035 * This function must be called before scaling, mirroring, translation, rotation and skewing.
11036 * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
11038 * @since 2.1.000 (2008-01-07)
11039 * @see StartTransform(), StopTransform()
11041 public function StartTransform() {
11042 if ($this->state
!= 2) {
11045 $this->_outSaveGraphicsState();
11046 if ($this->inxobj
) {
11047 // we are inside an XObject template
11048 $this->xobjects
[$this->xobjid
]['transfmrk'][] = strlen($this->xobjects
[$this->xobjid
]['outdata']);
11050 $this->transfmrk
[$this->page
][] = $this->pagelen
[$this->page
];
11052 ++
$this->transfmatrix_key
;
11053 $this->transfmatrix
[$this->transfmatrix_key
] = array();
11057 * Stops a 2D tranformation restoring previous graphic state.
11058 * This function must be called after scaling, mirroring, translation, rotation and skewing.
11059 * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
11061 * @since 2.1.000 (2008-01-07)
11062 * @see StartTransform(), StopTransform()
11064 public function StopTransform() {
11065 if ($this->state
!= 2) {
11068 $this->_outRestoreGraphicsState();
11069 if (isset($this->transfmatrix
[$this->transfmatrix_key
])) {
11070 array_pop($this->transfmatrix
[$this->transfmatrix_key
]);
11071 --$this->transfmatrix_key
;
11073 if ($this->inxobj
) {
11074 // we are inside an XObject template
11075 array_pop($this->xobjects
[$this->xobjid
]['transfmrk']);
11077 array_pop($this->transfmrk
[$this->page
]);
11081 * Horizontal Scaling.
11082 * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
11083 * @param $x (int) abscissa of the scaling center. Default is current x position
11084 * @param $y (int) ordinate of the scaling center. Default is current y position
11086 * @since 2.1.000 (2008-01-07)
11087 * @see StartTransform(), StopTransform()
11089 public function ScaleX($s_x, $x='', $y='') {
11090 $this->Scale($s_x, 100, $x, $y);
11094 * Vertical Scaling.
11095 * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
11096 * @param $x (int) abscissa of the scaling center. Default is current x position
11097 * @param $y (int) ordinate of the scaling center. Default is current y position
11099 * @since 2.1.000 (2008-01-07)
11100 * @see StartTransform(), StopTransform()
11102 public function ScaleY($s_y, $x='', $y='') {
11103 $this->Scale(100, $s_y, $x, $y);
11107 * Vertical and horizontal proportional Scaling.
11108 * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
11109 * @param $x (int) abscissa of the scaling center. Default is current x position
11110 * @param $y (int) ordinate of the scaling center. Default is current y position
11112 * @since 2.1.000 (2008-01-07)
11113 * @see StartTransform(), StopTransform()
11115 public function ScaleXY($s, $x='', $y='') {
11116 $this->Scale($s, $s, $x, $y);
11120 * Vertical and horizontal non-proportional Scaling.
11121 * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
11122 * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
11123 * @param $x (int) abscissa of the scaling center. Default is current x position
11124 * @param $y (int) ordinate of the scaling center. Default is current y position
11126 * @since 2.1.000 (2008-01-07)
11127 * @see StartTransform(), StopTransform()
11129 public function Scale($s_x, $s_y, $x='', $y='') {
11136 if (($s_x == 0) OR ($s_y == 0)) {
11137 $this->Error('Please do not use values equal to zero for scaling');
11139 $y = ($this->h
- $y) * $this->k
;
11141 //calculate elements of transformation matrix
11149 $tm[4] = $x * (1 - $s_x);
11150 $tm[5] = $y * (1 - $s_y);
11151 //scale the coordinate system
11152 $this->Transform($tm);
11156 * Horizontal Mirroring.
11157 * @param $x (int) abscissa of the point. Default is current x position
11159 * @since 2.1.000 (2008-01-07)
11160 * @see StartTransform(), StopTransform()
11162 public function MirrorH($x='') {
11163 $this->Scale(-100, 100, $x);
11167 * Verical Mirroring.
11168 * @param $y (int) ordinate of the point. Default is current y position
11170 * @since 2.1.000 (2008-01-07)
11171 * @see StartTransform(), StopTransform()
11173 public function MirrorV($y='') {
11174 $this->Scale(100, -100, '', $y);
11178 * Point reflection mirroring.
11179 * @param $x (int) abscissa of the point. Default is current x position
11180 * @param $y (int) ordinate of the point. Default is current y position
11182 * @since 2.1.000 (2008-01-07)
11183 * @see StartTransform(), StopTransform()
11185 public function MirrorP($x='',$y='') {
11186 $this->Scale(-100, -100, $x, $y);
11190 * Reflection against a straight line through point (x, y) with the gradient angle (angle).
11191 * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
11192 * @param $x (int) abscissa of the point. Default is current x position
11193 * @param $y (int) ordinate of the point. Default is current y position
11195 * @since 2.1.000 (2008-01-07)
11196 * @see StartTransform(), StopTransform()
11198 public function MirrorL($angle=0, $x='',$y='') {
11199 $this->Scale(-100, 100, $x, $y);
11200 $this->Rotate(-2*($angle-90), $x, $y);
11204 * Translate graphic object horizontally.
11205 * @param $t_x (int) movement to the right (or left for RTL)
11207 * @since 2.1.000 (2008-01-07)
11208 * @see StartTransform(), StopTransform()
11210 public function TranslateX($t_x) {
11211 $this->Translate($t_x, 0);
11215 * Translate graphic object vertically.
11216 * @param $t_y (int) movement to the bottom
11218 * @since 2.1.000 (2008-01-07)
11219 * @see StartTransform(), StopTransform()
11221 public function TranslateY($t_y) {
11222 $this->Translate(0, $t_y);
11226 * Translate graphic object horizontally and vertically.
11227 * @param $t_x (int) movement to the right
11228 * @param $t_y (int) movement to the bottom
11230 * @since 2.1.000 (2008-01-07)
11231 * @see StartTransform(), StopTransform()
11233 public function Translate($t_x, $t_y) {
11234 //calculate elements of transformation matrix
11240 $tm[4] = $t_x * $this->k
;
11241 $tm[5] = -$t_y * $this->k
;
11242 //translate the coordinate system
11243 $this->Transform($tm);
11248 * @param $angle (float) angle in degrees for counter-clockwise rotation
11249 * @param $x (int) abscissa of the rotation center. Default is current x position
11250 * @param $y (int) ordinate of the rotation center. Default is current y position
11252 * @since 2.1.000 (2008-01-07)
11253 * @see StartTransform(), StopTransform()
11255 public function Rotate($angle, $x='', $y='') {
11262 $y = ($this->h
- $y) * $this->k
;
11264 //calculate elements of transformation matrix
11266 $tm[0] = cos(deg2rad($angle));
11267 $tm[1] = sin(deg2rad($angle));
11270 $tm[4] = $x +
($tm[1] * $y) - ($tm[0] * $x);
11271 $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
11272 //rotate the coordinate system around ($x,$y)
11273 $this->Transform($tm);
11277 * Skew horizontally.
11278 * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
11279 * @param $x (int) abscissa of the skewing center. default is current x position
11280 * @param $y (int) ordinate of the skewing center. default is current y position
11282 * @since 2.1.000 (2008-01-07)
11283 * @see StartTransform(), StopTransform()
11285 public function SkewX($angle_x, $x='', $y='') {
11286 $this->Skew($angle_x, 0, $x, $y);
11291 * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
11292 * @param $x (int) abscissa of the skewing center. default is current x position
11293 * @param $y (int) ordinate of the skewing center. default is current y position
11295 * @since 2.1.000 (2008-01-07)
11296 * @see StartTransform(), StopTransform()
11298 public function SkewY($angle_y, $x='', $y='') {
11299 $this->Skew(0, $angle_y, $x, $y);
11304 * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
11305 * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
11306 * @param $x (int) abscissa of the skewing center. default is current x position
11307 * @param $y (int) ordinate of the skewing center. default is current y position
11309 * @since 2.1.000 (2008-01-07)
11310 * @see StartTransform(), StopTransform()
11312 public function Skew($angle_x, $angle_y, $x='', $y='') {
11319 if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
11320 $this->Error('Please use values between -90 and +90 degrees for Skewing.');
11323 $y = ($this->h
- $y) * $this->k
;
11324 //calculate elements of transformation matrix
11327 $tm[1] = tan(deg2rad($angle_y));
11328 $tm[2] = tan(deg2rad($angle_x));
11330 $tm[4] = -$tm[2] * $y;
11331 $tm[5] = -$tm[1] * $x;
11332 //skew the coordinate system
11333 $this->Transform($tm);
11337 * Apply graphic transformations.
11338 * @param $tm (array) transformation matrix
11340 * @since 2.1.000 (2008-01-07)
11341 * @see StartTransform(), StopTransform()
11343 protected function Transform($tm) {
11344 if ($this->state
!= 2) {
11347 $this->_out(sprintf('%F %F %F %F %F %F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
11348 // add tranformation matrix
11349 $this->transfmatrix
[$this->transfmatrix_key
][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
11350 // update transformation mark
11351 if ($this->inxobj
) {
11352 // we are inside an XObject template
11353 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
11354 $key = key($this->xobjects
[$this->xobjid
]['transfmrk']);
11355 $this->xobjects
[$this->xobjid
]['transfmrk'][$key] = strlen($this->xobjects
[$this->xobjid
]['outdata']);
11357 } elseif (end($this->transfmrk
[$this->page
]) !== false) {
11358 $key = key($this->transfmrk
[$this->page
]);
11359 $this->transfmrk
[$this->page
][$key] = $this->pagelen
[$this->page
];
11363 // END TRANSFORMATIONS SECTION -------------------------
11365 // START GRAPHIC FUNCTIONS SECTION ---------------------
11366 // The following section is based on the code provided by David Hernandez Sanz
11369 * Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
11370 * @param $width (float) The width.
11373 * @see Line(), Rect(), Cell(), MultiCell()
11375 public function SetLineWidth($width) {
11377 $this->LineWidth
= $width;
11378 $this->linestyleWidth
= sprintf('%F w', ($width * $this->k
));
11379 if ($this->state
== 2) {
11380 $this->_out($this->linestyleWidth
);
11385 * Returns the current the line width.
11386 * @return int Line width
11388 * @since 2.1.000 (2008-01-07)
11389 * @see Line(), SetLineWidth()
11391 public function GetLineWidth() {
11392 return $this->LineWidth
;
11397 * @param $style (array) Line style. Array with keys among the following:
11399 * <li>width (float): Width of the line in user units.</li>
11400 * <li>cap (string): Type of cap to put on the line. Possible values are:
11401 * butt, round, square. The difference between "square" and "butt" is that
11402 * "square" projects a flat end past the end of the line.</li>
11403 * <li>join (string): Type of join. Possible values are: miter, round,
11405 * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
11406 * series of length values, which are the lengths of the on and off dashes.
11407 * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
11408 * 1 off, 2 on, 1 off, ...</li>
11409 * <li>phase (integer): Modifier on the dash pattern which is used to shift
11410 * the point at which the pattern starts.</li>
11411 * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName).</li>
11413 * @param $ret (boolean) if true do not send the command.
11414 * @return string the PDF command
11416 * @since 2.1.000 (2008-01-08)
11418 public function SetLineStyle($style, $ret=false) {
11419 $s = ''; // string to be returned
11420 if (!is_array($style)) {
11423 if (isset($style['width'])) {
11424 $this->LineWidth
= $style['width'];
11425 $this->linestyleWidth
= sprintf('%F w', ($style['width'] * $this->k
));
11426 $s .= $this->linestyleWidth
.' ';
11428 if (isset($style['cap'])) {
11429 $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
11430 if (isset($ca[$style['cap']])) {
11431 $this->linestyleCap
= $ca[$style['cap']].' J';
11432 $s .= $this->linestyleCap
.' ';
11435 if (isset($style['join'])) {
11436 $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
11437 if (isset($ja[$style['join']])) {
11438 $this->linestyleJoin
= $ja[$style['join']].' j';
11439 $s .= $this->linestyleJoin
.' ';
11442 if (isset($style['dash'])) {
11444 if ($style['dash']) {
11445 if (preg_match('/^.+,/', $style['dash']) > 0) {
11446 $tab = explode(',', $style['dash']);
11448 $tab = array($style['dash']);
11451 foreach ($tab as $i => $v) {
11453 $dash_string .= ' ';
11455 $dash_string .= sprintf('%F', $v);
11458 if (!isset($style['phase']) OR !$style['dash']) {
11459 $style['phase'] = 0;
11461 $this->linestyleDash
= sprintf('[%s] %F d', $dash_string, $style['phase']);
11462 $s .= $this->linestyleDash
.' ';
11464 if (isset($style['color'])) {
11465 $s .= $this->SetDrawColorArray($style['color'], true).' ';
11467 if (!$ret AND ($this->state
== 2)) {
11474 * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
11475 * @param $x (float) Abscissa of point.
11476 * @param $y (float) Ordinate of point.
11478 * @since 2.1.000 (2008-01-08)
11480 protected function _outPoint($x, $y) {
11481 if ($this->state
== 2) {
11482 $this->_out(sprintf('%F %F m', ($x * $this->k
), (($this->h
- $y) * $this->k
)));
11487 * Append a straight line segment from the current point to the point (x, y).
11488 * The new current point shall be (x, y).
11489 * @param $x (float) Abscissa of end point.
11490 * @param $y (float) Ordinate of end point.
11492 * @since 2.1.000 (2008-01-08)
11494 protected function _outLine($x, $y) {
11495 if ($this->state
== 2) {
11496 $this->_out(sprintf('%F %F l', ($x * $this->k
), (($this->h
- $y) * $this->k
)));
11501 * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
11502 * @param $x (float) Abscissa of upper-left corner.
11503 * @param $y (float) Ordinate of upper-left corner.
11504 * @param $w (float) Width.
11505 * @param $h (float) Height.
11506 * @param $op (string) options
11508 * @since 2.1.000 (2008-01-08)
11510 protected function _outRect($x, $y, $w, $h, $op) {
11511 if ($this->state
== 2) {
11512 $this->_out(sprintf('%F %F %F %F re %s', ($x * $this->k
), (($this->h
- $y) * $this->k
), ($w * $this->k
), (-$h * $this->k
), $op));
11517 * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x2, y2) as the Bezier control points.
11518 * The new current point shall be (x3, y3).
11519 * @param $x1 (float) Abscissa of control point 1.
11520 * @param $y1 (float) Ordinate of control point 1.
11521 * @param $x2 (float) Abscissa of control point 2.
11522 * @param $y2 (float) Ordinate of control point 2.
11523 * @param $x3 (float) Abscissa of end point.
11524 * @param $y3 (float) Ordinate of end point.
11526 * @since 2.1.000 (2008-01-08)
11528 protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
11529 if ($this->state
== 2) {
11530 $this->_out(sprintf('%F %F %F %F %F %F 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
)));
11535 * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using the current point and (x2, y2) as the Bezier control points.
11536 * The new current point shall be (x3, y3).
11537 * @param $x2 (float) Abscissa of control point 2.
11538 * @param $y2 (float) Ordinate of control point 2.
11539 * @param $x3 (float) Abscissa of end point.
11540 * @param $y3 (float) Ordinate of end point.
11542 * @since 4.9.019 (2010-04-26)
11544 protected function _outCurveV($x2, $y2, $x3, $y3) {
11545 if ($this->state
== 2) {
11546 $this->_out(sprintf('%F %F %F %F v', ($x2 * $this->k
), (($this->h
- $y2) * $this->k
), ($x3 * $this->k
), (($this->h
- $y3) * $this->k
)));
11551 * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), using (x1, y1) and (x3, y3) as the Bezier control points.
11552 * The new current point shall be (x3, y3).
11553 * @param $x1 (float) Abscissa of control point 1.
11554 * @param $y1 (float) Ordinate of control point 1.
11555 * @param $x3 (float) Abscissa of end point.
11556 * @param $y3 (float) Ordinate of end point.
11558 * @since 2.1.000 (2008-01-08)
11560 protected function _outCurveY($x1, $y1, $x3, $y3) {
11561 if ($this->state
== 2) {
11562 $this->_out(sprintf('%F %F %F %F y', ($x1 * $this->k
), (($this->h
- $y1) * $this->k
), ($x3 * $this->k
), (($this->h
- $y3) * $this->k
)));
11567 * Draws a line between two points.
11568 * @param $x1 (float) Abscissa of first point.
11569 * @param $y1 (float) Ordinate of first point.
11570 * @param $x2 (float) Abscissa of second point.
11571 * @param $y2 (float) Ordinate of second point.
11572 * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
11575 * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
11577 public function Line($x1, $y1, $x2, $y2, $style=array()) {
11578 if ($this->state
!= 2) {
11581 if (is_array($style)) {
11582 $this->SetLineStyle($style);
11584 $this->_outPoint($x1, $y1);
11585 $this->_outLine($x2, $y2);
11590 * Draws a rectangle.
11591 * @param $x (float) Abscissa of upper-left corner.
11592 * @param $y (float) Ordinate of upper-left corner.
11593 * @param $w (float) Width.
11594 * @param $h (float) Height.
11595 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
11596 * @param $border_style (array) Border style of rectangle. Array with keys among the following:
11598 * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
11599 * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
11601 * If a key is not present or is null, the correspondent border is not drawn. Default value: default line style (empty array).
11602 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
11605 * @see SetLineStyle()
11607 public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
11608 if ($this->state
!= 2) {
11611 if (empty($style)) {
11614 if (!(strpos($style, 'F') === false) AND !empty($fill_color)) {
11615 // set background color
11616 $this->SetFillColorArray($fill_color);
11618 if (!empty($border_style)) {
11619 if (isset($border_style['all']) AND !empty($border_style['all'])) {
11620 //set global style for border
11621 $this->SetLineStyle($border_style['all']);
11622 $border_style = array();
11624 // remove stroke operator from style
11625 $opnostroke = array('S' => '', 'D' => '', 's' => '', 'd' => '', 'B' => 'F', 'FD' => 'F', 'DF' => 'F', 'B*' => 'F*', 'F*D' => 'F*', 'DF*' => 'F*', 'b' => 'f', 'fd' => 'f', 'df' => 'f', 'b*' => 'f*', 'f*d' => 'f*', 'df*' => 'f*' );
11626 if (isset($opnostroke[$style])) {
11627 $style = $opnostroke[$style];
11631 if (!empty($style)) {
11632 $op = TCPDF_STATIC
::getPathPaintOperator($style);
11633 $this->_outRect($x, $y, $w, $h, $op);
11635 if (!empty($border_style)) {
11636 $border_style2 = array();
11637 foreach ($border_style as $line => $value) {
11638 $length = strlen($line);
11639 for ($i = 0; $i < $length; ++
$i) {
11640 $border_style2[$line[$i]] = $value;
11643 $border_style = $border_style2;
11644 if (isset($border_style['L']) AND $border_style['L']) {
11645 $this->Line($x, $y, $x, $y +
$h, $border_style['L']);
11647 if (isset($border_style['T']) AND $border_style['T']) {
11648 $this->Line($x, $y, $x +
$w, $y, $border_style['T']);
11650 if (isset($border_style['R']) AND $border_style['R']) {
11651 $this->Line($x +
$w, $y, $x +
$w, $y +
$h, $border_style['R']);
11653 if (isset($border_style['B']) AND $border_style['B']) {
11654 $this->Line($x, $y +
$h, $x +
$w, $y +
$h, $border_style['B']);
11660 * Draws a Bezier curve.
11661 * The Bezier curve is a tangent to the line between the control points at
11662 * either end of the curve.
11663 * @param $x0 (float) Abscissa of start point.
11664 * @param $y0 (float) Ordinate of start point.
11665 * @param $x1 (float) Abscissa of control point 1.
11666 * @param $y1 (float) Ordinate of control point 1.
11667 * @param $x2 (float) Abscissa of control point 2.
11668 * @param $y2 (float) Ordinate of control point 2.
11669 * @param $x3 (float) Abscissa of end point.
11670 * @param $y3 (float) Ordinate of end point.
11671 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
11672 * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
11673 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
11675 * @see SetLineStyle()
11676 * @since 2.1.000 (2008-01-08)
11678 public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
11679 if ($this->state
!= 2) {
11682 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11683 $this->SetFillColorArray($fill_color);
11685 $op = TCPDF_STATIC
::getPathPaintOperator($style);
11687 $this->SetLineStyle($line_style);
11689 $this->_outPoint($x0, $y0);
11690 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
11695 * Draws a poly-Bezier curve.
11696 * Each Bezier curve segment is a tangent to the line between the control points at
11697 * either end of the curve.
11698 * @param $x0 (float) Abscissa of start point.
11699 * @param $y0 (float) Ordinate of start point.
11700 * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
11701 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
11702 * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
11703 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
11705 * @see SetLineStyle()
11706 * @since 3.0008 (2008-05-12)
11708 public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
11709 if ($this->state
!= 2) {
11712 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11713 $this->SetFillColorArray($fill_color);
11715 $op = TCPDF_STATIC
::getPathPaintOperator($style);
11717 $line_style = array();
11720 $this->SetLineStyle($line_style);
11722 $this->_outPoint($x0, $y0);
11723 foreach ($segments as $segment) {
11724 list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
11725 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
11731 * Draws an ellipse.
11732 * An ellipse is formed from n Bezier curves.
11733 * @param $x0 (float) Abscissa of center point.
11734 * @param $y0 (float) Ordinate of center point.
11735 * @param $rx (float) Horizontal radius.
11736 * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
11737 * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
11738 * @param $astart: (float) Angle start of draw line. Default value: 0.
11739 * @param $afinish: (float) Angle finish of draw line. Default value: 360.
11740 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
11741 * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
11742 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
11743 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
11744 * @author Nicola Asuni
11746 * @since 2.1.000 (2008-01-08)
11748 public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
11749 if ($this->state
!= 2) {
11752 if (TCPDF_STATIC
::empty_string($ry) OR ($ry == 0)) {
11755 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11756 $this->SetFillColorArray($fill_color);
11758 $op = TCPDF_STATIC
::getPathPaintOperator($style);
11760 $line_style = array();
11763 $this->SetLineStyle($line_style);
11765 $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc, true, true, false);
11770 * Append an elliptical arc to the current path.
11771 * An ellipse is formed from n Bezier curves.
11772 * @param $xc (float) Abscissa of center point.
11773 * @param $yc (float) Ordinate of center point.
11774 * @param $rx (float) Horizontal radius.
11775 * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
11776 * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
11777 * @param $angs: (float) Angle start of draw line. Default value: 0.
11778 * @param $angf: (float) Angle finish of draw line. Default value: 360.
11779 * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
11780 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
11781 * @param $startpoint (boolean) if true output a starting point.
11782 * @param $ccw (boolean) if true draws in counter-clockwise.
11783 * @param $svg (boolean) if true the angles are in svg mode (already calculated).
11784 * @return array bounding box coordinates (x min, y min, x max, y max)
11785 * @author Nicola Asuni
11787 * @since 4.9.019 (2010-04-26)
11789 protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true, $svg=false) {
11790 if (($rx <= 0) OR ($ry < 0)) {
11797 $xmin = 2147483647;
11798 $ymin = 2147483647;
11802 // center of the arc
11803 $this->_outPoint($xc, $yc);
11805 $xang = deg2rad((float) $xang);
11806 $angs = deg2rad((float) $angs);
11807 $angf = deg2rad((float) $angf);
11812 $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
11813 $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
11821 if ($ccw AND ($as > $af)) {
11822 // reverse rotation
11824 } elseif (!$ccw AND ($as < $af)) {
11825 // reverse rotation
11828 $total_angle = ($af - $as);
11832 // total arcs to draw
11833 $nc *= (2 * abs($total_angle) / M_PI
);
11834 $nc = round($nc) +
1;
11835 // angle of each arc
11836 $arcang = ($total_angle / $nc);
11837 // center point in PDF coordinates
11839 $y0 = ($this->h
- $yc);
11842 $alpha = sin($arcang) * ((sqrt(4 +
(3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
11843 $cos_xang = cos($xang);
11844 $sin_xang = sin($xang);
11845 $cos_ang = cos($ang);
11846 $sin_ang = sin($ang);
11848 $px1 = $x0 +
($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
11849 $py1 = $y0 +
($rx * $sin_xang * $cos_ang) +
($ry * $cos_xang * $sin_ang);
11850 // first Bezier control point
11851 $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
11852 $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) +
($ry * $cos_xang * $cos_ang)));
11854 // line from center to arc starting point
11855 $this->_outLine($px1, $this->h
- $py1);
11856 } elseif ($startpoint) {
11857 // arc starting point
11858 $this->_outPoint($px1, $this->h
- $py1);
11861 for ($i = 1; $i <= $nc; ++
$i) {
11863 $ang = $as +
($i * $arcang);
11867 $cos_ang = cos($ang);
11868 $sin_ang = sin($ang);
11869 // second arc point
11870 $px2 = $x0 +
($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
11871 $py2 = $y0 +
($rx * $sin_xang * $cos_ang) +
($ry * $cos_xang * $sin_ang);
11872 // second Bezier control point
11873 $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
11874 $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) +
($ry * $cos_xang * $cos_ang)));
11876 $cx1 = ($px1 +
$qx1);
11877 $cy1 = ($this->h
- ($py1 +
$qy1));
11878 $cx2 = ($px2 - $qx2);
11879 $cy2 = ($this->h
- ($py2 - $qy2));
11881 $cy3 = ($this->h
- $py2);
11882 $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
11883 // get bounding box coordinates
11884 $xmin = min($xmin, $cx1, $cx2, $cx3);
11885 $ymin = min($ymin, $cy1, $cy2, $cy3);
11886 $xmax = max($xmax, $cx1, $cx2, $cx3);
11887 $ymax = max($ymax, $cy1, $cy2, $cy3);
11888 // move to next point
11895 $this->_outLine($xc, $yc);
11896 // get bounding box coordinates
11897 $xmin = min($xmin, $xc);
11898 $ymin = min($ymin, $yc);
11899 $xmax = max($xmax, $xc);
11900 $ymax = max($ymax, $yc);
11902 return array($xmin, $ymin, $xmax, $ymax);
11907 * A circle is formed from n Bezier curves.
11908 * @param $x0 (float) Abscissa of center point.
11909 * @param $y0 (float) Ordinate of center point.
11910 * @param $r (float) Radius.
11911 * @param $angstr: (float) Angle start of draw line. Default value: 0.
11912 * @param $angend: (float) Angle finish of draw line. Default value: 360.
11913 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
11914 * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
11915 * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
11916 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
11918 * @since 2.1.000 (2008-01-08)
11920 public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
11921 $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
11925 * Draws a polygonal line
11926 * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
11927 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
11928 * @param $line_style (array) Line style of polygon. Array with keys among the following:
11930 * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
11931 * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
11933 * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
11934 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
11935 * @since 4.8.003 (2009-09-15)
11938 public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
11939 $this->Polygon($p, $style, $line_style, $fill_color, false);
11944 * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
11945 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
11946 * @param $line_style (array) Line style of polygon. Array with keys among the following:
11948 * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
11949 * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
11951 * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
11952 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
11953 * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
11955 * @since 2.1.000 (2008-01-08)
11957 public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
11958 if ($this->state
!= 2) {
11961 $nc = count($p); // number of coordinates
11962 $np = $nc / 2; // number of points
11964 // close polygon by adding the first 2 points at the end (one line)
11965 for ($i = 0; $i < 4; ++
$i) {
11966 $p[$nc +
$i] = $p[$i];
11968 // copy style for the last added line
11969 if (isset($line_style[0])) {
11970 $line_style[$np] = $line_style[0];
11974 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
11975 $this->SetFillColorArray($fill_color);
11977 $op = TCPDF_STATIC
::getPathPaintOperator($style);
11979 $line_style = array();
11983 if (isset($line_style['all'])) {
11984 $this->SetLineStyle($line_style['all']);
11990 $this->_outPoint($p[0], $p[1]);
11991 for ($i = 2; $i < $nc; $i = $i +
2) {
11992 $this->_outLine($p[$i], $p[$i +
1]);
11997 $this->_outPoint($p[0], $p[1]);
11998 for ($i = 2; $i < $nc; $i = $i +
2) {
11999 $line_num = ($i / 2) - 1;
12000 if (isset($line_style[$line_num])) {
12001 if ($line_style[$line_num] != 0) {
12002 if (is_array($line_style[$line_num])) {
12004 $this->SetLineStyle($line_style[$line_num]);
12005 $this->_outPoint($p[$i - 2], $p[$i - 1]);
12006 $this->_outLine($p[$i], $p[$i +
1]);
12008 $this->_outPoint($p[$i], $p[$i +
1]);
12010 $this->_outLine($p[$i], $p[$i +
1]);
12014 $this->_outLine($p[$i], $p[$i +
1]);
12021 $this->_outPoint($p[0], $p[1]);
12022 for ($i = 2; $i < $nc; $i = $i +
2) {
12023 $this->_outLine($p[$i], $p[$i +
1]);
12030 * Draws a regular polygon.
12031 * @param $x0 (float) Abscissa of center point.
12032 * @param $y0 (float) Ordinate of center point.
12033 * @param $r: (float) Radius of inscribed circle.
12034 * @param $ns (integer) Number of sides.
12035 * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
12036 * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
12037 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
12038 * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
12040 * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
12041 * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
12043 * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
12044 * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
12045 * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
12047 * <li>D or empty string: Draw (default).</li>
12048 * <li>F: Fill.</li>
12049 * <li>DF or FD: Draw and fill.</li>
12050 * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
12051 * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
12053 * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
12054 * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
12056 * @since 2.1.000 (2008-01-08)
12058 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()) {
12062 if ($draw_circle) {
12063 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
12066 for ($i = 0; $i < $ns; ++
$i) {
12067 $a = $angle +
($i * 360 / $ns);
12068 $a_rad = deg2rad((float) $a);
12069 $p[] = $x0 +
($r * sin($a_rad));
12070 $p[] = $y0 +
($r * cos($a_rad));
12072 $this->Polygon($p, $style, $line_style, $fill_color);
12076 * Draws a star polygon
12077 * @param $x0 (float) Abscissa of center point.
12078 * @param $y0 (float) Ordinate of center point.
12079 * @param $r (float) Radius of inscribed circle.
12080 * @param $nv (integer) Number of vertices.
12081 * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
12082 * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
12083 * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
12084 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
12085 * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
12087 * <li>all: Line style of all sides. Array like for
12088 * SetLineStyle().</li>
12089 * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
12091 * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
12092 * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
12093 * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
12095 * <li>D or empty string: Draw (default).</li>
12096 * <li>F: Fill.</li>
12097 * <li>DF or FD: Draw and fill.</li>
12098 * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
12099 * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
12101 * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
12102 * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
12104 * @since 2.1.000 (2008-01-08)
12106 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()) {
12110 if ($draw_circle) {
12111 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
12114 $visited = array();
12115 for ($i = 0; $i < $nv; ++
$i) {
12116 $a = $angle +
($i * 360 / $nv);
12117 $a_rad = deg2rad((float) $a);
12118 $p2[] = $x0 +
($r * sin($a_rad));
12119 $p2[] = $y0 +
($r * cos($a_rad));
12120 $visited[] = false;
12125 $p[] = $p2[$i * 2];
12126 $p[] = $p2[($i * 2) +
1];
12127 $visited[$i] = true;
12130 } while (!$visited[$i]);
12131 $this->Polygon($p, $style, $line_style, $fill_color);
12135 * Draws a rounded rectangle.
12136 * @param $x (float) Abscissa of upper-left corner.
12137 * @param $y (float) Ordinate of upper-left corner.
12138 * @param $w (float) Width.
12139 * @param $h (float) Height.
12140 * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
12141 * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
12142 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
12143 * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
12144 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
12146 * @since 2.1.000 (2008-01-08)
12148 public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
12149 $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
12153 * Draws a rounded rectangle.
12154 * @param $x (float) Abscissa of upper-left corner.
12155 * @param $y (float) Ordinate of upper-left corner.
12156 * @param $w (float) Width.
12157 * @param $h (float) Height.
12158 * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
12159 * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
12160 * @param $round_corner (string) Draws rounded corner or not. String with a 0 (not rounded i-corner) or 1 (rounded i-corner) in i-position. Positions are, in order and begin to 0: top right, bottom right, bottom left and top left. Default value: all rounded corner ("1111").
12161 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
12162 * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
12163 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K) or array(C,M,Y,K,SpotColorName). Default value: default color (empty array).
12165 * @since 4.9.019 (2010-04-22)
12167 public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
12168 if ($this->state
!= 2) {
12171 if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
12173 $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
12177 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
12178 $this->SetFillColorArray($fill_color);
12180 $op = TCPDF_STATIC
::getPathPaintOperator($style);
12182 $border_style = array();
12184 if ($border_style) {
12185 $this->SetLineStyle($border_style);
12187 $MyArc = 4 / 3 * (sqrt(2) - 1);
12188 $this->_outPoint($x +
$rx, $y);
12189 $xc = $x +
$w - $rx;
12191 $this->_outLine($xc, $y);
12192 if ($round_corner[0]) {
12193 $this->_outCurve($xc +
($rx * $MyArc), $yc - $ry, $xc +
$rx, $yc - ($ry * $MyArc), $xc +
$rx, $yc);
12195 $this->_outLine($x +
$w, $y);
12197 $xc = $x +
$w - $rx;
12198 $yc = $y +
$h - $ry;
12199 $this->_outLine($x +
$w, $yc);
12200 if ($round_corner[1]) {
12201 $this->_outCurve($xc +
$rx, $yc +
($ry * $MyArc), $xc +
($rx * $MyArc), $yc +
$ry, $xc, $yc +
$ry);
12203 $this->_outLine($x +
$w, $y +
$h);
12206 $yc = $y +
$h - $ry;
12207 $this->_outLine($xc, $y +
$h);
12208 if ($round_corner[2]) {
12209 $this->_outCurve($xc - ($rx * $MyArc), $yc +
$ry, $xc - $rx, $yc +
($ry * $MyArc), $xc - $rx, $yc);
12211 $this->_outLine($x, $y +
$h);
12215 $this->_outLine($x, $yc);
12216 if ($round_corner[3]) {
12217 $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
12219 $this->_outLine($x, $y);
12220 $this->_outLine($x +
$rx, $y);
12226 * Draws a grahic arrow.
12227 * @param $x0 (float) Abscissa of first point.
12228 * @param $y0 (float) Ordinate of first point.
12229 * @param $x1 (float) Abscissa of second point.
12230 * @param $y1 (float) Ordinate of second point.
12231 * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
12232 * @param $arm_size (float) length of arrowhead arms
12233 * @param $arm_angle (int) angle between an arm and the shaft
12234 * @author Piotr Galecki, Nicola Asuni, Andy Meier
12235 * @since 4.6.018 (2009-07-10)
12237 public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
12238 // getting arrow direction angle
12239 // 0 deg angle is when both arms go along X axis. angle grows clockwise.
12240 $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
12241 if ($dir_angle < 0) {
12242 $dir_angle +
= (2 * M_PI
);
12244 $arm_angle = deg2rad($arm_angle);
12247 if ($head_style > 0) {
12248 // calculate the stopping point for the arrow shaft
12249 $sx1 = $x1 +
(($arm_size - $this->LineWidth
) * cos($dir_angle));
12250 $sy1 = $y1 +
(($arm_size - $this->LineWidth
) * sin($dir_angle));
12252 // main arrow line / shaft
12253 $this->Line($x0, $y0, $sx1, $sy1);
12254 // left arrowhead arm tip
12255 $x2L = $x1 +
($arm_size * cos($dir_angle +
$arm_angle));
12256 $y2L = $y1 +
($arm_size * sin($dir_angle +
$arm_angle));
12257 // right arrowhead arm tip
12258 $x2R = $x1 +
($arm_size * cos($dir_angle - $arm_angle));
12259 $y2R = $y1 +
($arm_size * sin($dir_angle - $arm_angle));
12262 switch ($head_style) {
12264 // draw only arrowhead arms
12266 $style = array(1, 1, 0);
12270 // draw closed arrowhead, but no fill
12275 // closed and filled arrowhead
12280 // filled arrowhead
12285 $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
12288 // END GRAPHIC FUNCTIONS SECTION -----------------------
12291 * Add a Named Destination.
12292 * NOTE: destination names are unique, so only last entry will be saved.
12293 * @param $name (string) Destination name.
12294 * @param $y (float) Y position in user units of the destiantion on the selected page (default = -1 = current position; 0 = page start;).
12295 * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
12296 * @param $x (float) X position in user units of the destiantion on the selected page (default = -1 = current position;).
12297 * @return (string) Stripped named destination identifier or false in case of error.
12299 * @author Christian Deligant, Nicola Asuni
12300 * @since 5.9.097 (2011-06-23)
12302 public function setDestination($name, $y=-1, $page='', $x=-1) {
12303 // remove unsupported characters
12304 $name = TCPDF_STATIC
::encodeNameObject($name);
12305 if (TCPDF_STATIC
::empty_string($name)) {
12309 $y = $this->GetY();
12310 } elseif ($y < 0) {
12312 } elseif ($y > $this->h
) {
12316 $x = $this->GetX();
12317 } elseif ($x < 0) {
12319 } elseif ($x > $this->w
) {
12323 if (!empty($page) AND (substr($page, 0, 1) == '*')) {
12324 $page = intval(substr($page, 1));
12325 // this page number will not be changed when moving/add/deleting pages
12328 if (empty($page)) {
12329 $page = $this->PageNo();
12330 if (empty($page)) {
12334 $this->dests
[$name] = array('x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed);
12339 * Return the Named Destination array.
12340 * @return (array) Named Destination array.
12342 * @author Nicola Asuni
12343 * @since 5.9.097 (2011-06-23)
12345 public function getDestination() {
12346 return $this->dests
;
12350 * Insert Named Destinations.
12352 * @author Johannes G\FCntert, Nicola Asuni
12353 * @since 5.9.098 (2011-06-23)
12355 protected function _putdests() {
12356 if (empty($this->dests
)) {
12359 $this->n_dests
= $this->_newobj();
12361 foreach($this->dests
as $name => $o) {
12362 $out .= ' /'.$name.' '.sprintf('[%u 0 R /XYZ %F %F null]', $this->page_obj_id
[($o['p'])], ($o['x'] * $this->k
), ($this->pagedim
[$o['p']]['h'] - ($o['y'] * $this->k
)));
12365 $out .= "\n".'endobj';
12370 * Adds a bookmark - alias for Bookmark().
12371 * @param $txt (string) Bookmark description.
12372 * @param $level (int) Bookmark level (minimum value is 0).
12373 * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
12374 * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
12375 * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
12376 * @param $color (array) RGB color array (values from 0 to 255).
12377 * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
12378 * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
12381 public function setBookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
12382 $this->Bookmark($txt, $level, $y, $page, $style, $color, $x, $link);
12387 * @param $txt (string) Bookmark description.
12388 * @param $level (int) Bookmark level (minimum value is 0).
12389 * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
12390 * @param $page (int|string) Target page number (leave empty for current page). If you prefix a page number with the * character, then this page will not be changed when adding/deleting/moving pages.
12391 * @param $style (string) Font style: B = Bold, I = Italic, BI = Bold + Italic.
12392 * @param $color (array) RGB color array (values from 0 to 255).
12393 * @param $x (float) X position in user units of the bookmark on the selected page (default = -1 = current position;).
12394 * @param $link (mixed) URL, or numerical link ID, or named destination (# character followed by the destination name), or embedded file (* character followed by the file name).
12396 * @since 2.1.002 (2008-02-12)
12398 public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='') {
12402 if (isset($this->outlines
[0])) {
12403 $lastoutline = end($this->outlines
);
12404 $maxlevel = $lastoutline['l'] +
1;
12408 if ($level > $maxlevel) {
12409 $level = $maxlevel;
12412 $y = $this->GetY();
12413 } elseif ($y < 0) {
12415 } elseif ($y > $this->h
) {
12419 $x = $this->GetX();
12420 } elseif ($x < 0) {
12422 } elseif ($x > $this->w
) {
12426 $pageAsString = (string) $page;
12427 if ($pageAsString && $pageAsString[0] == '*') {
12428 $page = intval(substr($page, 1));
12429 // this page number will not be changed when moving/add/deleting pages
12432 if (empty($page)) {
12433 $page = $this->PageNo();
12434 if (empty($page)) {
12438 $this->outlines
[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link);
12442 * Sort bookmarks for page and key.
12444 * @since 5.9.119 (2011-09-19)
12446 protected function sortBookmarks() {
12447 // get sorting columns
12448 $outline_p = array();
12449 $outline_y = array();
12450 foreach ($this->outlines
as $key => $row) {
12451 $outline_p[$key] = $row['p'];
12452 $outline_k[$key] = $key;
12454 // sort outlines by page and original position
12455 array_multisort($outline_p, SORT_NUMERIC
, SORT_ASC
, $outline_k, SORT_NUMERIC
, SORT_ASC
, $this->outlines
);
12459 * Create a bookmark PDF string.
12461 * @author Olivier Plathey, Nicola Asuni
12462 * @since 2.1.002 (2008-02-12)
12464 protected function _putbookmarks() {
12465 $nb = count($this->outlines
);
12470 $this->sortBookmarks();
12473 foreach ($this->outlines
as $i => $o) {
12475 $parent = $lru[($o['l'] - 1)];
12476 //Set parent and last pointers
12477 $this->outlines
[$i]['parent'] = $parent;
12478 $this->outlines
[$parent]['last'] = $i;
12479 if ($o['l'] > $level) {
12480 //Level increasing: set first pointer
12481 $this->outlines
[$parent]['first'] = $i;
12484 $this->outlines
[$i]['parent'] = $nb;
12486 if (($o['l'] <= $level) AND ($i > 0)) {
12487 //Set prev and next pointers
12488 $prev = $lru[$o['l']];
12489 $this->outlines
[$prev]['next'] = $i;
12490 $this->outlines
[$i]['prev'] = $prev;
12492 $lru[$o['l']] = $i;
12497 $nltags = '/<br[\s]?\/>|<\/(blockquote|dd|dl|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|ul|tcpdf|table|tr|td)>/si';
12498 foreach ($this->outlines
as $i => $o) {
12499 $oid = $this->_newobj();
12500 // covert HTML title to string
12501 $title = preg_replace($nltags, "\n", $o['t']);
12502 $title = preg_replace("/[\r]+/si", '', $title);
12503 $title = preg_replace("/[\n]+/si", "\n", $title);
12504 $title = strip_tags($title);
12505 $title = $this->stringTrim($title);
12506 $out = '<</Title '.$this->_textstring($title, $oid);
12507 $out .= ' /Parent '.($n +
$o['parent']).' 0 R';
12508 if (isset($o['prev'])) {
12509 $out .= ' /Prev '.($n +
$o['prev']).' 0 R';
12511 if (isset($o['next'])) {
12512 $out .= ' /Next '.($n +
$o['next']).' 0 R';
12514 if (isset($o['first'])) {
12515 $out .= ' /First '.($n +
$o['first']).' 0 R';
12517 if (isset($o['last'])) {
12518 $out .= ' /Last '.($n +
$o['last']).' 0 R';
12520 if (isset($o['u']) AND !empty($o['u'])) {
12522 if (is_string($o['u'])) {
12523 if ($o['u'][0] == '#') {
12524 // internal destination
12525 $out .= ' /Dest /'.TCPDF_STATIC
::encodeNameObject(substr($o['u'], 1));
12526 } elseif ($o['u'][0] == '%') {
12527 // embedded PDF file
12528 $filename = basename(substr($o['u'], 1));
12529 $out .= ' /A <</S /GoToE /D [0 /Fit] /NewWindow true /T << /R /C /P '.($o['p'] - 1).' /A '.$this->embeddedfiles
[$filename]['a'].' >> >>';
12530 } elseif ($o['u'][0] == '*') {
12531 // embedded generic file
12532 $filename = basename(substr($o['u'], 1));
12533 $jsa = 'var D=event.target.doc;var MyData=D.dataObjects;for (var i in MyData) if (MyData[i].path=="'.$filename.'") D.exportDataObject( { cName : MyData[i].name, nLaunch : 2});';
12534 $out .= ' /A <</S /JavaScript /JS '.$this->_textstring($jsa, $oid).'>>';
12536 // external URI link
12537 $out .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($o['u']), $oid).'>>';
12539 } elseif (isset($this->links
[$o['u']])) {
12540 // internal link ID
12541 $l = $this->links
[$o['u']];
12542 if (isset($this->page_obj_id
[($l['p'])])) {
12543 $out .= sprintf(' /Dest [%u 0 R /XYZ 0 %F null]', $this->page_obj_id
[($l['p'])], ($this->pagedim
[$l['p']]['h'] - ($l['y'] * $this->k
)));
12546 } elseif (isset($this->page_obj_id
[($o['p'])])) {
12548 $out .= ' '.sprintf('/Dest [%u 0 R /XYZ %F %F null]', $this->page_obj_id
[($o['p'])], ($o['x'] * $this->k
), ($this->pagedim
[$o['p']]['h'] - ($o['y'] * $this->k
)));
12552 if (!empty($o['s'])) {
12554 if (strpos($o['s'], 'B') !== false) {
12558 if (strpos($o['s'], 'I') !== false) {
12562 $out .= sprintf(' /F %d', $style);
12563 // set bookmark color
12564 if (isset($o['c']) AND is_array($o['c']) AND (count($o['c']) == 3)) {
12565 $color = array_values($o['c']);
12566 $out .= sprintf(' /C [%F %F %F]', ($color[0] / 255), ($color[1] / 255), ($color[2] / 255));
12569 $out .= ' /C [0.0 0.0 0.0]';
12571 $out .= ' /Count 0'; // normally closed item
12573 $out .= "\n".'endobj';
12577 $this->OutlineRoot
= $this->_newobj();
12578 $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n +
$lru[0]).' 0 R >>'."\n".'endobj');
12581 // --- JAVASCRIPT ------------------------------------------------------
12584 * Adds a javascript
12585 * @param $script (string) Javascript code
12587 * @author Johannes G\FCntert, Nicola Asuni
12588 * @since 2.1.002 (2008-02-12)
12590 public function IncludeJS($script) {
12591 $this->javascript
.= $script;
12595 * Adds a javascript object and return object ID
12596 * @param $script (string) Javascript code
12597 * @param $onload (boolean) if true executes this object when opening the document
12598 * @return int internal object ID
12600 * @author Nicola Asuni
12601 * @since 4.8.000 (2009-09-07)
12603 public function addJavascriptObject($script, $onload=false) {
12604 if ($this->pdfa_mode
) {
12605 // javascript is not allowed in PDF/A mode
12609 $this->js_objects
[$this->n
] = array('n' => $this->n
, 'js' => $script, 'onload' => $onload);
12614 * Create a javascript PDF string.
12616 * @author Johannes G\FCntert, Nicola Asuni
12617 * @since 2.1.002 (2008-02-12)
12619 protected function _putjavascript() {
12620 if ($this->pdfa_mode
OR (empty($this->javascript
) AND empty($this->js_objects
))) {
12623 if (strpos($this->javascript
, 'this.addField') > 0) {
12624 if (!$this->ur
['enabled']) {
12625 //$this->setUserRights();
12627 // the following two lines are used to avoid form fields duplication after saving
12628 // The addField method only works when releasing user rights (UR3)
12629 $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%F,%F,%F,%F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
12630 $jsb = "getField('tcpdfdocsaved').value='saved';";
12631 $this->javascript
= $jsa."\n".$this->javascript
."\n".$jsb;
12633 // name tree for javascript
12634 $this->n_js
= '<< /Names [';
12635 if (!empty($this->javascript
)) {
12636 $this->n_js
.= ' (EmbeddedJS) '.($this->n +
1).' 0 R';
12638 if (!empty($this->js_objects
)) {
12639 foreach ($this->js_objects
as $key => $val) {
12640 if ($val['onload']) {
12641 $this->n_js
.= ' (JS'.$key.') '.$key.' 0 R';
12645 $this->n_js
.= ' ] >>';
12646 // default Javascript object
12647 if (!empty($this->javascript
)) {
12648 $obj_id = $this->_newobj();
12649 $out = '<< /S /JavaScript';
12650 $out .= ' /JS '.$this->_textstring($this->javascript
, $obj_id);
12652 $out .= "\n".'endobj';
12655 // additional Javascript objects
12656 if (!empty($this->js_objects
)) {
12657 foreach ($this->js_objects
as $key => $val) {
12658 $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
12665 * Adds a javascript form field.
12666 * @param $type (string) field type
12667 * @param $name (string) field name
12668 * @param $x (int) horizontal position
12669 * @param $y (int) vertical position
12670 * @param $w (int) width
12671 * @param $h (int) height
12672 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12674 * @author Denis Van Nuffelen, Nicola Asuni
12675 * @since 2.1.002 (2008-02-12)
12677 protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
12681 // the followind avoid fields duplication after saving the document
12682 $this->javascript
.= "if (getField('tcpdfdocsaved').value != 'saved') {";
12684 $this->javascript
.= sprintf("f".$name."=this.addField('%s','%s',%u,[%F,%F,%F,%F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h
-$y)*$k+
1, ($x+
$w)*$k, ($this->h
-$y-$h)*$k+
1)."\n";
12685 $this->javascript
.= 'f'.$name.'.textSize='.$this->FontSizePt
.";\n";
12686 foreach($prop as $key => $val) {
12687 if (strcmp(substr($key, -5), 'Color') == 0) {
12688 $val = TCPDF_COLORS
::_JScolor($val);
12690 $val = "'".$val."'";
12692 $this->javascript
.= 'f'.$name.'.'.$key.'='.$val.";\n";
12699 $this->javascript
.= '}';
12702 // --- FORM FIELDS -----------------------------------------------------
12707 * Set default properties for form fields.
12708 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12710 * @author Nicola Asuni
12711 * @since 4.8.000 (2009-09-06)
12713 public function setFormDefaultProp($prop=array()) {
12714 $this->default_form_prop
= $prop;
12718 * Return the default properties for form fields.
12719 * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12721 * @author Nicola Asuni
12722 * @since 4.8.000 (2009-09-06)
12724 public function getFormDefaultProp() {
12725 return $this->default_form_prop
;
12729 * Creates a text field
12730 * @param $name (string) field name
12731 * @param $w (float) Width of the rectangle
12732 * @param $h (float) Height of the rectangle
12733 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12734 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
12735 * @param $x (float) Abscissa of the upper-left corner of the rectangle
12736 * @param $y (float) Ordinate of the upper-left corner of the rectangle
12737 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
12739 * @author Nicola Asuni
12740 * @since 4.8.000 (2009-09-07)
12742 public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
12749 // check page for no-write regions and adapt page margins if necessary
12750 list($x, $y) = $this->checkPageRegions($h, $x, $y);
12752 $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
12755 // get default style
12756 $prop = array_merge($this->getFormDefaultProp(), $prop);
12757 // get annotation data
12758 $popt = TCPDF_STATIC
::getAnnotOptFromJSProp($prop, $this->spot_colors
, $this->rtl
);
12759 // set default appearance stream
12760 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
12761 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
12762 $popt['da'] = $fontstyle;
12763 // build appearance stream
12764 $popt['ap'] = array();
12765 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
12767 if (isset($prop['value']) AND !empty($prop['value'])) {
12768 $text = $prop['value'];
12769 } elseif (isset($opt['v']) AND !empty($opt['v'])) {
12772 $tmpid = $this->startTemplate($w, $h, false);
12774 if (isset($popt['q'])) {
12775 switch ($popt['q']) {
12794 $this->MultiCell($w, $h, $text, 0, $align, false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
12795 $this->endTemplate();
12797 $popt['ap']['n'] .= $this->xobjects
[$tmpid]['outdata'];
12798 unset($this->xobjects
[$tmpid]);
12799 $popt['ap']['n'] .= 'Q EMC';
12801 $opt = array_merge($popt, $opt);
12802 // remove some conflicting options
12804 // set remaining annotation data
12805 $opt['Subtype'] = 'Widget';
12808 // Additional annotation's parameters (check _putannotsobj() method):
12818 //$opt['mk']['bc'];
12819 //$opt['mk']['bg'];
12820 unset($opt['mk']['ca']);
12821 unset($opt['mk']['rc']);
12822 unset($opt['mk']['ac']);
12823 unset($opt['mk']['i']);
12824 unset($opt['mk']['ri']);
12825 unset($opt['mk']['ix']);
12826 unset($opt['mk']['if']);
12827 //$opt['mk']['if']['sw'];
12828 //$opt['mk']['if']['s'];
12829 //$opt['mk']['if']['a'];
12830 //$opt['mk']['if']['fb'];
12831 unset($opt['mk']['tp']);
12840 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
12849 * Creates a RadioButton field.
12850 * @param $name (string) Field name.
12851 * @param $w (int) Width of the radio button.
12852 * @param $prop (array) Javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12853 * @param $opt (array) Annotation parameters. Possible values are described on official PDF32000_2008 reference.
12854 * @param $onvalue (string) Value to be returned if selected.
12855 * @param $checked (boolean) Define the initial state.
12856 * @param $x (float) Abscissa of the upper-left corner of the rectangle
12857 * @param $y (float) Ordinate of the upper-left corner of the rectangle
12858 * @param $js (boolean) If true put the field using JavaScript (requires Acrobat Writer to be rendered).
12860 * @author Nicola Asuni
12861 * @since 4.8.000 (2009-09-07)
12863 public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
12870 // check page for no-write regions and adapt page margins if necessary
12871 list($x, $y) = $this->checkPageRegions($w, $x, $y);
12873 $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
12876 if (TCPDF_STATIC
::empty_string($onvalue)) {
12880 $defval = $onvalue;
12885 $font = 'zapfdingbats';
12886 if ($this->pdfa_mode
) {
12887 // all fonts must be embedded
12888 $font = 'pdfa'.$font;
12890 $this->AddFont($font);
12891 $tmpfont = $this->getFontBuffer($font);
12892 // set data for parent group
12893 if (!isset($this->radiobutton_groups
[$this->page
])) {
12894 $this->radiobutton_groups
[$this->page
] = array();
12896 if (!isset($this->radiobutton_groups
[$this->page
][$name])) {
12897 $this->radiobutton_groups
[$this->page
][$name] = array();
12899 $this->radiobutton_groups
[$this->page
][$name]['n'] = $this->n
;
12900 $this->radio_groups
[] = $this->n
;
12902 $kid = ($this->n +
1);
12903 // save object ID to be added on Kids entry on parent object
12904 $this->radiobutton_groups
[$this->page
][$name][] = array('kid' => $kid, 'def' => $defval);
12905 // get default style
12906 $prop = array_merge($this->getFormDefaultProp(), $prop);
12907 $prop['NoToggleToOff'] = 'true';
12908 $prop['Radio'] = 'true';
12909 $prop['borderStyle'] = 'inset';
12910 // get annotation data
12911 $popt = TCPDF_STATIC
::getAnnotOptFromJSProp($prop, $this->spot_colors
, $this->rtl
);
12912 // set additional default options
12913 $this->annotation_fonts
[$tmpfont['fontkey']] = $tmpfont['i'];
12914 $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt
, $this->TextColor
);
12915 $popt['da'] = $fontstyle;
12916 // build appearance stream
12917 $popt['ap'] = array();
12918 $popt['ap']['n'] = array();
12919 $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][108])) / 2) * $this->k
);
12920 $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt
/ 1000) / $this->k
)) * $this->k
);
12921 $popt['ap']['n'][$onvalue] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(108).') Tj ET Q', $this->TextColor
, $tmpfont['i'], $this->FontSizePt
, $fx, $fy);
12922 $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(109).') Tj ET Q', $this->TextColor
, $tmpfont['i'], $this->FontSizePt
, $fx, $fy);
12923 if (!isset($popt['mk'])) {
12924 $popt['mk'] = array();
12926 $popt['mk']['ca'] = '(l)';
12928 $opt = array_merge($popt, $opt);
12929 // set remaining annotation data
12930 $opt['Subtype'] = 'Widget';
12931 $opt['ft'] = 'Btn';
12933 $opt['v'] = array('/'.$onvalue);
12934 $opt['as'] = $onvalue;
12936 $opt['as'] = 'Off';
12938 // store readonly flag
12939 if (!isset($this->radiobutton_groups
[$this->page
][$name]['#readonly#'])) {
12940 $this->radiobutton_groups
[$this->page
][$name]['#readonly#'] = false;
12942 $this->radiobutton_groups
[$this->page
][$name]['#readonly#'] |
= ($opt['f'] & 64);
12943 $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
12952 * Creates a List-box field
12953 * @param $name (string) field name
12954 * @param $w (int) width
12955 * @param $h (int) height
12956 * @param $values (array) array containing the list of values.
12957 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
12958 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
12959 * @param $x (float) Abscissa of the upper-left corner of the rectangle
12960 * @param $y (float) Ordinate of the upper-left corner of the rectangle
12961 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
12963 * @author Nicola Asuni
12964 * @since 4.8.000 (2009-09-07)
12966 public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
12973 // check page for no-write regions and adapt page margins if necessary
12974 list($x, $y) = $this->checkPageRegions($h, $x, $y);
12976 $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
12978 foreach ($values as $value) {
12979 if (is_array($value)) {
12980 $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
12982 $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
12985 $this->javascript
.= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
12988 // get default style
12989 $prop = array_merge($this->getFormDefaultProp(), $prop);
12990 // get annotation data
12991 $popt = TCPDF_STATIC
::getAnnotOptFromJSProp($prop, $this->spot_colors
, $this->rtl
);
12992 // set additional default values
12993 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
12994 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
12995 $popt['da'] = $fontstyle;
12996 // build appearance stream
12997 $popt['ap'] = array();
12998 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
13000 foreach($values as $item) {
13001 if (is_array($item)) {
13002 $text .= $item[1]."\n";
13004 $text .= $item."\n";
13007 $tmpid = $this->startTemplate($w, $h, false);
13008 $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
13009 $this->endTemplate();
13011 $popt['ap']['n'] .= $this->xobjects
[$tmpid]['outdata'];
13012 unset($this->xobjects
[$tmpid]);
13013 $popt['ap']['n'] .= 'Q EMC';
13015 $opt = array_merge($popt, $opt);
13016 // set remaining annotation data
13017 $opt['Subtype'] = 'Widget';
13020 $opt['opt'] = $values;
13021 unset($opt['mk']['ca']);
13022 unset($opt['mk']['rc']);
13023 unset($opt['mk']['ac']);
13024 unset($opt['mk']['i']);
13025 unset($opt['mk']['ri']);
13026 unset($opt['mk']['ix']);
13027 unset($opt['mk']['if']);
13028 unset($opt['mk']['tp']);
13029 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
13038 * Creates a Combo-box field
13039 * @param $name (string) field name
13040 * @param $w (int) width
13041 * @param $h (int) height
13042 * @param $values (array) array containing the list of values.
13043 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
13044 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
13045 * @param $x (float) Abscissa of the upper-left corner of the rectangle
13046 * @param $y (float) Ordinate of the upper-left corner of the rectangle
13047 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
13049 * @author Nicola Asuni
13050 * @since 4.8.000 (2009-09-07)
13052 public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
13059 // check page for no-write regions and adapt page margins if necessary
13060 list($x, $y) = $this->checkPageRegions($h, $x, $y);
13062 $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
13064 foreach ($values as $value) {
13065 if (is_array($value)) {
13066 $s .= ',[\''.addslashes($value[1]).'\',\''.addslashes($value[0]).'\']';
13068 $s .= ',[\''.addslashes($value).'\',\''.addslashes($value).'\']';
13071 $this->javascript
.= 'f'.$name.'.setItems('.substr($s, 1).');'."\n";
13074 // get default style
13075 $prop = array_merge($this->getFormDefaultProp(), $prop);
13076 $prop['Combo'] = true;
13077 // get annotation data
13078 $popt = TCPDF_STATIC
::getAnnotOptFromJSProp($prop, $this->spot_colors
, $this->rtl
);
13079 // set additional default options
13080 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
13081 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
13082 $popt['da'] = $fontstyle;
13083 // build appearance stream
13084 $popt['ap'] = array();
13085 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
13087 foreach($values as $item) {
13088 if (is_array($item)) {
13089 $text .= $item[1]."\n";
13091 $text .= $item."\n";
13094 $tmpid = $this->startTemplate($w, $h, false);
13095 $this->MultiCell($w, $h, $text, 0, '', false, 0, 0, 0, true, 0, false, true, 0, 'T', false);
13096 $this->endTemplate();
13098 $popt['ap']['n'] .= $this->xobjects
[$tmpid]['outdata'];
13099 unset($this->xobjects
[$tmpid]);
13100 $popt['ap']['n'] .= 'Q EMC';
13102 $opt = array_merge($popt, $opt);
13103 // set remaining annotation data
13104 $opt['Subtype'] = 'Widget';
13107 $opt['opt'] = $values;
13108 unset($opt['mk']['ca']);
13109 unset($opt['mk']['rc']);
13110 unset($opt['mk']['ac']);
13111 unset($opt['mk']['i']);
13112 unset($opt['mk']['ri']);
13113 unset($opt['mk']['ix']);
13114 unset($opt['mk']['if']);
13115 unset($opt['mk']['tp']);
13116 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
13125 * Creates a CheckBox field
13126 * @param $name (string) field name
13127 * @param $w (int) width
13128 * @param $checked (boolean) define the initial state.
13129 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
13130 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
13131 * @param $onvalue (string) value to be returned if selected.
13132 * @param $x (float) Abscissa of the upper-left corner of the rectangle
13133 * @param $y (float) Ordinate of the upper-left corner of the rectangle
13134 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
13136 * @author Nicola Asuni
13137 * @since 4.8.000 (2009-09-07)
13139 public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
13146 // check page for no-write regions and adapt page margins if necessary
13147 list($x, $y) = $this->checkPageRegions($w, $x, $y);
13149 $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
13152 if (!isset($prop['value'])) {
13153 $prop['value'] = array('Yes');
13155 // get default style
13156 $prop = array_merge($this->getFormDefaultProp(), $prop);
13157 $prop['borderStyle'] = 'inset';
13158 // get annotation data
13159 $popt = TCPDF_STATIC
::getAnnotOptFromJSProp($prop, $this->spot_colors
, $this->rtl
);
13160 // set additional default options
13161 $font = 'zapfdingbats';
13162 if ($this->pdfa_mode
) {
13163 // all fonts must be embedded
13164 $font = 'pdfa'.$font;
13166 $this->AddFont($font);
13167 $tmpfont = $this->getFontBuffer($font);
13168 $this->annotation_fonts
[$tmpfont['fontkey']] = $tmpfont['i'];
13169 $fontstyle = sprintf('/F%d %F Tf %s', $tmpfont['i'], $this->FontSizePt
, $this->TextColor
);
13170 $popt['da'] = $fontstyle;
13171 // build appearance stream
13172 $popt['ap'] = array();
13173 $popt['ap']['n'] = array();
13174 $fx = ((($w - $this->getAbsFontMeasure($tmpfont['cw'][110])) / 2) * $this->k
);
13175 $fy = (($w - ((($tmpfont['desc']['Ascent'] - $tmpfont['desc']['Descent']) * $this->FontSizePt
/ 1000) / $this->k
)) * $this->k
);
13176 $popt['ap']['n']['Yes'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(110).') Tj ET Q', $this->TextColor
, $tmpfont['i'], $this->FontSizePt
, $fx, $fy);
13177 $popt['ap']['n']['Off'] = sprintf('q %s BT /F%d %F Tf %F %F Td ('.chr(111).') Tj ET Q', $this->TextColor
, $tmpfont['i'], $this->FontSizePt
, $fx, $fy);
13179 $opt = array_merge($popt, $opt);
13180 // set remaining annotation data
13181 $opt['Subtype'] = 'Widget';
13182 $opt['ft'] = 'Btn';
13184 if (TCPDF_STATIC
::empty_string($onvalue)) {
13187 $opt['opt'] = array($onvalue);
13189 $opt['v'] = array('/Yes');
13190 $opt['as'] = 'Yes';
13192 $opt['v'] = array('/Off');
13193 $opt['as'] = 'Off';
13195 $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
13204 * Creates a button field
13205 * @param $name (string) field name
13206 * @param $w (int) width
13207 * @param $h (int) height
13208 * @param $caption (string) caption.
13209 * @param $action (mixed) action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as on section 12.7.5 of PDF32000_2008.
13210 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
13211 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
13212 * @param $x (float) Abscissa of the upper-left corner of the rectangle
13213 * @param $y (float) Ordinate of the upper-left corner of the rectangle
13214 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
13216 * @author Nicola Asuni
13217 * @since 4.8.000 (2009-09-07)
13219 public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
13226 // check page for no-write regions and adapt page margins if necessary
13227 list($x, $y) = $this->checkPageRegions($h, $x, $y);
13229 $this->_addfield('button', $name, $this->x
, $this->y
, $w, $h, $prop);
13230 $this->javascript
.= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
13231 $this->javascript
.= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
13232 $this->javascript
.= 'f'.$name.".highlight='push';\n";
13233 $this->javascript
.= 'f'.$name.".print=false;\n";
13236 // get default style
13237 $prop = array_merge($this->getFormDefaultProp(), $prop);
13238 $prop['Pushbutton'] = 'true';
13239 $prop['highlight'] = 'push';
13240 $prop['display'] = 'display.noPrint';
13241 // get annotation data
13242 $popt = TCPDF_STATIC
::getAnnotOptFromJSProp($prop, $this->spot_colors
, $this->rtl
);
13243 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
13244 $fontstyle = sprintf('/F%d %F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
13245 $popt['da'] = $fontstyle;
13246 // build appearance stream
13247 $popt['ap'] = array();
13248 $popt['ap']['n'] = '/Tx BMC q '.$fontstyle.' ';
13249 $tmpid = $this->startTemplate($w, $h, false);
13250 $bw = (2 / $this->k
); // border width
13252 'L' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
13253 'R' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)),
13254 'T' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(231)),
13255 'B' => array('width' => $bw, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(51)));
13256 $this->SetFillColor(204);
13257 $this->Cell($w, $h, $caption, $border, 0, 'C', true, '', 1, false, 'T', 'M');
13258 $this->endTemplate();
13260 $popt['ap']['n'] .= $this->xobjects
[$tmpid]['outdata'];
13261 unset($this->xobjects
[$tmpid]);
13262 $popt['ap']['n'] .= 'Q EMC';
13263 // set additional default options
13264 if (!isset($popt['mk'])) {
13265 $popt['mk'] = array();
13267 $ann_obj_id = ($this->n +
1);
13268 if (!empty($action) AND !is_array($action)) {
13269 $ann_obj_id = ($this->n +
2);
13271 $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
13272 $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
13273 $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
13275 $opt = array_merge($popt, $opt);
13276 // set remaining annotation data
13277 $opt['Subtype'] = 'Widget';
13278 $opt['ft'] = 'Btn';
13279 $opt['t'] = $caption;
13281 if (!empty($action)) {
13282 if (is_array($action)) {
13283 // form action options as on section 12.7.5 of PDF32000_2008.
13284 $opt['aa'] = '/D <<';
13285 $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
13286 foreach ($action AS $key => $val) {
13287 if (($key == 'S') AND in_array($val, $bmode)) {
13288 $opt['aa'] .= ' /S /'.$val;
13289 } elseif (($key == 'F') AND (!empty($val))) {
13290 $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
13291 } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
13292 $opt['aa'] .= ' /Fields [';
13293 foreach ($val AS $field) {
13294 $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
13297 } elseif (($key == 'Flags')) {
13299 if (is_array($val)) {
13300 foreach ($val AS $flag) {
13302 case 'Include/Exclude': {
13306 case 'IncludeNoValueFields': {
13310 case 'ExportFormat': {
13314 case 'GetMethod': {
13318 case 'SubmitCoordinates': {
13326 case 'IncludeAppendSaves': {
13330 case 'IncludeAnnotations': {
13334 case 'SubmitPDF': {
13338 case 'CanonicalFormat': {
13342 case 'ExclNonUserAnnots': {
13350 case 'EmbedForm': {
13357 $ff = intval($val);
13359 $opt['aa'] .= ' /Flags '.$ff;
13362 $opt['aa'] .= ' >>';
13364 // Javascript action or raw action command
13365 $js_obj_id = $this->addJavascriptObject($action);
13366 $opt['aa'] = '/D '.$js_obj_id.' 0 R';
13369 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
13377 // --- END FORMS FIELDS ------------------------------------------------
13380 * Add certification signature (DocMDP or UR3)
13381 * You can set only one signature type
13383 * @author Nicola Asuni
13384 * @since 4.6.008 (2009-05-07)
13386 protected function _putsignature() {
13387 if ((!$this->sign
) OR (!isset($this->signature_data
['cert_type']))) {
13390 $sigobjid = ($this->sig_obj_id +
1);
13391 $out = $this->_getobj($sigobjid)."\n";
13392 $out .= '<< /Type /Sig';
13393 $out .= ' /Filter /Adobe.PPKLite';
13394 $out .= ' /SubFilter /adbe.pkcs7.detached';
13395 $out .= ' '.TCPDF_STATIC
::$byterange_string;
13396 $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length
).'>';
13397 if (empty($this->signature_data
['approval']) OR ($this->signature_data
['approval'] != 'A')) {
13398 $out .= ' /Reference ['; // array of signature reference dictionaries
13399 $out .= ' << /Type /SigRef';
13400 if ($this->signature_data
['cert_type'] > 0) {
13401 $out .= ' /TransformMethod /DocMDP';
13402 $out .= ' /TransformParams <<';
13403 $out .= ' /Type /TransformParams';
13404 $out .= ' /P '.$this->signature_data
['cert_type'];
13405 $out .= ' /V /1.2';
13407 $out .= ' /TransformMethod /UR3';
13408 $out .= ' /TransformParams <<';
13409 $out .= ' /Type /TransformParams';
13410 $out .= ' /V /2.2';
13411 if (!TCPDF_STATIC
::empty_string($this->ur
['document'])) {
13412 $out .= ' /Document['.$this->ur
['document'].']';
13414 if (!TCPDF_STATIC
::empty_string($this->ur
['form'])) {
13415 $out .= ' /Form['.$this->ur
['form'].']';
13417 if (!TCPDF_STATIC
::empty_string($this->ur
['signature'])) {
13418 $out .= ' /Signature['.$this->ur
['signature'].']';
13420 if (!TCPDF_STATIC
::empty_string($this->ur
['annots'])) {
13421 $out .= ' /Annots['.$this->ur
['annots'].']';
13423 if (!TCPDF_STATIC
::empty_string($this->ur
['ef'])) {
13424 $out .= ' /EF['.$this->ur
['ef'].']';
13426 if (!TCPDF_STATIC
::empty_string($this->ur
['formex'])) {
13427 $out .= ' /FormEX['.$this->ur
['formex'].']';
13430 $out .= ' >>'; // close TransformParams
13431 // optional digest data (values must be calculated and replaced later)
13432 //$out .= ' /Data ********** 0 R';
13433 //$out .= ' /DigestMethod/MD5';
13434 //$out .= ' /DigestLocation[********** 34]';
13435 //$out .= ' /DigestValue<********************************>';
13437 $out .= ' ]'; // end of reference
13439 if (isset($this->signature_data
['info']['Name']) AND !TCPDF_STATIC
::empty_string($this->signature_data
['info']['Name'])) {
13440 $out .= ' /Name '.$this->_textstring($this->signature_data
['info']['Name'], $sigobjid);
13442 if (isset($this->signature_data
['info']['Location']) AND !TCPDF_STATIC
::empty_string($this->signature_data
['info']['Location'])) {
13443 $out .= ' /Location '.$this->_textstring($this->signature_data
['info']['Location'], $sigobjid);
13445 if (isset($this->signature_data
['info']['Reason']) AND !TCPDF_STATIC
::empty_string($this->signature_data
['info']['Reason'])) {
13446 $out .= ' /Reason '.$this->_textstring($this->signature_data
['info']['Reason'], $sigobjid);
13448 if (isset($this->signature_data
['info']['ContactInfo']) AND !TCPDF_STATIC
::empty_string($this->signature_data
['info']['ContactInfo'])) {
13449 $out .= ' /ContactInfo '.$this->_textstring($this->signature_data
['info']['ContactInfo'], $sigobjid);
13451 $out .= ' /M '.$this->_datestring($sigobjid, $this->doc_modification_timestamp
);
13453 $out .= "\n".'endobj';
13458 * Set User's Rights for PDF Reader
13459 * WARNING: This is experimental and currently do not work.
13460 * Check the PDF Reference 8.7.1 Transform Methods,
13461 * Table 8.105 Entries in the UR transform parameters dictionary
13462 * @param $enable (boolean) if true enable user's rights on PDF reader
13463 * @param $document (string) Names specifying additional document-wide usage rights for the document. The only defined value is "/FullSave", which permits a user to save the document along with modified form and/or annotation data.
13464 * @param $annots (string) Names specifying additional annotation-related usage rights for the document. Valid names in PDF 1.5 and later are /Create/Delete/Modify/Copy/Import/Export, which permit the user to perform the named operation on annotations.
13465 * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
13466 * @param $signature (string) Names specifying additional signature-related usage rights for the document. The only defined value is /Modify, which permits a user to apply a digital signature to an existing signature form field or clear a signed signature form field.
13467 * @param $ef (string) Names specifying additional usage rights for named embedded files in the document. Valid names are /Create/Delete/Modify/Import, which permit the user to perform the named operation on named embedded files
13468 Names specifying additional embedded-files-related usage rights for the document.
13469 * @param $formex (string) Names specifying additional form-field-related usage rights. The only valid name is BarcodePlaintext, which permits text form field data to be encoded as a plaintext two-dimensional barcode.
13471 * @author Nicola Asuni
13472 * @since 2.9.000 (2008-03-26)
13474 public function setUserRights(
13476 $document='/FullSave',
13477 $annots='/Create/Delete/Modify/Copy/Import/Export',
13478 $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
13479 $signature='/Modify',
13480 $ef='/Create/Delete/Modify/Import',
13482 $this->ur
['enabled'] = $enable;
13483 $this->ur
['document'] = $document;
13484 $this->ur
['annots'] = $annots;
13485 $this->ur
['form'] = $form;
13486 $this->ur
['signature'] = $signature;
13487 $this->ur
['ef'] = $ef;
13488 $this->ur
['formex'] = $formex;
13489 if (!$this->sign
) {
13490 $this->setSignature('', '', '', '', 0, array());
13495 * Enable document signature (requires the OpenSSL Library).
13496 * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
13497 * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
13498 * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
13499 * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
13500 * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
13501 * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
13502 * @param $private_key_password (string) password
13503 * @param $extracerts (string) specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.
13504 * @param $cert_type (int) The access permissions granted for this document. Valid values shall be: 1 = No changes to the document shall be permitted; any change to the document shall invalidate the signature; 2 = Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature; 3 = Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
13505 * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
13506 * @param $approval (string) Enable approval signature eg. for PDF incremental update
13508 * @author Nicola Asuni
13509 * @since 4.6.005 (2009-04-24)
13511 public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array(), $approval='') {
13512 // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
13513 // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
13514 // to convert pfx certificate to pem: openssl
13515 // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
13516 $this->sign
= true;
13518 $this->sig_obj_id
= $this->n
; // signature widget
13519 ++
$this->n
; // signature object ($this->sig_obj_id + 1)
13520 $this->signature_data
= array();
13521 if (strlen($signing_cert) == 0) {
13522 $this->Error('Please provide a certificate file and password!');
13524 if (strlen($private_key) == 0) {
13525 $private_key = $signing_cert;
13527 $this->signature_data
['signcert'] = $signing_cert;
13528 $this->signature_data
['privkey'] = $private_key;
13529 $this->signature_data
['password'] = $private_key_password;
13530 $this->signature_data
['extracerts'] = $extracerts;
13531 $this->signature_data
['cert_type'] = $cert_type;
13532 $this->signature_data
['info'] = $info;
13533 $this->signature_data
['approval'] = $approval;
13537 * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
13538 * @param $x (float) Abscissa of the upper-left corner.
13539 * @param $y (float) Ordinate of the upper-left corner.
13540 * @param $w (float) Width of the signature area.
13541 * @param $h (float) Height of the signature area.
13542 * @param $page (int) option page number (if < 0 the current page is used).
13543 * @param $name (string) Name of the signature.
13545 * @author Nicola Asuni
13546 * @since 5.3.011 (2010-06-17)
13548 public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
13549 $this->signature_appearance
= $this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
13553 * Add an empty digital signature appearance (a cliccable rectangle area to get signature properties)
13554 * @param $x (float) Abscissa of the upper-left corner.
13555 * @param $y (float) Ordinate of the upper-left corner.
13556 * @param $w (float) Width of the signature area.
13557 * @param $h (float) Height of the signature area.
13558 * @param $page (int) option page number (if < 0 the current page is used).
13559 * @param $name (string) Name of the signature.
13561 * @author Nicola Asuni
13562 * @since 5.9.101 (2011-07-06)
13564 public function addEmptySignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
13566 $this->empty_signature_appearance
[] = array('objid' => $this->n
) +
$this->getSignatureAppearanceArray($x, $y, $w, $h, $page, $name);
13570 * Get the array that defines the signature appearance (page and rectangle coordinates).
13571 * @param $x (float) Abscissa of the upper-left corner.
13572 * @param $y (float) Ordinate of the upper-left corner.
13573 * @param $w (float) Width of the signature area.
13574 * @param $h (float) Height of the signature area.
13575 * @param $page (int) option page number (if < 0 the current page is used).
13576 * @param $name (string) Name of the signature.
13577 * @return (array) Array defining page and rectangle coordinates of signature appearance.
13579 * @author Nicola Asuni
13580 * @since 5.9.101 (2011-07-06)
13582 protected function getSignatureAppearanceArray($x=0, $y=0, $w=0, $h=0, $page=-1, $name='') {
13584 if (($page < 1) OR ($page > $this->numpages
)) {
13585 $sigapp['page'] = $this->page
;
13587 $sigapp['page'] = intval($page);
13589 if (empty($name)) {
13590 $sigapp['name'] = 'Signature';
13592 $sigapp['name'] = $name;
13594 $a = $x * $this->k
;
13595 $b = $this->pagedim
[($sigapp['page'])]['h'] - (($y +
$h) * $this->k
);
13596 $c = $w * $this->k
;
13597 $d = $h * $this->k
;
13598 $sigapp['rect'] = sprintf('%F %F %F %F', $a, $b, ($a +
$c), ($b +
$d));
13603 * Enable document timestamping (requires the OpenSSL Library).
13604 * The trusted timestamping improve document security that means that no one should be able to change the document once it has been recorded.
13605 * Use with digital signature only!
13606 * @param $tsa_host (string) Time Stamping Authority (TSA) server (prefixed with 'https://')
13607 * @param $tsa_username (string) Specifies the username for TSA authorization (optional) OR specifies the TSA authorization PEM file (see: example_66.php, optional)
13608 * @param $tsa_password (string) Specifies the password for TSA authorization (optional)
13609 * @param $tsa_cert (string) Specifies the location of TSA certificate for authorization (optional for cURL)
13611 * @author Richard Stockinger
13612 * @since 6.0.090 (2014-06-16)
13614 public function setTimeStamp($tsa_host='', $tsa_username='', $tsa_password='', $tsa_cert='') {
13615 $this->tsa_data
= array();
13616 if (!function_exists('curl_init')) {
13617 $this->Error('Please enable cURL PHP extension!');
13619 if (strlen($tsa_host) == 0) {
13620 $this->Error('Please specify the host of Time Stamping Authority (TSA)!');
13622 $this->tsa_data
['tsa_host'] = $tsa_host;
13623 if (is_file($tsa_username)) {
13624 $this->tsa_data
['tsa_auth'] = $tsa_username;
13626 $this->tsa_data
['tsa_username'] = $tsa_username;
13628 $this->tsa_data
['tsa_password'] = $tsa_password;
13629 $this->tsa_data
['tsa_cert'] = $tsa_cert;
13630 $this->tsa_timestamp
= true;
13634 * NOT YET IMPLEMENTED
13635 * Request TSA for a timestamp
13636 * @param $signature (string) Digital signature as binary string
13637 * @return (string) Timestamped digital signature
13639 * @author Richard Stockinger
13640 * @since 6.0.090 (2014-06-16)
13642 protected function applyTSA($signature) {
13643 if (!$this->tsa_timestamp
) {
13646 //@TODO: implement this feature
13651 * Create a new page group.
13652 * NOTE: call this function before calling AddPage()
13653 * @param $page (int) starting group page (leave empty for next page).
13655 * @since 3.0.000 (2008-03-27)
13657 public function startPageGroup($page='') {
13658 if (empty($page)) {
13659 $page = $this->page +
1;
13661 $this->newpagegroup
[$page] = sizeof($this->newpagegroup
) +
1;
13665 * Set the starting page number.
13666 * @param $num (int) Starting page number.
13667 * @since 5.9.093 (2011-06-16)
13670 public function setStartingPageNumber($num=1) {
13671 $this->starting_page_number
= max(0, intval($num));
13675 * Returns the string alias used right align page numbers.
13676 * If the current font is unicode type, the returned string wil contain an additional open curly brace.
13678 * @since 5.9.099 (2011-06-27)
13681 public function getAliasRightShift() {
13682 // calculate aproximatively the ratio between widths of aliases and replacements.
13683 $ref = '{'.TCPDF_STATIC
::$alias_right_shift.'}{'.TCPDF_STATIC
::$alias_tot_pages.'}{'.TCPDF_STATIC
::$alias_num_page.'}';
13684 $rep = str_repeat(' ', $this->GetNumChars($ref));
13685 $wrep = $this->GetStringWidth($rep);
13687 $wdiff = max(1, ($this->GetStringWidth($ref) / $wrep));
13691 $sdiff = sprintf('%F', $wdiff);
13692 $alias = TCPDF_STATIC
::$alias_right_shift.$sdiff.'}';
13693 if ($this->isUnicodeFont()) {
13694 $alias = '{'.$alias;
13700 * Returns the string alias used for the total number of pages.
13701 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13702 * This alias will be replaced by the total number of pages in the document.
13704 * @since 4.0.018 (2008-08-08)
13707 public function getAliasNbPages() {
13708 if ($this->isUnicodeFont()) {
13709 return '{'.TCPDF_STATIC
::$alias_tot_pages.'}';
13711 return TCPDF_STATIC
::$alias_tot_pages;
13715 * Returns the string alias used for the page number.
13716 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13717 * This alias will be replaced by the page number.
13719 * @since 4.5.000 (2009-01-02)
13722 public function getAliasNumPage() {
13723 if ($this->isUnicodeFont()) {
13724 return '{'.TCPDF_STATIC
::$alias_num_page.'}';
13726 return TCPDF_STATIC
::$alias_num_page;
13730 * Return the alias for the total number of pages in the current page group.
13731 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13732 * This alias will be replaced by the total number of pages in this group.
13733 * @return alias of the current page group
13735 * @since 3.0.000 (2008-03-27)
13737 public function getPageGroupAlias() {
13738 if ($this->isUnicodeFont()) {
13739 return '{'.TCPDF_STATIC
::$alias_group_tot_pages.'}';
13741 return TCPDF_STATIC
::$alias_group_tot_pages;
13745 * Return the alias for the page number on the current page group.
13746 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
13747 * This alias will be replaced by the page number (relative to the belonging group).
13748 * @return alias of the current page group
13750 * @since 4.5.000 (2009-01-02)
13752 public function getPageNumGroupAlias() {
13753 if ($this->isUnicodeFont()) {
13754 return '{'.TCPDF_STATIC
::$alias_group_num_page.'}';
13756 return TCPDF_STATIC
::$alias_group_num_page;
13760 * Return the current page in the group.
13761 * @return current page in the group
13763 * @since 3.0.000 (2008-03-27)
13765 public function getGroupPageNo() {
13766 return $this->pagegroups
[$this->currpagegroup
];
13770 * Returns the current group page number formatted as a string.
13772 * @since 4.3.003 (2008-11-18)
13773 * @see PaneNo(), formatPageNumber()
13775 public function getGroupPageNoFormatted() {
13776 return TCPDF_STATIC
::formatPageNumber($this->getGroupPageNo());
13780 * Returns the current page number formatted as a string.
13782 * @since 4.2.005 (2008-11-06)
13783 * @see PaneNo(), formatPageNumber()
13785 public function PageNoFormatted() {
13786 return TCPDF_STATIC
::formatPageNumber($this->PageNo());
13792 * @since 3.0.000 (2008-03-27)
13794 protected function _putocg() {
13795 if (empty($this->pdflayers
)) {
13798 foreach ($this->pdflayers
as $key => $layer) {
13799 $this->pdflayers
[$key]['objid'] = $this->_newobj();
13800 $out = '<< /Type /OCG';
13801 $out .= ' /Name '.$this->_textstring($layer['name'], $this->pdflayers
[$key]['objid']);
13802 $out .= ' /Usage <<';
13803 if (isset($layer['print']) AND ($layer['print'] !== NULL)) {
13804 $out .= ' /Print <</PrintState /'.($layer['print']?
'ON':'OFF').'>>';
13806 $out .= ' /View <</ViewState /'.($layer['view']?
'ON':'OFF').'>>';
13808 $out .= "\n".'endobj';
13814 * Start a new pdf layer.
13815 * @param $name (string) Layer name (only a-z letters and numbers). Leave empty for automatic name.
13816 * @param $print (boolean|null) Set to TRUE to print this layer, FALSE to not print and NULL to not set this option
13817 * @param $view (boolean) Set to true to view this layer.
13818 * @param $lock (boolean) If true lock the layer
13820 * @since 5.9.102 (2011-07-13)
13822 public function startLayer($name='', $print=true, $view=true, $lock=true) {
13823 if ($this->state
!= 2) {
13826 $layer = sprintf('LYR%03d', (count($this->pdflayers
) +
1));
13827 if (empty($name)) {
13830 $name = preg_replace('/[^a-zA-Z0-9_\-]/', '', $name);
13832 $this->pdflayers
[] = array('layer' => $layer, 'name' => $name, 'print' => $print, 'view' => $view, 'lock' => $lock);
13833 $this->openMarkedContent
= true;
13834 $this->_out('/OC /'.$layer.' BDC');
13838 * End the current PDF layer.
13840 * @since 5.9.102 (2011-07-13)
13842 public function endLayer() {
13843 if ($this->state
!= 2) {
13846 if ($this->openMarkedContent
) {
13847 // close existing open marked-content layer
13848 $this->_out('EMC');
13849 $this->openMarkedContent
= false;
13854 * Set the visibility of the successive elements.
13855 * This can be useful, for instance, to put a background
13856 * image or color that will show on screen but won't print.
13857 * @param $v (string) visibility mode. Legal values are: all, print, screen or view.
13859 * @since 3.0.000 (2008-03-27)
13861 public function setVisibility($v) {
13862 if ($this->state
!= 2) {
13868 $this->startLayer('Print', true, false);
13873 $this->startLayer('View', false, true);
13881 $this->Error('Incorrect visibility: '.$v);
13888 * Add transparency parameters to the current extgstate
13889 * @param $parms (array) parameters
13890 * @return the number of extgstates
13892 * @since 3.0.000 (2008-03-27)
13894 protected function addExtGState($parms) {
13895 if ($this->pdfa_mode
) {
13896 // transparencies are not allowed in PDF/A mode
13899 // check if this ExtGState already exist
13900 foreach ($this->extgstates
as $i => $ext) {
13901 if ($ext['parms'] == $parms) {
13902 if ($this->inxobj
) {
13903 // we are inside an XObject template
13904 $this->xobjects
[$this->xobjid
]['extgstates'][$i] = $ext;
13906 // return reference to existing ExtGState
13910 $n = (count($this->extgstates
) +
1);
13911 $this->extgstates
[$n] = array('parms' => $parms);
13912 if ($this->inxobj
) {
13913 // we are inside an XObject template
13914 $this->xobjects
[$this->xobjid
]['extgstates'][$n] = $this->extgstates
[$n];
13921 * @param $gs (array) extgstate
13923 * @since 3.0.000 (2008-03-27)
13925 protected function setExtGState($gs) {
13926 if ($this->pdfa_mode
OR ($this->state
!= 2)) {
13927 // transparency is not allowed in PDF/A mode
13930 $this->_out(sprintf('/GS%d gs', $gs));
13934 * Put extgstates for object transparency
13936 * @since 3.0.000 (2008-03-27)
13938 protected function _putextgstates() {
13939 foreach ($this->extgstates
as $i => $ext) {
13940 $this->extgstates
[$i]['n'] = $this->_newobj();
13941 $out = '<< /Type /ExtGState';
13942 foreach ($ext['parms'] as $k => $v) {
13943 if (is_float($v)) {
13944 $v = sprintf('%F', $v);
13945 } elseif ($v === true) {
13947 } elseif ($v === false) {
13950 $out .= ' /'.$k.' '.$v;
13953 $out .= "\n".'endobj';
13959 * Set overprint mode for stroking (OP) and non-stroking (op) painting operations.
13960 * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
13961 * @param $stroking (boolean) If true apply overprint for stroking operations.
13962 * @param $nonstroking (boolean) If true apply overprint for painting operations other than stroking.
13963 * @param $mode (integer) Overprint mode: (0 = each source colour component value replaces the value previously painted for the corresponding device colorant; 1 = a tint value of 0.0 for a source colour component shall leave the corresponding component of the previously painted colour unchanged).
13965 * @since 5.9.152 (2012-03-23)
13967 public function setOverprint($stroking=true, $nonstroking='', $mode=0) {
13968 if ($this->state
!= 2) {
13971 $stroking = $stroking ?
true : false;
13972 if (TCPDF_STATIC
::empty_string($nonstroking)) {
13973 // default value if not set
13974 $nonstroking = $stroking;
13976 $nonstroking = $nonstroking ?
true : false;
13978 if (($mode != 0) AND ($mode != 1)) {
13981 $this->overprint
= array('OP' => $stroking, 'op' => $nonstroking, 'OPM' => $mode);
13982 $gs = $this->addExtGState($this->overprint
);
13983 $this->setExtGState($gs);
13987 * Get the overprint mode array (OP, op, OPM).
13988 * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
13991 * @since 5.9.152 (2012-03-23)
13993 public function getOverprint() {
13994 return $this->overprint
;
13998 * Set alpha for stroking (CA) and non-stroking (ca) operations.
13999 * @param $stroking (float) Alpha value for stroking operations: real value from 0 (transparent) to 1 (opaque).
14000 * @param $bm (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
14001 * @param $nonstroking (float) Alpha value for non-stroking operations: real value from 0 (transparent) to 1 (opaque).
14002 * @param $ais (boolean)
14004 * @since 3.0.000 (2008-03-27)
14006 public function setAlpha($stroking=1, $bm='Normal', $nonstroking='', $ais=false) {
14007 if ($this->pdfa_mode
) {
14008 // transparency is not allowed in PDF/A mode
14011 $stroking = floatval($stroking);
14012 if (TCPDF_STATIC
::empty_string($nonstroking)) {
14013 // default value if not set
14014 $nonstroking = $stroking;
14016 $nonstroking = floatval($nonstroking);
14018 if ($bm[0] == '/') {
14019 // remove trailing slash
14020 $bm = substr($bm, 1);
14022 if (!in_array($bm, array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
14025 $ais = $ais ?
true : false;
14026 $this->alpha
= array('CA' => $stroking, 'ca' => $nonstroking, 'BM' => '/'.$bm, 'AIS' => $ais);
14027 $gs = $this->addExtGState($this->alpha
);
14028 $this->setExtGState($gs);
14032 * Get the alpha mode array (CA, ca, BM, AIS).
14033 * (Check the "Entries in a Graphics State Parameter Dictionary" on PDF 32000-1:2008).
14036 * @since 5.9.152 (2012-03-23)
14038 public function getAlpha() {
14039 return $this->alpha
;
14043 * Set the default JPEG compression quality (1-100)
14044 * @param $quality (int) JPEG quality, integer between 1 and 100
14046 * @since 3.0.000 (2008-03-27)
14048 public function setJPEGQuality($quality) {
14049 if (($quality < 1) OR ($quality > 100)) {
14052 $this->jpeg_quality
= intval($quality);
14056 * Set the default number of columns in a row for HTML tables.
14057 * @param $cols (int) number of columns
14059 * @since 3.0.014 (2008-06-04)
14061 public function setDefaultTableColumns($cols=4) {
14062 $this->default_table_columns
= intval($cols);
14066 * Set the height of the cell (line height) respect the font height.
14067 * @param $h (int) cell proportion respect font height (typical value = 1.25).
14069 * @since 3.0.014 (2008-06-04)
14071 public function setCellHeightRatio($h) {
14072 $this->cell_height_ratio
= $h;
14076 * return the height of cell repect font height.
14078 * @since 4.0.012 (2008-07-24)
14080 public function getCellHeightRatio() {
14081 return $this->cell_height_ratio
;
14085 * Set the PDF version (check PDF reference for valid values).
14086 * @param $version (string) PDF document version.
14088 * @since 3.1.000 (2008-06-09)
14090 public function setPDFVersion($version='1.7') {
14091 if ($this->pdfa_mode
&& $this->pdfa_version
== 1 ) {
14093 $this->PDFVersion
= '1.4';
14095 $this->PDFVersion
= $version;
14100 * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
14101 * (see Section 8.1 of PDF reference, "Viewer Preferences").
14102 * <ul><li>HideToolbar boolean (Optional) A flag specifying whether to hide the viewer application's tool bars when the document is active. Default value: false.</li><li>HideMenubar boolean (Optional) A flag specifying whether to hide the viewer application's menu bar when the document is active. Default value: false.</li><li>HideWindowUI boolean (Optional) A flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed. Default value: false.</li><li>FitWindow boolean (Optional) A flag specifying whether to resize the document's window to fit the size of the first displayed page. Default value: false.</li><li>CenterWindow boolean (Optional) A flag specifying whether to position the document's window in the center of the screen. Default value: false.</li><li>DisplayDocTitle boolean (Optional; PDF 1.4) A flag specifying whether the window's title bar should display the document title taken from the Title entry of the document information dictionary (see Section 10.2.1, "Document Information Dictionary"). If false, the title bar should instead display the name of the PDF file containing the document. Default value: false.</li><li>NonFullScreenPageMode name (Optional) The document's page mode, specifying how to display the document on exiting full-screen mode:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>UseOC Optional content group panel visible</li></ul>This entry is meaningful only if the value of the PageMode entry in the catalog dictionary (see Section 3.6.1, "Document Catalog") is FullScreen; it is ignored otherwise. Default value: UseNone.</li><li>ViewArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be displayed when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>ViewClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when viewing the document on the screen. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>PrintArea name (Optional; PDF 1.4) The name of the page boundary representing the area of a page to be rendered when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>PrintClip name (Optional; PDF 1.4) The name of the page boundary to which the contents of a page are to be clipped when printing the document. Valid values are (see Section 10.10.1, "Page Boundaries").:<ul><li>MediaBox</li><li>CropBox (default)</li><li>BleedBox</li><li>TrimBox</li><li>ArtBox</li></ul></li><li>PrintScaling name (Optional; PDF 1.6) The page scaling option to be selected when a print dialog is displayed for this document. Valid values are: <ul><li>None, which indicates that the print dialog should reflect no page scaling</li><li>AppDefault (default), which indicates that applications should use the current print scaling</li></ul></li><li>Duplex name (Optional; PDF 1.7) The paper handling option to use when printing the file from the print dialog. The following values are valid:<ul><li>Simplex - Print single-sided</li><li>DuplexFlipShortEdge - Duplex and flip on the short edge of the sheet</li><li>DuplexFlipLongEdge - Duplex and flip on the long edge of the sheet</li></ul>Default value: none</li><li>PickTrayByPDFSize boolean (Optional; PDF 1.7) A flag specifying whether the PDF page size is used to select the input paper tray. This setting influences only the preset values used to populate the print dialog presented by a PDF viewer application. If PickTrayByPDFSize is true, the check box in the print dialog associated with input paper tray is checked. Note: This setting has no effect on Mac OS systems, which do not provide the ability to pick the input tray by size.</li><li>PrintPageRange array (Optional; PDF 1.7) The page numbers used to initialize the print dialog box when the file is printed. The first page of the PDF file is denoted by 1. Each pair consists of the first and last pages in the sub-range. An odd number of integers causes this entry to be ignored. Negative numbers cause the entire array to be ignored. Default value: as defined by PDF viewer application</li><li>NumCopies integer (Optional; PDF 1.7) The number of copies to be printed when the print dialog is opened for this file. Supported values are the integers 2 through 5. Values outside this range are ignored. Default value: as defined by PDF viewer application, but typically 1</li></ul>
14103 * @param $preferences (array) array of options.
14104 * @author Nicola Asuni
14106 * @since 3.1.000 (2008-06-09)
14108 public function setViewerPreferences($preferences) {
14109 $this->viewer_preferences
= $preferences;
14113 * Paints color transition registration bars
14114 * @param $x (float) abscissa of the top left corner of the rectangle.
14115 * @param $y (float) ordinate of the top left corner of the rectangle.
14116 * @param $w (float) width of the rectangle.
14117 * @param $h (float) height of the rectangle.
14118 * @param $transition (boolean) if true prints tcolor transitions to white.
14119 * @param $vertical (boolean) if true prints bar vertically.
14120 * @param $colors (string) colors to print separated by comma. Valid values are: A,W,R,G,B,C,M,Y,K,RGB,CMYK,ALL,ALLSPOT,<SPOT_COLOR_NAME>. Where: A = grayscale black, W = grayscale white, R = RGB red, G RGB green, B RGB blue, C = CMYK cyan, M = CMYK magenta, Y = CMYK yellow, K = CMYK key/black, RGB = RGB registration color, CMYK = CMYK registration color, ALL = Spot registration color, ALLSPOT = print all defined spot colors, <SPOT_COLOR_NAME> = name of the spot color to print.
14121 * @author Nicola Asuni
14122 * @since 4.9.000 (2010-03-26)
14125 public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
14126 if (strpos($colors, 'ALLSPOT') !== false) {
14127 // expand spot colors
14129 foreach ($this->spot_colors
as $spot_color_name => $v) {
14130 $spot_colors .= ','.$spot_color_name;
14132 if (!empty($spot_colors)) {
14133 $spot_colors = substr($spot_colors, 1);
14134 $colors = str_replace('ALLSPOT', $spot_colors, $colors);
14136 $colors = str_replace('ALLSPOT', 'NONE', $colors);
14139 $bars = explode(',', $colors);
14140 $numbars = count($bars); // number of bars to print
14141 if ($numbars <= 0) {
14144 // set bar measures
14146 $coords = array(0, 0, 0, 1);
14147 $wb = $w / $numbars; // bar width
14148 $hb = $h; // bar height
14149 $xd = $wb; // delta x
14150 $yd = 0; // delta y
14152 $coords = array(1, 0, 0, 0);
14153 $wb = $w; // bar width
14154 $hb = $h / $numbars; // bar height
14155 $xd = 0; // delta x
14156 $yd = $hb; // delta y
14160 foreach ($bars as $col) {
14162 // set transition colors
14163 case 'A': { // BLACK (GRAYSCALE)
14164 $col_a = array(255);
14168 case 'W': { // WHITE (GRAYSCALE)
14170 $col_b = array(255);
14173 case 'R': { // RED (RGB)
14174 $col_a = array(255,255,255);
14175 $col_b = array(255,0,0);
14178 case 'G': { // GREEN (RGB)
14179 $col_a = array(255,255,255);
14180 $col_b = array(0,255,0);
14183 case 'B': { // BLUE (RGB)
14184 $col_a = array(255,255,255);
14185 $col_b = array(0,0,255);
14188 case 'C': { // CYAN (CMYK)
14189 $col_a = array(0,0,0,0);
14190 $col_b = array(100,0,0,0);
14193 case 'M': { // MAGENTA (CMYK)
14194 $col_a = array(0,0,0,0);
14195 $col_b = array(0,100,0,0);
14198 case 'Y': { // YELLOW (CMYK)
14199 $col_a = array(0,0,0,0);
14200 $col_b = array(0,0,100,0);
14203 case 'K': { // KEY - BLACK (CMYK)
14204 $col_a = array(0,0,0,0);
14205 $col_b = array(0,0,0,100);
14208 case 'RGB': { // BLACK REGISTRATION (RGB)
14209 $col_a = array(255,255,255);
14210 $col_b = array(0,0,0);
14213 case 'CMYK': { // BLACK REGISTRATION (CMYK)
14214 $col_a = array(0,0,0,0);
14215 $col_b = array(100,100,100,100);
14218 case 'ALL': { // SPOT COLOR REGISTRATION
14219 $col_a = array(0,0,0,0,'None');
14220 $col_b = array(100,100,100,100,'All');
14223 case 'NONE': { // SKIP THIS COLOR
14224 $col_a = array(0,0,0,0,'None');
14225 $col_b = array(0,0,0,0,'None');
14228 default: { // SPECIFIC SPOT COLOR NAME
14229 $col_a = array(0,0,0,0,'None');
14230 $col_b = TCPDF_COLORS
::getSpotColor($col, $this->spot_colors
);
14231 if ($col_b === false) {
14232 // in case of error defaults to the registration color
14233 $col_b = array(100,100,100,100,'All');
14238 if ($col != 'NONE') {
14241 $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
14243 $this->SetFillColorArray($col_b);
14244 // colored rectangle
14245 $this->Rect($xb, $yb, $wb, $hb, 'F', array());
14254 * Paints crop marks.
14255 * @param $x (float) abscissa of the crop mark center.
14256 * @param $y (float) ordinate of the crop mark center.
14257 * @param $w (float) width of the crop mark.
14258 * @param $h (float) height of the crop mark.
14259 * @param $type (string) type of crop mark, one symbol per type separated by comma: T = TOP, F = BOTTOM, L = LEFT, R = RIGHT, TL = A = TOP-LEFT, TR = B = TOP-RIGHT, BL = C = BOTTOM-LEFT, BR = D = BOTTOM-RIGHT.
14260 * @param $color (array) crop mark color (default spot registration color).
14261 * @author Nicola Asuni
14262 * @since 4.9.000 (2010-03-26)
14265 public function cropMark($x, $y, $w, $h, $type='T,R,B,L', $color=array(100,100,100,100,'All')) {
14266 $this->SetLineStyle(array('width' => (0.5 / $this->k
), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
14267 $type = strtoupper($type);
14268 $type = preg_replace('/[^A-Z\-\,]*/', '', $type);
14269 // split type in single components
14270 $type = str_replace('-', ',', $type);
14271 $type = str_replace('TL', 'T,L', $type);
14272 $type = str_replace('TR', 'T,R', $type);
14273 $type = str_replace('BL', 'F,L', $type);
14274 $type = str_replace('BR', 'F,R', $type);
14275 $type = str_replace('A', 'T,L', $type);
14276 $type = str_replace('B', 'T,R', $type);
14277 $type = str_replace('T,RO', 'BO', $type);
14278 $type = str_replace('C', 'F,L', $type);
14279 $type = str_replace('D', 'F,R', $type);
14280 $crops = explode(',', strtoupper($type));
14281 // remove duplicates
14282 $crops = array_unique($crops);
14283 $dw = ($w / 4); // horizontal space to leave before the intersection point
14284 $dh = ($h / 4); // vertical space to leave before the intersection point
14285 foreach ($crops as $crop) {
14320 $this->Line($x1, $y1, $x2, $y2);
14325 * Paints a registration mark
14326 * @param $x (float) abscissa of the registration mark center.
14327 * @param $y (float) ordinate of the registration mark center.
14328 * @param $r (float) radius of the crop mark.
14329 * @param $double (boolean) if true print two concentric crop marks.
14330 * @param $cola (array) crop mark color (default spot registration color 'All').
14331 * @param $colb (array) second crop mark color (default spot registration color 'None').
14332 * @author Nicola Asuni
14333 * @since 4.9.000 (2010-03-26)
14336 public function registrationMark($x, $y, $r, $double=false, $cola=array(100,100,100,100,'All'), $colb=array(0,0,0,0,'None')) {
14337 $line_style = array('width' => max((0.5 / $this->k
),($r / 30)), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
14338 $this->SetFillColorArray($cola);
14339 $this->PieSector($x, $y, $r, 90, 180, 'F');
14340 $this->PieSector($x, $y, $r, 270, 360, 'F');
14341 $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
14344 $this->SetFillColorArray($colb);
14345 $this->PieSector($x, $y, $ri, 90, 180, 'F');
14346 $this->PieSector($x, $y, $ri, 270, 360, 'F');
14347 $this->SetFillColorArray($cola);
14348 $this->PieSector($x, $y, $ri, 0, 90, 'F');
14349 $this->PieSector($x, $y, $ri, 180, 270, 'F');
14350 $this->Circle($x, $y, $ri, 0, 360, 'C', $line_style, array(), 8);
14355 * Paints a CMYK registration mark
14356 * @param $x (float) abscissa of the registration mark center.
14357 * @param $y (float) ordinate of the registration mark center.
14358 * @param $r (float) radius of the crop mark.
14359 * @author Nicola Asuni
14360 * @since 6.0.038 (2013-09-30)
14363 public function registrationMarkCMYK($x, $y, $r) {
14365 $lw = max((0.5 / $this->k
),($r / 8));
14371 $this->SetFillColorArray(array(100,0,0,0));
14372 $this->PieSector($x, $y, $ri, 270, 360, 'F');
14374 $this->SetFillColorArray(array(0,100,0,0));
14375 $this->PieSector($x, $y, $ri, 0, 90, 'F');
14377 $this->SetFillColorArray(array(0,0,100,0));
14378 $this->PieSector($x, $y, $ri, 90, 180, 'F');
14380 $this->SetFillColorArray(array(0,0,0,100));
14381 $this->PieSector($x, $y, $ri, 180, 270, 'F');
14382 // registration color
14383 $line_style = array('width' => $lw, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(100,100,100,100,'All'));
14384 $this->SetFillColorArray(array(100,100,100,100,'All'));
14386 $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
14388 $this->Line($x, ($y - $re), $x, ($y - $ri));
14389 $this->Line($x, ($y +
$ri), $x, ($y +
$re));
14390 $this->Line(($x - $re), $y, ($x - $ri), $y);
14391 $this->Line(($x +
$ri), $y, ($x +
$re), $y);
14395 * Paints a linear colour gradient.
14396 * @param $x (float) abscissa of the top left corner of the rectangle.
14397 * @param $y (float) ordinate of the top left corner of the rectangle.
14398 * @param $w (float) width of the rectangle.
14399 * @param $h (float) height of the rectangle.
14400 * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
14401 * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
14402 * @param $coords (array) array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg). The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
14403 * @author Andreas W\FCrmser, Nicola Asuni
14404 * @since 3.1.000 (2008-06-09)
14407 public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
14408 $this->Clip($x, $y, $w, $h);
14409 $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
14413 * Paints a radial colour gradient.
14414 * @param $x (float) abscissa of the top left corner of the rectangle.
14415 * @param $y (float) ordinate of the top left corner of the rectangle.
14416 * @param $w (float) width of the rectangle.
14417 * @param $h (float) height of the rectangle.
14418 * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
14419 * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
14420 * @param $coords (array) array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1, (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg). (fx, fy) should be inside the circle, otherwise some areas will not be defined.
14421 * @author Andreas W\FCrmser, Nicola Asuni
14422 * @since 3.1.000 (2008-06-09)
14425 public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
14426 $this->Clip($x, $y, $w, $h);
14427 $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
14431 * Paints a coons patch mesh.
14432 * @param $x (float) abscissa of the top left corner of the rectangle.
14433 * @param $y (float) ordinate of the top left corner of the rectangle.
14434 * @param $w (float) width of the rectangle.
14435 * @param $h (float) height of the rectangle.
14436 * @param $col1 (array) first color (lower left corner) (RGB components).
14437 * @param $col2 (array) second color (lower right corner) (RGB components).
14438 * @param $col3 (array) third color (upper right corner) (RGB components).
14439 * @param $col4 (array) fourth color (upper left corner) (RGB components).
14440 * @param $coords (array) <ul><li>for one patch mesh: array(float x1, float y1, .... float x12, float y12): 12 pairs of coordinates (normally from 0 to 1) which specify the Bezier control points that define the patch. First pair is the lower left edge point, next is its right control point (control point 2). Then the other points are defined in the order: control point 1, edge point, control point 2 going counter-clockwise around the patch. Last (x12, y12) is the first edge point's left control point (control point 1).</li><li>for two or more patch meshes: array[number of patches]: arrays with the following keys for each patch: f: where to put that patch (0 = first patch, 1, 2, 3 = right, top and left of precedent patch - I didn't figure this out completely - just try and error ;-) points: 12 pairs of coordinates of the Bezier control points as above for the first patch, 8 pairs of coordinates for the following patches, ignoring the coordinates already defined by the precedent patch (I also didn't figure out the order of these - also: try and see what's happening) colors: must be 4 colors for the first patch, 2 colors for the following patches</li></ul>
14441 * @param $coords_min (array) minimum value used by the coordinates. If a coordinate's value is smaller than this it will be cut to coords_min. default: 0
14442 * @param $coords_max (array) maximum value used by the coordinates. If a coordinate's value is greater than this it will be cut to coords_max. default: 1
14443 * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
14444 * @author Andreas W\FCrmser, Nicola Asuni
14445 * @since 3.1.000 (2008-06-09)
14448 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, $antialias=false) {
14449 if ($this->pdfa_mode
OR ($this->state
!= 2)) {
14452 $this->Clip($x, $y, $w, $h);
14453 $n = count($this->gradients
) +
1;
14454 $this->gradients
[$n] = array();
14455 $this->gradients
[$n]['type'] = 6; //coons patch mesh
14456 $this->gradients
[$n]['coords'] = array();
14457 $this->gradients
[$n]['antialias'] = $antialias;
14458 $this->gradients
[$n]['colors'] = array();
14459 $this->gradients
[$n]['transparency'] = false;
14460 //check the coords array if it is the simple array or the multi patch array
14461 if (!isset($coords[0]['f'])) {
14462 //simple array -> convert to multi patch array
14463 if (!isset($col1[1])) {
14464 $col1[1] = $col1[2] = $col1[0];
14466 if (!isset($col2[1])) {
14467 $col2[1] = $col2[2] = $col2[0];
14469 if (!isset($col3[1])) {
14470 $col3[1] = $col3[2] = $col3[0];
14472 if (!isset($col4[1])) {
14473 $col4[1] = $col4[2] = $col4[0];
14475 $patch_array[0]['f'] = 0;
14476 $patch_array[0]['points'] = $coords;
14477 $patch_array[0]['colors'][0]['r'] = $col1[0];
14478 $patch_array[0]['colors'][0]['g'] = $col1[1];
14479 $patch_array[0]['colors'][0]['b'] = $col1[2];
14480 $patch_array[0]['colors'][1]['r'] = $col2[0];
14481 $patch_array[0]['colors'][1]['g'] = $col2[1];
14482 $patch_array[0]['colors'][1]['b'] = $col2[2];
14483 $patch_array[0]['colors'][2]['r'] = $col3[0];
14484 $patch_array[0]['colors'][2]['g'] = $col3[1];
14485 $patch_array[0]['colors'][2]['b'] = $col3[2];
14486 $patch_array[0]['colors'][3]['r'] = $col4[0];
14487 $patch_array[0]['colors'][3]['g'] = $col4[1];
14488 $patch_array[0]['colors'][3]['b'] = $col4[2];
14490 //multi patch array
14491 $patch_array = $coords;
14493 $bpcd = 65535; //16 bits per coordinate
14494 //build the data stream
14495 $this->gradients
[$n]['stream'] = '';
14496 $count_patch = count($patch_array);
14497 for ($i=0; $i < $count_patch; ++
$i) {
14498 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
14499 $count_points = count($patch_array[$i]['points']);
14500 for ($j=0; $j < $count_points; ++
$j) {
14501 //each point as 16 bit
14502 $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
14503 if ($patch_array[$i]['points'][$j] < 0) {
14504 $patch_array[$i]['points'][$j] = 0;
14506 if ($patch_array[$i]['points'][$j] > $bpcd) {
14507 $patch_array[$i]['points'][$j] = $bpcd;
14509 $this->gradients
[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
14510 $this->gradients
[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] %
256));
14512 $count_cols = count($patch_array[$i]['colors']);
14513 for ($j=0; $j < $count_cols; ++
$j) {
14514 //each color component as 8 bit
14515 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
14516 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
14517 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
14520 //paint the gradient
14521 $this->_out('/Sh'.$n.' sh');
14522 //restore previous Graphic State
14523 $this->_outRestoreGraphicsState();
14524 if ($this->inxobj
) {
14525 // we are inside an XObject template
14526 $this->xobjects
[$this->xobjid
]['gradients'][$n] = $this->gradients
[$n];
14531 * Set a rectangular clipping area.
14532 * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
14533 * @param $y (float) ordinate of the top left corner of the rectangle.
14534 * @param $w (float) width of the rectangle.
14535 * @param $h (float) height of the rectangle.
14536 * @author Andreas W\FCrmser, Nicola Asuni
14537 * @since 3.1.000 (2008-06-09)
14540 protected function Clip($x, $y, $w, $h) {
14541 if ($this->state
!= 2) {
14545 $x = $this->w
- $x - $w;
14547 //save current Graphic State
14549 //set clipping area
14550 $s .= sprintf(' %F %F %F %F re W n', $x*$this->k
, ($this->h
-$y)*$this->k
, $w*$this->k
, -$h*$this->k
);
14551 //set up transformation matrix for gradient
14552 $s .= sprintf(' %F 0 0 %F %F %F cm', $w*$this->k
, $h*$this->k
, $x*$this->k
, ($this->h
-($y+
$h))*$this->k
);
14558 * @param $type (int) type of gradient (1 Function-based shading; 2 Axial shading; 3 Radial shading; 4 Free-form Gouraud-shaded triangle mesh; 5 Lattice-form Gouraud-shaded triangle mesh; 6 Coons patch mesh; 7 Tensor-product patch mesh). (Not all types are currently supported)
14559 * @param $coords (array) array of coordinates.
14560 * @param $stops (array) array gradient color components: color = array of GRAY, RGB or CMYK color components; offset = (0 to 1) represents a location along the gradient vector; exponent = exponent of the exponential interpolation function (default = 1).
14561 * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
14562 * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
14563 * @author Nicola Asuni
14564 * @since 3.1.000 (2008-06-09)
14567 public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
14568 if ($this->pdfa_mode
OR ($this->state
!= 2)) {
14571 $n = count($this->gradients
) +
1;
14572 $this->gradients
[$n] = array();
14573 $this->gradients
[$n]['type'] = $type;
14574 $this->gradients
[$n]['coords'] = $coords;
14575 $this->gradients
[$n]['antialias'] = $antialias;
14576 $this->gradients
[$n]['colors'] = array();
14577 $this->gradients
[$n]['transparency'] = false;
14579 $numcolspace = count($stops[0]['color']);
14580 $bcolor = array_values($background);
14581 switch($numcolspace) {
14584 $this->gradients
[$n]['colspace'] = 'DeviceCMYK';
14585 if (!empty($background)) {
14586 $this->gradients
[$n]['background'] = sprintf('%F %F %F %F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
14591 $this->gradients
[$n]['colspace'] = 'DeviceRGB';
14592 if (!empty($background)) {
14593 $this->gradients
[$n]['background'] = sprintf('%F %F %F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
14597 case 1: { // GRAY SCALE
14598 $this->gradients
[$n]['colspace'] = 'DeviceGray';
14599 if (!empty($background)) {
14600 $this->gradients
[$n]['background'] = sprintf('%F', $bcolor[0]/255);
14605 $num_stops = count($stops);
14606 $last_stop_id = $num_stops - 1;
14607 foreach ($stops as $key => $stop) {
14608 $this->gradients
[$n]['colors'][$key] = array();
14609 // offset represents a location along the gradient vector
14610 if (isset($stop['offset'])) {
14611 $this->gradients
[$n]['colors'][$key]['offset'] = $stop['offset'];
14614 $this->gradients
[$n]['colors'][$key]['offset'] = 0;
14615 } elseif ($key == $last_stop_id) {
14616 $this->gradients
[$n]['colors'][$key]['offset'] = 1;
14618 $offsetstep = (1 - $this->gradients
[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
14619 $this->gradients
[$n]['colors'][$key]['offset'] = $this->gradients
[$n]['colors'][($key - 1)]['offset'] +
$offsetstep;
14622 if (isset($stop['opacity'])) {
14623 $this->gradients
[$n]['colors'][$key]['opacity'] = $stop['opacity'];
14624 if ((!$this->pdfa_mode
) AND ($stop['opacity'] < 1)) {
14625 $this->gradients
[$n]['transparency'] = true;
14628 $this->gradients
[$n]['colors'][$key]['opacity'] = 1;
14630 // exponent for the exponential interpolation function
14631 if (isset($stop['exponent'])) {
14632 $this->gradients
[$n]['colors'][$key]['exponent'] = $stop['exponent'];
14634 $this->gradients
[$n]['colors'][$key]['exponent'] = 1;
14637 $color = array_values($stop['color']);
14638 switch($numcolspace) {
14641 $this->gradients
[$n]['colors'][$key]['color'] = sprintf('%F %F %F %F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
14645 $this->gradients
[$n]['colors'][$key]['color'] = sprintf('%F %F %F', $color[0]/255, $color[1]/255, $color[2]/255);
14648 case 1: { // GRAY SCALE
14649 $this->gradients
[$n]['colors'][$key]['color'] = sprintf('%F', $color[0]/255);
14654 if ($this->gradients
[$n]['transparency']) {
14655 // paint luminosity gradient
14656 $this->_out('/TGS'.$n.' gs');
14658 //paint the gradient
14659 $this->_out('/Sh'.$n.' sh');
14660 //restore previous Graphic State
14661 $this->_outRestoreGraphicsState();
14662 if ($this->inxobj
) {
14663 // we are inside an XObject template
14664 $this->xobjects
[$this->xobjid
]['gradients'][$n] = $this->gradients
[$n];
14669 * Output gradient shaders.
14670 * @author Nicola Asuni
14671 * @since 3.1.000 (2008-06-09)
14674 function _putshaders() {
14675 if ($this->pdfa_mode
) {
14678 $idt = count($this->gradients
); //index for transparency gradients
14679 foreach ($this->gradients
as $id => $grad) {
14680 if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
14681 $fc = $this->_newobj();
14683 $out .= ' /FunctionType 3';
14684 $out .= ' /Domain [0 1]';
14689 $num_cols = count($grad['colors']);
14690 $lastcols = $num_cols - 1;
14691 for ($i = 1; $i < $num_cols; ++
$i) {
14692 $functions .= ($fc +
$i).' 0 R ';
14693 if ($i < $lastcols) {
14694 $bounds .= sprintf('%F ', $grad['colors'][$i]['offset']);
14698 $out .= ' /Functions ['.trim($functions).']';
14699 $out .= ' /Bounds ['.trim($bounds).']';
14700 $out .= ' /Encode ['.trim($encode).']';
14702 $out .= "\n".'endobj';
14704 for ($i = 1; $i < $num_cols; ++
$i) {
14707 $out .= ' /FunctionType 2';
14708 $out .= ' /Domain [0 1]';
14709 $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
14710 $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
14711 $out .= ' /N '.$grad['colors'][$i]['exponent'];
14713 $out .= "\n".'endobj';
14716 // set transparency functions
14717 if ($grad['transparency']) {
14718 $ft = $this->_newobj();
14720 $out .= ' /FunctionType 3';
14721 $out .= ' /Domain [0 1]';
14724 $num_cols = count($grad['colors']);
14725 for ($i = 1; $i < $num_cols; ++
$i) {
14726 $functions .= ($ft +
$i).' 0 R ';
14728 $out .= ' /Functions ['.trim($functions).']';
14729 $out .= ' /Bounds ['.trim($bounds).']';
14730 $out .= ' /Encode ['.trim($encode).']';
14732 $out .= "\n".'endobj';
14734 for ($i = 1; $i < $num_cols; ++
$i) {
14737 $out .= ' /FunctionType 2';
14738 $out .= ' /Domain [0 1]';
14739 $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
14740 $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
14741 $out .= ' /N '.$grad['colors'][$i]['exponent'];
14743 $out .= "\n".'endobj';
14748 // set shading object
14750 $out = '<< /ShadingType '.$grad['type'];
14751 if (isset($grad['colspace'])) {
14752 $out .= ' /ColorSpace /'.$grad['colspace'];
14754 $out .= ' /ColorSpace /DeviceRGB';
14756 if (isset($grad['background']) AND !empty($grad['background'])) {
14757 $out .= ' /Background ['.$grad['background'].']';
14759 if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
14760 $out .= ' /AntiAlias true';
14762 if ($grad['type'] == 2) {
14763 $out .= ' '.sprintf('/Coords [%F %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
14764 $out .= ' /Domain [0 1]';
14765 $out .= ' /Function '.$fc.' 0 R';
14766 $out .= ' /Extend [true true]';
14768 } elseif ($grad['type'] == 3) {
14769 //x0, y0, r0, x1, y1, r1
14770 //at this this time radius of inner circle is 0
14771 $out .= ' '.sprintf('/Coords [%F %F 0 %F %F %F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
14772 $out .= ' /Domain [0 1]';
14773 $out .= ' /Function '.$fc.' 0 R';
14774 $out .= ' /Extend [true true]';
14776 } elseif ($grad['type'] == 6) {
14777 $out .= ' /BitsPerCoordinate 16';
14778 $out .= ' /BitsPerComponent 8';
14779 $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
14780 $out .= ' /BitsPerFlag 8';
14781 $stream = $this->_getrawstream($grad['stream']);
14782 $out .= ' /Length '.strlen($stream);
14784 $out .= ' stream'."\n".$stream."\n".'endstream';
14786 $out .= "\n".'endobj';
14788 if ($grad['transparency']) {
14789 $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
14790 $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
14792 $this->gradients
[$id]['id'] = $this->n
;
14793 // set pattern object
14795 $out = '<< /Type /Pattern /PatternType 2';
14796 $out .= ' /Shading '.$this->gradients
[$id]['id'].' 0 R';
14798 $out .= "\n".'endobj';
14800 $this->gradients
[$id]['pattern'] = $this->n
;
14801 // set shading and pattern for transparency mask
14802 if ($grad['transparency']) {
14803 // luminosity pattern
14804 $idgs = $id +
$idt;
14806 $this->_out($shading_transparency);
14807 $this->gradients
[$idgs]['id'] = $this->n
;
14809 $out = '<< /Type /Pattern /PatternType 2';
14810 $out .= ' /Shading '.$this->gradients
[$idgs]['id'].' 0 R';
14812 $out .= "\n".'endobj';
14814 $this->gradients
[$idgs]['pattern'] = $this->n
;
14815 // luminosity XObject
14816 $oid = $this->_newobj();
14817 $this->xobjects
['LX'.$oid] = array('n' => $oid);
14819 $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt
.' '.$this->hPt
.' re f Q';
14820 if ($this->compress
) {
14821 $filter = ' /Filter /FlateDecode';
14822 $stream = gzcompress($stream);
14824 $stream = $this->_getrawstream($stream);
14825 $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
14826 $out .= ' /Length '.strlen($stream);
14827 $rect = sprintf('%F %F', $this->wPt
, $this->hPt
);
14828 $out .= ' /BBox [0 0 '.$rect.']';
14829 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
14830 $out .= ' /Resources <<';
14831 $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
14832 $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients
[$idgs]['pattern'].' 0 R >>';
14835 $out .= ' stream'."\n".$stream."\n".'endstream';
14836 $out .= "\n".'endobj';
14840 $out = '<< /Type /Mask /S /Luminosity /G '.($this->n
- 1).' 0 R >>'."\n".'endobj';
14844 $out = '<< /Type /ExtGState /SMask '.($this->n
- 1).' 0 R /AIS false >>'."\n".'endobj';
14846 $this->extgstates
[] = array('n' => $this->n
, 'name' => 'TGS'.$id);
14852 * Draw the sector of a circle.
14853 * It can be used for instance to render pie charts.
14854 * @param $xc (float) abscissa of the center.
14855 * @param $yc (float) ordinate of the center.
14856 * @param $r (float) radius.
14857 * @param $a (float) start angle (in degrees).
14858 * @param $b (float) end angle (in degrees).
14859 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
14860 * @param $cw: (float) indicates whether to go clockwise (default: true).
14861 * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock). Default: 90.
14862 * @author Maxime Delorme, Nicola Asuni
14863 * @since 3.1.000 (2008-06-09)
14866 public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
14867 $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
14871 * Draw the sector of an ellipse.
14872 * It can be used for instance to render pie charts.
14873 * @param $xc (float) abscissa of the center.
14874 * @param $yc (float) ordinate of the center.
14875 * @param $rx (float) the x-axis radius.
14876 * @param $ry (float) the y-axis radius.
14877 * @param $a (float) start angle (in degrees).
14878 * @param $b (float) end angle (in degrees).
14879 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
14880 * @param $cw: (float) indicates whether to go clockwise.
14881 * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
14882 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
14883 * @author Maxime Delorme, Nicola Asuni
14884 * @since 3.1.000 (2008-06-09)
14887 public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
14888 if ($this->state
!= 2) {
14892 $xc = ($this->w
- $xc);
14894 $op = TCPDF_STATIC
::getPathPaintOperator($style);
14896 $line_style = array();
14900 $b = (360 - $a +
$o);
14901 $a = (360 - $d +
$o);
14906 $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
14911 * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
14912 * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
14913 * Only vector drawing is supported, not text or bitmap.
14914 * Although the script was successfully tested with various AI format versions, best results are probably achieved with files that were exported in the AI3 format (tested with Illustrator CS2, Freehand MX and Photoshop CS2).
14915 * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
14916 * @param $x (float) Abscissa of the upper-left corner.
14917 * @param $y (float) Ordinate of the upper-left corner.
14918 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
14919 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
14920 * @param $link (mixed) URL or identifier returned by AddLink().
14921 * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
14922 * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
14923 * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
14924 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
14925 * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
14926 * @param $fixoutvals (boolean) if true remove values outside the bounding box.
14927 * @author Valentin Schmidt, Nicola Asuni
14928 * @since 3.1.000 (2008-06-09)
14931 public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
14932 if ($this->state
!= 2) {
14935 if ($this->rasterize_vector_images
AND ($w > 0) AND ($h > 0)) {
14936 // convert EPS to raster image using GD or ImageMagick libraries
14937 return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
14945 // check page for no-write regions and adapt page margins if necessary
14946 list($x, $y) = $this->checkPageRegions($h, $x, $y);
14948 if ($file[0] === '@') { // image from string
14949 $data = substr($file, 1);
14950 } else { // EPS/AI file
14951 $data = $this->getCachedFileContents($file);
14953 if ($data === FALSE) {
14954 $this->Error('EPS file not found: '.$file);
14957 // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
14958 preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
14959 if (count($regs) > 1) {
14960 $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
14961 if (strpos($version_str, 'Adobe Illustrator') !== false) {
14962 $versexp = explode(' ', $version_str);
14963 $version = (float)array_pop($versexp);
14964 if ($version >= 9) {
14965 $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
14969 // strip binary bytes in front of PS-header
14970 $start = strpos($data, '%!PS-Adobe');
14972 $data = substr($data, $start);
14974 // find BoundingBox params
14975 preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
14976 if (count($regs) > 1) {
14977 list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
14979 $this->Error('No BoundingBox found in EPS/AI file: '.$file);
14981 $start = strpos($data, '%%EndSetup');
14982 if ($start === false) {
14983 $start = strpos($data, '%%EndProlog');
14985 if ($start === false) {
14986 $start = strpos($data, '%%BoundingBox');
14988 $data = substr($data, $start);
14989 $end = strpos($data, '%%PageTrailer');
14990 if ($end===false) {
14991 $end = strpos($data, 'showpage');
14994 $data = substr($data, 0, $end);
14996 // calculate image width and height on document
14997 if (($w <= 0) AND ($h <= 0)) {
14998 $w = ($x2 - $x1) / $k;
14999 $h = ($y2 - $y1) / $k;
15000 } elseif ($w <= 0) {
15001 $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
15002 } elseif ($h <= 0) {
15003 $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
15005 // fit the image on available space
15006 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
15007 if ($this->rasterize_vector_images
) {
15008 // convert EPS to raster image using GD or ImageMagick libraries
15009 return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
15011 // set scaling factors
15012 $scale_x = $w / (($x2 - $x1) / $k);
15013 $scale_y = $h / (($y2 - $y1) / $k);
15015 $this->img_rb_y
= $y +
$h;
15018 if ($palign == 'L') {
15019 $ximg = $this->lMargin
;
15020 } elseif ($palign == 'C') {
15021 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
15022 } elseif ($palign == 'R') {
15023 $ximg = $this->w
- $this->rMargin
- $w;
15027 $this->img_rb_x
= $ximg;
15029 if ($palign == 'L') {
15030 $ximg = $this->lMargin
;
15031 } elseif ($palign == 'C') {
15032 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
15033 } elseif ($palign == 'R') {
15034 $ximg = $this->w
- $this->rMargin
- $w;
15038 $this->img_rb_x
= $ximg +
$w;
15040 if ($useBoundingBox) {
15041 $dx = $ximg * $k - $x1;
15042 $dy = $y * $k - $y1;
15047 // save the current graphic state
15048 $this->_out('q'.$this->epsmarker
);
15050 $this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy +
($this->hPt
- (2 * $y * $k) - ($y2 - $y1))));
15052 if (isset($scale_x)) {
15053 $this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
15055 // handle pc/unix/mac line endings
15056 $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY
);
15058 $cnt = count($lines);
15059 for ($i=0; $i < $cnt; ++
$i) {
15060 $line = $lines[$i];
15061 if (($line == '') OR ($line[0] == '%')) {
15064 $len = strlen($line);
15065 // check for spot color names
15067 if (strcasecmp('x', substr(trim($line), -1)) == 0) {
15068 if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
15069 // extract spot color name
15070 $color_name = $matches[0];
15071 // remove color name from string
15072 $line = str_replace(' '.$color_name, '', $line);
15073 // remove pharentesis from color name
15074 $color_name = substr($color_name, 1, -1);
15077 $chunks = explode(' ', $line);
15078 $cmd = trim(array_pop($chunks));
15080 if (($cmd == 'Xa') OR ($cmd == 'XA')) {
15081 $b = array_pop($chunks);
15082 $g = array_pop($chunks);
15083 $r = array_pop($chunks);
15084 $this->_out(''.$r.' '.$g.' '.$b.' '.($cmd=='Xa'?
'rg':'RG')); //substr($line, 0, -2).'rg' -> in EPS (AI8): c m y k r g b rg!
15089 // check for values outside the bounding box
15094 // skip values outside bounding box
15095 foreach ($chunks as $key => $val) {
15096 if ((($key %
2) == 0) AND (($val < $x1) OR ($val > $x2))) {
15098 } elseif ((($key %
2) != 0) AND (($val < $y1) OR ($val > $y2))) {
15126 $this->_out($line);
15129 case 'x': {// custom fill color
15130 if (empty($color_name)) {
15132 list($col_c, $col_m, $col_y, $col_k) = $chunks;
15133 $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
15135 // Spot Color (CMYK + tint)
15136 list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
15137 $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
15138 $color_cmd = sprintf('/CS%d cs %F scn', $this->spot_colors
[$color_name]['i'], (1 - $col_t));
15139 $this->_out($color_cmd);
15143 case 'X': { // custom stroke color
15144 if (empty($color_name)) {
15146 list($col_c, $col_m, $col_y, $col_k) = $chunks;
15147 $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
15149 // Spot Color (CMYK + tint)
15150 list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
15151 $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
15152 $color_cmd = sprintf('/CS%d CS %F SCN', $this->spot_colors
[$color_name]['i'], (1 - $col_t));
15153 $this->_out($color_cmd);
15165 $line[($len - 1)] = strtolower($cmd);
15166 $this->_out($line);
15171 $this->_out($cmd . '*');
15178 $max = min(($i +
5), $cnt);
15179 for ($j = ($i +
1); $j < $max; ++
$j) {
15180 $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
15200 // restore previous graphic state
15201 $this->_out($this->epsmarker
.'Q');
15202 if (!empty($border)) {
15210 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
15215 $this->Link($ximg, $y, $w, $h, $link, 0);
15217 // set pointer to align the next text/objects
15221 $this->x
= $this->img_rb_x
;
15225 $this->y
= $y +
round($h/2);
15226 $this->x
= $this->img_rb_x
;
15230 $this->y
= $this->img_rb_y
;
15231 $this->x
= $this->img_rb_x
;
15235 $this->SetY($this->img_rb_y
);
15242 $this->endlinex
= $this->img_rb_x
;
15246 * Set document barcode.
15247 * @param $bc (string) barcode
15250 public function setBarcode($bc='') {
15251 $this->barcode
= $bc;
15255 * Get current barcode.
15258 * @since 4.0.012 (2008-07-24)
15260 public function getBarcode() {
15261 return $this->barcode
;
15265 * Print a Linear Barcode.
15266 * @param $code (string) code to print
15267 * @param $type (string) type of barcode (see tcpdf_barcodes_1d.php for supported formats).
15268 * @param $x (int) x position in user units (empty string = current x position)
15269 * @param $y (int) y position in user units (empty string = current y position)
15270 * @param $w (int) width in user units (empty string = remaining page width)
15271 * @param $h (int) height in user units (empty string = remaining page height)
15272 * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
15273 * @param $style (array) array of options:<ul>
15274 * <li>boolean $style['border'] if true prints a border</li>
15275 * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
15276 * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
15277 * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
15278 * <li>array $style['fgcolor'] color array for bars and text</li>
15279 * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
15280 * <li>boolean $style['text'] if true prints text below the barcode</li>
15281 * <li>string $style['label'] override default label</li>
15282 * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
15283 * <li>int $style['stretchtext']: 0 = disabled; 1 = horizontal scaling only if necessary; 2 = forced horizontal scaling; 3 = character spacing only if necessary; 4 = forced character spacing.</li>
15284 * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
15285 * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
15286 * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
15287 * <li>string $style['fitwidth'] if true reduce the width to fit the barcode width + padding. When this option is enabled the 'stretch' option is automatically disabled.</li>
15288 * <li>string $style['cellfitalign'] this option works only when 'fitwidth' is true and 'position' is unset or empty. Set the horizontal position of the containing barcode cell inside the specified rectangle: L = left; C = center; R = right.</li></ul>
15289 * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
15290 * @author Nicola Asuni
15291 * @since 3.1.000 (2008-06-09)
15294 public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style=array(), $align='') {
15295 if (TCPDF_STATIC
::empty_string(trim($code))) {
15298 require_once(dirname(__FILE__
).'/tcpdf_barcodes_1d.php');
15299 // save current graphic settings
15300 $gvars = $this->getGraphicVars();
15301 // create new barcode object
15302 $barcodeobj = new TCPDFBarcode($code, $type);
15303 $arrcode = $barcodeobj->getBarcodeArray();
15304 if (($arrcode === false) OR empty($arrcode) OR ($arrcode['maxw'] <= 0)) {
15305 $this->Error('Error in 1D barcode string');
15307 if ($arrcode['maxh'] <= 0) {
15308 $arrcode['maxh'] = 1;
15310 // set default values
15311 if (!isset($style['position'])) {
15312 $style['position'] = '';
15313 } elseif ($style['position'] == 'S') {
15314 // keep this for backward compatibility
15315 $style['position'] = '';
15316 $style['stretch'] = true;
15318 if (!isset($style['fitwidth'])) {
15319 if (!isset($style['stretch'])) {
15320 $style['fitwidth'] = true;
15322 $style['fitwidth'] = false;
15325 if ($style['fitwidth']) {
15327 $style['stretch'] = false;
15329 if (!isset($style['stretch'])) {
15330 if (($w === '') OR ($w <= 0)) {
15331 $style['stretch'] = false;
15333 $style['stretch'] = true;
15336 if (!isset($style['fgcolor'])) {
15337 $style['fgcolor'] = array(0,0,0); // default black
15339 if (!isset($style['bgcolor'])) {
15340 $style['bgcolor'] = false; // default transparent
15342 if (!isset($style['border'])) {
15343 $style['border'] = false;
15346 if (!isset($style['text'])) {
15347 $style['text'] = false;
15349 if ($style['text'] AND isset($style['font'])) {
15350 if (isset($style['fontsize'])) {
15351 $fontsize = $style['fontsize'];
15353 $this->SetFont($style['font'], '', $fontsize);
15355 if (!isset($style['stretchtext'])) {
15356 $style['stretchtext'] = 4;
15364 // check page for no-write regions and adapt page margins if necessary
15365 list($x, $y) = $this->checkPageRegions($h, $x, $y);
15366 if (($w === '') OR ($w <= 0)) {
15368 $w = $x - $this->lMargin
;
15370 $w = $this->w
- $this->rMargin
- $x;
15374 if (!isset($style['padding'])) {
15376 } elseif ($style['padding'] === 'auto') {
15377 $padding = 10 * ($w / ($arrcode['maxw'] +
20));
15379 $padding = floatval($style['padding']);
15381 // horizontal padding
15382 if (!isset($style['hpadding'])) {
15383 $hpadding = $padding;
15384 } elseif ($style['hpadding'] === 'auto') {
15385 $hpadding = 10 * ($w / ($arrcode['maxw'] +
20));
15387 $hpadding = floatval($style['hpadding']);
15389 // vertical padding
15390 if (!isset($style['vpadding'])) {
15391 $vpadding = $padding;
15392 } elseif ($style['vpadding'] === 'auto') {
15393 $vpadding = ($hpadding / 2);
15395 $vpadding = floatval($style['vpadding']);
15397 // calculate xres (single bar width)
15398 $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
15399 if ($style['stretch']) {
15402 if (TCPDF_STATIC
::empty_string($xres)) {
15403 $xres = (0.141 * $this->k
); // default bar width = 0.4 mm
15405 if ($xres > $max_xres) {
15406 // correct xres to fit on $w
15409 if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
15410 OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
15411 $hpadding = 10 * $xres;
15412 if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
15413 $vpadding = ($hpadding / 2);
15417 if ($style['fitwidth']) {
15419 $w = (($arrcode['maxw'] * $xres) +
(2 * $hpadding));
15420 if (isset($style['cellfitalign'])) {
15421 switch ($style['cellfitalign']) {
15424 $x -= ($wold - $w);
15430 $x +
= ($wold - $w);
15436 $x -= (($wold - $w) / 2);
15438 $x +
= (($wold - $w) / 2);
15448 $text_height = $this->getCellHeight($fontsize / $this->k
);
15450 if (($h === '') OR ($h <= 0)) {
15451 // set default height
15452 $h = (($arrcode['maxw'] * $xres) / 3) +
(2 * $vpadding) +
$text_height;
15454 $barh = $h - $text_height - (2 * $vpadding);
15456 // try to reduce font or padding to fit barcode on available height
15457 if ($text_height > $h) {
15458 $fontsize = (($h * $this->k
) / (4 * $this->cell_height_ratio
));
15459 $text_height = $this->getCellHeight($fontsize / $this->k
);
15460 $this->SetFont($style['font'], '', $fontsize);
15462 if ($vpadding > 0) {
15463 $vpadding = (($h - $text_height) / 4);
15465 $barh = $h - $text_height - (2 * $vpadding);
15467 // fit the barcode on available space
15468 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
15470 $this->img_rb_y
= $y +
$h;
15473 if ($style['position'] == 'L') {
15474 $xpos = $this->lMargin
;
15475 } elseif ($style['position'] == 'C') {
15476 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
15477 } elseif ($style['position'] == 'R') {
15478 $xpos = $this->w
- $this->rMargin
- $w;
15482 $this->img_rb_x
= $xpos;
15484 if ($style['position'] == 'L') {
15485 $xpos = $this->lMargin
;
15486 } elseif ($style['position'] == 'C') {
15487 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
15488 } elseif ($style['position'] == 'R') {
15489 $xpos = $this->w
- $this->rMargin
- $w;
15493 $this->img_rb_x
= $xpos +
$w;
15495 $xpos_rect = $xpos;
15496 if (!isset($style['align'])) {
15497 $style['align'] = 'C';
15499 switch ($style['align']) {
15501 $xpos = $xpos_rect +
$hpadding;
15505 $xpos = $xpos_rect +
($w - ($arrcode['maxw'] * $xres)) - $hpadding;
15510 $xpos = $xpos_rect +
(($w - ($arrcode['maxw'] * $xres)) / 2);
15514 $xpos_text = $xpos;
15515 // barcode is always printed in LTR direction
15516 $tempRTL = $this->rtl
;
15517 $this->rtl
= false;
15518 // print background color
15519 if ($style['bgcolor']) {
15520 $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ?
'DF' : 'F', '', $style['bgcolor']);
15521 } elseif ($style['border']) {
15522 $this->Rect($xpos_rect, $y, $w, $h, 'D');
15524 // set foreground color
15525 $this->SetDrawColorArray($style['fgcolor']);
15526 $this->SetTextColorArray($style['fgcolor']);
15528 foreach ($arrcode['bcode'] as $k => $v) {
15529 $bw = ($v['w'] * $xres);
15531 // draw a vertical bar
15532 $ypos = $y +
$vpadding +
($v['p'] * $barh / $arrcode['maxh']);
15533 $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
15538 if ($style['text']) {
15539 if (isset($style['label']) AND !TCPDF_STATIC
::empty_string($style['label'])) {
15540 $label = $style['label'];
15544 $txtwidth = ($arrcode['maxw'] * $xres);
15545 if ($this->GetStringWidth($label) > $txtwidth) {
15546 $style['stretchtext'] = 2;
15549 $this->x
= $xpos_text;
15550 $this->y
= $y +
$vpadding +
$barh;
15551 $cellpadding = $this->cell_padding
;
15552 $this->SetCellPadding(0);
15553 $this->Cell($txtwidth, 0, $label, 0, 0, 'C', false, '', $style['stretchtext'], false, 'T', 'T');
15554 $this->cell_padding
= $cellpadding;
15556 // restore original direction
15557 $this->rtl
= $tempRTL;
15558 // restore previous settings
15559 $this->setGraphicVars($gvars);
15560 // set pointer to align the next text/objects
15564 $this->x
= $this->img_rb_x
;
15568 $this->y
= $y +
round($h / 2);
15569 $this->x
= $this->img_rb_x
;
15573 $this->y
= $this->img_rb_y
;
15574 $this->x
= $this->img_rb_x
;
15578 $this->SetY($this->img_rb_y
);
15585 $this->endlinex
= $this->img_rb_x
;
15589 * Print 2D Barcode.
15590 * @param $code (string) code to print
15591 * @param $type (string) type of barcode (see tcpdf_barcodes_2d.php for supported formats).
15592 * @param $x (int) x position in user units
15593 * @param $y (int) y position in user units
15594 * @param $w (int) width in user units
15595 * @param $h (int) height in user units
15596 * @param $style (array) array of options:<ul>
15597 * <li>boolean $style['border'] if true prints a border around the barcode</li>
15598 * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
15599 * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
15600 * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
15601 * <li>int $style['module_width'] width of a single module in points</li>
15602 * <li>int $style['module_height'] height of a single module in points</li>
15603 * <li>array $style['fgcolor'] color array for bars and text</li>
15604 * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
15605 * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li>
15606 * @param $align (string) Indicates the alignment of the pointer next to barcode insertion relative to barcode height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
15607 * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
15608 * @author Nicola Asuni
15609 * @since 4.5.037 (2009-04-07)
15612 public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style=array(), $align='', $distort=false) {
15613 if (TCPDF_STATIC
::empty_string(trim($code))) {
15616 require_once(dirname(__FILE__
).'/tcpdf_barcodes_2d.php');
15617 // save current graphic settings
15618 $gvars = $this->getGraphicVars();
15619 // create new barcode object
15620 $barcodeobj = new TCPDF2DBarcode($code, $type);
15621 $arrcode = $barcodeobj->getBarcodeArray();
15622 if (($arrcode === false) OR empty($arrcode) OR !isset($arrcode['num_rows']) OR ($arrcode['num_rows'] == 0) OR !isset($arrcode['num_cols']) OR ($arrcode['num_cols'] == 0)) {
15623 $this->Error('Error in 2D barcode string');
15625 // set default values
15626 if (!isset($style['position'])) {
15627 $style['position'] = '';
15629 if (!isset($style['fgcolor'])) {
15630 $style['fgcolor'] = array(0,0,0); // default black
15632 if (!isset($style['bgcolor'])) {
15633 $style['bgcolor'] = false; // default transparent
15635 if (!isset($style['border'])) {
15636 $style['border'] = false;
15639 if (!isset($style['padding'])) {
15640 $style['padding'] = 0;
15641 } elseif ($style['padding'] === 'auto') {
15642 $style['padding'] = 4;
15644 if (!isset($style['hpadding'])) {
15645 $style['hpadding'] = $style['padding'];
15646 } elseif ($style['hpadding'] === 'auto') {
15647 $style['hpadding'] = 4;
15649 if (!isset($style['vpadding'])) {
15650 $style['vpadding'] = $style['padding'];
15651 } elseif ($style['vpadding'] === 'auto') {
15652 $style['vpadding'] = 4;
15654 $hpad = (2 * $style['hpadding']);
15655 $vpad = (2 * $style['vpadding']);
15656 // cell (module) dimension
15657 if (!isset($style['module_width'])) {
15658 $style['module_width'] = 1; // width of a single module in points
15660 if (!isset($style['module_height'])) {
15661 $style['module_height'] = 1; // height of a single module in points
15669 // check page for no-write regions and adapt page margins if necessary
15670 list($x, $y) = $this->checkPageRegions($h, $x, $y);
15671 // number of barcode columns and rows
15672 $rows = $arrcode['num_rows'];
15673 $cols = $arrcode['num_cols'];
15674 if (($rows <= 0) ||
($cols <= 0)){
15675 $this->Error('Error in 2D barcode string');
15677 // module width and height
15678 $mw = $style['module_width'];
15679 $mh = $style['module_height'];
15680 if (($mw <= 0) OR ($mh <= 0)) {
15681 $this->Error('Error in 2D barcode string');
15683 // get max dimensions
15685 $maxw = $x - $this->lMargin
;
15687 $maxw = $this->w
- $this->rMargin
- $x;
15689 $maxh = ($this->h
- $this->tMargin
- $this->bMargin
);
15690 $ratioHW = ((($rows * $mh) +
$hpad) / (($cols * $mw) +
$vpad));
15691 $ratioWH = ((($cols * $mw) +
$vpad) / (($rows * $mh) +
$hpad));
15693 if (($maxw * $ratioHW) > $maxh) {
15694 $maxw = $maxh * $ratioWH;
15696 if (($maxh * $ratioWH) > $maxw) {
15697 $maxh = $maxw * $ratioHW;
15700 // set maximum dimensions
15708 if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
15709 $w = ($cols +
$hpad) * ($mw / $this->k
);
15710 $h = ($rows +
$vpad) * ($mh / $this->k
);
15711 } elseif (($w === '') OR ($w <= 0)) {
15712 $w = $h * $ratioWH;
15713 } elseif (($h === '') OR ($h <= 0)) {
15714 $h = $w * $ratioHW;
15716 // barcode size (excluding padding)
15717 $bw = ($w * $cols) / ($cols +
$hpad);
15718 $bh = ($h * $rows) / ($rows +
$vpad);
15719 // dimension of single barcode cell unit
15723 if (($cw / $ch) > ($mw / $mh)) {
15724 // correct horizontal distortion
15725 $cw = $ch * $mw / $mh;
15727 $style['hpadding'] = ($w - $bw) / (2 * $cw);
15729 // correct vertical distortion
15730 $ch = $cw * $mh / $mw;
15732 $style['vpadding'] = ($h - $bh) / (2 * $ch);
15735 // fit the barcode on available space
15736 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, false);
15738 $this->img_rb_y
= $y +
$h;
15741 if ($style['position'] == 'L') {
15742 $xpos = $this->lMargin
;
15743 } elseif ($style['position'] == 'C') {
15744 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
15745 } elseif ($style['position'] == 'R') {
15746 $xpos = $this->w
- $this->rMargin
- $w;
15750 $this->img_rb_x
= $xpos;
15752 if ($style['position'] == 'L') {
15753 $xpos = $this->lMargin
;
15754 } elseif ($style['position'] == 'C') {
15755 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
15756 } elseif ($style['position'] == 'R') {
15757 $xpos = $this->w
- $this->rMargin
- $w;
15761 $this->img_rb_x
= $xpos +
$w;
15763 $xstart = $xpos +
($style['hpadding'] * $cw);
15764 $ystart = $y +
($style['vpadding'] * $ch);
15765 // barcode is always printed in LTR direction
15766 $tempRTL = $this->rtl
;
15767 $this->rtl
= false;
15768 // print background color
15769 if ($style['bgcolor']) {
15770 $this->Rect($xpos, $y, $w, $h, $style['border'] ?
'DF' : 'F', '', $style['bgcolor']);
15771 } elseif ($style['border']) {
15772 $this->Rect($xpos, $y, $w, $h, 'D');
15774 // set foreground color
15775 $this->SetDrawColorArray($style['fgcolor']);
15776 // print barcode cells
15778 for ($r = 0; $r < $rows; ++
$r) {
15781 for ($c = 0; $c < $cols; ++
$c) {
15782 if ($arrcode['bcode'][$r][$c] == 1) {
15783 // draw a single barcode cell
15784 $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
15790 // restore original direction
15791 $this->rtl
= $tempRTL;
15792 // restore previous settings
15793 $this->setGraphicVars($gvars);
15794 // set pointer to align the next text/objects
15798 $this->x
= $this->img_rb_x
;
15802 $this->y
= $y +
round($h/2);
15803 $this->x
= $this->img_rb_x
;
15807 $this->y
= $this->img_rb_y
;
15808 $this->x
= $this->img_rb_x
;
15812 $this->SetY($this->img_rb_y
);
15819 $this->endlinex
= $this->img_rb_x
;
15823 * Returns an array containing current margins:
15825 <li>$ret['left'] = left margin</li>
15826 <li>$ret['right'] = right margin</li>
15827 <li>$ret['top'] = top margin</li>
15828 <li>$ret['bottom'] = bottom margin</li>
15829 <li>$ret['header'] = header margin</li>
15830 <li>$ret['footer'] = footer margin</li>
15831 <li>$ret['cell'] = cell padding array</li>
15832 <li>$ret['padding_left'] = cell left padding</li>
15833 <li>$ret['padding_top'] = cell top padding</li>
15834 <li>$ret['padding_right'] = cell right padding</li>
15835 <li>$ret['padding_bottom'] = cell bottom padding</li>
15837 * @return array containing all margins measures
15839 * @since 3.2.000 (2008-06-23)
15841 public function getMargins() {
15843 'left' => $this->lMargin
,
15844 'right' => $this->rMargin
,
15845 'top' => $this->tMargin
,
15846 'bottom' => $this->bMargin
,
15847 'header' => $this->header_margin
,
15848 'footer' => $this->footer_margin
,
15849 'cell' => $this->cell_padding
,
15850 'padding_left' => $this->cell_padding
['L'],
15851 'padding_top' => $this->cell_padding
['T'],
15852 'padding_right' => $this->cell_padding
['R'],
15853 'padding_bottom' => $this->cell_padding
['B']
15859 * Returns an array containing original margins:
15861 <li>$ret['left'] = left margin</li>
15862 <li>$ret['right'] = right margin</li>
15864 * @return array containing all margins measures
15866 * @since 4.0.012 (2008-07-24)
15868 public function getOriginalMargins() {
15870 'left' => $this->original_lMargin
,
15871 'right' => $this->original_rMargin
15877 * Returns the current font size.
15878 * @return current font size
15880 * @since 3.2.000 (2008-06-23)
15882 public function getFontSize() {
15883 return $this->FontSize
;
15887 * Returns the current font size in points unit.
15888 * @return current font size in points unit
15890 * @since 3.2.000 (2008-06-23)
15892 public function getFontSizePt() {
15893 return $this->FontSizePt
;
15897 * Returns the current font family name.
15898 * @return string current font family name
15900 * @since 4.3.008 (2008-12-05)
15902 public function getFontFamily() {
15903 return $this->FontFamily
;
15907 * Returns the current font style.
15908 * @return string current font style
15910 * @since 4.3.008 (2008-12-05)
15912 public function getFontStyle() {
15913 return $this->FontStyle
;
15917 * Cleanup HTML code (requires HTML Tidy library).
15918 * @param $html (string) htmlcode to fix
15919 * @param $default_css (string) CSS commands to add
15920 * @param $tagvs (array) parameters for setHtmlVSpace method
15921 * @param $tidy_options (array) options for tidy_parse_string function
15922 * @return string XHTML code cleaned up
15923 * @author Nicola Asuni
15925 * @since 5.9.017 (2010-11-16)
15926 * @see setHtmlVSpace()
15928 public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
15929 return TCPDF_STATIC
::fixHTMLCode($html, $default_css, $tagvs, $tidy_options, $this->tagvspaces
);
15933 * Returns the border width from CSS property
15934 * @param $width (string) border width
15935 * @return int with in user units
15937 * @since 5.7.000 (2010-08-02)
15939 protected function getCSSBorderWidth($width) {
15940 if ($width == 'thin') {
15941 $width = (2 / $this->k
);
15942 } elseif ($width == 'medium') {
15943 $width = (4 / $this->k
);
15944 } elseif ($width == 'thick') {
15945 $width = (6 / $this->k
);
15947 $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
15953 * Returns the border dash style from CSS property
15954 * @param $style (string) border style to convert
15955 * @return int sash style (return -1 in case of none or hidden border)
15957 * @since 5.7.000 (2010-08-02)
15959 protected function getCSSBorderDashStyle($style) {
15960 switch (strtolower($style)) {
15989 * Returns the border style array from CSS border properties
15990 * @param $cssborder (string) border properties
15991 * @return array containing border properties
15993 * @since 5.7.000 (2010-08-02)
15995 protected function getCSSBorderStyle($cssborder) {
15996 $bprop = preg_split('/[\s]+/', trim($cssborder));
15997 $border = array(); // value to be returned
15998 switch (count($bprop)) {
16000 $width = $bprop[0];
16001 $style = $bprop[1];
16002 $color = $bprop[2];
16007 $style = $bprop[0];
16008 $color = $bprop[1];
16013 $style = $bprop[0];
16024 if ($style == 'none') {
16027 $border['cap'] = 'square';
16028 $border['join'] = 'miter';
16029 $border['dash'] = $this->getCSSBorderDashStyle($style);
16030 if ($border['dash'] < 0) {
16033 $border['width'] = $this->getCSSBorderWidth($width);
16034 $border['color'] = TCPDF_COLORS
::convertHTMLColorToDec($color, $this->spot_colors
);
16039 * Get the internal Cell padding from CSS attribute.
16040 * @param $csspadding (string) padding properties
16041 * @param $width (float) width of the containing element
16042 * @return array of cell paddings
16044 * @since 5.9.000 (2010-10-04)
16046 public function getCSSPadding($csspadding, $width=0) {
16047 $padding = preg_split('/[\s]+/', trim($csspadding));
16048 $cell_padding = array(); // value to be returned
16049 switch (count($padding)) {
16051 $cell_padding['T'] = $padding[0];
16052 $cell_padding['R'] = $padding[1];
16053 $cell_padding['B'] = $padding[2];
16054 $cell_padding['L'] = $padding[3];
16058 $cell_padding['T'] = $padding[0];
16059 $cell_padding['R'] = $padding[1];
16060 $cell_padding['B'] = $padding[2];
16061 $cell_padding['L'] = $padding[1];
16065 $cell_padding['T'] = $padding[0];
16066 $cell_padding['R'] = $padding[1];
16067 $cell_padding['B'] = $padding[0];
16068 $cell_padding['L'] = $padding[1];
16072 $cell_padding['T'] = $padding[0];
16073 $cell_padding['R'] = $padding[0];
16074 $cell_padding['B'] = $padding[0];
16075 $cell_padding['L'] = $padding[0];
16079 return $this->cell_padding
;
16083 $width = $this->w
- $this->lMargin
- $this->rMargin
;
16085 $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
16086 $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
16087 $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
16088 $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
16089 return $cell_padding;
16093 * Get the internal Cell margin from CSS attribute.
16094 * @param $cssmargin (string) margin properties
16095 * @param $width (float) width of the containing element
16096 * @return array of cell margins
16098 * @since 5.9.000 (2010-10-04)
16100 public function getCSSMargin($cssmargin, $width=0) {
16101 $margin = preg_split('/[\s]+/', trim($cssmargin));
16102 $cell_margin = array(); // value to be returned
16103 switch (count($margin)) {
16105 $cell_margin['T'] = $margin[0];
16106 $cell_margin['R'] = $margin[1];
16107 $cell_margin['B'] = $margin[2];
16108 $cell_margin['L'] = $margin[3];
16112 $cell_margin['T'] = $margin[0];
16113 $cell_margin['R'] = $margin[1];
16114 $cell_margin['B'] = $margin[2];
16115 $cell_margin['L'] = $margin[1];
16119 $cell_margin['T'] = $margin[0];
16120 $cell_margin['R'] = $margin[1];
16121 $cell_margin['B'] = $margin[0];
16122 $cell_margin['L'] = $margin[1];
16126 $cell_margin['T'] = $margin[0];
16127 $cell_margin['R'] = $margin[0];
16128 $cell_margin['B'] = $margin[0];
16129 $cell_margin['L'] = $margin[0];
16133 return $this->cell_margin
;
16137 $width = $this->w
- $this->lMargin
- $this->rMargin
;
16139 $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
16140 $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
16141 $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
16142 $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
16143 return $cell_margin;
16147 * Get the border-spacing from CSS attribute.
16148 * @param $cssbspace (string) border-spacing CSS properties
16149 * @param $width (float) width of the containing element
16150 * @return array of border spacings
16152 * @since 5.9.010 (2010-10-27)
16154 public function getCSSBorderMargin($cssbspace, $width=0) {
16155 $space = preg_split('/[\s]+/', trim($cssbspace));
16156 $border_spacing = array(); // value to be returned
16157 switch (count($space)) {
16159 $border_spacing['H'] = $space[0];
16160 $border_spacing['V'] = $space[1];
16164 $border_spacing['H'] = $space[0];
16165 $border_spacing['V'] = $space[0];
16169 return array('H' => 0, 'V' => 0);
16173 $width = $this->w
- $this->lMargin
- $this->rMargin
;
16175 $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
16176 $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
16177 return $border_spacing;
16181 * Returns the letter-spacing value from CSS value
16182 * @param $spacing (string) letter-spacing value
16183 * @param $parent (float) font spacing (tracking) value of the parent element
16184 * @return float quantity to increases or decreases the space between characters in a text.
16186 * @since 5.9.000 (2010-10-02)
16188 protected function getCSSFontSpacing($spacing, $parent=0) {
16189 $val = 0; // value to be returned
16190 $spacing = trim($spacing);
16191 switch ($spacing) {
16197 if ($parent == 'normal') {
16205 $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
16212 * Returns the percentage of font stretching from CSS value
16213 * @param $stretch (string) stretch mode
16214 * @param $parent (float) stretch value of the parent element
16215 * @return float font stretching percentage
16217 * @since 5.9.000 (2010-10-02)
16219 protected function getCSSFontStretching($stretch, $parent=100) {
16220 $val = 100; // value to be returned
16221 $stretch = trim($stretch);
16222 switch ($stretch) {
16223 case 'ultra-condensed': {
16227 case 'extra-condensed': {
16231 case 'condensed': {
16235 case 'semi-condensed': {
16243 case 'semi-expanded': {
16251 case 'extra-expanded': {
16255 case 'ultra-expanded': {
16260 $val = ($parent +
10);
16264 $val = ($parent - 10);
16268 if ($parent == 'normal') {
16276 $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
16283 * Convert HTML string containing font size value to points
16284 * @param $val (string) String containing font size value and unit.
16285 * @param $refsize (float) Reference font size in points.
16286 * @param $parent_size (float) Parent font size in points.
16287 * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
16288 * @return float value in points
16291 public function getHTMLFontUnits($val, $refsize=12, $parent_size=12, $defaultunit='pt') {
16292 $refsize = TCPDF_FONTS
::getFontRefSize($refsize);
16293 $parent_size = TCPDF_FONTS
::getFontRefSize($parent_size, $refsize);
16296 $size = ($refsize - 4);
16300 $size = ($refsize - 3);
16304 $size = ($refsize - 2);
16312 $size = ($refsize +
2);
16316 $size = ($refsize +
4);
16320 $size = ($refsize +
6);
16324 $size = ($parent_size - 3);
16328 $size = ($parent_size +
3);
16332 $size = $this->getHTMLUnitToUnits($val, $parent_size, $defaultunit, true);
16339 * Returns the HTML DOM array.
16340 * @param $html (string) html code
16343 * @since 3.2.000 (2008-06-20)
16345 protected function getHtmlDomArray($html) {
16346 // array of CSS styles ( selector => properties).
16348 // get CSS array defined at previous call
16349 $matches = array();
16350 if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
16351 if (isset($matches[1][0])) {
16352 $css = array_merge($css, json_decode($this->unhtmlentities($matches[1][0]), true));
16354 $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
16356 // extract external CSS files
16357 $matches = array();
16358 if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
16359 foreach ($matches[1] as $key => $link) {
16361 if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
16363 preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
16364 // get 'all' and 'print' media, other media types are discarded
16365 // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
16366 if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
16368 if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
16369 // read CSS data file
16370 $cssdata = $this->getCachedFileContents(trim($type[1]));
16371 if (($cssdata !== FALSE) AND (strlen($cssdata) > 0)) {
16372 $css = array_merge($css, TCPDF_STATIC
::extractCSSproperties($cssdata));
16379 // extract style tags
16380 $matches = array();
16381 if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
16382 foreach ($matches[1] as $key => $media) {
16384 preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
16385 // get 'all' and 'print' media, other media types are discarded
16386 // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
16387 if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
16388 $cssdata = $matches[2][$key];
16389 $css = array_merge($css, TCPDF_STATIC
::extractCSSproperties($cssdata));
16393 // create a special tag to contain the CSS array (used for table content)
16394 $csstagarray = '<cssarray>'.htmlentities(json_encode($css)).'</cssarray>';
16395 // remove head and style blocks
16396 $html = preg_replace('/<head([^\>]*)>(.*)?<\/head>/siU', '', $html);
16397 $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
16398 // define block tags
16399 $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
16400 // define self-closing tags
16401 $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
16402 // remove all unsupported tags (the line below lists all supported tags)
16403 $html = strip_tags($html, '<marker/><a><b><blockquote><body><br><br/><dd><del><div><dl><dt><em><font><form><h1><h2><h3><h4><h5><h6><hr><hr/><i><img><input><label><li><ol><option><p><pre><s><select><small><span><strike><strong><sub><sup><table><tablehead><tcpdf><td><textarea><th><thead><tr><tt><u><ul>');
16404 //replace some blank characters
16405 $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
16406 $html = preg_replace('/<(table|tr|td|th|tcpdf|blockquote|dd|div|dl|dt|form|h1|h2|h3|h4|h5|h6|br|hr|li|ol|ul|p)([^\>]*)>[\n\r\t]+/', '<\\1\\2>', $html);
16407 $html = preg_replace('@(\r\n|\r)@', "\n", $html);
16408 $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
16409 $html = strtr($html, $repTable);
16411 while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
16412 $html_a = substr($html, 0, $offset);
16413 $html_b = substr($html, $offset, ($pos - $offset +
6));
16414 while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
16415 // preserve newlines on <pre> tag
16416 $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
16418 while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space
['p']."(.*?)</pre>'".$this->re_space
['m'], $html_b)) {
16419 // preserve spaces on <pre> tag
16420 $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space
['p']."(.*?)</pre>'".$this->re_space
['m'], "<xre\\1>\\2 \\3</pre>", $html_b);
16422 $html = $html_a.$html_b.substr($html, $pos +
6);
16423 $offset = strlen($html_a.$html_b);
16426 while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
16427 $html_a = substr($html, 0, $offset);
16428 $html_b = substr($html, $offset, ($pos - $offset +
11));
16429 while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
16430 // preserve newlines on <textarea> tag
16431 $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
16432 $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
16434 $html = $html_a.$html_b.substr($html, $pos +
11);
16435 $offset = strlen($html_a.$html_b);
16437 $html = preg_replace('/([\s]*)<option/si', '<option', $html);
16438 $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
16440 while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
16441 $html_a = substr($html, 0, $offset);
16442 $html_b = substr($html, $offset, ($pos - $offset +
9));
16443 while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
16444 $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
16445 $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
16447 $html = $html_a.$html_b.substr($html, $pos +
9);
16448 $offset = strlen($html_a.$html_b);
16450 if (preg_match("'</select'si", $html)) {
16451 $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
16452 $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
16454 $html = str_replace("\n", ' ', $html);
16455 // restore textarea newlines
16456 $html = str_replace('<TBR>', "\n", $html);
16457 // remove extra spaces from code
16458 $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
16459 $html = preg_replace('/'.$this->re_space
['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space
['m'], '</\\1>', $html);
16460 $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
16461 $html = preg_replace('/'.$this->re_space
['p'].'+<(ul|ol|dl|br)/'.$this->re_space
['m'], '<\\1', $html);
16462 $html = preg_replace('/<\/(table|tr|td|th|blockquote|dd|dt|dl|div|dt|h1|h2|h3|h4|h5|h6|hr|li|ol|ul|p)>[\s]+</', '</\\1><', $html);
16463 $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
16464 $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
16465 $html = preg_replace('/'.$this->re_space
['p'].'+<img/'.$this->re_space
['m'], chr(32).'<img', $html);
16466 $html = preg_replace('/<img([^\>]*)>[\s]+([^\<])/xi', '<img\\1> \\2', $html);
16467 $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
16468 $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
16469 $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
16470 $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1> </li>', $html);
16471 $html = preg_replace('/<li([^\>]*)>'.$this->re_space
['p'].'*<img/'.$this->re_space
['m'], '<li\\1><font size="1"> </font><img', $html);
16472 $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1> ', $html); // preserve some spaces
16473 $html = preg_replace('/[\s]<\/([^\>]*)>/', ' </\\1>', $html); // preserve some spaces
16474 $html = preg_replace('/<su([bp])/', '<zws/><su\\1', $html); // fix sub/sup alignment
16475 $html = preg_replace('/<\/su([bp])>/', '</su\\1><zws/>', $html); // fix sub/sup alignment
16476 $html = preg_replace('/'.$this->re_space
['p'].'+/'.$this->re_space
['m'], chr(32), $html); // replace multiple spaces with a single space
16478 $html = $this->stringTrim($html);
16479 // fix br tag after li
16480 $html = preg_replace('/<li><br([^\>]*)>/', '<li> <br\\1>', $html);
16481 // fix first image tag alignment
16482 $html = preg_replace('/^<img/', '<span style="font-size:0"><br /></span> <img', $html, 1);
16483 // pattern for generic tag
16484 $tagpattern = '/(<[^>]+>)/';
16485 // explodes the string
16486 $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
16488 $maxel = count($a);
16491 // create an array of elements
16493 $dom[$key] = array();
16494 // set inheritable properties fot the first void element
16495 // possible inheritable properties are: azimuth, border-collapse, border-spacing, caption-side, color, cursor, direction, empty-cells, font, font-family, font-stretch, font-size, font-size-adjust, font-style, font-variant, font-weight, letter-spacing, line-height, list-style, list-style-image, list-style-position, list-style-type, orphans, page, page-break-inside, quotes, speak, speak-header, text-align, text-indent, text-transform, volume, white-space, widows, word-spacing
16496 $dom[$key]['tag'] = false;
16497 $dom[$key]['block'] = false;
16498 $dom[$key]['value'] = '';
16499 $dom[$key]['parent'] = 0;
16500 $dom[$key]['hide'] = false;
16501 $dom[$key]['fontname'] = $this->FontFamily
;
16502 $dom[$key]['fontstyle'] = $this->FontStyle
;
16503 $dom[$key]['fontsize'] = $this->FontSizePt
;
16504 $dom[$key]['font-stretch'] = $this->font_stretching
;
16505 $dom[$key]['letter-spacing'] = $this->font_spacing
;
16506 $dom[$key]['stroke'] = $this->textstrokewidth
;
16507 $dom[$key]['fill'] = (($this->textrendermode %
2) == 0);
16508 $dom[$key]['clip'] = ($this->textrendermode
> 3);
16509 $dom[$key]['line-height'] = $this->cell_height_ratio
;
16510 $dom[$key]['bgcolor'] = false;
16511 $dom[$key]['fgcolor'] = $this->fgcolor
; // color
16512 $dom[$key]['strokecolor'] = $this->strokecolor
;
16513 $dom[$key]['align'] = '';
16514 $dom[$key]['listtype'] = '';
16515 $dom[$key]['text-indent'] = 0;
16516 $dom[$key]['text-transform'] = '';
16517 $dom[$key]['border'] = array();
16518 $dom[$key]['dir'] = $this->rtl?
'rtl':'ltr';
16519 $thead = false; // true when we are inside the THEAD tag
16522 array_push($level, 0); // root
16523 while ($elkey < $maxel) {
16524 $dom[$key] = array();
16525 $element = $a[$elkey];
16526 $dom[$key]['elkey'] = $elkey;
16527 if (preg_match($tagpattern, $element)) {
16529 $element = substr($element, 1, -1);
16531 preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
16532 $tagname = strtolower($tag[1]);
16533 // check if we are inside a table header
16534 if ($tagname == 'thead') {
16535 if ($element[0] == '/') {
16543 $dom[$key]['tag'] = true;
16544 $dom[$key]['value'] = $tagname;
16545 if (in_array($dom[$key]['value'], $blocktags)) {
16546 $dom[$key]['block'] = true;
16548 $dom[$key]['block'] = false;
16550 if ($element[0] == '/') {
16551 // *** closing html tag
16552 $dom[$key]['opening'] = false;
16553 $dom[$key]['parent'] = end($level);
16555 $dom[$key]['hide'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['hide'];
16556 $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
16557 $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
16558 $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
16559 $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
16560 $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
16561 $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
16562 $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
16563 $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
16564 $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
16565 $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
16566 $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
16567 $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
16568 $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
16569 $dom[$key]['text-transform'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['text-transform'];
16570 $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
16571 if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
16572 $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
16574 // set the number of columns in table tag
16575 if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
16576 $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
16578 if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
16579 $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
16580 for ($i = ($dom[$key]['parent'] +
1); $i < $key; ++
$i) {
16581 $dom[($dom[$key]['parent'])]['content'] .= stripslashes($a[$dom[$i]['elkey']]);
16584 // mark nested tables
16585 $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
16586 // remove thead sections from nested tables
16587 $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
16588 $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
16590 // store header rows on a new table
16592 ($dom[$key]['value'] === 'tr')
16593 && !empty($dom[($dom[$key]['parent'])]['thead'])
16594 && ($dom[($dom[$key]['parent'])]['thead'] === true)
16596 if (TCPDF_STATIC
::empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
16597 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $csstagarray.$a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
16599 for ($i = $dom[$key]['parent']; $i <= $key; ++
$i) {
16600 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
16602 if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
16603 $dom[($dom[$key]['parent'])]['attribute'] = array();
16605 // header elements must be always contained in a single page
16606 $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
16608 if (($dom[$key]['value'] == 'table') AND (!TCPDF_STATIC
::empty_string($dom[($dom[$key]['parent'])]['thead']))) {
16609 // remove the nobr attributes from the table header
16610 $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
16611 $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
16614 // *** opening or self-closing html tag
16615 $dom[$key]['opening'] = true;
16616 $dom[$key]['parent'] = end($level);
16617 if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
16618 // self-closing tag
16619 $dom[$key]['self'] = true;
16622 array_push($level, $key);
16623 $dom[$key]['self'] = false;
16625 // copy some values from parent
16628 $parentkey = $dom[$key]['parent'];
16629 $dom[$key]['hide'] = $dom[$parentkey]['hide'];
16630 $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
16631 $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
16632 $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
16633 $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
16634 $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
16635 $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
16636 $dom[$key]['fill'] = $dom[$parentkey]['fill'];
16637 $dom[$key]['clip'] = $dom[$parentkey]['clip'];
16638 $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
16639 $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
16640 $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
16641 $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
16642 $dom[$key]['align'] = $dom[$parentkey]['align'];
16643 $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
16644 $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
16645 $dom[$key]['text-transform'] = $dom[$parentkey]['text-transform'];
16646 $dom[$key]['border'] = array();
16647 $dom[$key]['dir'] = $dom[$parentkey]['dir'];
16650 preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER
);
16651 $dom[$key]['attribute'] = array(); // reset attribute array
16652 foreach($attr_array[1] as $id => $name) {
16653 $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
16655 if (!empty($css)) {
16656 // merge CSS style to current style
16657 list($dom[$key]['csssel'], $dom[$key]['cssdata']) = TCPDF_STATIC
::getCSSdataArray($dom, $key, $css);
16658 $dom[$key]['attribute']['style'] = TCPDF_STATIC
::getTagStyleFromCSSarray($dom[$key]['cssdata']);
16660 // split style attributes
16661 if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
16662 // get style attributes
16663 preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER
);
16664 $dom[$key]['style'] = array(); // reset style attribute array
16665 foreach($style_array[1] as $id => $name) {
16666 // in case of duplicate attribute the last replace the previous
16667 $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
16669 // --- get some style attributes ---
16671 if (isset($dom[$key]['style']['direction'])) {
16672 $dom[$key]['dir'] = $dom[$key]['style']['direction'];
16675 if (isset($dom[$key]['style']['display'])) {
16676 $dom[$key]['hide'] = (trim(strtolower($dom[$key]['style']['display'])) == 'none');
16679 if (isset($dom[$key]['style']['font-family'])) {
16680 $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
16683 if (isset($dom[$key]['style']['list-style-type'])) {
16684 $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
16685 if ($dom[$key]['listtype'] == 'inherit') {
16686 $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
16690 if (isset($dom[$key]['style']['text-indent'])) {
16691 $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
16692 if ($dom[$key]['text-indent'] == 'inherit') {
16693 $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
16697 if (isset($dom[$key]['style']['text-transform'])) {
16698 $dom[$key]['text-transform'] = $dom[$key]['style']['text-transform'];
16701 if (isset($dom[$key]['style']['font-size'])) {
16702 $fsize = trim($dom[$key]['style']['font-size']);
16703 $dom[$key]['fontsize'] = $this->getHTMLFontUnits($fsize, $dom[0]['fontsize'], $dom[$parentkey]['fontsize'], 'pt');
16706 if (isset($dom[$key]['style']['font-stretch'])) {
16707 $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
16710 if (isset($dom[$key]['style']['letter-spacing'])) {
16711 $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
16713 // line-height (internally is the cell height ratio)
16714 if (isset($dom[$key]['style']['line-height'])) {
16715 $lineheight = trim($dom[$key]['style']['line-height']);
16716 switch ($lineheight) {
16717 // A normal line height. This is default
16719 $dom[$key]['line-height'] = $dom[0]['line-height'];
16723 $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
16726 if (is_numeric($lineheight)) {
16727 // convert to percentage of font height
16728 $lineheight = ($lineheight * 100).'%';
16730 $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
16731 if (substr($lineheight, -1) !== '%') {
16732 if ($dom[$key]['fontsize'] <= 0) {
16733 $dom[$key]['line-height'] = 1;
16735 $dom[$key]['line-height'] = (($dom[$key]['line-height'] - $this->cell_padding
['T'] - $this->cell_padding
['B']) / $dom[$key]['fontsize']);
16742 if (isset($dom[$key]['style']['font-weight'])) {
16743 if (strtolower($dom[$key]['style']['font-weight'][0]) == 'n') {
16744 if (strpos($dom[$key]['fontstyle'], 'B') !== false) {
16745 $dom[$key]['fontstyle'] = str_replace('B', '', $dom[$key]['fontstyle']);
16747 } elseif (strtolower($dom[$key]['style']['font-weight'][0]) == 'b') {
16748 $dom[$key]['fontstyle'] .= 'B';
16751 if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style'][0]) == 'i')) {
16752 $dom[$key]['fontstyle'] .= 'I';
16755 if (isset($dom[$key]['style']['color']) AND (!TCPDF_STATIC
::empty_string($dom[$key]['style']['color']))) {
16756 $dom[$key]['fgcolor'] = TCPDF_COLORS
::convertHTMLColorToDec($dom[$key]['style']['color'], $this->spot_colors
);
16757 } elseif ($dom[$key]['value'] == 'a') {
16758 $dom[$key]['fgcolor'] = $this->htmlLinkColorArray
;
16760 // background color
16761 if (isset($dom[$key]['style']['background-color']) AND (!TCPDF_STATIC
::empty_string($dom[$key]['style']['background-color']))) {
16762 $dom[$key]['bgcolor'] = TCPDF_COLORS
::convertHTMLColorToDec($dom[$key]['style']['background-color'], $this->spot_colors
);
16765 if (isset($dom[$key]['style']['text-decoration'])) {
16766 $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
16767 foreach ($decors as $dec) {
16769 if (!TCPDF_STATIC
::empty_string($dec)) {
16770 if ($dec[0] == 'u') {
16772 $dom[$key]['fontstyle'] .= 'U';
16773 } elseif ($dec[0] == 'l') {
16775 $dom[$key]['fontstyle'] .= 'D';
16776 } elseif ($dec[0] == 'o') {
16778 $dom[$key]['fontstyle'] .= 'O';
16782 } elseif ($dom[$key]['value'] == 'a') {
16783 $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle
;
16785 // check for width attribute
16786 if (isset($dom[$key]['style']['width'])) {
16787 $dom[$key]['width'] = $dom[$key]['style']['width'];
16789 // check for height attribute
16790 if (isset($dom[$key]['style']['height'])) {
16791 $dom[$key]['height'] = $dom[$key]['style']['height'];
16793 // check for text alignment
16794 if (isset($dom[$key]['style']['text-align'])) {
16795 $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align'][0]);
16797 // check for CSS border properties
16798 if (isset($dom[$key]['style']['border'])) {
16799 $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
16800 if (!empty($borderstyle)) {
16801 $dom[$key]['border']['LTRB'] = $borderstyle;
16804 if (isset($dom[$key]['style']['border-color'])) {
16805 $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
16806 if (isset($brd_colors[3])) {
16807 $dom[$key]['border']['L']['color'] = TCPDF_COLORS
::convertHTMLColorToDec($brd_colors[3], $this->spot_colors
);
16809 if (isset($brd_colors[1])) {
16810 $dom[$key]['border']['R']['color'] = TCPDF_COLORS
::convertHTMLColorToDec($brd_colors[1], $this->spot_colors
);
16812 if (isset($brd_colors[0])) {
16813 $dom[$key]['border']['T']['color'] = TCPDF_COLORS
::convertHTMLColorToDec($brd_colors[0], $this->spot_colors
);
16815 if (isset($brd_colors[2])) {
16816 $dom[$key]['border']['B']['color'] = TCPDF_COLORS
::convertHTMLColorToDec($brd_colors[2], $this->spot_colors
);
16819 if (isset($dom[$key]['style']['border-width'])) {
16820 $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
16821 if (isset($brd_widths[3])) {
16822 $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
16824 if (isset($brd_widths[1])) {
16825 $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
16827 if (isset($brd_widths[0])) {
16828 $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
16830 if (isset($brd_widths[2])) {
16831 $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
16834 if (isset($dom[$key]['style']['border-style'])) {
16835 $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
16836 if (isset($brd_styles[3]) AND ($brd_styles[3]!='none')) {
16837 $dom[$key]['border']['L']['cap'] = 'square';
16838 $dom[$key]['border']['L']['join'] = 'miter';
16839 $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
16840 if ($dom[$key]['border']['L']['dash'] < 0) {
16841 $dom[$key]['border']['L'] = array();
16844 if (isset($brd_styles[1])) {
16845 $dom[$key]['border']['R']['cap'] = 'square';
16846 $dom[$key]['border']['R']['join'] = 'miter';
16847 $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
16848 if ($dom[$key]['border']['R']['dash'] < 0) {
16849 $dom[$key]['border']['R'] = array();
16852 if (isset($brd_styles[0])) {
16853 $dom[$key]['border']['T']['cap'] = 'square';
16854 $dom[$key]['border']['T']['join'] = 'miter';
16855 $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
16856 if ($dom[$key]['border']['T']['dash'] < 0) {
16857 $dom[$key]['border']['T'] = array();
16860 if (isset($brd_styles[2])) {
16861 $dom[$key]['border']['B']['cap'] = 'square';
16862 $dom[$key]['border']['B']['join'] = 'miter';
16863 $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
16864 if ($dom[$key]['border']['B']['dash'] < 0) {
16865 $dom[$key]['border']['B'] = array();
16869 $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
16870 foreach ($cellside as $bsk => $bsv) {
16871 if (isset($dom[$key]['style']['border-'.$bsv])) {
16872 $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
16873 if (!empty($borderstyle)) {
16874 $dom[$key]['border'][$bsk] = $borderstyle;
16877 if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
16878 $dom[$key]['border'][$bsk]['color'] = TCPDF_COLORS
::convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color'], $this->spot_colors
);
16880 if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
16881 $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
16883 if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
16884 $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
16885 if ($dom[$key]['border'][$bsk]['dash'] < 0) {
16886 $dom[$key]['border'][$bsk] = array();
16890 // check for CSS padding properties
16891 if (isset($dom[$key]['style']['padding'])) {
16892 $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
16894 $dom[$key]['padding'] = $this->cell_padding
;
16896 foreach ($cellside as $psk => $psv) {
16897 if (isset($dom[$key]['style']['padding-'.$psv])) {
16898 $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
16901 // check for CSS margin properties
16902 if (isset($dom[$key]['style']['margin'])) {
16903 $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
16905 $dom[$key]['margin'] = $this->cell_margin
;
16907 foreach ($cellside as $psk => $psv) {
16908 if (isset($dom[$key]['style']['margin-'.$psv])) {
16909 $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
16912 // check for CSS border-spacing properties
16913 if (isset($dom[$key]['style']['border-spacing'])) {
16914 $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
16916 // page-break-inside
16917 if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
16918 $dom[$key]['attribute']['nobr'] = 'true';
16920 // page-break-before
16921 if (isset($dom[$key]['style']['page-break-before'])) {
16922 if ($dom[$key]['style']['page-break-before'] == 'always') {
16923 $dom[$key]['attribute']['pagebreak'] = 'true';
16924 } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
16925 $dom[$key]['attribute']['pagebreak'] = 'left';
16926 } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
16927 $dom[$key]['attribute']['pagebreak'] = 'right';
16930 // page-break-after
16931 if (isset($dom[$key]['style']['page-break-after'])) {
16932 if ($dom[$key]['style']['page-break-after'] == 'always') {
16933 $dom[$key]['attribute']['pagebreakafter'] = 'true';
16934 } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
16935 $dom[$key]['attribute']['pagebreakafter'] = 'left';
16936 } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
16937 $dom[$key]['attribute']['pagebreakafter'] = 'right';
16941 if (isset($dom[$key]['attribute']['display'])) {
16942 $dom[$key]['hide'] = (trim(strtolower($dom[$key]['attribute']['display'])) == 'none');
16944 if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
16945 $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
16946 if (!empty($borderstyle)) {
16947 $dom[$key]['border']['LTRB'] = $borderstyle;
16950 // check for font tag
16951 if ($dom[$key]['value'] == 'font') {
16953 if (isset($dom[$key]['attribute']['face'])) {
16954 $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
16957 if (isset($dom[$key]['attribute']['size'])) {
16959 if ($dom[$key]['attribute']['size'][0] == '+') {
16960 $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] +
intval(substr($dom[$key]['attribute']['size'], 1));
16961 } elseif ($dom[$key]['attribute']['size'][0] == '-') {
16962 $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
16964 $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
16967 $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
16971 // force natural alignment for lists
16972 if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
16973 AND (!isset($dom[$key]['align']) OR TCPDF_STATIC
::empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
16975 $dom[$key]['align'] = 'R';
16977 $dom[$key]['align'] = 'L';
16980 if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
16981 if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
16982 $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO
;
16985 if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
16986 $dom[$key]['fontstyle'] .= 'B';
16988 if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
16989 $dom[$key]['fontstyle'] .= 'I';
16991 if ($dom[$key]['value'] == 'u') {
16992 $dom[$key]['fontstyle'] .= 'U';
16994 if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
16995 $dom[$key]['fontstyle'] .= 'D';
16997 if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
16998 $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle
;
17000 if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
17001 $dom[$key]['fontname'] = $this->default_monospaced_font
;
17003 if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value'][1]) > 0) AND (intval($dom[$key]['value'][1]) < 7)) {
17004 // headings h1, h2, h3, h4, h5, h6
17005 if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
17006 $headsize = (4 - intval($dom[$key]['value'][1])) * 2;
17007 $dom[$key]['fontsize'] = $dom[0]['fontsize'] +
$headsize;
17009 if (!isset($dom[$key]['style']['font-weight'])) {
17010 $dom[$key]['fontstyle'] .= 'B';
17013 if (($dom[$key]['value'] == 'table')) {
17014 $dom[$key]['rows'] = 0; // number of rows
17015 $dom[$key]['trids'] = array(); // IDs of TR elements
17016 $dom[$key]['thead'] = ''; // table header rows
17018 if (($dom[$key]['value'] == 'tr')) {
17019 $dom[$key]['cols'] = 0;
17021 $dom[$key]['thead'] = true;
17022 // rows on thead block are printed as a separate table
17024 $dom[$key]['thead'] = false;
17025 $parent = $dom[$key]['parent'];
17027 if (!isset($dom[$parent]['rows'])) {
17028 $dom[$parent]['rows'] = 0;
17030 // store the number of rows on table element
17031 ++
$dom[$parent]['rows'];
17033 if (!isset($dom[$parent]['trids'])) {
17034 $dom[$parent]['trids'] = array();
17037 // store the TR elements IDs on table element
17038 array_push($dom[$parent]['trids'], $key);
17041 if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
17042 if (isset($dom[$key]['attribute']['colspan'])) {
17043 $colspan = intval($dom[$key]['attribute']['colspan']);
17047 $dom[$key]['attribute']['colspan'] = $colspan;
17048 $dom[($dom[$key]['parent'])]['cols'] +
= $colspan;
17051 if (isset($dom[$key]['attribute']['dir'])) {
17052 $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
17054 // set foreground color attribute
17055 if (isset($dom[$key]['attribute']['color']) AND (!TCPDF_STATIC
::empty_string($dom[$key]['attribute']['color']))) {
17056 $dom[$key]['fgcolor'] = TCPDF_COLORS
::convertHTMLColorToDec($dom[$key]['attribute']['color'], $this->spot_colors
);
17057 } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
17058 $dom[$key]['fgcolor'] = $this->htmlLinkColorArray
;
17060 // set background color attribute
17061 if (isset($dom[$key]['attribute']['bgcolor']) AND (!TCPDF_STATIC
::empty_string($dom[$key]['attribute']['bgcolor']))) {
17062 $dom[$key]['bgcolor'] = TCPDF_COLORS
::convertHTMLColorToDec($dom[$key]['attribute']['bgcolor'], $this->spot_colors
);
17064 // set stroke color attribute
17065 if (isset($dom[$key]['attribute']['strokecolor']) AND (!TCPDF_STATIC
::empty_string($dom[$key]['attribute']['strokecolor']))) {
17066 $dom[$key]['strokecolor'] = TCPDF_COLORS
::convertHTMLColorToDec($dom[$key]['attribute']['strokecolor'], $this->spot_colors
);
17068 // check for width attribute
17069 if (isset($dom[$key]['attribute']['width'])) {
17070 $dom[$key]['width'] = $dom[$key]['attribute']['width'];
17072 // check for height attribute
17073 if (isset($dom[$key]['attribute']['height'])) {
17074 $dom[$key]['height'] = $dom[$key]['attribute']['height'];
17076 // check for text alignment
17077 if (isset($dom[$key]['attribute']['align']) AND (!TCPDF_STATIC
::empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
17078 $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align'][0]);
17080 // check for text rendering mode (the following attributes do not exist in HTML)
17081 if (isset($dom[$key]['attribute']['stroke'])) {
17082 // font stroke width
17083 $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
17085 if (isset($dom[$key]['attribute']['fill'])) {
17087 if ($dom[$key]['attribute']['fill'] == 'true') {
17088 $dom[$key]['fill'] = true;
17090 $dom[$key]['fill'] = false;
17093 if (isset($dom[$key]['attribute']['clip'])) {
17095 if ($dom[$key]['attribute']['clip'] == 'true') {
17096 $dom[$key]['clip'] = true;
17098 $dom[$key]['clip'] = false;
17101 } // end opening tag
17104 $dom[$key]['tag'] = false;
17105 $dom[$key]['block'] = false;
17106 $dom[$key]['parent'] = end($level);
17107 $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
17108 if (!empty($dom[$dom[$key]['parent']]['text-transform'])) {
17109 // text-transform for unicode requires mb_convert_case (Multibyte String Functions)
17110 if (function_exists('mb_convert_case')) {
17111 $ttm = array('capitalize' => MB_CASE_TITLE
, 'uppercase' => MB_CASE_UPPER
, 'lowercase' => MB_CASE_LOWER
);
17112 if (isset($ttm[$dom[$dom[$key]['parent']]['text-transform']])) {
17113 $element = mb_convert_case($element, $ttm[$dom[$dom[$key]['parent']]['text-transform']], $this->encoding
);
17115 } elseif (!$this->isunicode
) {
17116 switch ($dom[$dom[$key]['parent']]['text-transform']) {
17117 case 'capitalize': {
17118 $element = ucwords(strtolower($element));
17121 case 'uppercase': {
17122 $element = strtoupper($element);
17125 case 'lowercase': {
17126 $element = strtolower($element);
17132 $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
17141 * Returns the string used to find spaces
17144 * @author Nicola Asuni
17145 * @since 4.8.024 (2010-01-15)
17147 protected function getSpaceString() {
17148 $spacestr = chr(32);
17149 if ($this->isUnicodeFont()) {
17150 $spacestr = chr(0).chr(32);
17156 * Return an hash code used to ensure that the serialized data has been generated by this TCPDF instance.
17157 * @param $data (string) serialized data
17161 protected function getHashForTCPDFtagParams($data) {
17162 return md5(strlen($data).$this->file_id
.$data);
17166 * Serialize an array of parameters to be used with TCPDF tag in HTML code.
17167 * @param $data (array) parameters array
17168 * @return string containing serialized data
17171 public function serializeTCPDFtagParameters($data) {
17172 $encoded = urlencode(json_encode($data));
17173 return $this->getHashForTCPDFtagParams($encoded).$encoded;
17177 * Unserialize parameters to be used with TCPDF tag in HTML code.
17178 * @param $data (string) serialized data
17179 * @return array containing unserialized data
17180 * @protected static
17182 protected function unserializeTCPDFtagParameters($data) {
17183 $hash = substr($data, 0, 32);
17184 $encoded = substr($data, 32);
17185 if ($hash != $this->getHashForTCPDFtagParams($encoded)) {
17186 $this->Error('Invalid parameters');
17188 return json_decode(urldecode($encoded), true);
17192 * Prints a cell (rectangular area) with optional borders, background color and html text string.
17193 * The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.<br />
17194 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
17195 * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
17196 * Supported tags are: a, b, blockquote, 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, tcpdf, td, th, thead, tr, tt, u, ul
17197 * NOTE: all the HTML attributes must be enclosed in double-quote.
17198 * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
17199 * @param $h (float) Cell minimum height. The cell extends automatically if needed.
17200 * @param $x (float) upper-left corner X coordinate
17201 * @param $y (float) upper-left corner Y coordinate
17202 * @param $html (string) html text to print. Default value: empty string.
17203 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
17204 * @param $ln (int) Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right (or left for RTL language)</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
17205 Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
17206 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
17207 * @param $reseth (boolean) if true reset the last cell height (default true).
17208 * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
17209 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
17210 * @see Multicell(), writeHTML()
17213 public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
17214 return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0, 'T', false);
17218 * Allows to preserve some HTML formatting (limited support).<br />
17219 * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
17220 * Supported tags are: a, b, blockquote, 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, tcpdf, td, th, thead, tr, tt, u, ul
17221 * NOTE: all the HTML attributes must be enclosed in double-quote.
17222 * @param $html (string) text to display
17223 * @param $ln (boolean) if true add a new line after text (default = true)
17224 * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
17225 * @param $reseth (boolean) if true reset the last cell height (default false).
17226 * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
17227 * @param $align (string) Allows to center or align the text. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
17230 public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
17231 $gvars = $this->getGraphicVars();
17232 // store current values
17233 $prev_cell_margin = $this->cell_margin
;
17234 $prev_cell_padding = $this->cell_padding
;
17235 $prevPage = $this->page
;
17236 $prevlMargin = $this->lMargin
;
17237 $prevrMargin = $this->rMargin
;
17238 $curfontname = $this->FontFamily
;
17239 $curfontstyle = $this->FontStyle
;
17240 $curfontsize = $this->FontSizePt
;
17241 $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
17242 $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
17243 $curfontstretcing = $this->font_stretching
;
17244 $curfonttracking = $this->font_spacing
;
17245 $this->newline
= true;
17247 $startlinepage = $this->page
;
17248 $minstartliney = $this->y
;
17249 $maxbottomliney = 0;
17250 $startlinex = $this->x
;
17251 $startliney = $this->y
;
17255 $this_method_vars = array();
17257 $fontaligned = false;
17258 $reverse_dir = false; // true when the text direction is reversed
17259 $this->premode
= false;
17260 if ($this->inxobj
) {
17261 // we are inside an XObject template
17262 $pask = count($this->xobjects
[$this->xobjid
]['annotations']);
17263 } elseif (isset($this->PageAnnots
[$this->page
])) {
17264 $pask = count($this->PageAnnots
[$this->page
]);
17268 if ($this->inxobj
) {
17269 // we are inside an XObject template
17270 $startlinepos = strlen($this->xobjects
[$this->xobjid
]['outdata']);
17271 } elseif (!$this->InFooter
) {
17272 if (isset($this->footerlen
[$this->page
])) {
17273 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerlen
[$this->page
];
17275 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
17277 $startlinepos = $this->footerpos
[$this->page
];
17279 // we are inside the footer
17280 $startlinepos = $this->pagelen
[$this->page
];
17285 $w = $this->x
- $this->lMargin
;
17287 $w = $this->w
- $this->rMargin
- $this->x
;
17289 $w -= ($this->cell_padding
['L'] +
$this->cell_padding
['R']);
17292 $this->x
-= $this->cell_padding
['R'];
17293 $this->lMargin +
= $this->cell_padding
['L'];
17295 $this->x +
= $this->cell_padding
['L'];
17296 $this->rMargin +
= $this->cell_padding
['R'];
17299 if ($this->customlistindent
>= 0) {
17300 $this->listindent
= $this->customlistindent
;
17302 $this->listindent
= $this->GetStringWidth('000000');
17304 $this->listindentlevel
= 0;
17305 // save previous states
17306 $prev_cell_height_ratio = $this->cell_height_ratio
;
17307 $prev_listnum = $this->listnum
;
17308 $prev_listordered = $this->listordered
;
17309 $prev_listcount = $this->listcount
;
17310 $prev_lispacer = $this->lispacer
;
17311 $this->listnum
= 0;
17312 $this->listordered
= array();
17313 $this->listcount
= array();
17314 $this->lispacer
= '';
17315 if ((TCPDF_STATIC
::empty_string($this->lasth
)) OR ($reseth)) {
17316 // reset row height
17317 $this->resetLastH();
17319 $dom = $this->getHtmlDomArray($html);
17320 $maxel = count($dom);
17322 while ($key < $maxel) {
17323 if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND $dom[$key]['hide']) {
17324 // store the node key
17325 $hidden_node_key = $key;
17326 if ($dom[$key]['self']) {
17327 // skip just this self-closing tag
17330 // skip this and all children tags
17331 while (($key < $maxel) AND (!$dom[$key]['tag'] OR $dom[$key]['opening'] OR ($dom[$key]['parent'] != $hidden_node_key))) {
17332 // skip hidden objects
17338 if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
17339 // check for pagebreak
17340 if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
17341 // add a page (or trig AcceptPageBreak() for multicolumn mode)
17342 $this->checkPageBreak($this->PageBreakTrigger +
1);
17343 $this->htmlvspace
= ($this->PageBreakTrigger +
1);
17345 if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl
) AND (($this->page %
2) == 0)) OR (($this->rtl
) AND (($this->page %
2) != 0))))
17346 OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl
) AND (($this->page %
2) != 0)) OR (($this->rtl
) AND (($this->page %
2) == 0))))) {
17347 // add a page (or trig AcceptPageBreak() for multicolumn mode)
17348 $this->checkPageBreak($this->PageBreakTrigger +
1);
17349 $this->htmlvspace
= ($this->PageBreakTrigger +
1);
17352 if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
17353 if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
17354 $dom[$key]['attribute']['nobr'] = false;
17356 // store current object
17357 $this->startTransaction();
17358 // save this method vars
17359 $this_method_vars['html'] = $html;
17360 $this_method_vars['ln'] = $ln;
17361 $this_method_vars['fill'] = $fill;
17362 $this_method_vars['reseth'] = $reseth;
17363 $this_method_vars['cell'] = $cell;
17364 $this_method_vars['align'] = $align;
17365 $this_method_vars['gvars'] = $gvars;
17366 $this_method_vars['prevPage'] = $prevPage;
17367 $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
17368 $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
17369 $this_method_vars['prevlMargin'] = $prevlMargin;
17370 $this_method_vars['prevrMargin'] = $prevrMargin;
17371 $this_method_vars['curfontname'] = $curfontname;
17372 $this_method_vars['curfontstyle'] = $curfontstyle;
17373 $this_method_vars['curfontsize'] = $curfontsize;
17374 $this_method_vars['curfontascent'] = $curfontascent;
17375 $this_method_vars['curfontdescent'] = $curfontdescent;
17376 $this_method_vars['curfontstretcing'] = $curfontstretcing;
17377 $this_method_vars['curfonttracking'] = $curfonttracking;
17378 $this_method_vars['minstartliney'] = $minstartliney;
17379 $this_method_vars['maxbottomliney'] = $maxbottomliney;
17380 $this_method_vars['yshift'] = $yshift;
17381 $this_method_vars['startlinepage'] = $startlinepage;
17382 $this_method_vars['startlinepos'] = $startlinepos;
17383 $this_method_vars['startlinex'] = $startlinex;
17384 $this_method_vars['startliney'] = $startliney;
17385 $this_method_vars['newline'] = $newline;
17386 $this_method_vars['loop'] = $loop;
17387 $this_method_vars['curpos'] = $curpos;
17388 $this_method_vars['pask'] = $pask;
17389 $this_method_vars['lalign'] = $lalign;
17390 $this_method_vars['plalign'] = $plalign;
17391 $this_method_vars['w'] = $w;
17392 $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
17393 $this_method_vars['prev_listnum'] = $prev_listnum;
17394 $this_method_vars['prev_listordered'] = $prev_listordered;
17395 $this_method_vars['prev_listcount'] = $prev_listcount;
17396 $this_method_vars['prev_lispacer'] = $prev_lispacer;
17397 $this_method_vars['fontaligned'] = $fontaligned;
17398 $this_method_vars['key'] = $key;
17399 $this_method_vars['dom'] = $dom;
17402 // print THEAD block
17403 if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
17404 if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !TCPDF_STATIC
::empty_string($dom[$dom[$key]['parent']]['thead'])) {
17405 $this->inthead
= true;
17406 // print table header (thead)
17407 $this->writeHTML($this->thead
, false, false, false, false, '');
17408 // check if we are on a new page or on a new column
17409 if (($this->y
< $this->start_transaction_y
) OR ($this->checkPageBreak($this->lasth
, '', false))) {
17410 // we are on a new page or on a new column and the total object height is less than the available vertical space.
17411 // restore previous object
17412 $this->rollbackTransaction(true);
17413 // restore previous values
17414 foreach ($this_method_vars as $vkey => $vval) {
17417 // disable table header
17418 $tmp_thead = $this->thead
;
17420 // add a page (or trig AcceptPageBreak() for multicolumn mode)
17422 if ((!$this->checkPageBreak($this->PageBreakTrigger +
1)) AND ($this->y
< $pre_y)) {
17423 // fix for multicolumn mode
17424 $startliney = $this->y
;
17426 $this->start_transaction_page
= $this->page
;
17427 $this->start_transaction_y
= $this->y
;
17428 // restore table header
17429 $this->thead
= $tmp_thead;
17430 // fix table border properties
17431 if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
17432 $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
17433 } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
17434 $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
17436 $tmp_cellspacing = 0;
17438 $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page
;
17439 $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column
;
17440 $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y +
$tmp_cellspacing;
17441 $xoffset = ($this->x
- $dom[$dom[$key]['parent']]['borderposition']['x']);
17442 $dom[$dom[$key]['parent']]['borderposition']['x'] +
= $xoffset;
17443 $dom[$dom[$key]['parent']]['borderposition']['xmax'] +
= $xoffset;
17444 // print table header (thead)
17445 $this->writeHTML($this->thead
, false, false, false, false, '');
17448 // move $key index forward to skip THEAD block
17449 while ( ($key < $maxel) AND (!(
17450 ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
17451 OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
17455 if ($dom[$key]['tag'] OR ($key == 0)) {
17456 if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
17457 $dom[$key]['align'] = ($this->rtl
) ?
'R' : 'L';
17459 // vertically align image in line
17460 if ((!$this->newline
) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
17461 // get image height
17462 $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], ($dom[$key]['fontsize'] / $this->k
), 'px');
17463 $autolinebreak = false;
17464 if (!empty($dom[$key]['width'])) {
17465 $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], ($dom[$key]['fontsize'] / $this->k
), 'px', false);
17466 if (($imgw <= ($this->w
- $this->lMargin
- $this->rMargin
- $this->cell_padding
['L'] - $this->cell_padding
['R']))
17467 AND ((($this->rtl
) AND (($this->x
- $imgw) < ($this->lMargin +
$this->cell_padding
['L'])))
17468 OR ((!$this->rtl
) AND (($this->x +
$imgw) > ($this->w
- $this->rMargin
- $this->cell_padding
['R']))))) {
17469 // add automatic line break
17470 $autolinebreak = true;
17471 $this->Ln('', $cell);
17472 if ((!$dom[($key-1)]['tag']) AND ($dom[($key-1)]['value'] == ' ')) {
17473 // go back to evaluate this line break
17478 if (!$autolinebreak) {
17479 if ($this->inPageBody()) {
17481 // check for page break
17482 if ((!$this->checkPageBreak($imgh)) AND ($this->y
< $pre_y)) {
17483 // fix for multicolumn mode
17484 $startliney = $this->y
;
17487 if ($this->page
> $startlinepage) {
17488 // fix line splitted over two pages
17489 if (isset($this->footerlen
[$startlinepage])) {
17490 $curpos = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
17492 // line to be moved one page forward
17493 $pagebuff = $this->getPageBuffer($startlinepage);
17494 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
17495 $tstart = substr($pagebuff, 0, $startlinepos);
17496 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
17497 // remove line from previous page
17498 $this->setPageBuffer($startlinepage, $tstart.''.$tend);
17499 $pagebuff = $this->getPageBuffer($this->page
);
17500 $tstart = substr($pagebuff, 0, $this->cntmrk
[$this->page
]);
17501 $tend = substr($pagebuff, $this->cntmrk
[$this->page
]);
17502 // add line start to current page
17503 $yshift = ($minstartliney - $this->y
);
17504 if ($fontaligned) {
17505 $yshift +
= ($curfontsize / $this->k
);
17507 $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k
));
17508 $this->setPageBuffer($this->page
, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
17509 // shift the annotations and links
17510 if (isset($this->PageAnnots
[$this->page
])) {
17511 $next_pask = count($this->PageAnnots
[$this->page
]);
17515 if (isset($this->PageAnnots
[$startlinepage])) {
17516 foreach ($this->PageAnnots
[$startlinepage] as $pak => $pac) {
17517 if ($pak >= $pask) {
17518 $this->PageAnnots
[$this->page
][] = $pac;
17519 unset($this->PageAnnots
[$startlinepage][$pak]);
17520 $npak = count($this->PageAnnots
[$this->page
]) - 1;
17521 $this->PageAnnots
[$this->page
][$npak]['y'] -= $yshift;
17525 $pask = $next_pask;
17526 $startlinepos = $this->cntmrk
[$this->page
];
17527 $startlinepage = $this->page
;
17528 $startliney = $this->y
;
17529 $this->newline
= false;
17531 $this->y +
= ($this->getCellHeight($curfontsize / $this->k
) - ($curfontdescent * $this->cell_height_ratio
) - $imgh);
17532 $minstartliney = min($this->y
, $minstartliney);
17533 $maxbottomliney = ($startliney +
$this->getCellHeight($curfontsize / $this->k
));
17535 } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
17536 // account for different font size
17537 $pfontname = $curfontname;
17538 $pfontstyle = $curfontstyle;
17539 $pfontsize = $curfontsize;
17540 $fontname = (isset($dom[$key]['fontname']) ?
$dom[$key]['fontname'] : $curfontname);
17541 $fontstyle = (isset($dom[$key]['fontstyle']) ?
$dom[$key]['fontstyle'] : $curfontstyle);
17542 $fontsize = (isset($dom[$key]['fontsize']) ?
$dom[$key]['fontsize'] : $curfontsize);
17543 $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
17544 $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
17545 if (($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
17546 OR ($this->cell_height_ratio
!= $dom[$key]['line-height'])
17547 OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
17548 if (($key < ($maxel - 1)) AND (
17549 ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li'))
17550 OR ($this->cell_height_ratio
!= $dom[$key]['line-height'])
17551 OR (!$this->newline
AND is_numeric($fontsize) AND is_numeric($curfontsize)
17552 AND ($fontsize >= 0) AND ($curfontsize >= 0)
17553 AND (($fontsize != $curfontsize) OR ($fontstyle != $curfontstyle) OR ($fontname != $curfontname)))
17555 if ($this->page
> $startlinepage) {
17556 // fix lines splitted over two pages
17557 if (isset($this->footerlen
[$startlinepage])) {
17558 $curpos = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
17560 // line to be moved one page forward
17561 $pagebuff = $this->getPageBuffer($startlinepage);
17562 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
17563 $tstart = substr($pagebuff, 0, $startlinepos);
17564 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
17565 // remove line start from previous page
17566 $this->setPageBuffer($startlinepage, $tstart.''.$tend);
17567 $pagebuff = $this->getPageBuffer($this->page
);
17568 $tstart = substr($pagebuff, 0, $this->cntmrk
[$this->page
]);
17569 $tend = substr($pagebuff, $this->cntmrk
[$this->page
]);
17570 // add line start to current page
17571 $yshift = ($minstartliney - $this->y
);
17572 $try = sprintf('1 0 0 1 0 %F cm', ($yshift * $this->k
));
17573 $this->setPageBuffer($this->page
, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
17574 // shift the annotations and links
17575 if (isset($this->PageAnnots
[$this->page
])) {
17576 $next_pask = count($this->PageAnnots
[$this->page
]);
17580 if (isset($this->PageAnnots
[$startlinepage])) {
17581 foreach ($this->PageAnnots
[$startlinepage] as $pak => $pac) {
17582 if ($pak >= $pask) {
17583 $this->PageAnnots
[$this->page
][] = $pac;
17584 unset($this->PageAnnots
[$startlinepage][$pak]);
17585 $npak = count($this->PageAnnots
[$this->page
]) - 1;
17586 $this->PageAnnots
[$this->page
][$npak]['y'] -= $yshift;
17590 $pask = $next_pask;
17591 $startlinepos = $this->cntmrk
[$this->page
];
17592 $startlinepage = $this->page
;
17593 $startliney = $this->y
;
17595 if (!isset($dom[$key]['line-height'])) {
17596 $dom[$key]['line-height'] = $this->cell_height_ratio
;
17598 if (!$dom[$key]['block']) {
17599 if (!(isset($dom[($key +
1)]) AND $dom[($key +
1)]['tag'] AND (!$dom[($key +
1)]['opening']) AND ($dom[($key +
1)]['value'] != 'li') AND $dom[$key]['tag'] AND (!$dom[$key]['opening']))) {
17600 $this->y +
= (((($curfontsize * $this->cell_height_ratio
) - ($fontsize * $dom[$key]['line-height'])) / $this->k
) +
$curfontascent - $fontascent - $curfontdescent +
$fontdescent) / 2;
17602 if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
17603 $current_line_align_data = array($key, $minstartliney, $maxbottomliney);
17604 if (isset($line_align_data) AND (($line_align_data[0] == ($key - 1)) OR (($line_align_data[0] == ($key - 2)) AND (isset($dom[($key - 1)])) AND (preg_match('/^([\s]+)$/', $dom[($key - 1)]['value']) > 0)))) {
17605 $minstartliney = min($this->y
, $line_align_data[1]);
17606 $maxbottomliney = max(($this->y +
$this->getCellHeight($fontsize / $this->k
)), $line_align_data[2]);
17608 $minstartliney = min($this->y
, $minstartliney);
17609 $maxbottomliney = max(($this->y +
$this->getCellHeight($fontsize / $this->k
)), $maxbottomliney);
17611 $line_align_data = $current_line_align_data;
17614 $this->cell_height_ratio
= $dom[$key]['line-height'];
17615 $fontaligned = true;
17617 $this->SetFont($fontname, $fontstyle, $fontsize);
17618 // reset row height
17619 $this->resetLastH();
17620 $curfontname = $fontname;
17621 $curfontstyle = $fontstyle;
17622 $curfontsize = $fontsize;
17623 $curfontascent = $fontascent;
17624 $curfontdescent = $fontdescent;
17627 // set text rendering mode
17628 $textstroke = isset($dom[$key]['stroke']) ?
$dom[$key]['stroke'] : $this->textstrokewidth
;
17629 $textfill = isset($dom[$key]['fill']) ?
$dom[$key]['fill'] : (($this->textrendermode %
2) == 0);
17630 $textclip = isset($dom[$key]['clip']) ?
$dom[$key]['clip'] : ($this->textrendermode
> 3);
17631 $this->setTextRenderingMode($textstroke, $textfill, $textclip);
17632 if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
17633 $this->setFontStretching($dom[$key]['font-stretch']);
17635 if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
17636 $this->setFontSpacing($dom[$key]['letter-spacing']);
17638 if (($plalign == 'J') AND $dom[$key]['block']) {
17641 // get current position on page buffer
17642 $curpos = $this->pagelen
[$startlinepage];
17643 if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
17644 $this->SetFillColorArray($dom[$key]['bgcolor']);
17647 $wfill = $fill |
false;
17649 if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
17650 $this->SetTextColorArray($dom[$key]['fgcolor']);
17652 if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
17653 $this->SetDrawColorArray($dom[$key]['strokecolor']);
17655 if (isset($dom[$key]['align'])) {
17656 $lalign = $dom[$key]['align'];
17658 if (TCPDF_STATIC
::empty_string($lalign)) {
17663 if ($this->newline
AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
17665 $fontaligned = false;
17666 // we are at the beginning of a new line
17667 if (isset($startlinex)) {
17668 $yshift = ($minstartliney - $startliney);
17669 if (($yshift > 0) OR ($this->page
> $startlinepage)) {
17673 // the last line must be shifted to be aligned as requested
17674 $linew = abs($this->endlinex
- $startlinex);
17675 if ($this->inxobj
) {
17676 // we are inside an XObject template
17677 $pstart = substr($this->xobjects
[$this->xobjid
]['outdata'], 0, $startlinepos);
17678 if (isset($opentagpos)) {
17679 $midpos = $opentagpos;
17684 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos, ($midpos - $startlinepos));
17685 $pend = substr($this->xobjects
[$this->xobjid
]['outdata'], $midpos);
17687 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos);
17691 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
17692 if (isset($opentagpos) AND isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
17693 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
17694 $midpos = min($opentagpos, $this->footerpos
[$startlinepage]);
17695 } elseif (isset($opentagpos)) {
17696 $midpos = $opentagpos;
17697 } elseif (isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
17698 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
17699 $midpos = $this->footerpos
[$startlinepage];
17704 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
17705 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
17707 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
17711 if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl
)) OR (($plalign == 'L') AND ($this->rtl
)))))) {
17712 // calculate shifting amount
17714 if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns
> 1)) {
17715 $tw +
= $this->cell_padding
['R'];
17717 if ($this->lMargin
!= $prevlMargin) {
17718 $tw +
= ($prevlMargin - $this->lMargin
);
17720 if ($this->rMargin
!= $prevrMargin) {
17721 $tw +
= ($prevrMargin - $this->rMargin
);
17723 $one_space_width = $this->GetStringWidth(chr(32));
17724 $no = 0; // number of spaces on a line contained on a single block
17725 if ($this->isRTLTextDir()) { // RTL
17726 // remove left space if exist
17727 $pos1 = TCPDF_STATIC
::revstrpos($pmid, '[(');
17729 $pos1 = intval($pos1);
17730 if ($this->isUnicodeFont()) {
17731 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, '[('.chr(0).chr(32)));
17734 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, '[('.chr(32)));
17737 if ($pos1 == $pos2) {
17738 $pmid = substr($pmid, 0, ($pos1 +
2)).substr($pmid, ($pos1 +
2 +
$spacelen));
17739 if (substr($pmid, $pos1, 4) == '[()]') {
17740 $linew -= $one_space_width;
17741 } elseif ($pos1 == strpos($pmid, '[(')) {
17747 // remove right space if exist
17748 $pos1 = TCPDF_STATIC
::revstrpos($pmid, ')]');
17750 $pos1 = intval($pos1);
17751 if ($this->isUnicodeFont()) {
17752 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, chr(0).chr(32).')]')) +
2;
17755 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, chr(32).')]')) +
1;
17758 if ($pos1 == $pos2) {
17759 $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
17760 $linew -= $one_space_width;
17764 $mdiff = ($tw - $linew);
17765 if ($plalign == 'C') {
17767 $t_x = -($mdiff / 2);
17769 $t_x = ($mdiff / 2);
17771 } elseif ($plalign == 'R') {
17772 // right alignment on LTR document
17774 } elseif ($plalign == 'L') {
17775 // left alignment on RTL document
17777 } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
17779 if ($this->isRTLTextDir()) {
17780 // align text on the left
17783 $ns = 0; // number of spaces
17785 // escape special characters
17786 $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
17787 $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
17789 if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER
)) {
17790 $spacestr = $this->getSpaceString();
17791 $maxkk = count($lnstring[1]) - 1;
17792 for ($kk=0; $kk <= $maxkk; ++
$kk) {
17793 // restore special characters
17794 $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
17795 $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
17796 // store number of spaces on the strings
17797 $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
17798 // count total spaces on line
17799 $ns +
= $lnstring[2][$kk];
17800 $lnstring[3][$kk] = $ns;
17805 // calculate additional space to add to each existing space
17806 $spacewidth = ($mdiff / ($ns - $no)) * $this->k
;
17807 if ($this->FontSize
<= 0) {
17808 $this->FontSize
= 1;
17810 $spacewidthu = -1000 * ($mdiff +
(($ns +
$no) * $one_space_width)) / $ns / $this->FontSize
;
17811 if ($this->font_spacing
!= 0) {
17812 // fixed spacing mode
17813 $osw = -1000 * $this->font_spacing
/ $this->FontSize
;
17814 $spacewidthu +
= $osw;
17821 $prev_epsposbeg = 0;
17823 if ($this->isRTLTextDir()) {
17824 $textpos = $this->wPt
;
17826 while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE
, $offset) == 1) {
17827 // check if we are inside a string section '[( ... )]'
17828 $stroffset = strpos($pmid, '[(', $offset);
17829 if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
17830 // set offset to the end of string section
17831 $offset = strpos($pmid, ')]', $stroffset);
17832 while (($offset !== false) AND ($pmid[($offset - 1)] == '\\')) {
17833 $offset = strpos($pmid, ')]', ($offset +
1));
17835 if ($offset === false) {
17836 $this->Error('HTML Justification: malformed PDF code.');
17840 if ($this->isRTLTextDir()) {
17841 $spacew = ($spacewidth * ($nsmax - $ns));
17843 $spacew = ($spacewidth * $ns);
17845 $offset = $strpiece[2][1] +
strlen($strpiece[2][0]);
17846 $epsposend = strpos($pmid, $this->epsmarker
.'Q', $offset);
17847 if ($epsposend !== null) {
17848 $epsposend +
= strlen($this->epsmarker
.'Q');
17849 $epsposbeg = strpos($pmid, 'q'.$this->epsmarker
, $offset);
17850 if ($epsposbeg === null) {
17851 $epsposbeg = strpos($pmid, 'q'.$this->epsmarker
, ($prev_epsposbeg - 6));
17852 $prev_epsposbeg = $epsposbeg;
17854 if (($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend)) {
17855 // shift EPS images
17856 $trx = sprintf('1 0 0 1 %F 0 cm', $spacew);
17857 $pmid_b = substr($pmid, 0, $epsposbeg);
17858 $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
17859 $pmid_e = substr($pmid, $epsposend);
17860 $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
17861 $offset = $epsposend;
17866 // shift blocks of code
17867 switch ($strpiece[2][0]) {
17872 // get current X position
17873 preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
17874 if (!isset($xmatches[1])) {
17877 $currentxpos = $xmatches[1];
17878 $textpos = $currentxpos;
17879 if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
17880 $ns = $lnstring[3][$strcount];
17881 if ($this->isRTLTextDir()) {
17882 $spacew = ($spacewidth * ($nsmax - $ns));
17887 if (preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $pmatch) == 1) {
17888 $newpmid = sprintf('%F',(floatval($pmatch[1]) +
$spacew)).' '.$pmatch[2].' x*#!#*x'.$pmatch[3].$pmatch[4];
17889 $pmid = str_replace($pmatch[0], $newpmid, $pmid);
17890 unset($pmatch, $newpmid);
17896 if (!TCPDF_STATIC
::empty_string($this->lispacer
)) {
17897 $this->lispacer
= '';
17900 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
17901 if (!isset($xmatches[1])) {
17904 $currentxpos = $xmatches[1];
17907 if ($this->isRTLTextDir()) { // RTL
17908 if ($currentxpos < $textpos) {
17909 $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
17910 $w_diff = ($spacewidth * $lnstring[2][$strcount]);
17912 if ($strcount > 0) {
17913 $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
17914 $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
17918 if ($currentxpos > $textpos) {
17919 if ($strcount > 0) {
17920 $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
17922 $w_diff = ($spacewidth * $lnstring[2][$strcount]);
17924 if ($strcount > 1) {
17925 $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
17927 if ($strcount > 0) {
17928 $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
17932 if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $pmatch) == 1) {
17933 $newx = sprintf('%F',(floatval($pmatch[1]) +
$x_diff));
17934 $neww = sprintf('%F',(floatval($pmatch[3]) +
$w_diff));
17935 $newpmid = $newx.' '.$pmatch[2].' '.$neww.' '.$pmatch[4].' x*#!#*x'.$pmatch[5].$pmatch[6];
17936 $pmid = str_replace($pmatch[0], $newpmid, $pmid);
17937 unset($pmatch, $newpmid, $newx, $neww);
17942 // get current X position
17943 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x', $pmid, $xmatches);
17944 if (!isset($xmatches[1])) {
17947 $currentxpos = $xmatches[1];
17949 if (preg_match('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x', $pmid, $pmatch) == 1) {
17950 $newx1 = sprintf('%F',(floatval($pmatch[1]) +
$spacew));
17951 $newx2 = sprintf('%F',(floatval($pmatch[3]) +
$spacew));
17952 $newx3 = sprintf('%F',(floatval($pmatch[5]) +
$spacew));
17953 $newpmid = $newx1.' '.$pmatch[2].' '.$newx2.' '.$pmatch[4].' '.$newx3.' '.$pmatch[6].' x*#!#*x'.$pmatch[7].$pmatch[8];
17954 $pmid = str_replace($pmatch[0], $newpmid, $pmid);
17955 unset($pmatch, $newpmid, $newx1, $newx2, $newx3);
17960 // shift the annotations and links
17961 $cxpos = ($currentxpos / $this->k
);
17962 $lmpos = ($this->lMargin +
$this->cell_padding
['L'] +
$this->feps
);
17963 if ($this->inxobj
) {
17964 // we are inside an XObject template
17965 foreach ($this->xobjects
[$this->xobjid
]['annotations'] as $pak => $pac) {
17966 if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k
) >= ($currentxpos - $this->feps
)) AND (($pac['x'] * $this->k
) <= ($currentxpos +
$this->feps
))) {
17967 if ($cxpos > $lmpos) {
17968 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['x'] +
= ($spacew / $this->k
);
17969 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
17971 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
17976 } elseif (isset($this->PageAnnots
[$this->page
])) {
17977 foreach ($this->PageAnnots
[$this->page
] as $pak => $pac) {
17978 if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k
) >= ($currentxpos - $this->feps
)) AND (($pac['x'] * $this->k
) <= ($currentxpos +
$this->feps
))) {
17979 if ($cxpos > $lmpos) {
17980 $this->PageAnnots
[$this->page
][$pak]['x'] +
= ($spacew / $this->k
);
17981 $this->PageAnnots
[$this->page
][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
17983 $this->PageAnnots
[$this->page
][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
17991 $pmid = str_replace('x*#!#*x', '', $pmid);
17992 if ($this->isUnicodeFont()) {
17993 // multibyte characters
17994 $spacew = $spacewidthu;
17995 if ($this->font_stretching
!= 100) {
17996 // word spacing is affected by stretching
17997 $spacew /= ($this->font_stretching
/ 100);
17999 // escape special characters
18001 $pmid = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmid);
18002 $pmid = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmid);
18003 if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmid, $pamatch) > 0) {
18004 foreach($pamatch[0] as $pk => $pmatch) {
18005 $replace = $pamatch[1][$pk];
18006 $replace = str_replace('#!#OP#!#', '(', $replace);
18007 $replace = str_replace('#!#CP#!#', ')', $replace);
18008 $newpmid = '[('.str_replace(chr(0).chr(32), ') '.sprintf('%F', $spacew).' (', $replace).')]';
18009 $pos = strpos($pmid, $pmatch, $pos);
18010 if ($pos !== FALSE) {
18011 $pmid = substr_replace($pmid, $newpmid, $pos, strlen($pmatch));
18017 if ($this->inxobj
) {
18018 // we are inside an XObject template
18019 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart."\n".$pmid."\n".$pend;
18021 $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
18023 $endlinepos = strlen($pstart."\n".$pmid."\n");
18025 // non-unicode (single-byte characters)
18026 if ($this->font_stretching
!= 100) {
18027 // word spacing (Tw) is affected by stretching
18028 $spacewidth /= ($this->font_stretching
/ 100);
18030 $rs = sprintf('%F Tw', $spacewidth);
18031 $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
18032 if ($this->inxobj
) {
18033 // we are inside an XObject template
18034 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
18036 $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
18038 $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
18042 } // end if $startlinex
18043 if (($t_x != 0) OR ($yshift < 0)) {
18045 $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k
), ($yshift * $this->k
));
18046 $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
18047 $endlinepos = strlen($pstart);
18048 if ($this->inxobj
) {
18049 // we are inside an XObject template
18050 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$pend;
18051 foreach ($this->xobjects
[$this->xobjid
]['annotations'] as $pak => $pac) {
18052 if ($pak >= $pask) {
18053 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['x'] +
= $t_x;
18054 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['y'] -= $yshift;
18058 $this->setPageBuffer($startlinepage, $pstart.$pend);
18059 // shift the annotations and links
18060 if (isset($this->PageAnnots
[$this->page
])) {
18061 foreach ($this->PageAnnots
[$this->page
] as $pak => $pac) {
18062 if ($pak >= $pask) {
18063 $this->PageAnnots
[$this->page
][$pak]['x'] +
= $t_x;
18064 $this->PageAnnots
[$this->page
][$pak]['y'] -= $yshift;
18069 $this->y
-= $yshift;
18072 $pbrk = $this->checkPageBreak($this->lasth
);
18073 $this->newline
= false;
18074 $startlinex = $this->x
;
18075 $startliney = $this->y
;
18076 if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
18077 $startliney -= ((0.3 * $this->FontSizePt
) / $this->k
);
18078 } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
18079 $startliney -= (($this->FontSizePt
/ 0.7) / $this->k
);
18081 $minstartliney = $startliney;
18082 $maxbottomliney = ($this->y +
$this->getCellHeight($fontsize / $this->k
));
18084 $startlinepage = $this->page
;
18085 if (isset($endlinepos) AND (!$pbrk)) {
18086 $startlinepos = $endlinepos;
18088 if ($this->inxobj
) {
18089 // we are inside an XObject template
18090 $startlinepos = strlen($this->xobjects
[$this->xobjid
]['outdata']);
18091 } elseif (!$this->InFooter
) {
18092 if (isset($this->footerlen
[$this->page
])) {
18093 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerlen
[$this->page
];
18095 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
18097 $startlinepos = $this->footerpos
[$this->page
];
18099 $startlinepos = $this->pagelen
[$this->page
];
18102 unset($endlinepos);
18103 $plalign = $lalign;
18104 if (isset($this->PageAnnots
[$this->page
])) {
18105 $pask = count($this->PageAnnots
[$this->page
]);
18109 if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
18110 AND (isset($this->emptypagemrk
[$this->page
]))
18111 AND ($this->emptypagemrk
[$this->page
] == $this->pagelen
[$this->page
]))) {
18112 $this->SetFont($fontname, $fontstyle, $fontsize);
18114 $this->SetFillColorArray($this->bgcolor
);
18118 if (isset($opentagpos)) {
18119 unset($opentagpos);
18121 if ($dom[$key]['tag']) {
18122 if ($dom[$key]['opening']) {
18123 // get text indentation (if any)
18124 if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
18125 $this->textindent
= $dom[$key]['text-indent'];
18126 $this->newline
= true;
18129 if (($dom[$key]['value'] == 'table') AND isset($dom[$key]['cols']) AND ($dom[$key]['cols'] > 0)) {
18130 // available page width
18132 $wtmp = $this->x
- $this->lMargin
;
18134 $wtmp = $this->w
- $this->rMargin
- $this->x
;
18136 // get cell spacing
18137 if (isset($dom[$key]['attribute']['cellspacing'])) {
18138 $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
18139 $cellspacing = array('H' => $clsp, 'V' => $clsp);
18140 } elseif (isset($dom[$key]['border-spacing'])) {
18141 $cellspacing = $dom[$key]['border-spacing'];
18143 $cellspacing = array('H' => 0, 'V' => 0);
18146 if (isset($dom[$key]['width'])) {
18147 $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
18149 $table_width = $wtmp;
18151 $table_width -= (2 * $cellspacing['H']);
18152 if (!$this->inthead
) {
18153 $this->y +
= $cellspacing['V'];
18156 $cellspacingx = -$cellspacing['H'];
18158 $cellspacingx = $cellspacing['H'];
18160 // total table width without cellspaces
18161 $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
18162 // minimum column width
18163 $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
18164 // array of custom column widths
18165 $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
18168 if ($dom[$key]['value'] == 'tr') {
18169 // reset column counter
18173 if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
18174 $trid = $dom[$key]['parent'];
18175 $table_el = $dom[$trid]['parent'];
18176 if (!isset($dom[$table_el]['cols'])) {
18177 $dom[$table_el]['cols'] = $dom[$trid]['cols'];
18179 // store border info
18181 if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
18182 $tdborder = $dom[$key]['border'];
18184 $colspan = intval($dom[$key]['attribute']['colspan']);
18185 if ($colspan <= 0) {
18188 $old_cell_padding = $this->cell_padding
;
18189 if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
18190 $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
18191 $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
18192 } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
18193 $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
18195 $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
18197 $this->cell_padding
= $current_cell_padding;
18198 if (isset($dom[$key]['height'])) {
18199 // minimum cell height
18200 $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
18204 if (isset($dom[$key]['content'])) {
18205 $cell_content = $dom[$key]['content'];
18207 $cell_content = ' ';
18209 $tagtype = $dom[$key]['value'];
18211 while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
18212 // move $key index forward
18215 if (!isset($dom[$trid]['startpage'])) {
18216 $dom[$trid]['startpage'] = $this->page
;
18218 $this->setPage($dom[$trid]['startpage']);
18220 if (!isset($dom[$trid]['startcolumn'])) {
18221 $dom[$trid]['startcolumn'] = $this->current_column
;
18222 } elseif ($this->current_column
!= $dom[$trid]['startcolumn']) {
18224 $this->selectColumn($dom[$trid]['startcolumn']);
18227 if (!isset($dom[$trid]['starty'])) {
18228 $dom[$trid]['starty'] = $this->y
;
18230 $this->y
= $dom[$trid]['starty'];
18232 if (!isset($dom[$trid]['startx'])) {
18233 $dom[$trid]['startx'] = $this->x
;
18234 $this->x +
= $cellspacingx;
18236 $this->x +
= ($cellspacingx / 2);
18238 if (isset($dom[$parentid]['attribute']['rowspan'])) {
18239 $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
18243 // skip row-spanned cells started on the previous rows
18244 if (isset($dom[$table_el]['rowspans'])) {
18246 $rskmax = count($dom[$table_el]['rowspans']);
18247 while ($rsk < $rskmax) {
18248 $trwsp = $dom[$table_el]['rowspans'][$rsk];
18249 $rsstartx = $trwsp['startx'];
18250 $rsendx = $trwsp['endx'];
18251 // account for margin changes
18252 if ($trwsp['startpage'] < $this->page
) {
18253 if (($this->rtl
) AND ($this->pagedim
[$this->page
]['orm'] != $this->pagedim
[$trwsp['startpage']]['orm'])) {
18254 $dl = ($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$trwsp['startpage']]['orm']);
18257 } elseif ((!$this->rtl
) AND ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$trwsp['startpage']]['olm'])) {
18258 $dl = ($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$trwsp['startpage']]['olm']);
18263 if (($trwsp['rowspan'] > 0)
18264 AND ($rsstartx > ($this->x
- $cellspacing['H'] - $current_cell_padding['L'] - $this->feps
))
18265 AND ($rsstartx < ($this->x +
$cellspacing['H'] +
$current_cell_padding['R'] +
$this->feps
))
18266 AND (($trwsp['starty'] < ($this->y
- $this->feps
)) OR ($trwsp['startpage'] < $this->page
) OR ($trwsp['startcolumn'] < $this->current_column
))) {
18267 // set the starting X position of the current cell
18268 $this->x
= $rsendx +
$cellspacingx;
18269 // increment column indicator
18270 $colid +
= $trwsp['colspan'];
18271 if (($trwsp['rowspan'] == 1)
18272 AND (isset($dom[$trid]['endy']))
18273 AND (isset($dom[$trid]['endpage']))
18274 AND (isset($dom[$trid]['endcolumn']))
18275 AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
18276 AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
18277 // set ending Y position for row
18278 $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
18279 $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
18287 if (isset($dom[$parentid]['width'])) {
18288 // user specified width
18289 $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
18290 $tmpcw = ($cellw / $colspan);
18291 for ($i = 0; $i < $colspan; ++
$i) {
18292 $table_colwidths[($colid +
$i)] = $tmpcw;
18295 // inherit column width
18297 for ($i = 0; $i < $colspan; ++
$i) {
18298 $cellw +
= (isset($table_colwidths[($colid +
$i)]) ?
$table_colwidths[($colid +
$i)] : 0);
18301 $cellw +
= (($colspan - 1) * $cellspacing['H']);
18302 // increment column indicator
18303 $colid +
= $colspan;
18304 // add rowspan information to table element
18305 if ($rowspan > 1) {
18306 $trsid = array_push($dom[$table_el]['rowspans'], array('trid' => $trid, 'rowspan' => $rowspan, 'mrowspan' => $rowspan, 'colspan' => $colspan, 'startpage' => $this->page
, 'startcolumn' => $this->current_column
, 'startx' => $this->x
, 'starty' => $this->y
));
18308 $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x
));
18309 if ($rowspan > 1) {
18310 $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
18312 // push background colors
18313 if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
18314 $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
18316 // store border info
18317 if (isset($tdborder) AND !empty($tdborder)) {
18318 $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
18320 $prevLastH = $this->lasth
;
18321 // store some info for multicolumn mode
18323 $this->colxshift
['x'] = $this->w
- $this->x
- $this->rMargin
;
18325 $this->colxshift
['x'] = $this->x
- $this->lMargin
;
18327 $this->colxshift
['s'] = $cellspacing;
18328 $this->colxshift
['p'] = $current_cell_padding;
18329 // ****** write the cell content ******
18330 $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true, true, 0, 'T', false);
18331 // restore some values
18332 $this->colxshift
= array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
18333 $this->lasth
= $prevLastH;
18334 $this->cell_padding
= $old_cell_padding;
18335 $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x
;
18336 // update the end of row position
18337 if ($rowspan <= 1) {
18338 if (isset($dom[$trid]['endy'])) {
18339 if (($this->page
== $dom[$trid]['endpage']) AND ($this->current_column
== $dom[$trid]['endcolumn'])) {
18340 $dom[$trid]['endy'] = max($this->y
, $dom[$trid]['endy']);
18341 } elseif (($this->page
> $dom[$trid]['endpage']) OR ($this->current_column
> $dom[$trid]['endcolumn'])) {
18342 $dom[$trid]['endy'] = $this->y
;
18345 $dom[$trid]['endy'] = $this->y
;
18347 if (isset($dom[$trid]['endpage'])) {
18348 $dom[$trid]['endpage'] = max($this->page
, $dom[$trid]['endpage']);
18350 $dom[$trid]['endpage'] = $this->page
;
18352 if (isset($dom[$trid]['endcolumn'])) {
18353 $dom[$trid]['endcolumn'] = max($this->current_column
, $dom[$trid]['endcolumn']);
18355 $dom[$trid]['endcolumn'] = $this->current_column
;
18358 // account for row-spanned cells
18359 $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x
;
18360 $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y
;
18361 $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page
;
18362 $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column
;
18364 if (isset($dom[$table_el]['rowspans'])) {
18365 // update endy and endpage on rowspanned cells
18366 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
18367 if ($trwsp['rowspan'] > 0) {
18368 if (isset($dom[$trid]['endpage'])) {
18369 if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
18370 $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
18371 } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
18372 $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
18373 $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
18374 $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
18376 $dom[$trid]['endy'] = $this->pagedim
[$dom[$trid]['endpage']]['hk'] - $this->pagedim
[$dom[$trid]['endpage']]['bm'];
18382 $this->x +
= ($cellspacingx / 2);
18384 // opening tag (or self-closing tag)
18385 if (!isset($opentagpos)) {
18386 if ($this->inxobj
) {
18387 // we are inside an XObject template
18388 $opentagpos = strlen($this->xobjects
[$this->xobjid
]['outdata']);
18389 } elseif (!$this->InFooter
) {
18390 if (isset($this->footerlen
[$this->page
])) {
18391 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerlen
[$this->page
];
18393 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
18395 $opentagpos = $this->footerpos
[$this->page
];
18398 $dom = $this->openHTMLTagHandler($dom, $key, $cell);
18400 } else { // closing tag
18401 $prev_numpages = $this->numpages
;
18402 $old_bordermrk = $this->bordermrk
[$this->page
];
18403 $dom = $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
18404 if ($this->bordermrk
[$this->page
] > $old_bordermrk) {
18405 $startlinepos +
= ($this->bordermrk
[$this->page
] - $old_bordermrk);
18407 if ($prev_numpages > $this->numpages
) {
18408 $startlinepage = $this->page
;
18411 } elseif (strlen($dom[$key]['value']) > 0) {
18413 if (!TCPDF_STATIC
::empty_string($this->lispacer
) AND ($this->lispacer
!= '^')) {
18414 $this->SetFont($pfontname, $pfontstyle, $pfontsize);
18415 $this->resetLastH();
18416 $minstartliney = $this->y
;
18417 $maxbottomliney = ($startliney +
$this->getCellHeight($this->FontSize
));
18418 if (is_numeric($pfontsize) AND ($pfontsize > 0)) {
18419 $this->putHtmlListBullet($this->listnum
, $this->lispacer
, $pfontsize);
18421 $this->SetFont($curfontname, $curfontstyle, $curfontsize);
18422 $this->resetLastH();
18423 if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
18424 $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
18425 $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
18426 $this->y +
= ($this->getCellHeight(($pfontsize - $curfontsize) / $this->k
) +
$pfontascent - $curfontascent - $pfontdescent +
$curfontdescent) / 2;
18427 $minstartliney = min($this->y
, $minstartliney);
18428 $maxbottomliney = max(($this->y +
$this->getCellHeight($pfontsize / $this->k
)), $maxbottomliney);
18432 $this->htmlvspace
= 0;
18433 $isRTLString = preg_match(TCPDF_FONT_DATA
::$uni_RE_PATTERN_RTL, $dom[$key]['value']) ||
preg_match(TCPDF_FONT_DATA
::$uni_RE_PATTERN_ARABIC, $dom[$key]['value']);
18434 if ((!$this->premode
) AND $this->isRTLTextDir() AND !$isRTLString) {
18435 // reverse spaces order
18436 $lsp = ''; // left spaces
18437 $rsp = ''; // right spaces
18438 if (preg_match('/^('.$this->re_space
['p'].'+)/'.$this->re_space
['m'], $dom[$key]['value'], $matches)) {
18439 $lsp = $matches[1];
18441 if (preg_match('/('.$this->re_space
['p'].'+)$/'.$this->re_space
['m'], $dom[$key]['value'], $matches)) {
18442 $rsp = $matches[1];
18444 $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
18447 if (!$this->premode
) {
18448 $prelen = strlen($dom[$key]['value']);
18449 if ($this->isRTLTextDir() AND !$isRTLString) {
18450 // right trim except non-breaking space
18451 $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
18453 // left trim except non-breaking space
18454 $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
18456 $postlen = strlen($dom[$key]['value']);
18457 if (($postlen == 0) AND ($prelen > 0)) {
18458 $dom[$key]['trimmed_space'] = true;
18462 $firstblock = true;
18464 $firstblock = false;
18465 // replace empty multiple spaces string with a single space
18466 $dom[$key]['value'] = preg_replace('/^'.$this->re_space
['p'].'+$/'.$this->re_space
['m'], chr(32), $dom[$key]['value']);
18470 $this->x
-= $this->textindent
;
18472 $this->x +
= $this->textindent
;
18474 if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
18475 $strlinelen = $this->GetStringWidth($dom[$key]['value']);
18476 if (!empty($this->HREF
) AND (isset($this->HREF
['url']))) {
18479 if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
18480 $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
18483 if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
18484 $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
18486 $strrest = $this->addHtmlLink($this->HREF
['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
18488 $wadj = 0; // space to leave for block continuity
18490 $cwa = ($this->x
- $this->lMargin
);
18492 $cwa = ($this->w
- $this->rMargin
- $this->x
);
18494 if (($strlinelen < $cwa) AND (isset($dom[($key +
1)])) AND ($dom[($key +
1)]['tag']) AND (!$dom[($key +
1)]['block'])) {
18495 // check the next text blocks for continuity
18496 $nkey = ($key +
1);
18497 $write_block = true;
18498 $same_textdir = true;
18499 $tmp_fontname = $this->FontFamily
;
18500 $tmp_fontstyle = $this->FontStyle
;
18501 $tmp_fontsize = $this->FontSizePt
;
18502 while ($write_block AND isset($dom[$nkey])) {
18503 if ($dom[$nkey]['tag']) {
18504 if ($dom[$nkey]['block']) {
18506 $write_block = false;
18508 $tmp_fontname = isset($dom[$nkey]['fontname']) ?
$dom[$nkey]['fontname'] : $this->FontFamily
;
18509 $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ?
$dom[$nkey]['fontstyle'] : $this->FontStyle
;
18510 $tmp_fontsize = isset($dom[$nkey]['fontsize']) ?
$dom[$nkey]['fontsize'] : $this->FontSizePt
;
18511 $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
18513 $nextstr = TCPDF_STATIC
::pregSplit('/'.$this->re_space
['p'].'+/', $this->re_space
['m'], $dom[$nkey]['value']);
18514 if (isset($nextstr[0]) AND $same_textdir) {
18515 $wadj +
= $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
18516 if (isset($nextstr[1])) {
18517 $write_block = false;
18524 if (($wadj > 0) AND (($strlinelen +
$wadj) >= $cwa)) {
18526 $nextstr = TCPDF_STATIC
::pregSplit('/'.$this->re_space
['p'].'/', $this->re_space
['m'], $dom[$key]['value']);
18527 $numblks = count($nextstr);
18528 if ($numblks > 1) {
18529 // try to split on blank spaces
18530 $wadj = ($cwa - $strlinelen +
$this->GetStringWidth($nextstr[($numblks - 1)]));
18532 // set the entire block on new line
18533 $wadj = $this->GetStringWidth($nextstr[0]);
18536 // check for reversed text direction
18537 if (($wadj > 0) AND (($this->rtl
AND ($this->tmprtl
=== 'L')) OR (!$this->rtl
AND ($this->tmprtl
=== 'R')))) {
18538 // LTR text on RTL direction or RTL text on LTR direction
18539 $reverse_dir = true;
18540 $this->rtl
= !$this->rtl
;
18541 $revshift = ($strlinelen +
$wadj +
0.000001); // add little quantity for rounding problems
18543 $this->x +
= $revshift;
18545 $this->x
-= $revshift;
18549 // ****** write only until the end of the line and get the rest ******
18550 $strrest = $this->Write($this->lasth
, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
18551 // restore default direction
18552 if ($reverse_dir AND ($wadj == 0)) {
18554 $this->rtl
= !$this->rtl
;
18555 $reverse_dir = false;
18559 $this->textindent
= 0;
18560 if (strlen($strrest) > 0) {
18561 // store the remaining string on the previous $key position
18562 $this->newline
= true;
18563 if ($strrest == $dom[$key]['value']) {
18564 // used to avoid infinite loop
18569 $dom[$key]['value'] = $strrest;
18572 $this->x
-= $this->cell_padding
['R'];
18574 $this->x +
= $this->cell_padding
['L'];
18582 // add the positive font spacing of the last character (if any)
18583 if ($this->font_spacing
> 0) {
18585 $this->x
-= $this->font_spacing
;
18587 $this->x +
= $this->font_spacing
;
18593 if (isset($dom[$key]['tag']) AND $dom[$key]['tag'] AND (!isset($dom[$key]['opening']) OR !$dom[$key]['opening']) AND isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
18594 // check if we are on a new page or on a new column
18595 if ((!$undo) AND (($this->y
< $this->start_transaction_y
) OR (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['endy'] < $this->start_transaction_y
)))) {
18596 // we are on a new page or on a new column and the total object height is less than the available vertical space.
18597 // restore previous object
18598 $this->rollbackTransaction(true);
18599 // restore previous values
18600 foreach ($this_method_vars as $vkey => $vval) {
18603 if (!empty($dom[$key]['thead'])) {
18604 $this->inthead
= true;
18606 // add a page (or trig AcceptPageBreak() for multicolumn mode)
18608 if ((!$this->checkPageBreak($this->PageBreakTrigger +
1)) AND ($this->y
< $pre_y)) {
18609 $startliney = $this->y
;
18611 $undo = true; // avoid infinite loop
18616 } // end for each $key
18617 // align the last line
18618 if (isset($startlinex)) {
18619 $yshift = ($minstartliney - $startliney);
18620 if (($yshift > 0) OR ($this->page
> $startlinepage)) {
18624 // the last line must be shifted to be aligned as requested
18625 $linew = abs($this->endlinex
- $startlinex);
18626 if ($this->inxobj
) {
18627 // we are inside an XObject template
18628 $pstart = substr($this->xobjects
[$this->xobjid
]['outdata'], 0, $startlinepos);
18629 if (isset($opentagpos)) {
18630 $midpos = $opentagpos;
18635 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos, ($midpos - $startlinepos));
18636 $pend = substr($this->xobjects
[$this->xobjid
]['outdata'], $midpos);
18638 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos);
18642 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
18643 if (isset($opentagpos) AND isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
18644 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
18645 $midpos = min($opentagpos, $this->footerpos
[$startlinepage]);
18646 } elseif (isset($opentagpos)) {
18647 $midpos = $opentagpos;
18648 } elseif (isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
18649 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
18650 $midpos = $this->footerpos
[$startlinepage];
18655 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
18656 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
18658 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
18662 if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl
)) OR (($plalign == 'L') AND ($this->rtl
)))))) {
18663 // calculate shifting amount
18665 if ($this->lMargin
!= $prevlMargin) {
18666 $tw +
= ($prevlMargin - $this->lMargin
);
18668 if ($this->rMargin
!= $prevrMargin) {
18669 $tw +
= ($prevrMargin - $this->rMargin
);
18671 $one_space_width = $this->GetStringWidth(chr(32));
18672 $no = 0; // number of spaces on a line contained on a single block
18673 if ($this->isRTLTextDir()) { // RTL
18674 // remove left space if exist
18675 $pos1 = TCPDF_STATIC
::revstrpos($pmid, '[(');
18677 $pos1 = intval($pos1);
18678 if ($this->isUnicodeFont()) {
18679 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, '[('.chr(0).chr(32)));
18682 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, '[('.chr(32)));
18685 if ($pos1 == $pos2) {
18686 $pmid = substr($pmid, 0, ($pos1 +
2)).substr($pmid, ($pos1 +
2 +
$spacelen));
18687 if (substr($pmid, $pos1, 4) == '[()]') {
18688 $linew -= $one_space_width;
18689 } elseif ($pos1 == strpos($pmid, '[(')) {
18695 // remove right space if exist
18696 $pos1 = TCPDF_STATIC
::revstrpos($pmid, ')]');
18698 $pos1 = intval($pos1);
18699 if ($this->isUnicodeFont()) {
18700 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, chr(0).chr(32).')]')) +
2;
18703 $pos2 = intval(TCPDF_STATIC
::revstrpos($pmid, chr(32).')]')) +
1;
18706 if ($pos1 == $pos2) {
18707 $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
18708 $linew -= $one_space_width;
18712 $mdiff = ($tw - $linew);
18713 if ($plalign == 'C') {
18715 $t_x = -($mdiff / 2);
18717 $t_x = ($mdiff / 2);
18719 } elseif ($plalign == 'R') {
18720 // right alignment on LTR document
18722 } elseif ($plalign == 'L') {
18723 // left alignment on RTL document
18726 } // end if startlinex
18727 if (($t_x != 0) OR ($yshift < 0)) {
18729 $trx = sprintf('1 0 0 1 %F %F cm', ($t_x * $this->k
), ($yshift * $this->k
));
18730 $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
18731 $endlinepos = strlen($pstart);
18732 if ($this->inxobj
) {
18733 // we are inside an XObject template
18734 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$pend;
18735 foreach ($this->xobjects
[$this->xobjid
]['annotations'] as $pak => $pac) {
18736 if ($pak >= $pask) {
18737 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['x'] +
= $t_x;
18738 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['y'] -= $yshift;
18742 $this->setPageBuffer($startlinepage, $pstart.$pend);
18743 // shift the annotations and links
18744 if (isset($this->PageAnnots
[$this->page
])) {
18745 foreach ($this->PageAnnots
[$this->page
] as $pak => $pac) {
18746 if ($pak >= $pask) {
18747 $this->PageAnnots
[$this->page
][$pak]['x'] +
= $t_x;
18748 $this->PageAnnots
[$this->page
][$pak]['y'] -= $yshift;
18753 $this->y
-= $yshift;
18757 // restore previous values
18758 $this->setGraphicVars($gvars);
18759 if ($this->num_columns
> 1) {
18760 $this->selectColumn();
18761 } elseif ($this->page
> $prevPage) {
18762 $this->lMargin
= $this->pagedim
[$this->page
]['olm'];
18763 $this->rMargin
= $this->pagedim
[$this->page
]['orm'];
18765 // restore previous list state
18766 $this->cell_height_ratio
= $prev_cell_height_ratio;
18767 $this->listnum
= $prev_listnum;
18768 $this->listordered
= $prev_listordered;
18769 $this->listcount
= $prev_listcount;
18770 $this->lispacer
= $prev_lispacer;
18771 if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
18772 $this->Ln($this->lasth
);
18773 if (($this->y
< $maxbottomliney) AND ($startlinepage == $this->page
)) {
18774 $this->y
= $maxbottomliney;
18781 * Process opening tags.
18782 * @param $dom (array) html dom array
18783 * @param $key (int) current element id
18784 * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
18785 * @return $dom array
18788 protected function openHTMLTagHandler($dom, $key, $cell) {
18790 $parent = $dom[($dom[$key]['parent'])];
18791 $firsttag = ($key == 1);
18792 // check for text direction attribute
18793 if (isset($tag['dir'])) {
18794 $this->setTempRTL($tag['dir']);
18796 $this->tmprtl
= false;
18798 if ($tag['block']) {
18799 $hbz = 0; // distance from y to line bottom
18800 $hb = 0; // vertical space between block tags
18801 // calculate vertical space for block tags
18802 if (isset($this->tagvspaces
[$tag['value']][0]['h']) && !empty($this->tagvspaces
[$tag['value']][0]['h']) && ($this->tagvspaces
[$tag['value']][0]['h'] >= 0)) {
18803 $cur_h = $this->tagvspaces
[$tag['value']][0]['h'];
18804 } elseif (isset($tag['fontsize'])) {
18805 $cur_h = $this->getCellHeight($tag['fontsize'] / $this->k
);
18807 $cur_h = $this->getCellHeight($this->FontSize
);
18809 if (isset($this->tagvspaces
[$tag['value']][0]['n'])) {
18810 $on = $this->tagvspaces
[$tag['value']][0]['n'];
18811 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
18816 if ((!isset($this->tagvspaces
[$tag['value']])) AND (in_array($tag['value'], array('div', 'dt', 'dd', 'li', 'br', 'hr')))) {
18819 $hb = ($on * $cur_h);
18821 if (($this->htmlvspace
<= 0) AND ($on > 0)) {
18822 if (isset($parent['fontsize'])) {
18823 $hbz = (($parent['fontsize'] / $this->k
) * $this->cell_height_ratio
);
18825 $hbz = $this->getCellHeight($this->FontSize
);
18828 if (isset($dom[($key - 1)]) AND ($dom[($key - 1)]['value'] == 'table')) {
18829 // fix vertical space after table
18832 // closing vertical space
18834 if (isset($this->tagvspaces
[$tag['value']][1]['h']) && !empty($this->tagvspaces
[$tag['value']][1]['h']) && ($this->tagvspaces
[$tag['value']][1]['h'] >= 0)) {
18835 $pre_h = $this->tagvspaces
[$tag['value']][1]['h'];
18836 } elseif (isset($parent['fontsize'])) {
18837 $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k
);
18839 $pre_h = $this->getCellHeight($this->FontSize
);
18841 if (isset($this->tagvspaces
[$tag['value']][1]['n'])) {
18842 $cn = $this->tagvspaces
[$tag['value']][1]['n'];
18843 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
18848 if (isset($this->tagvspaces
[$tag['value']][1])) {
18849 $hbc = ($cn * $pre_h);
18853 switch($tag['value']) {
18857 $dom[$key]['rowspans'] = array();
18858 if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
18859 $this->htmlvspace
= 0;
18860 // set table header
18861 if (!TCPDF_STATIC
::empty_string($dom[$key]['thead'])) {
18862 // set table header
18863 $this->thead
= $dom[$key]['thead'];
18864 if (!isset($this->theadMargins
) OR (empty($this->theadMargins
))) {
18865 $this->theadMargins
= array();
18866 $this->theadMargins
['cell_padding'] = $this->cell_padding
;
18867 $this->theadMargins
['lmargin'] = $this->lMargin
;
18868 $this->theadMargins
['rmargin'] = $this->rMargin
;
18869 $this->theadMargins
['page'] = $this->page
;
18870 $this->theadMargins
['cell'] = $cell;
18871 $this->theadMargins
['gvars'] = $this->getGraphicVars();
18875 // store current margins and page
18876 $dom[$key]['old_cell_padding'] = $this->cell_padding
;
18877 if (isset($tag['attribute']['cellpadding'])) {
18878 $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
18879 $this->SetCellPadding($pad);
18880 } elseif (isset($tag['padding'])) {
18881 $this->cell_padding
= $tag['padding'];
18883 if (isset($tag['attribute']['cellspacing'])) {
18884 $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
18885 } elseif (isset($tag['border-spacing'])) {
18886 $cs = $tag['border-spacing']['V'];
18888 $prev_y = $this->y
;
18889 if ($this->checkPageBreak(((2 * $cp) +
(2 * $cs) +
$this->lasth
), '', false) OR ($this->y
< $prev_y)) {
18890 $this->inthead
= true;
18891 // add a page (or trig AcceptPageBreak() for multicolumn mode)
18892 $this->checkPageBreak($this->PageBreakTrigger +
1);
18897 // array of columns positions
18898 $dom[$key]['cellpos'] = array();
18902 if ((isset($tag['height'])) AND ($tag['height'] != '')) {
18903 $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
18905 $hrHeight = $this->GetLineWidth();
18907 $this->addHTMLVertSpace($hbz, max($hb, ($hrHeight / 2)), $cell, $firsttag);
18908 $x = $this->GetX();
18909 $y = $this->GetY();
18910 $wtmp = $this->w
- $this->lMargin
- $this->rMargin
;
18912 $wtmp -= ($this->cell_padding
['L'] +
$this->cell_padding
['R']);
18914 if ((isset($tag['width'])) AND ($tag['width'] != '')) {
18915 $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
18919 $prevlinewidth = $this->GetLineWidth();
18920 $this->SetLineWidth($hrHeight);
18922 $lineStyle = array(
18923 'color' => $tag['fgcolor'],
18924 'cap' => $tag['style']['cap'],
18925 'join' => $tag['style']['join'],
18926 'dash' => $tag['style']['dash'],
18927 'phase' => $tag['style']['phase'],
18930 $lineStyle = array_filter($lineStyle);
18932 $this->Line($x, $y, $x +
$hrWidth, $y, $lineStyle);
18933 $this->SetLineWidth($prevlinewidth);
18934 $this->addHTMLVertSpace(max($hbc, ($hrHeight / 2)), 0, $cell, !isset($dom[($key +
1)]));
18938 if (array_key_exists('href', $tag['attribute'])) {
18939 $this->HREF
['url'] = $tag['attribute']['href'];
18944 if (empty($tag['attribute']['src'])) {
18947 $imgsrc = $tag['attribute']['src'];
18948 if ($imgsrc[0] === '@') {
18950 $imgsrc = '@'.base64_decode(substr($imgsrc, 1));
18952 } elseif ( $this->allowLocalFiles
&& substr($imgsrc, 0, 7) === 'file://') {
18953 // get image type from a local file path
18954 $imgsrc = substr($imgsrc, 7);
18955 $type = TCPDF_IMAGES
::getImageFileType($imgsrc);
18957 if (($imgsrc[0] === '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
18959 $findroot = strpos($imgsrc, $_SERVER['DOCUMENT_ROOT']);
18960 if (($findroot === false) OR ($findroot > 1)) {
18961 if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
18962 $imgsrc = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$imgsrc;
18964 $imgsrc = $_SERVER['DOCUMENT_ROOT'].$imgsrc;
18967 $imgsrc = urldecode($imgsrc);
18968 $testscrtype = @parse_url
($imgsrc);
18969 if (empty($testscrtype['query'])) {
18970 // convert URL to server path
18971 $imgsrc = str_replace(K_PATH_URL
, K_PATH_MAIN
, $imgsrc);
18972 } elseif (preg_match('|^https?://|', $imgsrc) !== 1) {
18973 // convert URL to server path
18974 $imgsrc = str_replace(K_PATH_MAIN
, K_PATH_URL
, $imgsrc);
18978 $type = TCPDF_IMAGES
::getImageFileType($imgsrc);
18980 if (!isset($tag['width'])) {
18983 if (!isset($tag['height'])) {
18984 $tag['height'] = 0;
18986 //if (!isset($tag['attribute']['align'])) {
18987 // the only alignment supported is "bottom"
18988 // further development is required for other modes.
18989 $tag['attribute']['align'] = 'bottom';
18991 switch($tag['attribute']['align']) {
19012 if (isset($this->HREF
['url']) AND !TCPDF_STATIC
::empty_string($this->HREF
['url'])) {
19013 $imglink = $this->HREF
['url'];
19014 if ($imglink[0] == '#') {
19015 // convert url to internal link
19016 $lnkdata = explode(',', $imglink);
19017 if (isset($lnkdata[0])) {
19018 $page = intval(substr($lnkdata[0], 1));
19019 if (empty($page) OR ($page <= 0)) {
19020 $page = $this->page
;
19022 if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
19023 $lnky = floatval($lnkdata[1]);
19027 $imglink = $this->AddLink();
19028 $this->SetLink($imglink, $lnky, $page);
19033 if (isset($tag['border']) AND !empty($tag['border'])) {
19034 // currently only support 1 (frame) or a combination of 'LTRB'
19035 $border = $tag['border'];
19038 if (isset($tag['width'])) {
19039 $iw = $this->getHTMLUnitToUnits($tag['width'], ($tag['fontsize'] / $this->k
), 'px', false);
19042 if (isset($tag['height'])) {
19043 $ih = $this->getHTMLUnitToUnits($tag['height'], ($tag['fontsize'] / $this->k
), 'px', false);
19045 if (($type == 'eps') OR ($type == 'ai')) {
19046 $this->ImageEps($imgsrc, $xpos, $this->y
, $iw, $ih, $imglink, true, $align, '', $border, true);
19047 } elseif ($type == 'svg') {
19048 $this->ImageSVG($imgsrc, $xpos, $this->y
, $iw, $ih, $imglink, $align, '', $border, true);
19050 $this->Image($imgsrc, $xpos, $this->y
, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
19058 $this->y
= (($this->img_rb_y +
$prevy - ($this->getCellHeight($tag['fontsize'] / $this->k
))) / 2);
19062 $this->y
= $this->img_rb_y
- ($this->getCellHeight($tag['fontsize'] / $this->k
) - ($this->getFontDescent($tag['fontname'], $tag['fontstyle'], $tag['fontsize']) * $this->cell_height_ratio
));
19070 if ($this->listnum
== 1) {
19071 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19073 $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
19078 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19083 $this->rMargin +
= $this->listindent
;
19085 $this->lMargin +
= $this->listindent
;
19087 ++
$this->listindentlevel
;
19088 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19094 if ($tag['value'] == 'ol') {
19095 $this->listordered
[$this->listnum
] = true;
19097 $this->listordered
[$this->listnum
] = false;
19099 if (isset($tag['attribute']['start'])) {
19100 $this->listcount
[$this->listnum
] = intval($tag['attribute']['start']) - 1;
19102 $this->listcount
[$this->listnum
] = 0;
19105 $this->rMargin +
= $this->listindent
;
19106 $this->x
-= $this->listindent
;
19108 $this->lMargin +
= $this->listindent
;
19109 $this->x +
= $this->listindent
;
19111 ++
$this->listindentlevel
;
19112 if ($this->listnum
== 1) {
19114 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19117 $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
19123 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19125 if ($this->listordered
[$this->listnum
]) {
19127 if (isset($parent['attribute']['type']) AND !TCPDF_STATIC
::empty_string($parent['attribute']['type'])) {
19128 $this->lispacer
= $parent['attribute']['type'];
19129 } elseif (isset($parent['listtype']) AND !TCPDF_STATIC
::empty_string($parent['listtype'])) {
19130 $this->lispacer
= $parent['listtype'];
19131 } elseif (isset($this->lisymbol
) AND !TCPDF_STATIC
::empty_string($this->lisymbol
)) {
19132 $this->lispacer
= $this->lisymbol
;
19134 $this->lispacer
= '#';
19136 ++
$this->listcount
[$this->listnum
];
19137 if (isset($tag['attribute']['value'])) {
19138 $this->listcount
[$this->listnum
] = intval($tag['attribute']['value']);
19142 if (isset($parent['attribute']['type']) AND !TCPDF_STATIC
::empty_string($parent['attribute']['type'])) {
19143 $this->lispacer
= $parent['attribute']['type'];
19144 } elseif (isset($parent['listtype']) AND !TCPDF_STATIC
::empty_string($parent['listtype'])) {
19145 $this->lispacer
= $parent['listtype'];
19146 } elseif (isset($this->lisymbol
) AND !TCPDF_STATIC
::empty_string($this->lisymbol
)) {
19147 $this->lispacer
= $this->lisymbol
;
19149 $this->lispacer
= '!';
19154 case 'blockquote': {
19156 $this->rMargin +
= $this->listindent
;
19158 $this->lMargin +
= $this->listindent
;
19160 ++
$this->listindentlevel
;
19161 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19165 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19169 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19173 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19177 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19178 $this->premode
= true;
19182 $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt
) / $this->k
));
19186 $this->SetXY($this->GetX(), $this->GetY() +
((0.3 * $this->FontSizePt
) / $this->k
));
19195 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
19198 // Form fields (since 4.8.000 - 2009-09-07)
19200 if (isset($tag['attribute']['action'])) {
19201 $this->form_action
= $tag['attribute']['action'];
19203 $this->Error('Please explicitly set action attribute path!');
19205 if (isset($tag['attribute']['enctype'])) {
19206 $this->form_enctype
= $tag['attribute']['enctype'];
19208 $this->form_enctype
= 'application/x-www-form-urlencoded';
19210 if (isset($tag['attribute']['method'])) {
19211 $this->form_mode
= $tag['attribute']['method'];
19213 $this->form_mode
= 'post';
19218 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['name'])) {
19219 $name = $tag['attribute']['name'];
19225 if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['readonly'])) {
19226 $prop['readonly'] = true;
19228 if (isset($tag['attribute']['value']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['value'])) {
19229 $value = $tag['attribute']['value'];
19231 if (isset($tag['attribute']['maxlength']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['maxlength'])) {
19232 $opt['maxlen'] = intval($tag['attribute']['maxlength']);
19234 $h = $this->getCellHeight($this->FontSize
);
19235 if (isset($tag['attribute']['size']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['size'])) {
19236 $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
19240 if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
19245 if (isset($tag['align'])) {
19246 switch ($tag['align']) {
19261 switch ($tag['attribute']['type']) {
19263 if (isset($value)) {
19264 $opt['v'] = $value;
19266 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19270 if (isset($value)) {
19271 $opt['v'] = $value;
19273 $prop['password'] = 'true';
19274 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19278 if (!isset($value)) {
19281 $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
19285 if (!isset($value)) {
19288 $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
19292 if (!isset($value)) {
19295 $w = $this->GetStringWidth($value) * 1.5;
19297 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19299 $action['S'] = 'SubmitForm';
19300 $action['F'] = $this->form_action
;
19301 if ($this->form_enctype
!= 'FDF') {
19302 $action['Flags'] = array('ExportFormat');
19304 if ($this->form_mode
== 'get') {
19305 $action['Flags'] = array('GetMethod');
19307 $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
19311 if (!isset($value)) {
19314 $w = $this->GetStringWidth($value) * 1.5;
19316 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19317 $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
19321 $prop['fileSelect'] = 'true';
19322 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19323 if (!isset($value)) {
19326 $w = $this->GetStringWidth($value) * 2;
19328 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19329 $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
19330 $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
19334 if (isset($value)) {
19335 $opt['v'] = $value;
19337 $opt['f'] = array('invisible', 'hidden');
19338 $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
19342 // THIS TYPE MUST BE FIXED
19343 if (isset($tag['attribute']['src']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['src'])) {
19344 $img = $tag['attribute']['src'];
19349 //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
19350 if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
19351 $jsaction = $tag['attribute']['onclick'];
19355 $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
19359 if (!isset($value)) {
19362 $w = $this->GetStringWidth($value) * 1.5;
19364 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
19365 if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
19366 $jsaction = $tag['attribute']['onclick'];
19370 $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
19379 if (isset($tag['attribute']['readonly']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['readonly'])) {
19380 $prop['readonly'] = true;
19382 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['name'])) {
19383 $name = $tag['attribute']['name'];
19387 if (isset($tag['attribute']['value']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['value'])) {
19388 $opt['v'] = $tag['attribute']['value'];
19390 if (isset($tag['attribute']['cols']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['cols'])) {
19391 $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
19395 if (isset($tag['attribute']['rows']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['rows'])) {
19396 $h = intval($tag['attribute']['rows']) * $this->getCellHeight($this->FontSize
);
19400 $prop['multiline'] = 'true';
19401 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
19405 $h = $this->getCellHeight($this->FontSize
);
19406 if (isset($tag['attribute']['size']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['size'])) {
19407 $h *= ($tag['attribute']['size'] +
1);
19411 if (isset($tag['attribute']['name']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['name'])) {
19412 $name = $tag['attribute']['name'];
19417 if (isset($tag['attribute']['opt']) AND !TCPDF_STATIC
::empty_string($tag['attribute']['opt'])) {
19418 $options = explode('#!NwL!#', $tag['attribute']['opt']);
19420 foreach ($options as $val) {
19421 if (strpos($val, '#!TaB!#') !== false) {
19422 $opts = explode('#!TaB!#', $val);
19424 $w = max($w, $this->GetStringWidth($opts[1]));
19427 $w = max($w, $this->GetStringWidth($val));
19434 if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
19435 $prop['multipleSelection'] = 'true';
19436 $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
19438 $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
19443 if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML
=== true)) {
19444 // Special tag used to call TCPDF methods
19445 if (isset($tag['attribute']['method'])) {
19446 $tcpdf_method = $tag['attribute']['method'];
19447 if (method_exists($this, $tcpdf_method)) {
19448 if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
19449 $params = $this->unserializeTCPDFtagParameters($tag['attribute']['params']);
19450 call_user_func_array(array($this, $tcpdf_method), $params);
19452 $this->$tcpdf_method();
19454 $this->newline
= true;
19464 // define tags that support borders and background colors
19465 $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
19466 if (in_array($tag['value'], $bordertags)) {
19468 $dom[$key]['borderposition'] = $this->getBorderStartPosition();
19470 if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
19471 $pba = $dom[$key]['attribute']['pagebreakafter'];
19472 // check for pagebreak
19473 if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
19474 // add a page (or trig AcceptPageBreak() for multicolumn mode)
19475 $this->checkPageBreak($this->PageBreakTrigger +
1);
19477 if ((($pba == 'left') AND (((!$this->rtl
) AND (($this->page %
2) == 0)) OR (($this->rtl
) AND (($this->page %
2) != 0))))
19478 OR (($pba == 'right') AND (((!$this->rtl
) AND (($this->page %
2) != 0)) OR (($this->rtl
) AND (($this->page %
2) == 0))))) {
19479 // add a page (or trig AcceptPageBreak() for multicolumn mode)
19480 $this->checkPageBreak($this->PageBreakTrigger +
1);
19487 * Process closing tags.
19488 * @param $dom (array) html dom array
19489 * @param $key (int) current element id
19490 * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
19491 * @param $maxbottomliney (int) maximum y value of current line
19492 * @return $dom array
19495 protected function closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney=0) {
19497 $parent = $dom[($dom[$key]['parent'])];
19498 $lasttag = ((!isset($dom[($key +
1)])) OR ((!isset($dom[($key +
2)])) AND ($dom[($key +
1)]['value'] == 'marker')));
19499 $in_table_head = false;
19500 // maximum x position (used to draw borders)
19506 if ($tag['block']) {
19507 $hbz = 0; // distance from y to line bottom
19508 $hb = 0; // vertical space between block tags
19509 // calculate vertical space for block tags
19510 if (isset($this->tagvspaces
[$tag['value']][1]['h']) && !empty($this->tagvspaces
[$tag['value']][1]['h']) && ($this->tagvspaces
[$tag['value']][1]['h'] >= 0)) {
19511 $pre_h = $this->tagvspaces
[$tag['value']][1]['h'];
19512 } elseif (isset($parent['fontsize'])) {
19513 $pre_h = $this->getCellHeight($parent['fontsize'] / $this->k
);
19515 $pre_h = $this->getCellHeight($this->FontSize
);
19517 if (isset($this->tagvspaces
[$tag['value']][1]['n'])) {
19518 $cn = $this->tagvspaces
[$tag['value']][1]['n'];
19519 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
19524 if ((!isset($this->tagvspaces
[$tag['value']])) AND ($tag['value'] == 'div')) {
19527 $hb = ($cn * $pre_h);
19529 if ($maxbottomliney > $this->PageBreakTrigger
) {
19530 $hbz = $this->getCellHeight($this->FontSize
);
19531 } elseif ($this->y
< $maxbottomliney) {
19532 $hbz = ($maxbottomliney - $this->y
);
19536 switch($tag['value']) {
19538 $table_el = $dom[($dom[$key]['parent'])]['parent'];
19539 if (!isset($parent['endy'])) {
19540 $dom[($dom[$key]['parent'])]['endy'] = $this->y
;
19541 $parent['endy'] = $this->y
;
19543 if (!isset($parent['endpage'])) {
19544 $dom[($dom[$key]['parent'])]['endpage'] = $this->page
;
19545 $parent['endpage'] = $this->page
;
19547 if (!isset($parent['endcolumn'])) {
19548 $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column
;
19549 $parent['endcolumn'] = $this->current_column
;
19551 // update row-spanned cells
19552 if (isset($dom[$table_el]['rowspans'])) {
19553 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
19554 $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
19555 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
19556 if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
19557 $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
19558 } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
19559 $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
19560 $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
19561 $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
19565 // report new endy and endpage to the rowspanned cells
19566 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
19567 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
19568 $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
19569 $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
19570 $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
19571 $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
19572 $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
19573 $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
19576 // update remaining rowspanned cells
19577 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
19578 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
19579 $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
19580 $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
19581 $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
19585 $prev_page = $this->page
;
19586 $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
19587 if ($this->num_columns
> 1) {
19588 if (($prev_page < $this->page
)
19589 AND ((($this->current_column
== 0) AND ($dom[($dom[$key]['parent'])]['endcolumn'] == ($this->num_columns
- 1)))
19590 OR ($this->current_column
== $dom[($dom[$key]['parent'])]['endcolumn']))) {
19592 $this->selectColumn(0);
19593 $dom[($dom[$key]['parent'])]['endcolumn'] = 0;
19594 $dom[($dom[$key]['parent'])]['endy'] = $this->y
;
19596 $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
19597 $this->y
= $dom[($dom[$key]['parent'])]['endy'];
19600 $this->y
= $dom[($dom[$key]['parent'])]['endy'];
19602 if (isset($dom[$table_el]['attribute']['cellspacing'])) {
19603 $this->y +
= $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
19604 } elseif (isset($dom[$table_el]['border-spacing'])) {
19605 $this->y +
= $dom[$table_el]['border-spacing']['V'];
19607 $this->Ln(0, $cell);
19608 if ($this->current_column
== $parent['startcolumn']) {
19609 $this->x
= $parent['startx'];
19611 // account for booklet mode
19612 if ($this->page
> $parent['startpage']) {
19613 if (($this->rtl
) AND ($this->pagedim
[$this->page
]['orm'] != $this->pagedim
[$parent['startpage']]['orm'])) {
19614 $this->x
-= ($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$parent['startpage']]['orm']);
19615 } elseif ((!$this->rtl
) AND ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$parent['startpage']]['olm'])) {
19616 $this->x +
= ($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$parent['startpage']]['olm']);
19622 // closing tag used for the thead part
19623 $in_table_head = true;
19624 $this->inthead
= false;
19626 $table_el = $parent;
19627 // set default border
19628 if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
19629 // set default border
19630 $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
19634 $default_border = $border;
19635 // fix bottom line alignment of last line before page break
19636 foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
19637 // update row-spanned cells
19638 if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
19639 foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
19640 if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] > 0)) {
19641 $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
19643 if ($dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] == $trkey) {
19644 $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
19648 if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
19649 $pgendy = $this->pagedim
[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim
[$dom[$prevtrkey]['endpage']]['bm'];
19650 $dom[$prevtrkey]['endy'] = $pgendy;
19651 // update row-spanned cells
19652 if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
19653 foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
19654 if (($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
19655 $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
19656 $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
19661 $prevtrkey = $trkey;
19662 $table_el = $dom[($dom[$key]['parent'])];
19665 if (count($table_el['trids']) > 0) {
19668 foreach ($table_el['trids'] as $j => $trkey) {
19669 $parent = $dom[$trkey];
19670 if (!isset($xmax)) {
19671 $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
19673 // for each cell on the row
19674 foreach ($parent['cellpos'] as $k => $cellpos) {
19675 if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
19676 $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
19677 $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
19678 $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
19679 $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
19680 $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
19681 $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
19682 $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
19684 $endy = $parent['endy'];
19685 $startpage = $parent['startpage'];
19686 $endpage = $parent['endpage'];
19687 $startcolumn = $parent['startcolumn'];
19688 $endcolumn = $parent['endcolumn'];
19690 if ($this->num_columns
== 0) {
19691 $this->num_columns
= 1;
19693 if (isset($cellpos['border'])) {
19694 $border = $cellpos['border'];
19696 if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
19697 $this->SetFillColorArray($cellpos['bgcolor']);
19702 $x = $cellpos['startx'];
19703 $y = $parent['starty'];
19705 $w = abs($cellpos['endx'] - $cellpos['startx']);
19706 // get border modes
19707 $border_start = TCPDF_STATIC
::getBorderMode($border, $position='start', $this->opencell
);
19708 $border_end = TCPDF_STATIC
::getBorderMode($border, $position='end', $this->opencell
);
19709 $border_middle = TCPDF_STATIC
::getBorderMode($border, $position='middle', $this->opencell
);
19710 // design borders around HTML cells.
19711 for ($page = $startpage; $page <= $endpage; ++
$page) { // for each page
19713 $this->setPage($page);
19714 if ($this->num_columns
< 2) {
19715 // single-column mode
19717 $this->y
= $this->tMargin
;
19719 // account for margin changes
19720 if ($page > $startpage) {
19721 if (($this->rtl
) AND ($this->pagedim
[$page]['orm'] != $this->pagedim
[$startpage]['orm'])) {
19722 $this->x
-= ($this->pagedim
[$page]['orm'] - $this->pagedim
[$startpage]['orm']);
19723 } elseif ((!$this->rtl
) AND ($this->pagedim
[$page]['olm'] != $this->pagedim
[$startpage]['olm'])) {
19724 $this->x +
= ($this->pagedim
[$page]['olm'] - $this->pagedim
[$startpage]['olm']);
19727 if ($startpage == $endpage) { // single page
19730 for ($column = $startcolumn; $column <= $endcolumn; ++
$column) { // for each column
19731 $this->selectColumn($column);
19732 if ($startcolumn == $endcolumn) { // single column
19733 $cborder = $border;
19734 $h = $endy - $parent['starty'];
19737 } elseif ($column == $startcolumn) { // first column
19738 $cborder = $border_start;
19739 $this->y
= $starty;
19741 $h = $this->h
- $this->y
- $this->bMargin
;
19743 $deltacol = $this->x +
$this->rMargin
- $this->w
;
19745 $deltacol = $this->x
- $this->lMargin
;
19747 } elseif ($column == $endcolumn) { // end column
19748 $cborder = $border_end;
19749 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
19750 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
19752 $this->x +
= $deltacol;
19753 $h = $endy - $this->y
;
19754 } else { // middle column
19755 $cborder = $border_middle;
19756 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
19757 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
19759 $this->x +
= $deltacol;
19760 $h = $this->h
- $this->y
- $this->bMargin
;
19762 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19763 } // end for each column
19764 } elseif ($page == $startpage) { // first page
19767 for ($column = $startcolumn; $column < $this->num_columns
; ++
$column) { // for each column
19768 $this->selectColumn($column);
19769 if ($column == $startcolumn) { // first column
19770 $cborder = $border_start;
19771 $this->y
= $starty;
19773 $h = $this->h
- $this->y
- $this->bMargin
;
19775 $deltacol = $this->x +
$this->rMargin
- $this->w
;
19777 $deltacol = $this->x
- $this->lMargin
;
19779 } else { // middle column
19780 $cborder = $border_middle;
19781 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
19782 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
19784 $this->x +
= $deltacol;
19785 $h = $this->h
- $this->y
- $this->bMargin
;
19787 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19788 } // end for each column
19789 } elseif ($page == $endpage) { // last page
19792 for ($column = 0; $column <= $endcolumn; ++
$column) { // for each column
19793 $this->selectColumn($column);
19794 if ($column == $endcolumn) { // end column
19795 $cborder = $border_end;
19796 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
19797 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
19799 $this->x +
= $deltacol;
19800 $h = $endy - $this->y
;
19801 } else { // middle column
19802 $cborder = $border_middle;
19803 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
19804 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
19806 $this->x +
= $deltacol;
19807 $h = $this->h
- $this->y
- $this->bMargin
;
19809 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19810 } // end for each column
19811 } else { // middle page
19814 for ($column = 0; $column < $this->num_columns
; ++
$column) { // for each column
19815 $this->selectColumn($column);
19816 $cborder = $border_middle;
19817 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
19818 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
19820 $this->x +
= $deltacol;
19821 $h = $this->h
- $this->y
- $this->bMargin
;
19822 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
19823 } // end for each column
19825 if (!empty($cborder) OR !empty($fill)) {
19826 $offsetlen = strlen($ccode);
19827 // draw border and fill
19828 if ($this->inxobj
) {
19829 // we are inside an XObject template
19830 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
19831 $pagemarkkey = key($this->xobjects
[$this->xobjid
]['transfmrk']);
19832 $pagemark = $this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey];
19833 $this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey] +
= $offsetlen;
19835 $pagemark = $this->xobjects
[$this->xobjid
]['intmrk'];
19836 $this->xobjects
[$this->xobjid
]['intmrk'] +
= $offsetlen;
19838 $pagebuff = $this->xobjects
[$this->xobjid
]['outdata'];
19839 $pstart = substr($pagebuff, 0, $pagemark);
19840 $pend = substr($pagebuff, $pagemark);
19841 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$ccode.$pend;
19843 // draw border and fill
19844 if (end($this->transfmrk
[$this->page
]) !== false) {
19845 $pagemarkkey = key($this->transfmrk
[$this->page
]);
19846 $pagemark = $this->transfmrk
[$this->page
][$pagemarkkey];
19847 } elseif ($this->InFooter
) {
19848 $pagemark = $this->footerpos
[$this->page
];
19850 $pagemark = $this->intmrk
[$this->page
];
19852 $pagebuff = $this->getPageBuffer($this->page
);
19853 $pstart = substr($pagebuff, 0, $pagemark);
19854 $pend = substr($pagebuff, $pagemark);
19855 $this->setPageBuffer($this->page
, $pstart.$ccode.$pend);
19858 } // end for each page
19859 // restore default border
19860 $border = $default_border;
19861 } // end for each cell on the row
19862 if (isset($table_el['attribute']['cellspacing'])) {
19863 $this->y +
= $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
19864 } elseif (isset($table_el['border-spacing'])) {
19865 $this->y +
= $table_el['border-spacing']['V'];
19867 $this->Ln(0, $cell);
19868 $this->x
= $parent['startx'];
19869 if ($endpage > $startpage) {
19870 if (($this->rtl
) AND ($this->pagedim
[$endpage]['orm'] != $this->pagedim
[$startpage]['orm'])) {
19871 $this->x +
= ($this->pagedim
[$endpage]['orm'] - $this->pagedim
[$startpage]['orm']);
19872 } elseif ((!$this->rtl
) AND ($this->pagedim
[$endpage]['olm'] != $this->pagedim
[$startpage]['olm'])) {
19873 $this->x +
= ($this->pagedim
[$endpage]['olm'] - $this->pagedim
[$startpage]['olm']);
19877 if (!$in_table_head) { // we are not inside a thead section
19878 $this->cell_padding
= isset($table_el['old_cell_padding']) ?
$table_el['old_cell_padding'] : null;
19879 // reset row height
19880 $this->resetLastH();
19881 if (($this->page
== ($this->numpages
- 1)) AND ($this->pageopen
[$this->numpages
])) {
19882 $plendiff = ($this->pagelen
[$this->numpages
] - $this->emptypagemrk
[$this->numpages
]);
19883 if (($plendiff > 0) AND ($plendiff < 60)) {
19884 $pagediff = substr($this->getPageBuffer($this->numpages
), $this->emptypagemrk
[$this->numpages
], $plendiff);
19885 if (substr($pagediff, 0, 5) == 'BT /F') {
19886 // the difference is only a font setting
19890 if ($plendiff == 0) {
19891 // remove last blank page
19892 $this->deletePage($this->numpages
);
19895 if (isset($this->theadMargins
['top'])) {
19896 // restore top margin
19897 $this->tMargin
= $this->theadMargins
['top'];
19899 if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
19900 // reset main table header
19902 $this->theadMargins
= array();
19903 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
19906 $parent = $table_el;
19910 $this->HREF
= array();
19914 $this->SetXY($this->GetX(), $this->GetY() +
((0.7 * $parent['fontsize']) / $this->k
));
19918 $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize']) / $this->k
));
19922 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19925 case 'blockquote': {
19927 $this->rMargin
-= $this->listindent
;
19929 $this->lMargin
-= $this->listindent
;
19931 --$this->listindentlevel
;
19932 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19936 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19940 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19941 $this->premode
= false;
19946 if ($this->listnum
<= 0) {
19947 $this->listnum
= 0;
19948 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19950 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
19952 $this->resetLastH();
19956 $this->lispacer
= '';
19957 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
19961 $this->lispacer
= '';
19963 $this->rMargin
-= $this->listindent
;
19965 $this->lMargin
-= $this->listindent
;
19967 --$this->listindentlevel
;
19968 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
19974 $this->lispacer
= '';
19976 $this->rMargin
-= $this->listindent
;
19978 $this->lMargin
-= $this->listindent
;
19980 --$this->listindentlevel
;
19981 if ($this->listnum
<= 0) {
19982 $this->listnum
= 0;
19983 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
19985 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
19987 $this->resetLastH();
19991 $this->lispacer
= '';
19992 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
20001 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
20004 // Form fields (since 4.8.000 - 2009-09-07)
20006 $this->form_action
= '';
20007 $this->form_enctype
= 'application/x-www-form-urlencoded';
20014 // draw border and background (if any)
20015 $this->drawHTMLTagBorder($parent, $xmax);
20016 if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
20017 $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
20018 // check for pagebreak
20019 if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
20020 // add a page (or trig AcceptPageBreak() for multicolumn mode)
20021 $this->checkPageBreak($this->PageBreakTrigger +
1);
20023 if ((($pba == 'left') AND (((!$this->rtl
) AND (($this->page %
2) == 0)) OR (($this->rtl
) AND (($this->page %
2) != 0))))
20024 OR (($pba == 'right') AND (((!$this->rtl
) AND (($this->page %
2) != 0)) OR (($this->rtl
) AND (($this->page %
2) == 0))))) {
20025 // add a page (or trig AcceptPageBreak() for multicolumn mode)
20026 $this->checkPageBreak($this->PageBreakTrigger +
1);
20029 $this->tmprtl
= false;
20034 * Add vertical spaces if needed.
20035 * @param $hbz (string) Distance between current y and line bottom.
20036 * @param $hb (string) The height of the break.
20037 * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
20038 * @param $firsttag (boolean) set to true when the tag is the first.
20039 * @param $lasttag (boolean) set to true when the tag is the last.
20042 protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
20044 $this->Ln(0, $cell);
20045 $this->htmlvspace
= 0;
20049 $this->Ln($hbz, $cell);
20050 $this->htmlvspace
= 0;
20053 if ($hb < $this->htmlvspace
) {
20056 $hd = $hb - $this->htmlvspace
;
20057 $this->htmlvspace
= $hb;
20059 $this->Ln(($hbz +
$hd), $cell);
20063 * Return the starting coordinates to draw an html border
20064 * @return array containing top-left border coordinates
20066 * @since 5.7.000 (2010-08-03)
20068 protected function getBorderStartPosition() {
20070 $xmax = $this->lMargin
;
20072 $xmax = $this->w
- $this->rMargin
;
20074 return array('page' => $this->page
, 'column' => $this->current_column
, 'x' => $this->x
, 'y' => $this->y
, 'xmax' => $xmax);
20078 * Draw an HTML block border and fill
20079 * @param $tag (array) array of tag properties.
20080 * @param $xmax (int) end X coordinate for border.
20082 * @since 5.7.000 (2010-08-03)
20084 protected function drawHTMLTagBorder($tag, $xmax) {
20085 if (!isset($tag['borderposition'])) {
20089 $prev_x = $this->x
;
20090 $prev_y = $this->y
;
20091 $prev_lasth = $this->lasth
;
20095 if (isset($tag['border']) AND !empty($tag['border'])) {
20096 // get border style
20097 $border = $tag['border'];
20098 if (!TCPDF_STATIC
::empty_string($this->thead
) AND (!$this->inthead
)) {
20099 // border for table header
20100 $border = TCPDF_STATIC
::getBorderMode($border, $position='middle', $this->opencell
);
20103 if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
20104 // get background color
20105 $old_bgcolor = $this->bgcolor
;
20106 $this->SetFillColorArray($tag['bgcolor']);
20109 if (!$border AND !$fill) {
20113 if (isset($tag['attribute']['cellspacing'])) {
20114 $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
20115 $cellspacing = array('H' => $clsp, 'V' => $clsp);
20116 } elseif (isset($tag['border-spacing'])) {
20117 $cellspacing = $tag['border-spacing'];
20119 $cellspacing = array('H' => 0, 'V' => 0);
20121 if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
20122 // draw the border externally respect the sqare edge.
20123 $border['mode'] = 'ext';
20126 if ($xmax >= $tag['borderposition']['x']) {
20127 $xmax = $tag['borderposition']['xmax'];
20129 $w = ($tag['borderposition']['x'] - $xmax);
20131 if ($xmax <= $tag['borderposition']['x']) {
20132 $xmax = $tag['borderposition']['xmax'];
20134 $w = ($xmax - $tag['borderposition']['x']);
20139 $w +
= $cellspacing['H'];
20140 $startpage = $tag['borderposition']['page'];
20141 $startcolumn = $tag['borderposition']['column'];
20142 $x = $tag['borderposition']['x'];
20143 $y = $tag['borderposition']['y'];
20144 $endpage = $this->page
;
20145 $starty = $tag['borderposition']['y'] - $cellspacing['V'];
20146 $currentY = $this->y
;
20148 // get latest column
20149 $endcolumn = $this->current_column
;
20150 if ($this->num_columns
== 0) {
20151 $this->num_columns
= 1;
20153 // get border modes
20154 $border_start = TCPDF_STATIC
::getBorderMode($border, $position='start', $this->opencell
);
20155 $border_end = TCPDF_STATIC
::getBorderMode($border, $position='end', $this->opencell
);
20156 $border_middle = TCPDF_STATIC
::getBorderMode($border, $position='middle', $this->opencell
);
20157 // temporary disable page regions
20158 $temp_page_regions = $this->page_regions
;
20159 $this->page_regions
= array();
20160 // design borders around HTML cells.
20161 for ($page = $startpage; $page <= $endpage; ++
$page) { // for each page
20163 $this->setPage($page);
20164 if ($this->num_columns
< 2) {
20165 // single-column mode
20167 $this->y
= $this->tMargin
;
20169 // account for margin changes
20170 if ($page > $startpage) {
20171 if (($this->rtl
) AND ($this->pagedim
[$page]['orm'] != $this->pagedim
[$startpage]['orm'])) {
20172 $this->x
-= ($this->pagedim
[$page]['orm'] - $this->pagedim
[$startpage]['orm']);
20173 } elseif ((!$this->rtl
) AND ($this->pagedim
[$page]['olm'] != $this->pagedim
[$startpage]['olm'])) {
20174 $this->x +
= ($this->pagedim
[$page]['olm'] - $this->pagedim
[$startpage]['olm']);
20177 if ($startpage == $endpage) {
20179 for ($column = $startcolumn; $column <= $endcolumn; ++
$column) { // for each column
20180 $this->selectColumn($column);
20181 if ($startcolumn == $endcolumn) { // single column
20182 $cborder = $border;
20183 $h = ($currentY - $y) +
$cellspacing['V'];
20184 $this->y
= $starty;
20185 } elseif ($column == $startcolumn) { // first column
20186 $cborder = $border_start;
20187 $this->y
= $starty;
20188 $h = $this->h
- $this->y
- $this->bMargin
;
20189 } elseif ($column == $endcolumn) { // end column
20190 $cborder = $border_end;
20191 $h = $currentY - $this->y
;
20192 } else { // middle column
20193 $cborder = $border_middle;
20194 $h = $this->h
- $this->y
- $this->bMargin
;
20196 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20197 } // end for each column
20198 } elseif ($page == $startpage) { // first page
20199 for ($column = $startcolumn; $column < $this->num_columns
; ++
$column) { // for each column
20200 $this->selectColumn($column);
20201 if ($column == $startcolumn) { // first column
20202 $cborder = $border_start;
20203 $this->y
= $starty;
20204 $h = $this->h
- $this->y
- $this->bMargin
;
20205 } else { // middle column
20206 $cborder = $border_middle;
20207 $h = $this->h
- $this->y
- $this->bMargin
;
20209 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20210 } // end for each column
20211 } elseif ($page == $endpage) { // last page
20212 for ($column = 0; $column <= $endcolumn; ++
$column) { // for each column
20213 $this->selectColumn($column);
20214 if ($column == $endcolumn) {
20216 $cborder = $border_end;
20217 $h = $currentY - $this->y
;
20220 $cborder = $border_middle;
20221 $h = $this->h
- $this->y
- $this->bMargin
;
20223 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20224 } // end for each column
20225 } else { // middle page
20226 for ($column = 0; $column < $this->num_columns
; ++
$column) { // for each column
20227 $this->selectColumn($column);
20228 $cborder = $border_middle;
20229 $h = $this->h
- $this->y
- $this->bMargin
;
20230 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
20231 } // end for each column
20233 if ($cborder OR $fill) {
20234 $offsetlen = strlen($ccode);
20235 // draw border and fill
20236 if ($this->inxobj
) {
20237 // we are inside an XObject template
20238 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
20239 $pagemarkkey = key($this->xobjects
[$this->xobjid
]['transfmrk']);
20240 $pagemark = $this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey];
20241 $this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey] +
= $offsetlen;
20243 $pagemark = $this->xobjects
[$this->xobjid
]['intmrk'];
20244 $this->xobjects
[$this->xobjid
]['intmrk'] +
= $offsetlen;
20246 $pagebuff = $this->xobjects
[$this->xobjid
]['outdata'];
20247 $pstart = substr($pagebuff, 0, $pagemark);
20248 $pend = substr($pagebuff, $pagemark);
20249 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$ccode.$pend;
20251 if (end($this->transfmrk
[$this->page
]) !== false) {
20252 $pagemarkkey = key($this->transfmrk
[$this->page
]);
20253 $pagemark = $this->transfmrk
[$this->page
][$pagemarkkey];
20254 } elseif ($this->InFooter
) {
20255 $pagemark = $this->footerpos
[$this->page
];
20257 $pagemark = $this->intmrk
[$this->page
];
20259 $pagebuff = $this->getPageBuffer($this->page
);
20260 $pstart = substr($pagebuff, 0, $pagemark);
20261 $pend = substr($pagebuff, $pagemark);
20262 $this->setPageBuffer($this->page
, $pstart.$ccode.$pend);
20263 $this->bordermrk
[$this->page
] +
= $offsetlen;
20264 $this->cntmrk
[$this->page
] +
= $offsetlen;
20267 } // end for each page
20268 // restore page regions
20269 $this->page_regions
= $temp_page_regions;
20270 if (isset($old_bgcolor)) {
20271 // restore background color
20272 $this->SetFillColorArray($old_bgcolor);
20274 // restore pointer position
20275 $this->x
= $prev_x;
20276 $this->y
= $prev_y;
20277 $this->lasth
= $prev_lasth;
20281 * Set the default bullet to be used as LI bullet symbol
20282 * @param $symbol (string) character or string to be used (legal values are: '' = automatic, '!' = auto bullet, '#' = auto numbering, 'disc', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek', 'img|type|width|height|image.ext')
20284 * @since 4.0.028 (2008-09-26)
20286 public function setLIsymbol($symbol='!') {
20287 // check for custom image symbol
20288 if (substr($symbol, 0, 4) == 'img|') {
20289 $this->lisymbol
= $symbol;
20292 $symbol = strtolower($symbol);
20293 $valid_symbols = array('!', '#', 'disc', 'circle', 'square', '1', 'decimal', 'decimal-leading-zero', 'i', 'lower-roman', 'I', 'upper-roman', 'a', 'lower-alpha', 'lower-latin', 'A', 'upper-alpha', 'upper-latin', 'lower-greek');
20294 if (in_array($symbol, $valid_symbols)) {
20295 $this->lisymbol
= $symbol;
20297 $this->lisymbol
= '';
20302 * Set the booklet mode for double-sided pages.
20303 * @param $booklet (boolean) true set the booklet mode on, false otherwise.
20304 * @param $inner (float) Inner page margin.
20305 * @param $outer (float) Outer page margin.
20307 * @since 4.2.000 (2008-10-29)
20309 public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
20310 $this->booklet
= $booklet;
20312 $this->lMargin
= $inner;
20315 $this->rMargin
= $outer;
20320 * Swap the left and right margins.
20321 * @param $reverse (boolean) if true swap left and right margins.
20323 * @since 4.2.000 (2008-10-29)
20325 protected function swapMargins($reverse=true) {
20327 // swap left and right margins
20328 $mtemp = $this->original_lMargin
;
20329 $this->original_lMargin
= $this->original_rMargin
;
20330 $this->original_rMargin
= $mtemp;
20331 $deltam = $this->original_lMargin
- $this->original_rMargin
;
20332 $this->lMargin +
= $deltam;
20333 $this->rMargin
-= $deltam;
20338 * Set the vertical spaces for HTML tags.
20339 * The array must have the following structure (example):
20340 * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
20341 * The first array level contains the tag names,
20342 * the second level contains 0 for opening tags or 1 for closing tags,
20343 * the third level contains the vertical space unit (h) and the number spaces to add (n).
20344 * If the h parameter is not specified, default values are used.
20345 * @param $tagvs (array) array of tags and relative vertical spaces.
20347 * @since 4.2.001 (2008-10-30)
20349 public function setHtmlVSpace($tagvs) {
20350 $this->tagvspaces
= $tagvs;
20354 * Set custom width for list indentation.
20355 * @param $width (float) width of the indentation. Use negative value to disable it.
20357 * @since 4.2.007 (2008-11-12)
20359 public function setListIndentWidth($width) {
20360 return $this->customlistindent
= floatval($width);
20364 * Set the top/bottom cell sides to be open or closed when the cell cross the page.
20365 * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
20367 * @since 4.2.010 (2008-11-14)
20369 public function setOpenCell($isopen) {
20370 $this->opencell
= $isopen;
20374 * Set the color and font style for HTML links.
20375 * @param $color (array) RGB array of colors
20376 * @param $fontstyle (string) additional font styles to add
20378 * @since 4.4.003 (2008-12-09)
20380 public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
20381 $this->htmlLinkColorArray
= $color;
20382 $this->htmlLinkFontStyle
= $fontstyle;
20386 * Convert HTML string containing value and unit of measure to user's units or points.
20387 * @param $htmlval (string) String containing values and unit.
20388 * @param $refsize (string) Reference value in points.
20389 * @param $defaultunit (string) Default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
20390 * @param $points (boolean) If true returns points, otherwise returns value in user's units.
20391 * @return float value in user's unit or point if $points=true
20393 * @since 4.4.004 (2008-12-10)
20395 public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
20396 $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
20405 if (in_array($defaultunit, $supportedunits)) {
20406 $unit = $defaultunit;
20408 if (is_numeric($htmlval)) {
20409 $value = floatval($htmlval);
20410 } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
20411 $value = floatval($mnum[1]);
20412 if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
20413 if (in_array($munit[1], $supportedunits)) {
20421 $retval = (($value * $refsize) / 100);
20426 $retval = ($value * $refsize);
20429 // height of lower case 'x' (about half the font-size)
20431 $retval = ($value * ($refsize / 2));
20436 $retval = (($value * $this->dpi
) / $k);
20441 $retval = (($value / 2.54 * $this->dpi
) / $k);
20446 $retval = (($value / 25.4 * $this->dpi
) / $k);
20449 // one pica is 12 points
20451 $retval = (($value * 12) / $k);
20456 $retval = ($value / $k);
20461 $retval = $this->pixelsToUnits($value);
20463 $retval *= $this->k
;
20472 * Output an HTML list bullet or ordered item symbol
20473 * @param $listdepth (int) list nesting level
20474 * @param $listtype (string) type of list
20475 * @param $size (float) current font size
20477 * @since 4.4.004 (2008-12-10)
20479 protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
20480 if ($this->state
!= 2) {
20485 $bgcolor = $this->bgcolor
;
20486 $color = $this->fgcolor
;
20487 $strokecolor = $this->strokecolor
;
20491 $lspace = $this->GetStringWidth(' ');
20492 if ($listtype == '^') {
20493 // special symbol used for avoid justification of rect bullet
20494 $this->lispacer
= '';
20496 } elseif ($listtype == '!') {
20497 // set default list type for unordered list
20498 $deftypes = array('disc', 'circle', 'square');
20499 $listtype = $deftypes[($listdepth - 1) %
3];
20500 } elseif ($listtype == '#') {
20501 // set default list type for ordered list
20502 $listtype = 'decimal';
20503 } elseif (substr($listtype, 0, 4) == 'img|') {
20504 // custom image type ('img|type|width|height|image.ext')
20505 $img = explode('|', $listtype);
20508 switch ($listtype) {
20515 $lspace +
= (2 * $r);
20517 $this->x +
= $lspace;
20519 $this->x
-= $lspace;
20521 $this->Circle(($this->x +
$r), ($this->y +
($this->lasth
/ 2)), $r, 0, 360, 'F', array(), $color, 8);
20526 $lspace +
= (2 * $r);
20528 $this->x +
= $lspace;
20530 $this->x
-= $lspace;
20532 $prev_line_style = $this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
;
20533 $new_line_style = array('width' => ($r / 3), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'phase' => 0, 'color'=>$color);
20534 $this->Circle(($this->x +
$r), ($this->y +
($this->lasth
/ 2)), ($r * (1 - (1/6))), 0, 360, 'D', $new_line_style, array(), 8);
20535 $this->_out($prev_line_style); // restore line settings
20542 $this->x +
= $lspace;
20544 $this->x
-= $lspace;
20546 $this->Rect($this->x
, ($this->y +
(($this->lasth
- $l) / 2)), $l, $l, 'F', array(), $color);
20550 // 1=>type, 2=>width, 3=>height, 4=>image.ext
20551 $lspace +
= $img[2];
20553 $this->x +
= $lspace;
20555 $this->x
-= $lspace;
20557 $imgtype = strtolower($img[1]);
20558 $prev_y = $this->y
;
20559 switch ($imgtype) {
20561 $this->ImageSVG($img[4], $this->x
, ($this->y +
(($this->lasth
- $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
20566 $this->ImageEps($img[4], $this->x
, ($this->y +
(($this->lasth
- $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
20570 $this->Image($img[4], $this->x
, ($this->y +
(($this->lasth
- $img[3]) / 2)), $img[2], $img[3], $img[1], '', 'T', false, 300, '', false, false, 0, false, false, false);
20574 $this->y
= $prev_y;
20578 // $this->listcount[$this->listnum];
20582 $textitem = $this->listcount
[$this->listnum
];
20585 case 'decimal-leading-zero': {
20586 $textitem = sprintf('%02d', $this->listcount
[$this->listnum
]);
20590 case 'lower-roman': {
20591 $textitem = strtolower(TCPDF_STATIC
::intToRoman($this->listcount
[$this->listnum
]));
20595 case 'upper-roman': {
20596 $textitem = TCPDF_STATIC
::intToRoman($this->listcount
[$this->listnum
]);
20600 case 'lower-alpha':
20601 case 'lower-latin': {
20602 $textitem = chr(97 +
$this->listcount
[$this->listnum
] - 1);
20606 case 'upper-alpha':
20607 case 'upper-latin': {
20608 $textitem = chr(65 +
$this->listcount
[$this->listnum
] - 1);
20611 case 'lower-greek': {
20612 $textitem = TCPDF_FONTS
::unichr((945 +
$this->listcount
[$this->listnum
] - 1), $this->isunicode
);
20616 // Types to be implemented (special handling)
20626 case 'cjk-ideographic': {
20635 case 'hiragana-iroha': {
20638 case 'katakana-iroha': {
20643 $textitem = $this->listcount
[$this->listnum
];
20646 if (!TCPDF_STATIC
::empty_string($textitem)) {
20647 // Check whether we need a new page or new column
20648 $prev_y = $this->y
;
20649 $h = $this->getCellHeight($this->FontSize
);
20650 if ($this->checkPageBreak($h) OR ($this->y
< $prev_y)) {
20653 // print ordered item
20655 $textitem = '.'.$textitem;
20657 $textitem = $textitem.'.';
20659 $lspace +
= $this->GetStringWidth($textitem);
20661 $this->x +
= $lspace;
20663 $this->x
-= $lspace;
20665 $this->Write($this->lasth
, $textitem, '', false, '', false, 0, false);
20668 $this->lispacer
= '^';
20670 $this->SetFillColorArray($bgcolor);
20671 $this->SetDrawColorArray($strokecolor);
20672 $this->SettextColorArray($color);
20676 * Returns current graphic variables as array.
20677 * @return array of graphic variables
20679 * @since 4.2.010 (2008-11-14)
20681 protected function getGraphicVars() {
20683 'FontFamily' => $this->FontFamily
,
20684 'FontStyle' => $this->FontStyle
,
20685 'FontSizePt' => $this->FontSizePt
,
20686 'rMargin' => $this->rMargin
,
20687 'lMargin' => $this->lMargin
,
20688 'cell_padding' => $this->cell_padding
,
20689 'cell_margin' => $this->cell_margin
,
20690 'LineWidth' => $this->LineWidth
,
20691 'linestyleWidth' => $this->linestyleWidth
,
20692 'linestyleCap' => $this->linestyleCap
,
20693 'linestyleJoin' => $this->linestyleJoin
,
20694 'linestyleDash' => $this->linestyleDash
,
20695 'textrendermode' => $this->textrendermode
,
20696 'textstrokewidth' => $this->textstrokewidth
,
20697 'DrawColor' => $this->DrawColor
,
20698 'FillColor' => $this->FillColor
,
20699 'TextColor' => $this->TextColor
,
20700 'ColorFlag' => $this->ColorFlag
,
20701 'bgcolor' => $this->bgcolor
,
20702 'fgcolor' => $this->fgcolor
,
20703 'htmlvspace' => $this->htmlvspace
,
20704 'listindent' => $this->listindent
,
20705 'listindentlevel' => $this->listindentlevel
,
20706 'listnum' => $this->listnum
,
20707 'listordered' => $this->listordered
,
20708 'listcount' => $this->listcount
,
20709 'lispacer' => $this->lispacer
,
20710 'cell_height_ratio' => $this->cell_height_ratio
,
20711 'font_stretching' => $this->font_stretching
,
20712 'font_spacing' => $this->font_spacing
,
20713 'alpha' => $this->alpha
,
20715 'lasth' => $this->lasth
,
20716 'tMargin' => $this->tMargin
,
20717 'bMargin' => $this->bMargin
,
20718 'AutoPageBreak' => $this->AutoPageBreak
,
20719 'PageBreakTrigger' => $this->PageBreakTrigger
,
20724 'wPt' => $this->wPt
,
20725 'hPt' => $this->hPt
,
20726 'fwPt' => $this->fwPt
,
20727 'fhPt' => $this->fhPt
,
20728 'page' => $this->page
,
20729 'current_column' => $this->current_column
,
20730 'num_columns' => $this->num_columns
20736 * Set graphic variables.
20737 * @param $gvars (array) array of graphic variablesto restore
20738 * @param $extended (boolean) if true restore extended graphic variables
20740 * @since 4.2.010 (2008-11-14)
20742 protected function setGraphicVars($gvars, $extended=false) {
20743 if ($this->state
!= 2) {
20746 $this->FontFamily
= $gvars['FontFamily'];
20747 $this->FontStyle
= $gvars['FontStyle'];
20748 $this->FontSizePt
= $gvars['FontSizePt'];
20749 $this->rMargin
= $gvars['rMargin'];
20750 $this->lMargin
= $gvars['lMargin'];
20751 $this->cell_padding
= $gvars['cell_padding'];
20752 $this->cell_margin
= $gvars['cell_margin'];
20753 $this->LineWidth
= $gvars['LineWidth'];
20754 $this->linestyleWidth
= $gvars['linestyleWidth'];
20755 $this->linestyleCap
= $gvars['linestyleCap'];
20756 $this->linestyleJoin
= $gvars['linestyleJoin'];
20757 $this->linestyleDash
= $gvars['linestyleDash'];
20758 $this->textrendermode
= $gvars['textrendermode'];
20759 $this->textstrokewidth
= $gvars['textstrokewidth'];
20760 $this->DrawColor
= $gvars['DrawColor'];
20761 $this->FillColor
= $gvars['FillColor'];
20762 $this->TextColor
= $gvars['TextColor'];
20763 $this->ColorFlag
= $gvars['ColorFlag'];
20764 $this->bgcolor
= $gvars['bgcolor'];
20765 $this->fgcolor
= $gvars['fgcolor'];
20766 $this->htmlvspace
= $gvars['htmlvspace'];
20767 $this->listindent
= $gvars['listindent'];
20768 $this->listindentlevel
= $gvars['listindentlevel'];
20769 $this->listnum
= $gvars['listnum'];
20770 $this->listordered
= $gvars['listordered'];
20771 $this->listcount
= $gvars['listcount'];
20772 $this->lispacer
= $gvars['lispacer'];
20773 $this->cell_height_ratio
= $gvars['cell_height_ratio'];
20774 $this->font_stretching
= $gvars['font_stretching'];
20775 $this->font_spacing
= $gvars['font_spacing'];
20776 $this->alpha
= $gvars['alpha'];
20778 // restore extended values
20779 $this->lasth
= $gvars['lasth'];
20780 $this->tMargin
= $gvars['tMargin'];
20781 $this->bMargin
= $gvars['bMargin'];
20782 $this->AutoPageBreak
= $gvars['AutoPageBreak'];
20783 $this->PageBreakTrigger
= $gvars['PageBreakTrigger'];
20784 $this->x
= $gvars['x'];
20785 $this->y
= $gvars['y'];
20786 $this->w
= $gvars['w'];
20787 $this->h
= $gvars['h'];
20788 $this->wPt
= $gvars['wPt'];
20789 $this->hPt
= $gvars['hPt'];
20790 $this->fwPt
= $gvars['fwPt'];
20791 $this->fhPt
= $gvars['fhPt'];
20792 $this->page
= $gvars['page'];
20793 $this->current_column
= $gvars['current_column'];
20794 $this->num_columns
= $gvars['num_columns'];
20796 $this->_out(''.$this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
.' '.$this->FillColor
.'');
20797 if (!TCPDF_STATIC
::empty_string($this->FontFamily
)) {
20798 $this->SetFont($this->FontFamily
, $this->FontStyle
, $this->FontSizePt
);
20803 * Outputs the "save graphics state" operator 'q'
20806 protected function _outSaveGraphicsState() {
20811 * Outputs the "restore graphics state" operator 'Q'
20814 protected function _outRestoreGraphicsState() {
20819 * Set buffer content (always append data).
20820 * @param $data (string) data
20822 * @since 4.5.000 (2009-01-02)
20824 protected function setBuffer($data) {
20825 $this->bufferlen +
= strlen($data);
20826 $this->buffer
.= $data;
20830 * Replace the buffer content
20831 * @param $data (string) data
20833 * @since 5.5.000 (2010-06-22)
20835 protected function replaceBuffer($data) {
20836 $this->bufferlen
= strlen($data);
20837 $this->buffer
= $data;
20841 * Get buffer content.
20842 * @return string buffer content
20844 * @since 4.5.000 (2009-01-02)
20846 protected function getBuffer() {
20847 return $this->buffer
;
20851 * Set page buffer content.
20852 * @param $page (int) page number
20853 * @param $data (string) page data
20854 * @param $append (boolean) if true append data, false replace.
20856 * @since 4.5.000 (2008-12-31)
20858 protected function setPageBuffer($page, $data, $append=false) {
20860 $this->pages
[$page] .= $data;
20862 $this->pages
[$page] = $data;
20864 if ($append AND isset($this->pagelen
[$page])) {
20865 $this->pagelen
[$page] +
= strlen($data);
20867 $this->pagelen
[$page] = strlen($data);
20872 * Get page buffer content.
20873 * @param $page (int) page number
20874 * @return string page buffer content or false in case of error
20876 * @since 4.5.000 (2008-12-31)
20878 protected function getPageBuffer($page) {
20879 if (isset($this->pages
[$page])) {
20880 return $this->pages
[$page];
20886 * Set image buffer content.
20887 * @param $image (string) image key
20888 * @param $data (array) image data
20889 * @return int image index number
20891 * @since 4.5.000 (2008-12-31)
20893 protected function setImageBuffer($image, $data) {
20894 if (($data['i'] = array_search($image, $this->imagekeys
)) === FALSE) {
20895 $this->imagekeys
[$this->numimages
] = $image;
20896 $data['i'] = $this->numimages
;
20897 ++
$this->numimages
;
20899 $this->images
[$image] = $data;
20904 * Set image buffer content for a specified sub-key.
20905 * @param $image (string) image key
20906 * @param $key (string) image sub-key
20907 * @param $data (array) image data
20909 * @since 4.5.000 (2008-12-31)
20911 protected function setImageSubBuffer($image, $key, $data) {
20912 if (!isset($this->images
[$image])) {
20913 $this->setImageBuffer($image, array());
20915 $this->images
[$image][$key] = $data;
20919 * Get image buffer content.
20920 * @param $image (string) image key
20921 * @return string image buffer content or false in case of error
20923 * @since 4.5.000 (2008-12-31)
20925 protected function getImageBuffer($image) {
20926 if (isset($this->images
[$image])) {
20927 return $this->images
[$image];
20933 * Set font buffer content.
20934 * @param $font (string) font key
20935 * @param $data (array) font data
20937 * @since 4.5.000 (2009-01-02)
20939 protected function setFontBuffer($font, $data) {
20940 $this->fonts
[$font] = $data;
20941 if (!in_array($font, $this->fontkeys
)) {
20942 $this->fontkeys
[] = $font;
20943 // store object ID for current font
20945 $this->font_obj_ids
[$font] = $this->n
;
20946 $this->setFontSubBuffer($font, 'n', $this->n
);
20951 * Set font buffer content.
20952 * @param $font (string) font key
20953 * @param $key (string) font sub-key
20954 * @param $data (array) font data
20956 * @since 4.5.000 (2009-01-02)
20958 protected function setFontSubBuffer($font, $key, $data) {
20959 if (!isset($this->fonts
[$font])) {
20960 $this->setFontBuffer($font, array());
20962 $this->fonts
[$font][$key] = $data;
20966 * Get font buffer content.
20967 * @param $font (string) font key
20968 * @return string font buffer content or false in case of error
20970 * @since 4.5.000 (2009-01-02)
20972 protected function getFontBuffer($font) {
20973 if (isset($this->fonts
[$font])) {
20974 return $this->fonts
[$font];
20980 * Move a page to a previous position.
20981 * @param $frompage (int) number of the source page
20982 * @param $topage (int) number of the destination page (must be less than $frompage)
20983 * @return true in case of success, false in case of error.
20985 * @since 4.5.000 (2009-01-02)
20987 public function movePage($frompage, $topage) {
20988 if (($frompage > $this->numpages
) OR ($frompage <= $topage)) {
20991 if ($frompage == $this->page
) {
20992 // close the page before moving it
20995 // move all page-related states
20996 $tmppage = $this->getPageBuffer($frompage);
20997 $tmppagedim = $this->pagedim
[$frompage];
20998 $tmppagelen = $this->pagelen
[$frompage];
20999 $tmpintmrk = $this->intmrk
[$frompage];
21000 $tmpbordermrk = $this->bordermrk
[$frompage];
21001 $tmpcntmrk = $this->cntmrk
[$frompage];
21002 $tmppageobjects = $this->pageobjects
[$frompage];
21003 if (isset($this->footerpos
[$frompage])) {
21004 $tmpfooterpos = $this->footerpos
[$frompage];
21006 if (isset($this->footerlen
[$frompage])) {
21007 $tmpfooterlen = $this->footerlen
[$frompage];
21009 if (isset($this->transfmrk
[$frompage])) {
21010 $tmptransfmrk = $this->transfmrk
[$frompage];
21012 if (isset($this->PageAnnots
[$frompage])) {
21013 $tmpannots = $this->PageAnnots
[$frompage];
21015 if (isset($this->newpagegroup
) AND !empty($this->newpagegroup
)) {
21016 for ($i = $frompage; $i > $topage; --$i) {
21017 if (isset($this->newpagegroup
[$i]) AND (($i +
$this->pagegroups
[$this->newpagegroup
[$i]]) > $frompage)) {
21018 --$this->pagegroups
[$this->newpagegroup
[$i]];
21022 for ($i = $topage; $i > 0; --$i) {
21023 if (isset($this->newpagegroup
[$i]) AND (($i +
$this->pagegroups
[$this->newpagegroup
[$i]]) > $topage)) {
21024 ++
$this->pagegroups
[$this->newpagegroup
[$i]];
21029 for ($i = $frompage; $i > $topage; --$i) {
21031 // shift pages down
21032 $this->setPageBuffer($i, $this->getPageBuffer($j));
21033 $this->pagedim
[$i] = $this->pagedim
[$j];
21034 $this->pagelen
[$i] = $this->pagelen
[$j];
21035 $this->intmrk
[$i] = $this->intmrk
[$j];
21036 $this->bordermrk
[$i] = $this->bordermrk
[$j];
21037 $this->cntmrk
[$i] = $this->cntmrk
[$j];
21038 $this->pageobjects
[$i] = $this->pageobjects
[$j];
21039 if (isset($this->footerpos
[$j])) {
21040 $this->footerpos
[$i] = $this->footerpos
[$j];
21041 } elseif (isset($this->footerpos
[$i])) {
21042 unset($this->footerpos
[$i]);
21044 if (isset($this->footerlen
[$j])) {
21045 $this->footerlen
[$i] = $this->footerlen
[$j];
21046 } elseif (isset($this->footerlen
[$i])) {
21047 unset($this->footerlen
[$i]);
21049 if (isset($this->transfmrk
[$j])) {
21050 $this->transfmrk
[$i] = $this->transfmrk
[$j];
21051 } elseif (isset($this->transfmrk
[$i])) {
21052 unset($this->transfmrk
[$i]);
21054 if (isset($this->PageAnnots
[$j])) {
21055 $this->PageAnnots
[$i] = $this->PageAnnots
[$j];
21056 } elseif (isset($this->PageAnnots
[$i])) {
21057 unset($this->PageAnnots
[$i]);
21059 if (isset($this->newpagegroup
[$j])) {
21060 $this->newpagegroup
[$i] = $this->newpagegroup
[$j];
21061 unset($this->newpagegroup
[$j]);
21063 if ($this->currpagegroup
== $j) {
21064 $this->currpagegroup
= $i;
21067 $this->setPageBuffer($topage, $tmppage);
21068 $this->pagedim
[$topage] = $tmppagedim;
21069 $this->pagelen
[$topage] = $tmppagelen;
21070 $this->intmrk
[$topage] = $tmpintmrk;
21071 $this->bordermrk
[$topage] = $tmpbordermrk;
21072 $this->cntmrk
[$topage] = $tmpcntmrk;
21073 $this->pageobjects
[$topage] = $tmppageobjects;
21074 if (isset($tmpfooterpos)) {
21075 $this->footerpos
[$topage] = $tmpfooterpos;
21076 } elseif (isset($this->footerpos
[$topage])) {
21077 unset($this->footerpos
[$topage]);
21079 if (isset($tmpfooterlen)) {
21080 $this->footerlen
[$topage] = $tmpfooterlen;
21081 } elseif (isset($this->footerlen
[$topage])) {
21082 unset($this->footerlen
[$topage]);
21084 if (isset($tmptransfmrk)) {
21085 $this->transfmrk
[$topage] = $tmptransfmrk;
21086 } elseif (isset($this->transfmrk
[$topage])) {
21087 unset($this->transfmrk
[$topage]);
21089 if (isset($tmpannots)) {
21090 $this->PageAnnots
[$topage] = $tmpannots;
21091 } elseif (isset($this->PageAnnots
[$topage])) {
21092 unset($this->PageAnnots
[$topage]);
21095 $tmpoutlines = $this->outlines
;
21096 foreach ($tmpoutlines as $key => $outline) {
21097 if (!$outline['f']) {
21098 if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
21099 $this->outlines
[$key]['p'] = ($outline['p'] +
1);
21100 } elseif ($outline['p'] == $frompage) {
21101 $this->outlines
[$key]['p'] = $topage;
21106 $tmpdests = $this->dests
;
21107 foreach ($tmpdests as $key => $dest) {
21109 if (($dest['p'] >= $topage) AND ($dest['p'] < $frompage)) {
21110 $this->dests
[$key]['p'] = ($dest['p'] +
1);
21111 } elseif ($dest['p'] == $frompage) {
21112 $this->dests
[$key]['p'] = $topage;
21117 $tmplinks = $this->links
;
21118 foreach ($tmplinks as $key => $link) {
21120 if (($link['p'] >= $topage) AND ($link['p'] < $frompage)) {
21121 $this->links
[$key]['p'] = ($link['p'] +
1);
21122 } elseif ($link['p'] == $frompage) {
21123 $this->links
[$key]['p'] = $topage;
21127 // adjust javascript
21128 $jfrompage = $frompage;
21129 $jtopage = $topage;
21130 if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript
, $pamatch) > 0) {
21131 foreach($pamatch[0] as $pk => $pmatch) {
21132 $pagenum = intval($pamatch[3][$pk]) +
1;
21133 if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
21134 $newpage = ($pagenum +
1);
21135 } elseif ($pagenum == $jfrompage) {
21136 $newpage = $jtopage;
21138 $newpage = $pagenum;
21141 $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
21142 $this->javascript
= str_replace($pmatch, $newjs, $this->javascript
);
21146 // return to last page
21147 $this->lastPage(true);
21152 * Remove the specified page.
21153 * @param $page (int) page to remove
21154 * @return true in case of success, false in case of error.
21156 * @since 4.6.004 (2009-04-23)
21158 public function deletePage($page) {
21159 if (($page < 1) OR ($page > $this->numpages
)) {
21162 // delete current page
21163 unset($this->pages
[$page]);
21164 unset($this->pagedim
[$page]);
21165 unset($this->pagelen
[$page]);
21166 unset($this->intmrk
[$page]);
21167 unset($this->bordermrk
[$page]);
21168 unset($this->cntmrk
[$page]);
21169 foreach ($this->pageobjects
[$page] as $oid) {
21170 if (isset($this->offsets
[$oid])){
21171 unset($this->offsets
[$oid]);
21174 unset($this->pageobjects
[$page]);
21175 if (isset($this->footerpos
[$page])) {
21176 unset($this->footerpos
[$page]);
21178 if (isset($this->footerlen
[$page])) {
21179 unset($this->footerlen
[$page]);
21181 if (isset($this->transfmrk
[$page])) {
21182 unset($this->transfmrk
[$page]);
21184 if (isset($this->PageAnnots
[$page])) {
21185 unset($this->PageAnnots
[$page]);
21187 if (isset($this->newpagegroup
) AND !empty($this->newpagegroup
)) {
21188 for ($i = $page; $i > 0; --$i) {
21189 if (isset($this->newpagegroup
[$i]) AND (($i +
$this->pagegroups
[$this->newpagegroup
[$i]]) > $page)) {
21190 --$this->pagegroups
[$this->newpagegroup
[$i]];
21195 if (isset($this->pageopen
[$page])) {
21196 unset($this->pageopen
[$page]);
21198 if ($page < $this->numpages
) {
21199 // update remaining pages
21200 for ($i = $page; $i < $this->numpages
; ++
$i) {
21203 $this->setPageBuffer($i, $this->getPageBuffer($j));
21204 $this->pagedim
[$i] = $this->pagedim
[$j];
21205 $this->pagelen
[$i] = $this->pagelen
[$j];
21206 $this->intmrk
[$i] = $this->intmrk
[$j];
21207 $this->bordermrk
[$i] = $this->bordermrk
[$j];
21208 $this->cntmrk
[$i] = $this->cntmrk
[$j];
21209 $this->pageobjects
[$i] = $this->pageobjects
[$j];
21210 if (isset($this->footerpos
[$j])) {
21211 $this->footerpos
[$i] = $this->footerpos
[$j];
21212 } elseif (isset($this->footerpos
[$i])) {
21213 unset($this->footerpos
[$i]);
21215 if (isset($this->footerlen
[$j])) {
21216 $this->footerlen
[$i] = $this->footerlen
[$j];
21217 } elseif (isset($this->footerlen
[$i])) {
21218 unset($this->footerlen
[$i]);
21220 if (isset($this->transfmrk
[$j])) {
21221 $this->transfmrk
[$i] = $this->transfmrk
[$j];
21222 } elseif (isset($this->transfmrk
[$i])) {
21223 unset($this->transfmrk
[$i]);
21225 if (isset($this->PageAnnots
[$j])) {
21226 $this->PageAnnots
[$i] = $this->PageAnnots
[$j];
21227 } elseif (isset($this->PageAnnots
[$i])) {
21228 unset($this->PageAnnots
[$i]);
21230 if (isset($this->newpagegroup
[$j])) {
21231 $this->newpagegroup
[$i] = $this->newpagegroup
[$j];
21232 unset($this->newpagegroup
[$j]);
21234 if ($this->currpagegroup
== $j) {
21235 $this->currpagegroup
= $i;
21237 if (isset($this->pageopen
[$j])) {
21238 $this->pageopen
[$i] = $this->pageopen
[$j];
21239 } elseif (isset($this->pageopen
[$i])) {
21240 unset($this->pageopen
[$i]);
21243 // remove last page
21244 unset($this->pages
[$this->numpages
]);
21245 unset($this->pagedim
[$this->numpages
]);
21246 unset($this->pagelen
[$this->numpages
]);
21247 unset($this->intmrk
[$this->numpages
]);
21248 unset($this->bordermrk
[$this->numpages
]);
21249 unset($this->cntmrk
[$this->numpages
]);
21250 foreach ($this->pageobjects
[$this->numpages
] as $oid) {
21251 if (isset($this->offsets
[$oid])){
21252 unset($this->offsets
[$oid]);
21255 unset($this->pageobjects
[$this->numpages
]);
21256 if (isset($this->footerpos
[$this->numpages
])) {
21257 unset($this->footerpos
[$this->numpages
]);
21259 if (isset($this->footerlen
[$this->numpages
])) {
21260 unset($this->footerlen
[$this->numpages
]);
21262 if (isset($this->transfmrk
[$this->numpages
])) {
21263 unset($this->transfmrk
[$this->numpages
]);
21265 if (isset($this->PageAnnots
[$this->numpages
])) {
21266 unset($this->PageAnnots
[$this->numpages
]);
21268 if (isset($this->newpagegroup
[$this->numpages
])) {
21269 unset($this->newpagegroup
[$this->numpages
]);
21271 if ($this->currpagegroup
== $this->numpages
) {
21272 $this->currpagegroup
= ($this->numpages
- 1);
21274 if (isset($this->pagegroups
[$this->numpages
])) {
21275 unset($this->pagegroups
[$this->numpages
]);
21277 if (isset($this->pageopen
[$this->numpages
])) {
21278 unset($this->pageopen
[$this->numpages
]);
21282 $this->page
= $this->numpages
;
21284 $tmpoutlines = $this->outlines
;
21285 foreach ($tmpoutlines as $key => $outline) {
21286 if (!$outline['f']) {
21287 if ($outline['p'] > $page) {
21288 $this->outlines
[$key]['p'] = $outline['p'] - 1;
21289 } elseif ($outline['p'] == $page) {
21290 unset($this->outlines
[$key]);
21295 $tmpdests = $this->dests
;
21296 foreach ($tmpdests as $key => $dest) {
21298 if ($dest['p'] > $page) {
21299 $this->dests
[$key]['p'] = $dest['p'] - 1;
21300 } elseif ($dest['p'] == $page) {
21301 unset($this->dests
[$key]);
21306 $tmplinks = $this->links
;
21307 foreach ($tmplinks as $key => $link) {
21309 if ($link['p'] > $page) {
21310 $this->links
[$key]['p'] = $link['p'] - 1;
21311 } elseif ($link['p'] == $page) {
21312 unset($this->links
[$key]);
21316 // adjust javascript
21318 if (preg_match_all('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/', $this->javascript
, $pamatch) > 0) {
21319 foreach($pamatch[0] as $pk => $pmatch) {
21320 $pagenum = intval($pamatch[3][$pk]) +
1;
21321 if ($pagenum >= $jpage) {
21322 $newpage = ($pagenum - 1);
21323 } elseif ($pagenum == $jpage) {
21326 $newpage = $pagenum;
21329 $newjs = "this.addField(\'".$pamatch[1][$pk]."\',\'".$pamatch[2][$pk]."\',".$newpage;
21330 $this->javascript
= str_replace($pmatch, $newjs, $this->javascript
);
21334 // return to last page
21335 if ($this->numpages
> 0) {
21336 $this->lastPage(true);
21342 * Clone the specified page to a new page.
21343 * @param $page (int) number of page to copy (0 = current page)
21344 * @return true in case of success, false in case of error.
21346 * @since 4.9.015 (2010-04-20)
21348 public function copyPage($page=0) {
21351 $page = $this->page
;
21353 if (($page < 1) OR ($page > $this->numpages
)) {
21356 // close the last page
21358 // copy all page-related states
21360 $this->page
= $this->numpages
;
21361 $this->setPageBuffer($this->page
, $this->getPageBuffer($page));
21362 $this->pagedim
[$this->page
] = $this->pagedim
[$page];
21363 $this->pagelen
[$this->page
] = $this->pagelen
[$page];
21364 $this->intmrk
[$this->page
] = $this->intmrk
[$page];
21365 $this->bordermrk
[$this->page
] = $this->bordermrk
[$page];
21366 $this->cntmrk
[$this->page
] = $this->cntmrk
[$page];
21367 $this->pageobjects
[$this->page
] = $this->pageobjects
[$page];
21368 $this->pageopen
[$this->page
] = false;
21369 if (isset($this->footerpos
[$page])) {
21370 $this->footerpos
[$this->page
] = $this->footerpos
[$page];
21372 if (isset($this->footerlen
[$page])) {
21373 $this->footerlen
[$this->page
] = $this->footerlen
[$page];
21375 if (isset($this->transfmrk
[$page])) {
21376 $this->transfmrk
[$this->page
] = $this->transfmrk
[$page];
21378 if (isset($this->PageAnnots
[$page])) {
21379 $this->PageAnnots
[$this->page
] = $this->PageAnnots
[$page];
21381 if (isset($this->newpagegroup
[$page])) {
21382 // start a new group
21383 $this->newpagegroup
[$this->page
] = sizeof($this->newpagegroup
) +
1;
21384 $this->currpagegroup
= $this->newpagegroup
[$this->page
];
21385 $this->pagegroups
[$this->currpagegroup
] = 1;
21386 } elseif (isset($this->currpagegroup
) AND ($this->currpagegroup
> 0)) {
21387 ++
$this->pagegroups
[$this->currpagegroup
];
21390 $tmpoutlines = $this->outlines
;
21391 foreach ($tmpoutlines as $key => $outline) {
21392 if ($outline['p'] == $page) {
21393 $this->outlines
[] = array('t' => $outline['t'], 'l' => $outline['l'], 'x' => $outline['x'], 'y' => $outline['y'], 'p' => $this->page
, 'f' => $outline['f'], 's' => $outline['s'], 'c' => $outline['c']);
21397 $tmplinks = $this->links
;
21398 foreach ($tmplinks as $key => $link) {
21399 if ($link['p'] == $page) {
21400 $this->links
[] = array('p' => $this->page
, 'y' => $link['y'], 'f' => $link['f']);
21403 // return to last page
21404 $this->lastPage(true);
21409 * Output a Table of Content Index (TOC).
21410 * This method must be called after all Bookmarks were set.
21411 * Before calling this method you have to open the page using the addTOCPage() method.
21412 * After calling this method you have to call endTOCPage() to close the TOC page.
21413 * You can override this method to achieve different styles.
21414 * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
21415 * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
21416 * @param $filler (string) string used to fill the space between text and page number.
21417 * @param $toc_name (string) name to use for TOC bookmark.
21418 * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
21419 * @param $color (array) RGB color array for bookmark title (values from 0 to 255).
21421 * @author Nicola Asuni
21422 * @since 4.5.000 (2009-01-02)
21423 * @see addTOCPage(), endTOCPage(), addHTMLTOC()
21425 public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC', $style='', $color=array(0,0,0)) {
21426 $fontsize = $this->FontSizePt
;
21427 $fontfamily = $this->FontFamily
;
21428 $fontstyle = $this->FontStyle
;
21429 $w = $this->w
- $this->lMargin
- $this->rMargin
;
21430 $spacer = $this->GetStringWidth(chr(32)) * 4;
21431 $lmargin = $this->lMargin
;
21432 $rmargin = $this->rMargin
;
21433 $x_start = $this->GetX();
21434 $page_first = $this->page
;
21435 $current_page = $this->page
;
21436 $page_fill_start = false;
21437 $page_fill_end = false;
21438 $current_column = $this->current_column
;
21439 if (TCPDF_STATIC
::empty_string($numbersfont)) {
21440 $numbersfont = $this->default_monospaced_font
;
21442 if (TCPDF_STATIC
::empty_string($filler)) {
21445 if (TCPDF_STATIC
::empty_string($page)) {
21453 $this->SetFont($numbersfont, $fontstyle, $fontsize);
21454 $numwidth = $this->GetStringWidth('00000');
21455 $maxpage = 0; //used for pages on attached documents
21456 foreach ($this->outlines
as $key => $outline) {
21457 // check for extra pages (used for attachments)
21458 if (($this->page
> $page_first) AND ($outline['p'] >= $this->numpages
)) {
21459 $outline['p'] +
= ($this->page
- $page_first);
21468 if ($outline['l'] == 0) {
21469 $this->SetFont($fontfamily, $outline['s'].'B', $fontsize);
21471 $this->SetFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
21473 $this->SetTextColorArray($outline['c']);
21474 // check for page break
21475 $this->checkPageBreak(2 * $this->getCellHeight($this->FontSize
));
21476 // set margins and X position
21477 if (($this->page
== $current_page) AND ($this->current_column
== $current_column)) {
21478 $this->lMargin
= $lmargin;
21479 $this->rMargin
= $rmargin;
21481 if ($this->current_column
!= $current_column) {
21483 $x_start = $this->w
- $this->columns
[$this->current_column
]['x'];
21485 $x_start = $this->columns
[$this->current_column
]['x'];
21488 $lmargin = $this->lMargin
;
21489 $rmargin = $this->rMargin
;
21490 $current_page = $this->page
;
21491 $current_column = $this->current_column
;
21493 $this->SetX($x_start);
21494 $indent = ($spacer * $outline['l']);
21496 $this->x
-= $indent;
21497 $this->rMargin
= $this->w
- $this->x
;
21499 $this->x +
= $indent;
21500 $this->lMargin
= $this->x
;
21502 $link = $this->AddLink();
21503 $this->SetLink($link, $outline['y'], $outline['p']);
21506 $txt = ' '.$outline['t'];
21508 $txt = $outline['t'].' ';
21510 $this->Write(0, $txt, $link, false, $aligntext, false, 0, false, false, 0, $numwidth, '');
21512 $tw = $this->x
- $this->lMargin
;
21514 $tw = $this->w
- $this->rMargin
- $this->x
;
21516 $this->SetFont($numbersfont, $fontstyle, $fontsize);
21517 if (TCPDF_STATIC
::empty_string($page)) {
21518 $pagenum = $outline['p'];
21520 // placemark to be replaced with the correct number
21521 $pagenum = '{#'.($outline['p']).'}';
21522 if ($this->isUnicodeFont()) {
21523 $pagenum = '{'.$pagenum.'}';
21525 $maxpage = max($maxpage, $outline['p']);
21527 $fw = ($tw - $this->GetStringWidth($pagenum.$filler));
21528 $wfiller = $this->GetStringWidth($filler);
21529 if ($wfiller > 0) {
21530 $numfills = floor($fw / $wfiller);
21534 if ($numfills > 0) {
21535 $rowfill = str_repeat($filler, $numfills);
21540 $pagenum = $pagenum.$gap.$rowfill;
21542 $pagenum = $rowfill.$gap.$pagenum;
21544 // write the number
21545 $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
21547 $page_last = $this->getPage();
21548 $numpages = ($page_last - $page_first +
1);
21549 // account for booklet mode
21550 if ($this->booklet
) {
21551 // check if a blank page is required before TOC
21552 $page_fill_start = ((($page_first %
2) == 0) XOR (($page %
2) == 0));
21553 $page_fill_end = (!((($numpages %
2) == 0) XOR ($page_fill_start)));
21554 if ($page_fill_start) {
21555 // add a page at the end (to be moved before TOC)
21560 if ($page_fill_end) {
21561 // add a page at the end
21567 $maxpage = max($maxpage, $page_last);
21568 if (!TCPDF_STATIC
::empty_string($page)) {
21569 for ($p = $page_first; $p <= $page_last; ++
$p) {
21571 $temppage = $this->getPageBuffer($p);
21572 for ($n = 1; $n <= $maxpage; ++
$n) {
21573 // update page numbers
21575 // get page number aliases
21576 $pnalias = $this->getInternalPageNumberAliases($a);
21577 // calculate replacement number
21578 if (($n >= $page) AND ($n <= $this->numpages
)) {
21579 $np = $n +
$numpages;
21583 $na = TCPDF_STATIC
::formatTOCPageNumber(($this->starting_page_number +
$np - 1));
21584 $nu = TCPDF_FONTS
::UTF8ToUTF16BE($na, false, $this->isunicode
, $this->CurrentFont
);
21585 // replace aliases with numbers
21586 foreach ($pnalias['u'] as $u) {
21587 $sfill = str_repeat($filler, max(0, (strlen($u) - strlen($nu.' '))));
21589 $nr = $nu.TCPDF_FONTS
::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode
, $this->CurrentFont
);
21591 $nr = TCPDF_FONTS
::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode
, $this->CurrentFont
).$nu;
21593 $temppage = str_replace($u, $nr, $temppage);
21595 foreach ($pnalias['a'] as $a) {
21596 $sfill = str_repeat($filler, max(0, (strlen($a) - strlen($na.' '))));
21598 $nr = $na.' '.$sfill;
21600 $nr = $sfill.' '.$na;
21602 $temppage = str_replace($a, $nr, $temppage);
21606 $this->setPageBuffer($p, $temppage);
21609 $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
21610 if ($page_fill_start) {
21611 $this->movePage($page_last, $page_first);
21613 for ($i = 0; $i < $numpages; ++
$i) {
21614 $this->movePage($page_last, $page);
21620 * Output a Table Of Content Index (TOC) using HTML templates.
21621 * This method must be called after all Bookmarks were set.
21622 * Before calling this method you have to open the page using the addTOCPage() method.
21623 * After calling this method you have to call endTOCPage() to close the TOC page.
21624 * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
21625 * @param $toc_name (string) name to use for TOC bookmark.
21626 * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
21627 * @param $correct_align (boolean) if true correct the number alignment (numbers must be in monospaced font like courier and right aligned on LTR, or left aligned on RTL)
21628 * @param $style (string) Font style for title: B = Bold, I = Italic, BI = Bold + Italic.
21629 * @param $color (array) RGB color array for title (values from 0 to 255).
21631 * @author Nicola Asuni
21632 * @since 5.0.001 (2010-05-06)
21633 * @see addTOCPage(), endTOCPage(), addTOC()
21635 public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true, $style='', $color=array(0,0,0)) {
21637 $prev_htmlLinkColorArray = $this->htmlLinkColorArray
;
21638 $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle
;
21639 // set new style for link
21640 $this->htmlLinkColorArray
= array();
21641 $this->htmlLinkFontStyle
= '';
21642 $page_first = $this->getPage();
21643 $page_fill_start = false;
21644 $page_fill_end = false;
21645 // get the font type used for numbers in each template
21646 $current_font = $this->FontFamily
;
21647 foreach ($templates as $level => $html) {
21648 $dom = $this->getHtmlDomArray($html);
21649 foreach ($dom as $key => $value) {
21650 if ($value['value'] == '#TOC_PAGE_NUMBER#') {
21651 $this->SetFont($dom[($key - 1)]['fontname']);
21652 $templates['F'.$level] = $this->isUnicodeFont();
21656 $this->SetFont($current_font);
21657 $maxpage = 0; //used for pages on attached documents
21658 foreach ($this->outlines
as $key => $outline) {
21659 // get HTML template
21660 $row = $templates[$outline['l']];
21661 if (TCPDF_STATIC
::empty_string($page)) {
21662 $pagenum = $outline['p'];
21664 // placemark to be replaced with the correct number
21665 $pagenum = '{#'.($outline['p']).'}';
21666 if (isset($templates['F'.$outline['l']]) && $templates['F'.$outline['l']]) {
21667 $pagenum = '{'.$pagenum.'}';
21669 $maxpage = max($maxpage, $outline['p']);
21671 // replace templates with current values
21672 $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
21673 $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
21674 // add link to page
21675 $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
21676 // write bookmark entry
21677 $this->writeHTML($row, false, false, true, false, '');
21679 // restore link styles
21680 $this->htmlLinkColorArray
= $prev_htmlLinkColorArray;
21681 $this->htmlLinkFontStyle
= $prev_htmlLinkFontStyle;
21682 // move TOC page and replace numbers
21683 $page_last = $this->getPage();
21684 $numpages = ($page_last - $page_first +
1);
21685 // account for booklet mode
21686 if ($this->booklet
) {
21687 // check if a blank page is required before TOC
21688 $page_fill_start = ((($page_first %
2) == 0) XOR (($page %
2) == 0));
21689 $page_fill_end = (!((($numpages %
2) == 0) XOR ($page_fill_start)));
21690 if ($page_fill_start) {
21691 // add a page at the end (to be moved before TOC)
21696 if ($page_fill_end) {
21697 // add a page at the end
21703 $maxpage = max($maxpage, $page_last);
21704 if (!TCPDF_STATIC
::empty_string($page)) {
21705 for ($p = $page_first; $p <= $page_last; ++
$p) {
21707 $temppage = $this->getPageBuffer($p);
21708 for ($n = 1; $n <= $maxpage; ++
$n) {
21709 // update page numbers
21711 // get page number aliases
21712 $pnalias = $this->getInternalPageNumberAliases($a);
21713 // calculate replacement number
21715 $np = $n +
$numpages;
21719 $na = TCPDF_STATIC
::formatTOCPageNumber(($this->starting_page_number +
$np - 1));
21720 $nu = TCPDF_FONTS
::UTF8ToUTF16BE($na, false, $this->isunicode
, $this->CurrentFont
);
21721 // replace aliases with numbers
21722 foreach ($pnalias['u'] as $u) {
21723 if ($correct_align) {
21724 $sfill = str_repeat($filler, (strlen($u) - strlen($nu.' ')));
21726 $nr = $nu.TCPDF_FONTS
::UTF8ToUTF16BE(' '.$sfill, false, $this->isunicode
, $this->CurrentFont
);
21728 $nr = TCPDF_FONTS
::UTF8ToUTF16BE($sfill.' ', false, $this->isunicode
, $this->CurrentFont
).$nu;
21733 $temppage = str_replace($u, $nr, $temppage);
21735 foreach ($pnalias['a'] as $a) {
21736 if ($correct_align) {
21737 $sfill = str_repeat($filler, (strlen($a) - strlen($na.' ')));
21739 $nr = $na.' '.$sfill;
21741 $nr = $sfill.' '.$na;
21746 $temppage = str_replace($a, $nr, $temppage);
21750 $this->setPageBuffer($p, $temppage);
21753 $this->Bookmark($toc_name, 0, 0, $page_first, $style, $color);
21754 if ($page_fill_start) {
21755 $this->movePage($page_last, $page_first);
21757 for ($i = 0; $i < $numpages; ++
$i) {
21758 $this->movePage($page_last, $page);
21764 * Stores a copy of the current TCPDF object used for undo operation.
21766 * @since 4.5.029 (2009-03-19)
21768 public function startTransaction() {
21769 if (isset($this->objcopy
)) {
21770 // remove previous copy
21771 $this->commitTransaction();
21773 // record current page number and Y position
21774 $this->start_transaction_page
= $this->page
;
21775 $this->start_transaction_y
= $this->y
;
21776 // clone current object
21777 $this->objcopy
= TCPDF_STATIC
::objclone($this);
21781 * Delete the copy of the current TCPDF object used for undo operation.
21783 * @since 4.5.029 (2009-03-19)
21785 public function commitTransaction() {
21786 if (isset($this->objcopy
)) {
21787 $this->objcopy
->_destroy(true, true);
21788 /* The unique file_id should not be used during cleanup again */
21789 $this->objcopy
->file_id
= NULL;
21790 unset($this->objcopy
);
21795 * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
21796 * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
21797 * @return TCPDF object.
21799 * @since 4.5.029 (2009-03-19)
21801 public function rollbackTransaction($self=false) {
21802 if (isset($this->objcopy
)) {
21803 $objcopy = $this->objcopy
;
21804 $this->_destroy(true, true);
21806 $objvars = get_object_vars($objcopy);
21807 foreach ($objvars as $key => $value) {
21808 $this->$key = $value;
21810 $objcopy->_destroy(true, true);
21811 /* The unique file_id should not be used during cleanup again */
21812 $objcopy->file_id
= NULL;
21816 /* The unique file_id should not be used during cleanup again */
21817 $this->file_id
= NULL;
21823 // --- MULTI COLUMNS METHODS -----------------------
21826 * Set multiple columns of the same size
21827 * @param $numcols (int) number of columns (set to zero to disable columns mode)
21828 * @param $width (int) column width
21829 * @param $y (int) column starting Y position (leave empty for current Y position)
21831 * @since 4.9.001 (2010-03-28)
21833 public function setEqualColumns($numcols=0, $width=0, $y='') {
21834 $this->columns
= array();
21835 if ($numcols < 2) {
21837 $this->columns
= array();
21839 // maximum column width
21840 $maxwidth = ($this->w
- $this->original_lMargin
- $this->original_rMargin
) / $numcols;
21841 if (($width == 0) OR ($width > $maxwidth)) {
21842 $width = $maxwidth;
21844 if (TCPDF_STATIC
::empty_string($y)) {
21847 // space between columns
21848 $space = (($this->w
- $this->original_lMargin
- $this->original_rMargin
- ($numcols * $width)) / ($numcols - 1));
21849 // fill the columns array (with, space, starting Y position)
21850 for ($i = 0; $i < $numcols; ++
$i) {
21851 $this->columns
[$i] = array('w' => $width, 's' => $space, 'y' => $y);
21854 $this->num_columns
= $numcols;
21855 $this->current_column
= 0;
21856 $this->column_start_page
= $this->page
;
21857 $this->selectColumn(0);
21861 * Remove columns and reset page margins.
21863 * @since 5.9.072 (2011-04-26)
21865 public function resetColumns() {
21866 $this->lMargin
= $this->original_lMargin
;
21867 $this->rMargin
= $this->original_rMargin
;
21868 $this->setEqualColumns();
21872 * Set columns array.
21873 * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
21874 * @param $columns (array)
21876 * @since 4.9.001 (2010-03-28)
21878 public function setColumnsArray($columns) {
21879 $this->columns
= $columns;
21880 $this->num_columns
= count($columns);
21881 $this->current_column
= 0;
21882 $this->column_start_page
= $this->page
;
21883 $this->selectColumn(0);
21887 * Set position at a given column
21888 * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
21890 * @since 4.9.001 (2010-03-28)
21892 public function selectColumn($col='') {
21893 if (is_string($col)) {
21894 $col = $this->current_column
;
21895 } elseif ($col >= $this->num_columns
) {
21898 $xshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
21899 $enable_thead = false;
21900 if ($this->num_columns
> 1) {
21901 if ($col != $this->current_column
) {
21902 // move Y pointer at the top of the column
21903 if ($this->column_start_page
== $this->page
) {
21904 $this->y
= $this->columns
[$col]['y'];
21906 $this->y
= $this->tMargin
;
21908 // Avoid to write table headers more than once
21909 if (($this->page
> $this->maxselcol
['page']) OR (($this->page
== $this->maxselcol
['page']) AND ($col > $this->maxselcol
['column']))) {
21910 $enable_thead = true;
21911 $this->maxselcol
['page'] = $this->page
;
21912 $this->maxselcol
['column'] = $col;
21915 $xshift = $this->colxshift
;
21916 // set X position of the current column by case
21917 $listindent = ($this->listindentlevel
* $this->listindent
);
21918 // calculate column X position
21920 for ($i = 0; $i < $col; ++
$i) {
21921 $colpos +
= ($this->columns
[$i]['w'] +
$this->columns
[$i]['s']);
21924 $x = $this->w
- $this->original_rMargin
- $colpos;
21925 $this->rMargin
= ($this->w
- $x +
$listindent);
21926 $this->lMargin
= ($x - $this->columns
[$col]['w']);
21927 $this->x
= $x - $listindent;
21929 $x = $this->original_lMargin +
$colpos;
21930 $this->lMargin
= ($x +
$listindent);
21931 $this->rMargin
= ($this->w
- $x - $this->columns
[$col]['w']);
21932 $this->x
= $x +
$listindent;
21934 $this->columns
[$col]['x'] = $x;
21936 $this->current_column
= $col;
21937 // fix for HTML mode
21938 $this->newline
= true;
21939 // print HTML table header (if any)
21940 if ((!TCPDF_STATIC
::empty_string($this->thead
)) AND (!$this->inthead
)) {
21941 if ($enable_thead) {
21942 // print table header
21943 $this->writeHTML($this->thead
, false, false, false, false, '');
21944 $this->y +
= $xshift['s']['V'];
21945 // store end of header position
21946 if (!isset($this->columns
[$col]['th'])) {
21947 $this->columns
[$col]['th'] = array();
21949 $this->columns
[$col]['th']['\''.$this->page
.'\''] = $this->y
;
21951 } elseif (isset($this->columns
[$col]['th']['\''.$this->page
.'\''])) {
21952 $this->y
= $this->columns
[$col]['th']['\''.$this->page
.'\''];
21955 // account for an html table cell over multiple columns
21957 $this->rMargin +
= $xshift['x'];
21958 $this->x
-= ($xshift['x'] +
$xshift['p']['R']);
21960 $this->lMargin +
= $xshift['x'];
21961 $this->x +
= $xshift['x'] +
$xshift['p']['L'];
21966 * Return the current column number
21967 * @return int current column number
21969 * @since 5.5.011 (2010-07-08)
21971 public function getColumn() {
21972 return $this->current_column
;
21976 * Return the current number of columns.
21977 * @return int number of columns
21979 * @since 5.8.018 (2010-08-25)
21981 public function getNumberOfColumns() {
21982 return $this->num_columns
;
21986 * Set Text rendering mode.
21987 * @param $stroke (int) outline size in user units (0 = disable).
21988 * @param $fill (boolean) if true fills the text (default).
21989 * @param $clip (boolean) if true activate clipping mode
21991 * @since 4.9.008 (2009-04-02)
21993 public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
21994 // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
21995 // convert text rendering parameters
21999 if ($fill === true) {
22001 if ($clip === true) {
22002 // Fill, then stroke text and add to path for clipping
22003 $textrendermode = 6;
22005 // Fill, then stroke text
22006 $textrendermode = 2;
22008 $textstrokewidth = $stroke;
22010 if ($clip === true) {
22011 // Fill text and add to path for clipping
22012 $textrendermode = 4;
22015 $textrendermode = 0;
22020 if ($clip === true) {
22021 // Stroke text and add to path for clipping
22022 $textrendermode = 5;
22025 $textrendermode = 1;
22027 $textstrokewidth = $stroke;
22029 if ($clip === true) {
22030 // Add text to path for clipping
22031 $textrendermode = 7;
22033 // Neither fill nor stroke text (invisible)
22034 $textrendermode = 3;
22038 $this->textrendermode
= $textrendermode;
22039 $this->textstrokewidth
= $stroke;
22043 * Set parameters for drop shadow effect for text.
22044 * @param $params (array) Array of parameters: enabled (boolean) set to true to enable shadow; depth_w (float) shadow width in user units; depth_h (float) shadow height in user units; color (array) shadow color or false to use the stroke color; opacity (float) Alpha value: real value from 0 (transparent) to 1 (opaque); blend_mode (string) blend mode, one of the following: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity.
22045 * @since 5.9.174 (2012-07-25)
22048 public function setTextShadow($params=array('enabled'=>false, 'depth_w'=>0, 'depth_h'=>0, 'color'=>false, 'opacity'=>1, 'blend_mode'=>'Normal')) {
22049 if (isset($params['enabled'])) {
22050 $this->txtshadow
['enabled'] = $params['enabled']?
true:false;
22052 $this->txtshadow
['enabled'] = false;
22054 if (isset($params['depth_w'])) {
22055 $this->txtshadow
['depth_w'] = floatval($params['depth_w']);
22057 $this->txtshadow
['depth_w'] = 0;
22059 if (isset($params['depth_h'])) {
22060 $this->txtshadow
['depth_h'] = floatval($params['depth_h']);
22062 $this->txtshadow
['depth_h'] = 0;
22064 if (isset($params['color']) AND ($params['color'] !== false) AND is_array($params['color'])) {
22065 $this->txtshadow
['color'] = $params['color'];
22067 $this->txtshadow
['color'] = $this->strokecolor
;
22069 if (isset($params['opacity'])) {
22070 $this->txtshadow
['opacity'] = min(1, max(0, floatval($params['opacity'])));
22072 $this->txtshadow
['opacity'] = 1;
22074 if (isset($params['blend_mode']) AND in_array($params['blend_mode'], array('Normal', 'Multiply', 'Screen', 'Overlay', 'Darken', 'Lighten', 'ColorDodge', 'ColorBurn', 'HardLight', 'SoftLight', 'Difference', 'Exclusion', 'Hue', 'Saturation', 'Color', 'Luminosity'))) {
22075 $this->txtshadow
['blend_mode'] = $params['blend_mode'];
22077 $this->txtshadow
['blend_mode'] = 'Normal';
22079 if ((($this->txtshadow
['depth_w'] == 0) AND ($this->txtshadow
['depth_h'] == 0)) OR ($this->txtshadow
['opacity'] == 0)) {
22080 $this->txtshadow
['enabled'] = false;
22085 * Return the text shadow parameters array.
22086 * @return Array of parameters.
22087 * @since 5.9.174 (2012-07-25)
22090 public function getTextShadow() {
22091 return $this->txtshadow
;
22095 * Returns an array of chars containing soft hyphens.
22096 * @param $word (array) array of chars
22097 * @param $patterns (array) Array of hypenation patterns.
22098 * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm.
22099 * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
22100 * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
22101 * @param $charmin (int) Minimum word length to apply the hyphenation algorithm.
22102 * @param $charmax (int) Maximum length of broken piece of word.
22103 * @return array text with soft hyphens
22104 * @author Nicola Asuni
22105 * @since 4.9.012 (2010-04-12)
22108 protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
22109 $hyphenword = array(); // hyphens positions
22110 $numchars = count($word);
22111 if ($numchars <= $charmin) {
22114 $word_string = TCPDF_FONTS
::UTF8ArrSubString($word, '', '', $this->isunicode
);
22115 // some words will be returned as-is
22116 $pattern = '/^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
22117 if (preg_match($pattern, $word_string) > 0) {
22121 $pattern = '/(([a-zA-Z0-9\-]+\.)?)((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
22122 if (preg_match($pattern, $word_string) > 0) {
22126 if (isset($dictionary[$word_string])) {
22127 return TCPDF_FONTS
::UTF8StringToArray($dictionary[$word_string], $this->isunicode
, $this->CurrentFont
);
22129 // surround word with '_' characters
22130 $tmpword = array_merge(array(46), $word, array(46));
22131 $tmpnumchars = $numchars +
2;
22132 $maxpos = $tmpnumchars - 1;
22133 for ($pos = 0; $pos < $maxpos; ++
$pos) {
22134 $imax = min(($tmpnumchars - $pos), $charmax);
22135 for ($i = 1; $i <= $imax; ++
$i) {
22136 $subword = strtolower(TCPDF_FONTS
::UTF8ArrSubString($tmpword, $pos, ($pos +
$i), $this->isunicode
));
22137 if (isset($patterns[$subword])) {
22138 $pattern = TCPDF_FONTS
::UTF8StringToArray($patterns[$subword], $this->isunicode
, $this->CurrentFont
);
22139 $pattern_length = count($pattern);
22141 for ($j = 0; $j < $pattern_length; ++
$j) {
22142 // check if $pattern[$j] is a number = hyphenation level (only numbers from 1 to 5 are valid)
22143 if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
22147 $zero = $pos +
$j - $digits;
22149 // get hyphenation level
22150 $level = ($pattern[$j] - 48);
22151 // if two levels from two different patterns match at the same point, the higher one is selected.
22152 if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] < $level)) {
22153 $hyphenword[$zero] = $level;
22162 $maxpos = $numchars - $rightmin;
22163 for ($i = $leftmin; $i <= $maxpos; ++
$i) {
22164 // only odd levels indicate allowed hyphenation points
22165 if (isset($hyphenword[$i]) AND (($hyphenword[$i] %
2) != 0)) {
22166 // 173 = soft hyphen character
22167 array_splice($word, $i +
$inserted, 0, 173);
22175 * Returns text with soft hyphens.
22176 * @param $text (string) text to process
22177 * @param $patterns (mixed) Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
22178 * @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm.
22179 * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
22180 * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
22181 * @param $charmin (int) Minimum word length to apply the hyphenation algorithm.
22182 * @param $charmax (int) Maximum length of broken piece of word.
22183 * @return array text with soft hyphens
22184 * @author Nicola Asuni
22185 * @since 4.9.012 (2010-04-12)
22188 public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
22189 $text = $this->unhtmlentities($text);
22190 $word = array(); // last word
22191 $txtarr = array(); // text to be returned
22192 $intag = false; // true if we are inside an HTML tag
22193 $skip = false; // true to skip hyphenation
22194 if (!is_array($patterns)) {
22195 $patterns = TCPDF_STATIC
::getHyphenPatternsFromTEX($patterns);
22197 // get array of characters
22198 $unichars = TCPDF_FONTS
::UTF8StringToArray($text, $this->isunicode
, $this->CurrentFont
);
22200 foreach ($unichars as $char) {
22201 if ((!$intag) AND (!$skip) AND TCPDF_FONT_DATA
::$uni_type[$char] == 'L') {
22202 // letter character
22205 // other type of character
22206 if (!TCPDF_STATIC
::empty_string($word)) {
22207 // hypenate the word
22208 $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
22212 if (chr($char) == '<') {
22213 // we are inside an HTML tag
22215 } elseif ($intag AND (chr($char) == '>')) {
22218 // check for style tag
22219 $expected = array(115, 116, 121, 108, 101); // = 'style'
22220 $current = array_slice($txtarr, -6, 5); // last 5 chars
22221 $compare = array_diff($expected, $current);
22222 if (empty($compare)) {
22223 // check if it is a closing tag
22224 $expected = array(47); // = '/'
22225 $current = array_slice($txtarr, -7, 1);
22226 $compare = array_diff($expected, $current);
22227 if (empty($compare)) {
22228 // closing style tag
22231 // opening style tag
22238 if (!TCPDF_STATIC
::empty_string($word)) {
22239 // hypenate the word
22240 $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
22242 // convert char array to string and return
22243 return TCPDF_FONTS
::UTF8ArrSubString($txtarr, '', '', $this->isunicode
);
22247 * Enable/disable rasterization of vector images using ImageMagick library.
22248 * @param $mode (boolean) if true enable rasterization, false otherwise.
22250 * @since 5.0.000 (2010-04-27)
22252 public function setRasterizeVectorImages($mode) {
22253 $this->rasterize_vector_images
= $mode;
22257 * Enable or disable default option for font subsetting.
22258 * @param $enable (boolean) if true enable font subsetting by default.
22259 * @author Nicola Asuni
22261 * @since 5.3.002 (2010-06-07)
22263 public function setFontSubsetting($enable=true) {
22264 if ($this->pdfa_mode
) {
22265 $this->font_subsetting
= false;
22267 $this->font_subsetting
= $enable ?
true : false;
22272 * Return the default option for font subsetting.
22273 * @return boolean default font subsetting state.
22274 * @author Nicola Asuni
22276 * @since 5.3.002 (2010-06-07)
22278 public function getFontSubsetting() {
22279 return $this->font_subsetting
;
22283 * Left trim the input string
22284 * @param $str (string) string to trim
22285 * @param $replace (string) string that replace spaces.
22286 * @return left trimmed string
22287 * @author Nicola Asuni
22289 * @since 5.8.000 (2010-08-11)
22291 public function stringLeftTrim($str, $replace='') {
22292 return preg_replace('/^'.$this->re_space
['p'].'+/'.$this->re_space
['m'], $replace, $str);
22296 * Right trim the input string
22297 * @param $str (string) string to trim
22298 * @param $replace (string) string that replace spaces.
22299 * @return right trimmed string
22300 * @author Nicola Asuni
22302 * @since 5.8.000 (2010-08-11)
22304 public function stringRightTrim($str, $replace='') {
22305 return preg_replace('/'.$this->re_space
['p'].'+$/'.$this->re_space
['m'], $replace, $str);
22309 * Trim the input string
22310 * @param $str (string) string to trim
22311 * @param $replace (string) string that replace spaces.
22312 * @return trimmed string
22313 * @author Nicola Asuni
22315 * @since 5.8.000 (2010-08-11)
22317 public function stringTrim($str, $replace='') {
22318 $str = $this->stringLeftTrim($str, $replace);
22319 $str = $this->stringRightTrim($str, $replace);
22324 * Return true if the current font is unicode type.
22325 * @return true for unicode font, false otherwise.
22326 * @author Nicola Asuni
22328 * @since 5.8.002 (2010-08-14)
22330 public function isUnicodeFont() {
22331 return (($this->CurrentFont
['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont
['type'] == 'cidfont0'));
22335 * Return normalized font name
22336 * @param $fontfamily (string) property string containing font family names
22337 * @return string normalized font name
22338 * @author Nicola Asuni
22340 * @since 5.8.004 (2010-08-17)
22342 public function getFontFamilyName($fontfamily) {
22343 // remove spaces and symbols
22344 $fontfamily = preg_replace('/[^a-z0-9_\,]/', '', strtolower($fontfamily));
22345 // extract all font names
22346 $fontslist = preg_split('/[,]/', $fontfamily);
22347 // find first valid font name
22348 foreach ($fontslist as $font) {
22349 // replace font variations
22350 $font = preg_replace('/regular$/', '', $font);
22351 $font = preg_replace('/italic$/', 'I', $font);
22352 $font = preg_replace('/oblique$/', 'I', $font);
22353 $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
22354 // replace common family names and core fonts
22355 $pattern = array();
22356 $replacement = array();
22357 $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
22358 $replacement[] = 'times';
22359 $pattern[] = '/^sansserif/';
22360 $replacement[] = 'helvetica';
22361 $pattern[] = '/^monospace/';
22362 $replacement[] = 'courier';
22363 $font = preg_replace($pattern, $replacement, $font);
22364 if (in_array(strtolower($font), $this->fontlist
) OR in_array($font, $this->fontkeys
)) {
22368 // return current font as default
22369 return $this->CurrentFont
['fontkey'];
22373 * Start a new XObject Template.
22374 * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
22375 * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
22376 * Note: X,Y coordinates will be reset to 0,0.
22377 * @param $w (int) Template width in user units (empty string or zero = page width less margins).
22378 * @param $h (int) Template height in user units (empty string or zero = page height less margins).
22379 * @param $group (mixed) Set transparency group. Can be a boolean value or an array specifying optional parameters: 'CS' (solour space name), 'I' (boolean flag to indicate isolated group) and 'K' (boolean flag to indicate knockout group).
22380 * @return int the XObject Template ID in case of success or false in case of error.
22381 * @author Nicola Asuni
22383 * @since 5.8.017 (2010-08-24)
22384 * @see endTemplate(), printTemplate()
22386 public function startTemplate($w=0, $h=0, $group=false) {
22387 if ($this->inxobj
) {
22388 // we are already inside an XObject template
22391 $this->inxobj
= true;
22394 $this->xobjid
= 'XT'.$this->n
;
22396 $this->xobjects
[$this->xobjid
] = array('n' => $this->n
);
22397 // store current graphic state
22398 $this->xobjects
[$this->xobjid
]['gvars'] = $this->getGraphicVars();
22400 $this->xobjects
[$this->xobjid
]['intmrk'] = 0;
22401 $this->xobjects
[$this->xobjid
]['transfmrk'] = array();
22402 $this->xobjects
[$this->xobjid
]['outdata'] = '';
22403 $this->xobjects
[$this->xobjid
]['xobjects'] = array();
22404 $this->xobjects
[$this->xobjid
]['images'] = array();
22405 $this->xobjects
[$this->xobjid
]['fonts'] = array();
22406 $this->xobjects
[$this->xobjid
]['annotations'] = array();
22407 $this->xobjects
[$this->xobjid
]['extgstates'] = array();
22408 $this->xobjects
[$this->xobjid
]['gradients'] = array();
22409 $this->xobjects
[$this->xobjid
]['spot_colors'] = array();
22410 // set new environment
22411 $this->num_columns
= 1;
22412 $this->current_column
= 0;
22413 $this->SetAutoPageBreak(false);
22414 if (($w === '') OR ($w <= 0)) {
22415 $w = $this->w
- $this->lMargin
- $this->rMargin
;
22417 if (($h === '') OR ($h <= 0)) {
22418 $h = $this->h
- $this->tMargin
- $this->bMargin
;
22420 $this->xobjects
[$this->xobjid
]['x'] = 0;
22421 $this->xobjects
[$this->xobjid
]['y'] = 0;
22422 $this->xobjects
[$this->xobjid
]['w'] = $w;
22423 $this->xobjects
[$this->xobjid
]['h'] = $h;
22426 $this->wPt
= $this->w
* $this->k
;
22427 $this->hPt
= $this->h
* $this->k
;
22428 $this->fwPt
= $this->wPt
;
22429 $this->fhPt
= $this->hPt
;
22432 $this->lMargin
= 0;
22433 $this->rMargin
= 0;
22434 $this->tMargin
= 0;
22435 $this->bMargin
= 0;
22437 $this->xobjects
[$this->xobjid
]['group'] = $group;
22438 return $this->xobjid
;
22442 * End the current XObject Template started with startTemplate() and restore the previous graphic state.
22443 * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
22444 * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
22445 * @return int the XObject Template ID in case of success or false in case of error.
22446 * @author Nicola Asuni
22448 * @since 5.8.017 (2010-08-24)
22449 * @see startTemplate(), printTemplate()
22451 public function endTemplate() {
22452 if (!$this->inxobj
) {
22453 // we are not inside a template
22456 $this->inxobj
= false;
22457 // restore previous graphic state
22458 $this->setGraphicVars($this->xobjects
[$this->xobjid
]['gvars'], true);
22459 return $this->xobjid
;
22463 * Print an XObject Template.
22464 * You can print an XObject Template inside the currently opened Template.
22465 * An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images).
22466 * An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.
22467 * @param $id (string) The ID of XObject Template to print.
22468 * @param $x (int) X position in user units (empty string = current x position)
22469 * @param $y (int) Y position in user units (empty string = current y position)
22470 * @param $w (int) Width in user units (zero = remaining page width)
22471 * @param $h (int) Height in user units (zero = remaining page height)
22472 * @param $align (string) Indicates the alignment of the pointer next to template insertion relative to template height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
22473 * @param $palign (string) Allows to center or align the template on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
22474 * @param $fitonpage (boolean) If true the template is resized to not exceed page dimensions.
22475 * @author Nicola Asuni
22477 * @since 5.8.017 (2010-08-24)
22478 * @see startTemplate(), endTemplate()
22480 public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
22481 if ($this->state
!= 2) {
22484 if (!isset($this->xobjects
[$id])) {
22485 $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
22487 if ($this->inxobj
) {
22488 if ($id == $this->xobjid
) {
22489 // close current template
22490 $this->endTemplate();
22492 // use the template as resource for the template currently opened
22493 $this->xobjects
[$this->xobjid
]['xobjects'][$id] = $this->xobjects
[$id];
22496 // set default values
22503 // check page for no-write regions and adapt page margins if necessary
22504 list($x, $y) = $this->checkPageRegions($h, $x, $y);
22505 $ow = $this->xobjects
[$id]['w'];
22509 $oh = $this->xobjects
[$id]['h'];
22513 // calculate template width and height on document
22514 if (($w <= 0) AND ($h <= 0)) {
22517 } elseif ($w <= 0) {
22518 $w = $h * $ow / $oh;
22519 } elseif ($h <= 0) {
22520 $h = $w * $oh / $ow;
22522 // fit the template on available space
22523 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
22524 // set page alignment
22528 if ($palign == 'L') {
22529 $xt = $this->lMargin
;
22530 } elseif ($palign == 'C') {
22531 $xt = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
22532 } elseif ($palign == 'R') {
22533 $xt = $this->w
- $this->rMargin
- $w;
22539 if ($palign == 'L') {
22540 $xt = $this->lMargin
;
22541 } elseif ($palign == 'C') {
22542 $xt = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
22543 } elseif ($palign == 'R') {
22544 $xt = $this->w
- $this->rMargin
- $w;
22550 // print XObject Template + Transformation matrix
22551 $this->StartTransform();
22552 // translate and scale
22560 $tm[4] = $xt * $this->k
;
22561 $tm[5] = ($this->h
- $h - $y) * $this->k
;
22562 $this->Transform($tm);
22564 $this->_out('/'.$id.' Do');
22565 $this->StopTransform();
22567 if (!empty($this->xobjects
[$id]['annotations'])) {
22568 foreach ($this->xobjects
[$id]['annotations'] as $annot) {
22569 // transform original coordinates
22570 $coordlt = TCPDF_STATIC
::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k
), (-$annot['y'] * $this->k
)));
22571 $ax = ($coordlt[4] / $this->k
);
22572 $ay = ($this->h
- $h - ($coordlt[5] / $this->k
));
22573 $coordrb = TCPDF_STATIC
::getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] +
$annot['w']) * $this->k
), ((-$annot['y'] - $annot['h']) * $this->k
)));
22574 $aw = ($coordrb[4] / $this->k
) - $ax;
22575 $ah = ($this->h
- $h - ($coordrb[5] / $this->k
)) - $ay;
22576 $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
22579 // set pointer to align the next text/objects
22587 $this->y
= $y +
round($h/2);
22597 $this->SetY($rb_y);
22607 * Set the percentage of character stretching.
22608 * @param $perc (int) percentage of stretching (100 = no stretching)
22609 * @author Nicola Asuni
22611 * @since 5.9.000 (2010-09-29)
22613 public function setFontStretching($perc=100) {
22614 $this->font_stretching
= $perc;
22618 * Get the percentage of character stretching.
22619 * @return float stretching value
22620 * @author Nicola Asuni
22622 * @since 5.9.000 (2010-09-29)
22624 public function getFontStretching() {
22625 return $this->font_stretching
;
22629 * Set the amount to increase or decrease the space between characters in a text.
22630 * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
22631 * @author Nicola Asuni
22633 * @since 5.9.000 (2010-09-29)
22635 public function setFontSpacing($spacing=0) {
22636 $this->font_spacing
= $spacing;
22640 * Get the amount to increase or decrease the space between characters in a text.
22641 * @return int font spacing (tracking) value
22642 * @author Nicola Asuni
22644 * @since 5.9.000 (2010-09-29)
22646 public function getFontSpacing() {
22647 return $this->font_spacing
;
22651 * Return an array of no-write page regions
22652 * @return array of no-write page regions
22653 * @author Nicola Asuni
22655 * @since 5.9.003 (2010-10-13)
22656 * @see setPageRegions(), addPageRegion()
22658 public function getPageRegions() {
22659 return $this->page_regions
;
22663 * Set no-write regions on page.
22664 * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
22665 * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
22666 * You can set multiple regions for the same page.
22667 * @param $regions (array) array of no-write regions. For each region you can define an array as follow: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right). Omit this parameter to remove all regions.
22668 * @author Nicola Asuni
22670 * @since 5.9.003 (2010-10-13)
22671 * @see addPageRegion(), getPageRegions()
22673 public function setPageRegions($regions=array()) {
22674 // empty current regions array
22675 $this->page_regions
= array();
22677 foreach ($regions as $data) {
22678 $this->addPageRegion($data);
22683 * Add a single no-write region on selected page.
22684 * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
22685 * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
22686 * You can set multiple regions for the same page.
22687 * @param $region (array) array of a single no-write region array: ('page' => page number or empy for current page, 'xt' => X top, 'yt' => Y top, 'xb' => X bottom, 'yb' => Y bottom, 'side' => page side 'L' = left or 'R' = right).
22688 * @author Nicola Asuni
22690 * @since 5.9.003 (2010-10-13)
22691 * @see setPageRegions(), getPageRegions()
22693 public function addPageRegion($region) {
22694 if (!isset($region['page']) OR empty($region['page'])) {
22695 $region['page'] = $this->page
;
22697 if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
22698 AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
22699 AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
22700 $this->page_regions
[] = $region;
22705 * Remove a single no-write region.
22706 * @param $key (int) region key
22707 * @author Nicola Asuni
22709 * @since 5.9.003 (2010-10-13)
22710 * @see setPageRegions(), getPageRegions()
22712 public function removePageRegion($key) {
22713 if (isset($this->page_regions
[$key])) {
22714 unset($this->page_regions
[$key]);
22719 * Check page for no-write regions and adapt current coordinates and page margins if necessary.
22720 * A no-write region is a portion of the page with a rectangular or trapezium shape that will not be covered when writing text or html code.
22721 * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
22722 * @param $h (float) height of the text/image/object to print in user units
22723 * @param $x (float) current X coordinate in user units
22724 * @param $y (float) current Y coordinate in user units
22725 * @return array($x, $y)
22726 * @author Nicola Asuni
22728 * @since 5.9.003 (2010-10-13)
22730 protected function checkPageRegions($h, $x, $y) {
22731 // set default values
22738 if (!$this->check_page_regions
OR empty($this->page_regions
)) {
22739 // no page regions defined
22740 return array($x, $y);
22743 $h = $this->getCellHeight($this->FontSize
);
22745 // check for page break
22746 if ($this->checkPageBreak($h, $y)) {
22747 // the content will be printed on a new page
22751 if ($this->num_columns
> 1) {
22753 $this->lMargin
= ($this->columns
[$this->current_column
]['x'] - $this->columns
[$this->current_column
]['w']);
22755 $this->rMargin
= ($this->w
- $this->columns
[$this->current_column
]['x'] - $this->columns
[$this->current_column
]['w']);
22759 $this->lMargin
= max($this->clMargin
, $this->original_lMargin
);
22761 $this->rMargin
= max($this->crMargin
, $this->original_rMargin
);
22764 // adjust coordinates and page margins
22765 foreach ($this->page_regions
as $regid => $regdata) {
22766 if ($regdata['page'] == $this->page
) {
22767 // check region boundaries
22768 if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
22769 // Y is inside the region
22770 $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
22771 $yt = max($y, $regdata['yt']);
22772 $yb = min(($yt +
$h), $regdata['yb']);
22773 $xt = (($yt - $regdata['yt']) * $minv) +
$regdata['xt'];
22774 $xb = (($yb - $regdata['yt']) * $minv) +
$regdata['xt'];
22775 if ($regdata['side'] == 'L') { // left side
22776 $new_margin = max($xt, $xb);
22777 if ($this->lMargin
< $new_margin) {
22779 // adjust left page margin
22780 $this->lMargin
= max(0, $new_margin);
22782 if ($x < $new_margin) {
22783 // adjust x position
22785 if ($new_margin > ($this->w
- $this->rMargin
)) {
22786 // adjust y position
22787 $y = $regdata['yb'] - $h;
22791 } elseif ($regdata['side'] == 'R') { // right side
22792 $new_margin = min($xt, $xb);
22793 if (($this->w
- $this->rMargin
) > $new_margin) {
22795 // adjust right page margin
22796 $this->rMargin
= max(0, ($this->w
- $new_margin));
22798 if ($x > $new_margin) {
22799 // adjust x position
22801 if ($new_margin > $this->lMargin
) {
22802 // adjust y position
22803 $y = $regdata['yb'] - $h;
22811 return array($x, $y);
22814 // --- SVG METHODS ---------------------------------------------------------
22817 * Embedd a Scalable Vector Graphics (SVG) image.
22818 * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
22819 * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
22820 * @param $x (float) Abscissa of the upper-left corner.
22821 * @param $y (float) Ordinate of the upper-left corner.
22822 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
22823 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
22824 * @param $link (mixed) URL or identifier returned by AddLink().
22825 * @param $align (string) Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul> If the alignment is an empty string, then the pointer will be restored on the starting SVG position.
22826 * @param $palign (string) Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
22827 * @param $border (mixed) Indicates if borders must be drawn around the cell. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul> or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
22828 * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
22829 * @author Nicola Asuni
22830 * @since 5.0.000 (2010-05-02)
22833 public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
22834 if ($this->state
!= 2) {
22838 $this->svggradients
= array();
22839 $this->svggradientid
= 0;
22840 $this->svgdefsmode
= false;
22841 $this->svgdefs
= array();
22842 $this->svgclipmode
= false;
22843 $this->svgclippaths
= array();
22844 $this->svgcliptm
= array();
22845 $this->svgclipid
= 0;
22846 $this->svgtext
= '';
22847 $this->svgtextmode
= array();
22848 if ($this->rasterize_vector_images
AND ($w > 0) AND ($h > 0)) {
22849 // convert SVG to raster image using GD or ImageMagick libraries
22850 return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
22852 if ($file[0] === '@') { // image from string
22853 $this->svgdir
= '';
22854 $svgdata = substr($file, 1);
22855 } else { // SVG file
22856 $this->svgdir
= dirname($file);
22857 $svgdata = $this->getCachedFileContents($file);
22859 if ($svgdata === FALSE) {
22860 $this->Error('SVG file not found: '.$file);
22868 // check page for no-write regions and adapt page margins if necessary
22869 list($x, $y) = $this->checkPageRegions($h, $x, $y);
22875 $aspect_ratio_align = 'xMidYMid';
22876 $aspect_ratio_ms = 'meet';
22878 // get original image width and height
22879 preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
22880 if (isset($regs[1]) AND !empty($regs[1])) {
22882 if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22883 $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit
, false);
22886 if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22887 $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit
, false);
22890 if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22891 $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
22894 if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22895 $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
22898 $view_box = array();
22899 if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
22900 if (count($tmp) == 5) {
22902 foreach ($tmp as $key => $val) {
22903 $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit
, false);
22905 $ox = $view_box[0];
22906 $oy = $view_box[1];
22908 // get aspect ratio
22910 if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
22911 $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
22912 switch (count($aspect_ratio)) {
22914 $aspect_ratio_align = $aspect_ratio[1];
22915 $aspect_ratio_ms = $aspect_ratio[2];
22919 $aspect_ratio_align = $aspect_ratio[0];
22920 $aspect_ratio_ms = $aspect_ratio[1];
22924 $aspect_ratio_align = $aspect_ratio[0];
22925 $aspect_ratio_ms = 'meet';
22938 // calculate image width and height on document
22939 if (($w <= 0) AND ($h <= 0)) {
22940 // convert image size to document unit
22943 } elseif ($w <= 0) {
22944 $w = $h * $ow / $oh;
22945 } elseif ($h <= 0) {
22946 $h = $w * $oh / $ow;
22948 // fit the image on available space
22949 list($w, $h, $x, $y) = $this->fitBlock($w, $h, $x, $y, $fitonpage);
22950 if ($this->rasterize_vector_images
) {
22951 // convert SVG to raster image using GD or ImageMagick libraries
22952 return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
22955 $this->img_rb_y
= $y +
$h;
22958 if ($palign == 'L') {
22959 $ximg = $this->lMargin
;
22960 } elseif ($palign == 'C') {
22961 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
22962 } elseif ($palign == 'R') {
22963 $ximg = $this->w
- $this->rMargin
- $w;
22967 $this->img_rb_x
= $ximg;
22969 if ($palign == 'L') {
22970 $ximg = $this->lMargin
;
22971 } elseif ($palign == 'C') {
22972 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
22973 } elseif ($palign == 'R') {
22974 $ximg = $this->w
- $this->rMargin
- $w;
22978 $this->img_rb_x
= $ximg +
$w;
22980 // store current graphic vars
22981 $gvars = $this->getGraphicVars();
22982 // store SVG position and scale factors
22983 $svgoffset_x = ($ximg - $ox) * $this->k
;
22984 $svgoffset_y = -($y - $oy) * $this->k
;
22985 if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
22986 $ow = $view_box[2];
22987 $oh = $view_box[3];
22996 $svgscale_x = $w / $ow;
22997 $svgscale_y = $h / $oh;
22998 // scaling and alignment
22999 if ($aspect_ratio_align != 'none') {
23000 // store current scaling values
23001 $svgscale_old_x = $svgscale_x;
23002 $svgscale_old_y = $svgscale_y;
23003 // force uniform scaling
23004 if ($aspect_ratio_ms == 'slice') {
23005 // the entire viewport is covered by the viewBox
23006 if ($svgscale_x > $svgscale_y) {
23007 $svgscale_y = $svgscale_x;
23008 } elseif ($svgscale_x < $svgscale_y) {
23009 $svgscale_x = $svgscale_y;
23012 // the entire viewBox is visible within the viewport
23013 if ($svgscale_x < $svgscale_y) {
23014 $svgscale_y = $svgscale_x;
23015 } elseif ($svgscale_x > $svgscale_y) {
23016 $svgscale_x = $svgscale_y;
23019 // correct X alignment
23020 switch (substr($aspect_ratio_align, 1, 3)) {
23026 $svgoffset_x +
= (($w * $this->k
) - ($ow * $this->k
* $svgscale_x));
23031 $svgoffset_x +
= ((($w * $this->k
) - ($ow * $this->k
* $svgscale_x)) / 2);
23035 // correct Y alignment
23036 switch (substr($aspect_ratio_align, 5)) {
23042 $svgoffset_y -= (($h * $this->k
) - ($oh * $this->k
* $svgscale_y));
23047 $svgoffset_y -= ((($h * $this->k
) - ($oh * $this->k
* $svgscale_y)) / 2);
23052 // store current page break mode
23053 $page_break_mode = $this->AutoPageBreak
;
23054 $page_break_margin = $this->getBreakMargin();
23055 $cell_padding = $this->cell_padding
;
23056 $this->SetCellPadding(0);
23057 $this->SetAutoPageBreak(false);
23058 // save the current graphic state
23059 $this->_out('q'.$this->epsmarker
);
23060 // set initial clipping mask
23061 $this->Rect($ximg, $y, $w, $h, 'CNZ', array(), array());
23062 // scale and translate
23063 $e = $ox * $this->k
* (1 - $svgscale_x);
23064 $f = ($this->h
- $oy) * $this->k
* (1 - $svgscale_y);
23065 $this->_out(sprintf('%F %F %F %F %F %F cm', $svgscale_x, 0, 0, $svgscale_y, ($e +
$svgoffset_x), ($f +
$svgoffset_y)));
23066 // creates a new XML parser to be used by the other XML functions
23067 $parser = xml_parser_create('UTF-8');
23068 // the following function allows to use parser inside object
23069 xml_set_object($parser, $this);
23070 // disable case-folding for this XML parser
23071 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING
, 0);
23072 // sets the element handler functions for the XML parser
23073 xml_set_element_handler($parser, 'startSVGElementHandler', 'endSVGElementHandler');
23074 // sets the character data handler function for the XML parser
23075 xml_set_character_data_handler($parser, 'segSVGContentHandler');
23076 // start parsing an XML document
23077 if (!xml_parse($parser, $svgdata)) {
23078 $error_message = sprintf('SVG Error: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser));
23079 $this->Error($error_message);
23081 // free this XML parser
23082 xml_parser_free($parser);
23084 // >= PHP 7.0.0 "explicitly unset the reference to parser to avoid memory leaks"
23087 // restore previous graphic state
23088 $this->_out($this->epsmarker
.'Q');
23089 // restore graphic vars
23090 $this->setGraphicVars($gvars);
23091 $this->lasth
= $gvars['lasth'];
23092 if (!empty($border)) {
23100 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
23105 $this->Link($ximg, $y, $w, $h, $link, 0);
23107 // set pointer to align the next text/objects
23111 $this->x
= $this->img_rb_x
;
23115 $this->y
= $y +
round($h/2);
23116 $this->x
= $this->img_rb_x
;
23120 $this->y
= $this->img_rb_y
;
23121 $this->x
= $this->img_rb_x
;
23125 $this->SetY($this->img_rb_y
);
23129 // restore pointer to starting position
23130 $this->x
= $gvars['x'];
23131 $this->y
= $gvars['y'];
23132 $this->page
= $gvars['page'];
23133 $this->current_column
= $gvars['current_column'];
23134 $this->tMargin
= $gvars['tMargin'];
23135 $this->bMargin
= $gvars['bMargin'];
23136 $this->w
= $gvars['w'];
23137 $this->h
= $gvars['h'];
23138 $this->wPt
= $gvars['wPt'];
23139 $this->hPt
= $gvars['hPt'];
23140 $this->fwPt
= $gvars['fwPt'];
23141 $this->fhPt
= $gvars['fhPt'];
23145 $this->endlinex
= $this->img_rb_x
;
23146 // restore page break
23147 $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
23148 $this->cell_padding
= $cell_padding;
23152 * Convert SVG transformation matrix to PDF.
23153 * @param $tm (array) original SVG transformation matrix
23154 * @return array transformation matrix
23156 * @since 5.0.000 (2010-05-02)
23158 protected function convertSVGtMatrix($tm) {
23163 $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit
, false) * $this->k
;
23164 $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit
, false) * $this->k
;
23166 $y = $this->h
* $this->k
;
23167 $e = ($x * (1 - $a)) - ($y * $c) +
$e;
23168 $f = ($y * (1 - $d)) - ($x * $b) +
$f;
23169 return array($a, $b, $c, $d, $e, $f);
23173 * Apply SVG graphic transformation matrix.
23174 * @param $tm (array) original SVG transformation matrix
23176 * @since 5.0.000 (2010-05-02)
23178 protected function SVGTransform($tm) {
23179 $this->Transform($this->convertSVGtMatrix($tm));
23183 * Apply the requested SVG styles (*** TO BE COMPLETED ***)
23184 * @param $svgstyle (array) array of SVG styles to apply
23185 * @param $prevsvgstyle (array) array of previous SVG style
23186 * @param $x (int) X origin of the bounding box
23187 * @param $y (int) Y origin of the bounding box
23188 * @param $w (int) width of the bounding box
23189 * @param $h (int) height of the bounding box
23190 * @param $clip_function (string) clip function
23191 * @param $clip_params (array) array of parameters for clipping function
23192 * @return object style
23193 * @author Nicola Asuni
23194 * @since 5.0.000 (2010-05-02)
23197 protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
23198 if ($this->state
!= 2) {
23202 $minlen = (0.01 / $this->k
); // minimum acceptable length
23203 if (!isset($svgstyle['opacity'])) {
23208 if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
23209 $clip_path = $this->svgclippaths
[$regs[1]];
23210 foreach ($clip_path as $cp) {
23211 $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
23215 if ($svgstyle['opacity'] != 1) {
23216 $this->setAlpha($svgstyle['opacity'], 'Normal', $svgstyle['opacity'], false);
23219 $fill_color = TCPDF_COLORS
::convertHTMLColorToDec($svgstyle['color'], $this->spot_colors
);
23220 $this->SetFillColorArray($fill_color);
23222 $text_color = TCPDF_COLORS
::convertHTMLColorToDec($svgstyle['text-color'], $this->spot_colors
);
23223 $this->SetTextColorArray($text_color);
23225 if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
23226 $top = (isset($regs[1])?
$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit
, false):0);
23227 $right = (isset($regs[2])?
$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit
, false):0);
23228 $bottom = (isset($regs[3])?
$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit
, false):0);
23229 $left = (isset($regs[4])?
$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit
, false):0);
23232 $cw = $w - $left - $right;
23233 $ch = $h - $top - $bottom;
23234 if ($svgstyle['clip-rule'] == 'evenodd') {
23235 $clip_rule = 'CNZ';
23237 $clip_rule = 'CEO';
23239 $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
23243 if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
23245 $gradient = $this->svggradients
[$regs[1]];
23246 if (isset($gradient['xref'])) {
23247 // reference to another gradient definition
23248 $newgradient = $this->svggradients
[$gradient['xref']];
23249 $newgradient['coords'] = $gradient['coords'];
23250 $newgradient['mode'] = $gradient['mode'];
23251 $newgradient['type'] = $gradient['type'];
23252 $newgradient['gradientUnits'] = $gradient['gradientUnits'];
23253 if (isset($gradient['gradientTransform'])) {
23254 $newgradient['gradientTransform'] = $gradient['gradientTransform'];
23256 $gradient = $newgradient;
23258 //save current Graphic State
23259 $this->_outSaveGraphicsState();
23260 //set clipping area
23261 if (!empty($clip_function) AND method_exists($this, $clip_function)) {
23262 $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
23263 if ((!isset($gradient['type']) OR ($gradient['type'] != 3)) AND is_array($bbox) AND (count($bbox) == 4)) {
23264 list($x, $y, $w, $h) = $bbox;
23267 if ($gradient['mode'] == 'measure') {
23268 if (!isset($gradient['coords'][4])) {
23269 $gradient['coords'][4] = 0.5;
23271 if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
23272 $gtm = $gradient['gradientTransform'];
23273 // apply transformation matrix
23274 $xa = ($gtm[0] * $gradient['coords'][0]) +
($gtm[2] * $gradient['coords'][1]) +
$gtm[4];
23275 $ya = ($gtm[1] * $gradient['coords'][0]) +
($gtm[3] * $gradient['coords'][1]) +
$gtm[5];
23276 $xb = ($gtm[0] * $gradient['coords'][2]) +
($gtm[2] * $gradient['coords'][3]) +
$gtm[4];
23277 $yb = ($gtm[1] * $gradient['coords'][2]) +
($gtm[3] * $gradient['coords'][3]) +
$gtm[5];
23278 $r = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) +
pow(($gtm[1] * $gradient['coords'][4]), 2));
23279 $gradient['coords'][0] = $xa;
23280 $gradient['coords'][1] = $ya;
23281 $gradient['coords'][2] = $xb;
23282 $gradient['coords'][3] = $yb;
23283 $gradient['coords'][4] = $r;
23285 // convert SVG coordinates to user units
23286 $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit
, false);
23287 $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit
, false);
23288 $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit
, false);
23289 $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit
, false);
23290 $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit
, false);
23291 if ($w <= $minlen) {
23294 if ($h <= $minlen) {
23298 if ($gradient['gradientUnits'] == 'objectBoundingBox') {
23299 // convert to SVG coordinate system
23300 $gradient['coords'][0] +
= $x;
23301 $gradient['coords'][1] +
= $y;
23302 $gradient['coords'][2] +
= $x;
23303 $gradient['coords'][3] +
= $y;
23305 // calculate percentages
23306 $gradient['coords'][0] = (($gradient['coords'][0] - $x) / $w);
23307 $gradient['coords'][1] = (($gradient['coords'][1] - $y) / $h);
23308 $gradient['coords'][2] = (($gradient['coords'][2] - $x) / $w);
23309 $gradient['coords'][3] = (($gradient['coords'][3] - $y) / $h);
23310 $gradient['coords'][4] /= $w;
23311 } elseif ($gradient['mode'] == 'percentage') {
23312 foreach($gradient['coords'] as $key => $val) {
23313 $gradient['coords'][$key] = (intval($val) / 100);
23315 $gradient['coords'][$key] = 0;
23316 } elseif ($val > 1) {
23317 $gradient['coords'][$key] = 1;
23321 if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
23322 // single color (no shading)
23323 $gradient['coords'][0] = 1;
23324 $gradient['coords'][1] = 0;
23325 $gradient['coords'][2] = 0.999;
23326 $gradient['coords'][3] = 0;
23328 // swap Y coordinates
23329 $tmp = $gradient['coords'][1];
23330 $gradient['coords'][1] = $gradient['coords'][3];
23331 $gradient['coords'][3] = $tmp;
23332 // set transformation map for gradient
23333 $cy = ($this->h
- $y);
23334 if ($gradient['type'] == 3) {
23335 // circular gradient
23336 $cy -= ($gradient['coords'][1] * ($w +
$h));
23337 $h = $w = max($w, $h);
23341 $this->_out(sprintf('%F 0 0 %F %F %F cm', ($w * $this->k
), ($h * $this->k
), ($x * $this->k
), ($cy * $this->k
)));
23342 if (count($gradient['stops']) > 1) {
23343 $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
23345 } elseif ($svgstyle['fill'] != 'none') {
23346 $fill_color = TCPDF_COLORS
::convertHTMLColorToDec($svgstyle['fill'], $this->spot_colors
);
23347 if ($svgstyle['fill-opacity'] != 1) {
23348 $this->setAlpha($this->alpha
['CA'], 'Normal', $svgstyle['fill-opacity'], false);
23350 $this->SetFillColorArray($fill_color);
23351 if ($svgstyle['fill-rule'] == 'evenodd') {
23358 if ($svgstyle['stroke'] != 'none') {
23359 if ($svgstyle['stroke-opacity'] != 1) {
23360 $this->setAlpha($svgstyle['stroke-opacity'], 'Normal', $this->alpha
['ca'], false);
23361 } elseif (preg_match('/rgba\(\d+%?,\s*\d+%?,\s*\d+%?,\s*(\d+(?:\.\d+)?)\)/i', $svgstyle['stroke'], $rgba_matches)) {
23362 $this->setAlpha($rgba_matches[1], 'Normal', $this->alpha
['ca'], false);
23364 $stroke_style = array(
23365 'color' => TCPDF_COLORS
::convertHTMLColorToDec($svgstyle['stroke'], $this->spot_colors
),
23366 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit
, false),
23367 'cap' => $svgstyle['stroke-linecap'],
23368 'join' => $svgstyle['stroke-linejoin']
23370 if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
23371 $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
23373 $this->SetLineStyle($stroke_style);
23378 if (!empty($svgstyle['font'])) {
23379 if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
23380 $font_family = $this->getFontFamilyName($regs[1]);
23382 $font_family = $svgstyle['font-family'];
23384 if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23385 $font_size = trim($regs[1]);
23387 $font_size = $svgstyle['font-size'];
23389 if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23390 $font_style = trim($regs[1]);
23392 $font_style = $svgstyle['font-style'];
23394 if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23395 $font_weight = trim($regs[1]);
23397 $font_weight = $svgstyle['font-weight'];
23399 if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23400 $font_stretch = trim($regs[1]);
23402 $font_stretch = $svgstyle['font-stretch'];
23404 if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
23405 $font_spacing = trim($regs[1]);
23407 $font_spacing = $svgstyle['letter-spacing'];
23410 $font_family = $this->getFontFamilyName($svgstyle['font-family']);
23411 $font_size = $svgstyle['font-size'];
23412 $font_style = $svgstyle['font-style'];
23413 $font_weight = $svgstyle['font-weight'];
23414 $font_stretch = $svgstyle['font-stretch'];
23415 $font_spacing = $svgstyle['letter-spacing'];
23417 $font_size = $this->getHTMLFontUnits($font_size, $this->svgstyles
[0]['font-size'], $prevsvgstyle['font-size'], $this->svgunit
);
23418 $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
23419 $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
23420 switch ($font_style) {
23435 switch ($font_weight) {
23438 $font_style .= 'B';
23442 if ((substr($font_family, -1) == 'I') AND (substr($font_family, -2, 1) == 'B')) {
23443 $font_family = substr($font_family, 0, -2).'I';
23444 } elseif (substr($font_family, -1) == 'B') {
23445 $font_family = substr($font_family, 0, -1);
23450 switch ($svgstyle['text-decoration']) {
23451 case 'underline': {
23452 $font_style .= 'U';
23456 $font_style .= 'O';
23459 case 'line-through': {
23460 $font_style .= 'D';
23468 $this->SetFont($font_family, $font_style, $font_size);
23469 $this->setFontStretching($font_stretch);
23470 $this->setFontSpacing($font_spacing);
23475 * Draws an SVG path
23476 * @param $d (string) attribute d of the path SVG element
23477 * @param $style (string) Style of rendering. Possible values are:
23479 * <li>D or empty string: Draw (default).</li>
23480 * <li>F: Fill.</li>
23481 * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
23482 * <li>DF or FD: Draw and fill.</li>
23483 * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
23484 * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
23485 * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
23487 * @return array of container box measures (x, y, w, h)
23488 * @author Nicola Asuni
23489 * @since 5.0.000 (2010-05-02)
23492 protected function SVGPath($d, $style='') {
23493 if ($this->state
!= 2) {
23496 // set fill/stroke style
23497 $op = TCPDF_STATIC
::getPathPaintOperator($style, '');
23502 $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
23503 $d = preg_replace('/(\.[0-9]+)(\.)/s', '\\1 \\2', $d);
23504 preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER
);
23511 $xmin = 2147483647;
23513 $ymin = 2147483647;
23518 $minlen = (0.01 / $this->k
); // minimum acceptable length (3 point)
23519 $firstcmd = true; // used to print first point
23520 // draw curve pieces
23521 foreach ($paths as $key => $val) {
23523 $cmd = trim($val[1]);
23524 if (strtolower($cmd) == $cmd) {
23525 // use relative coordinated instead of absolute
23535 if (isset($val[2])) {
23536 // get curve parameters
23537 $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
23539 foreach ($rawparams as $ck => $cp) {
23540 $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit
, false);
23541 if (abs($params[$ck]) < $minlen) {
23542 // approximate little values to zero
23547 // store current origin point
23550 switch (strtoupper($cmd)) {
23551 case 'M': { // moveto
23552 foreach ($params as $ck => $cp) {
23553 if (($ck %
2) == 0) {
23554 $x = $cp +
$xoffset;
23556 $y = $cp +
$yoffset;
23557 if ($firstcmd OR (abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23559 $this->_outPoint($x, $y);
23564 $this->_outLine($x, $y);
23569 $xmin = min($xmin, $x);
23570 $ymin = min($ymin, $y);
23571 $xmax = max($xmax, $x);
23572 $ymax = max($ymax, $y);
23581 case 'L': { // lineto
23582 foreach ($params as $ck => $cp) {
23583 if (($ck %
2) == 0) {
23584 $x = $cp +
$xoffset;
23586 $y = $cp +
$yoffset;
23587 if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23588 $this->_outLine($x, $y);
23592 $xmin = min($xmin, $x);
23593 $ymin = min($ymin, $y);
23594 $xmax = max($xmax, $x);
23595 $ymax = max($ymax, $y);
23604 case 'H': { // horizontal lineto
23605 foreach ($params as $ck => $cp) {
23606 $x = $cp +
$xoffset;
23607 if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23608 $this->_outLine($x, $y);
23612 $xmin = min($xmin, $x);
23613 $xmax = max($xmax, $x);
23620 case 'V': { // vertical lineto
23621 foreach ($params as $ck => $cp) {
23622 $y = $cp +
$yoffset;
23623 if ((abs($x0 - $x) >= $minlen) OR (abs($y0 - $y) >= $minlen)) {
23624 $this->_outLine($x, $y);
23628 $ymin = min($ymin, $y);
23629 $ymax = max($ymax, $y);
23636 case 'C': { // curveto
23637 foreach ($params as $ck => $cp) {
23638 $params[$ck] = $cp;
23639 if ((($ck +
1) %
6) == 0) {
23640 $x1 = $params[($ck - 5)] +
$xoffset;
23641 $y1 = $params[($ck - 4)] +
$yoffset;
23642 $x2 = $params[($ck - 3)] +
$xoffset;
23643 $y2 = $params[($ck - 2)] +
$yoffset;
23644 $x = $params[($ck - 1)] +
$xoffset;
23645 $y = $params[($ck)] +
$yoffset;
23646 $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
23647 $xmin = min($xmin, $x, $x1, $x2);
23648 $ymin = min($ymin, $y, $y1, $y2);
23649 $xmax = max($xmax, $x, $x1, $x2);
23650 $ymax = max($ymax, $y, $y1, $y2);
23659 case 'S': { // shorthand/smooth curveto
23660 foreach ($params as $ck => $cp) {
23661 $params[$ck] = $cp;
23662 if ((($ck +
1) %
4) == 0) {
23663 if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
23664 $x1 = (2 * $x) - $x2;
23665 $y1 = (2 * $y) - $y2;
23670 $x2 = $params[($ck - 3)] +
$xoffset;
23671 $y2 = $params[($ck - 2)] +
$yoffset;
23672 $x = $params[($ck - 1)] +
$xoffset;
23673 $y = $params[($ck)] +
$yoffset;
23674 $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
23675 $xmin = min($xmin, $x, $x1, $x2);
23676 $ymin = min($ymin, $y, $y1, $y2);
23677 $xmax = max($xmax, $x, $x1, $x2);
23678 $ymax = max($ymax, $y, $y1, $y2);
23687 case 'Q': { // quadratic Bezier curveto
23688 foreach ($params as $ck => $cp) {
23689 $params[$ck] = $cp;
23690 if ((($ck +
1) %
4) == 0) {
23691 // convert quadratic points to cubic points
23692 $x1 = $params[($ck - 3)] +
$xoffset;
23693 $y1 = $params[($ck - 2)] +
$yoffset;
23694 $xa = ($x +
(2 * $x1)) / 3;
23695 $ya = ($y +
(2 * $y1)) / 3;
23696 $x = $params[($ck - 1)] +
$xoffset;
23697 $y = $params[($ck)] +
$yoffset;
23698 $xb = ($x +
(2 * $x1)) / 3;
23699 $yb = ($y +
(2 * $y1)) / 3;
23700 $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
23701 $xmin = min($xmin, $x, $xa, $xb);
23702 $ymin = min($ymin, $y, $ya, $yb);
23703 $xmax = max($xmax, $x, $xa, $xb);
23704 $ymax = max($ymax, $y, $ya, $yb);
23713 case 'T': { // shorthand/smooth quadratic Bezier curveto
23714 foreach ($params as $ck => $cp) {
23715 $params[$ck] = $cp;
23716 if (($ck %
2) != 0) {
23717 if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
23718 $x1 = (2 * $x) - $x1;
23719 $y1 = (2 * $y) - $y1;
23724 // convert quadratic points to cubic points
23725 $xa = ($x +
(2 * $x1)) / 3;
23726 $ya = ($y +
(2 * $y1)) / 3;
23727 $x = $params[($ck - 1)] +
$xoffset;
23728 $y = $params[($ck)] +
$yoffset;
23729 $xb = ($x +
(2 * $x1)) / 3;
23730 $yb = ($y +
(2 * $y1)) / 3;
23731 $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
23732 $xmin = min($xmin, $x, $xa, $xb);
23733 $ymin = min($ymin, $y, $ya, $yb);
23734 $xmax = max($xmax, $x, $xa, $xb);
23735 $ymax = max($ymax, $y, $ya, $yb);
23744 case 'A': { // elliptical arc
23745 foreach ($params as $ck => $cp) {
23746 $params[$ck] = $cp;
23747 if ((($ck +
1) %
7) == 0) {
23750 $rx = max(abs($params[($ck - 6)]), .000000001);
23751 $ry = max(abs($params[($ck - 5)]), .000000001);
23752 $ang = -$rawparams[($ck - 4)];
23753 $angle = deg2rad($ang);
23754 $fa = $rawparams[($ck - 3)]; // large-arc-flag
23755 $fs = $rawparams[($ck - 2)]; // sweep-flag
23756 $x = $params[($ck - 1)] +
$xoffset;
23757 $y = $params[$ck] +
$yoffset;
23758 if ((abs($x0 - $x) < $minlen) AND (abs($y0 - $y) < $minlen)) {
23759 // endpoints are almost identical
23760 $xmin = min($xmin, $x);
23761 $ymin = min($ymin, $y);
23762 $xmax = max($xmax, $x);
23763 $ymax = max($ymax, $y);
23765 $cos_ang = cos($angle);
23766 $sin_ang = sin($angle);
23767 $a = (($x0 - $x) / 2);
23768 $b = (($y0 - $y) / 2);
23769 $xa = ($a * $cos_ang) - ($b * $sin_ang);
23770 $ya = ($a * $sin_ang) +
($b * $cos_ang);
23775 $delta = ($xa2 / $rx2) +
($ya2 / $ry2);
23777 $rx *= sqrt($delta);
23778 $ry *= sqrt($delta);
23782 $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
23783 if ($numerator < 0) {
23786 $root = sqrt($numerator / (($rx2 * $ya2) +
($ry2 * $xa2)));
23791 $cax = $root * (($rx * $ya) / $ry);
23792 $cay = -$root * (($ry * $xa) / $rx);
23793 // coordinates of ellipse center
23794 $cx = ($cax * $cos_ang) - ($cay * $sin_ang) +
(($x0 +
$x) / 2);
23795 $cy = ($cax * $sin_ang) +
($cay * $cos_ang) +
(($y0 +
$y) / 2);
23797 $angs = TCPDF_STATIC
::getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
23798 $dang = TCPDF_STATIC
::getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
23799 if (($fs == 0) AND ($dang > 0)) {
23800 $dang -= (2 * M_PI
);
23801 } elseif (($fs == 1) AND ($dang < 0)) {
23802 $dang +
= (2 * M_PI
);
23804 $angf = $angs - $dang;
23805 if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
23811 $angs = round(rad2deg($angs), 6);
23812 $angf = round(rad2deg($angf), 6);
23813 // covent angles to positive values
23814 if (($angs < 0) AND ($angf < 0)) {
23819 if (($key == 0) AND (isset($paths[($key +
1)][1])) AND (trim($paths[($key +
1)][1]) == 'z')) {
23822 list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0), true);
23823 $xmin = min($xmin, $x, $axmin);
23824 $ymin = min($ymin, $y, $aymin);
23825 $xmax = max($xmax, $x, $axmax);
23826 $ymax = max($ymax, $y, $aymax);
23838 $x = $x0 = $xinitial;
23839 $y = $y0 = $yinitial;
23848 return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
23852 * Return the tag name without the namespace
23853 * @param $name (string) Tag name
23856 protected function removeTagNamespace($name) {
23857 if(strpos($name, ':') !== false) {
23858 $parts = explode(':', $name);
23859 return $parts[(sizeof($parts) - 1)];
23865 * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
23866 * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
23867 * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
23868 * @param $attribs (array) The third parameter, attribs, contains an associative array with the element's attributes (if any). The keys of this array are the attribute names, the values are the attribute values. Attribute names are case-folded on the same criteria as element names. Attribute values are not case-folded. The original order of the attributes can be retrieved by walking through attribs the normal way, using each(). The first key in the array was the first attribute, and so on.
23869 * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
23870 * @author Nicola Asuni
23871 * @since 5.0.000 (2010-05-02)
23874 protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
23875 $name = $this->removeTagNamespace($name);
23876 // check if we are in clip mode
23877 if ($this->svgclipmode
) {
23878 $this->svgclippaths
[$this->svgclipid
][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm
[$this->svgclipid
]);
23881 if ($this->svgdefsmode
AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
23882 if (isset($attribs['id'])) {
23883 $attribs['child_elements'] = array();
23884 $this->svgdefs
[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
23887 if (end($this->svgdefs
) !== FALSE) {
23888 $last_svgdefs_id = key($this->svgdefs
);
23889 if (isset($this->svgdefs
[$last_svgdefs_id]['attribs']['child_elements'])) {
23890 $attribs['id'] = 'DF_'.(count($this->svgdefs
[$last_svgdefs_id]['attribs']['child_elements']) +
1);
23891 $this->svgdefs
[$last_svgdefs_id]['attribs']['child_elements'][$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
23898 if ($parser == 'clip-path') {
23899 // set clipping mode
23902 // get styling properties
23903 $prev_svgstyle = $this->svgstyles
[max(0,(count($this->svgstyles
) - 1))]; // previous style
23904 $svgstyle = $this->svgstyles
[0]; // set default style
23905 if ($clipping AND !isset($attribs['fill']) AND (!isset($attribs['style']) OR (!preg_match('/[;\"\s]{1}fill[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval)))) {
23906 // default fill attribute for clipping
23907 $attribs['fill'] = 'none';
23909 if (isset($attribs['style']) AND !TCPDF_STATIC
::empty_string($attribs['style']) AND ($attribs['style'][0] != ';')) {
23910 // fix style for regular expression
23911 $attribs['style'] = ';'.$attribs['style'];
23913 foreach ($prev_svgstyle as $key => $val) {
23914 if (in_array($key, TCPDF_IMAGES
::$svginheritprop)) {
23915 // inherit previous value
23916 $svgstyle[$key] = $val;
23918 if (isset($attribs[$key]) AND !TCPDF_STATIC
::empty_string($attribs[$key])) {
23919 // specific attribute settings
23920 if ($attribs[$key] == 'inherit') {
23921 $svgstyle[$key] = $val;
23923 $svgstyle[$key] = $attribs[$key];
23925 } elseif (isset($attribs['style']) AND !TCPDF_STATIC
::empty_string($attribs['style'])) {
23926 // CSS style syntax
23927 $attrval = array();
23928 if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
23929 if ($attrval[1] == 'inherit') {
23930 $svgstyle[$key] = $val;
23932 $svgstyle[$key] = $attrval[1];
23937 // transformation matrix
23938 if (!empty($ctm)) {
23941 $tm = array(1,0,0,1,0,0);
23943 if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
23944 $tm = TCPDF_STATIC
::getTransformationMatrixProduct($tm, TCPDF_STATIC
::getSVGTransformMatrix($attribs['transform']));
23946 $svgstyle['transfmatrix'] = $tm;
23947 $invisible = false;
23948 if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
23949 // the current graphics element is invisible (nothing is painted)
23955 $this->svgdefsmode
= true;
23963 $this->svgclipmode
= true;
23964 if (!isset($attribs['id'])) {
23965 $attribs['id'] = 'CP_'.(count($this->svgcliptm
) +
1);
23967 $this->svgclipid
= $attribs['id'];
23968 $this->svgclippaths
[$this->svgclipid
] = array();
23969 $this->svgcliptm
[$this->svgclipid
] = $tm;
23973 // start of SVG object
23974 if(++
$this->svg_tag_depth
<= 1) {
23978 array_push($this->svgstyles
, $svgstyle);
23979 $this->StartTransform();
23980 $svgX = (isset($attribs['x'])?
$attribs['x']:0);
23981 $svgY = (isset($attribs['y'])?
$attribs['y']:0);
23982 $svgW = (isset($attribs['width'])?
$attribs['width']:0);
23983 $svgH = (isset($attribs['height'])?
$attribs['height']:0);
23984 // set x, y position using transform matrix
23985 $tm = TCPDF_STATIC
::getTransformationMatrixProduct($tm, array( 1, 0, 0, 1, $svgX, $svgY));
23986 $this->SVGTransform($tm);
23987 // set clipping for width and height
23990 $w = (isset($attribs['width'])?
$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit
, false):$this->w
);
23991 $h = (isset($attribs['height'])?
$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit
, false):$this->h
);
23992 // draw clipping rect
23993 $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
23994 // parse viewbox, calculate extra transformation matrix
23995 if (isset($attribs['viewBox'])) {
23997 preg_match_all("/[0-9]+/", $attribs['viewBox'], $tmp);
23999 if (sizeof($tmp) == 4) {
24004 // get aspect ratio
24009 if (isset($attribs['preserveAspectRatio'])) {
24010 if($attribs['preserveAspectRatio'] == 'none') {
24013 preg_match_all('/[a-zA-Z]+/', $attribs['preserveAspectRatio'], $tmp);
24015 if ((sizeof($tmp) == 2) AND (strlen($tmp[0]) == 8) AND (in_array($tmp[1], array('meet', 'slice', 'none')))) {
24016 $aspectX = substr($tmp[0], 0, 4);
24017 $aspectY = substr($tmp[0], 4, 4);
24022 $wr = ($svgW / $vw);
24023 $hr = ($svgH / $vh);
24025 if ((($fit == 'meet') AND ($hr < $wr)) OR (($fit == 'slice') AND ($hr > $wr))) {
24026 if ($aspectX == 'xMax') {
24027 $ax = (($vw * ($wr / $hr)) - $vw);
24029 if ($aspectX == 'xMid') {
24030 $ax = ((($vw * ($wr / $hr)) - $vw) / 2);
24033 } elseif ((($fit == 'meet') AND ($hr > $wr)) OR (($fit == 'slice') AND ($hr < $wr))) {
24034 if ($aspectY == 'YMax') {
24035 $ay = (($vh * ($hr / $wr)) - $vh);
24037 if ($aspectY == 'YMid') {
24038 $ay = ((($vh * ($hr / $wr)) - $vh) / 2);
24042 $newtm = array($wr, 0, 0, $hr, (($wr * ($ax - $vx)) - $svgX), (($hr * ($ay - $vy)) - $svgY));
24043 $tm = TCPDF_STATIC
::getTransformationMatrixProduct($tm, $newtm);
24044 $this->SVGTransform($tm);
24047 $this->setSVGStyles($svgstyle, $prev_svgstyle);
24051 // group together related graphics elements
24052 array_push($this->svgstyles
, $svgstyle);
24053 $this->StartTransform();
24054 $x = (isset($attribs['x'])?
$attribs['x']:0);
24055 $y = (isset($attribs['y'])?
$attribs['y']:0);
24056 $w = 1;//(isset($attribs['width'])?$attribs['width']:1);
24057 $h = 1;//(isset($attribs['height'])?$attribs['height']:1);
24058 $tm = TCPDF_STATIC
::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
24059 $this->SVGTransform($tm);
24060 $this->setSVGStyles($svgstyle, $prev_svgstyle);
24063 case 'linearGradient': {
24064 if ($this->pdfa_mode
) {
24067 if (!isset($attribs['id'])) {
24068 $attribs['id'] = 'GR_'.(count($this->svggradients
) +
1);
24070 $this->svggradientid
= $attribs['id'];
24071 $this->svggradients
[$this->svggradientid
] = array();
24072 $this->svggradients
[$this->svggradientid
]['type'] = 2;
24073 $this->svggradients
[$this->svggradientid
]['stops'] = array();
24074 if (isset($attribs['gradientUnits'])) {
24075 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = $attribs['gradientUnits'];
24077 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = 'objectBoundingBox';
24079 //$attribs['spreadMethod']
24080 if (((!isset($attribs['x1'])) AND (!isset($attribs['y1'])) AND (!isset($attribs['x2'])) AND (!isset($attribs['y2'])))
24081 OR ((isset($attribs['x1']) AND (substr($attribs['x1'], -1) == '%'))
24082 OR (isset($attribs['y1']) AND (substr($attribs['y1'], -1) == '%'))
24083 OR (isset($attribs['x2']) AND (substr($attribs['x2'], -1) == '%'))
24084 OR (isset($attribs['y2']) AND (substr($attribs['y2'], -1) == '%')))) {
24085 $this->svggradients
[$this->svggradientid
]['mode'] = 'percentage';
24087 $this->svggradients
[$this->svggradientid
]['mode'] = 'measure';
24089 $x1 = (isset($attribs['x1'])?
$attribs['x1']:'0');
24090 $y1 = (isset($attribs['y1'])?
$attribs['y1']:'0');
24091 $x2 = (isset($attribs['x2'])?
$attribs['x2']:'100');
24092 $y2 = (isset($attribs['y2'])?
$attribs['y2']:'0');
24093 if (isset($attribs['gradientTransform'])) {
24094 $this->svggradients
[$this->svggradientid
]['gradientTransform'] = TCPDF_STATIC
::getSVGTransformMatrix($attribs['gradientTransform']);
24096 $this->svggradients
[$this->svggradientid
]['coords'] = array($x1, $y1, $x2, $y2);
24097 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
24098 // gradient is defined on another place
24099 $this->svggradients
[$this->svggradientid
]['xref'] = substr($attribs['xlink:href'], 1);
24103 case 'radialGradient': {
24104 if ($this->pdfa_mode
) {
24107 if (!isset($attribs['id'])) {
24108 $attribs['id'] = 'GR_'.(count($this->svggradients
) +
1);
24110 $this->svggradientid
= $attribs['id'];
24111 $this->svggradients
[$this->svggradientid
] = array();
24112 $this->svggradients
[$this->svggradientid
]['type'] = 3;
24113 $this->svggradients
[$this->svggradientid
]['stops'] = array();
24114 if (isset($attribs['gradientUnits'])) {
24115 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = $attribs['gradientUnits'];
24117 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = 'objectBoundingBox';
24119 //$attribs['spreadMethod']
24120 if (((!isset($attribs['cx'])) AND (!isset($attribs['cy'])))
24121 OR ((isset($attribs['cx']) AND (substr($attribs['cx'], -1) == '%'))
24122 OR (isset($attribs['cy']) AND (substr($attribs['cy'], -1) == '%')))) {
24123 $this->svggradients
[$this->svggradientid
]['mode'] = 'percentage';
24124 } elseif (isset($attribs['r']) AND is_numeric($attribs['r']) AND ($attribs['r']) <= 1) {
24125 $this->svggradients
[$this->svggradientid
]['mode'] = 'ratio';
24127 $this->svggradients
[$this->svggradientid
]['mode'] = 'measure';
24129 $cx = (isset($attribs['cx']) ?
$attribs['cx'] : 0.5);
24130 $cy = (isset($attribs['cy']) ?
$attribs['cy'] : 0.5);
24131 $fx = (isset($attribs['fx']) ?
$attribs['fx'] : $cx);
24132 $fy = (isset($attribs['fy']) ?
$attribs['fy'] : $cy);
24133 $r = (isset($attribs['r']) ?
$attribs['r'] : 0.5);
24134 if (isset($attribs['gradientTransform'])) {
24135 $this->svggradients
[$this->svggradientid
]['gradientTransform'] = TCPDF_STATIC
::getSVGTransformMatrix($attribs['gradientTransform']);
24137 $this->svggradients
[$this->svggradientid
]['coords'] = array($cx, $cy, $fx, $fy, $r);
24138 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
24139 // gradient is defined on another place
24140 $this->svggradients
[$this->svggradientid
]['xref'] = substr($attribs['xlink:href'], 1);
24146 if (substr($attribs['offset'], -1) == '%') {
24147 $offset = floatval(substr($attribs['offset'], 0, -1)) / 100;
24149 $offset = floatval($attribs['offset']);
24154 $stop_color = isset($svgstyle['stop-color'])?TCPDF_COLORS
::convertHTMLColorToDec($svgstyle['stop-color'], $this->spot_colors
):'black';
24155 $opacity = isset($svgstyle['stop-opacity'])?
$svgstyle['stop-opacity']:1;
24156 $this->svggradients
[$this->svggradientid
]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
24164 if (isset($attribs['d'])) {
24165 $d = trim($attribs['d']);
24167 $x = (isset($attribs['x'])?
$attribs['x']:0);
24168 $y = (isset($attribs['y'])?
$attribs['y']:0);
24169 $w = (isset($attribs['width'])?
$attribs['width']:1);
24170 $h = (isset($attribs['height'])?
$attribs['height']:1);
24171 $tm = TCPDF_STATIC
::getTransformationMatrixProduct($tm, array($w, 0, 0, $h, $x, $y));
24173 $this->SVGTransform($tm);
24174 $this->SVGPath($d, 'CNZ');
24176 $this->StartTransform();
24177 $this->SVGTransform($tm);
24178 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'SVGPath', array($d, 'CNZ'));
24179 if (!empty($obstyle)) {
24180 $this->SVGPath($d, $obstyle);
24182 $this->StopTransform();
24193 $x = (isset($attribs['x'])?
$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false):0);
24194 $y = (isset($attribs['y'])?
$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false):0);
24195 $w = (isset($attribs['width'])?
$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit
, false):0);
24196 $h = (isset($attribs['height'])?
$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit
, false):0);
24197 $rx = (isset($attribs['rx'])?
$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit
, false):0);
24198 $ry = (isset($attribs['ry'])?
$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit
, false):$rx);
24200 $this->SVGTransform($tm);
24201 $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
24203 $this->StartTransform();
24204 $this->SVGTransform($tm);
24205 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
24206 if (!empty($obstyle)) {
24207 $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
24209 $this->StopTransform();
24217 $r = (isset($attribs['r']) ?
$this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit
, false) : 0);
24218 $cx = (isset($attribs['cx']) ?
$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit
, false) : (isset($attribs['x']) ?
$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false) : 0));
24219 $cy = (isset($attribs['cy']) ?
$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit
, false) : (isset($attribs['y']) ?
$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false) : 0));
24225 $this->SVGTransform($tm);
24226 $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
24228 $this->StartTransform();
24229 $this->SVGTransform($tm);
24230 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
24231 if (!empty($obstyle)) {
24232 $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
24234 $this->StopTransform();
24242 $rx = (isset($attribs['rx']) ?
$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit
, false) : 0);
24243 $ry = (isset($attribs['ry']) ?
$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit
, false) : 0);
24244 $cx = (isset($attribs['cx']) ?
$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit
, false) : (isset($attribs['x']) ?
$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false) : 0));
24245 $cy = (isset($attribs['cy']) ?
$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit
, false) : (isset($attribs['y']) ?
$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false) : 0));
24251 $this->SVGTransform($tm);
24252 $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
24254 $this->StartTransform();
24255 $this->SVGTransform($tm);
24256 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
24257 if (!empty($obstyle)) {
24258 $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
24260 $this->StopTransform();
24268 $x1 = (isset($attribs['x1'])?
$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit
, false):0);
24269 $y1 = (isset($attribs['y1'])?
$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit
, false):0);
24270 $x2 = (isset($attribs['x2'])?
$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit
, false):0);
24271 $y2 = (isset($attribs['y2'])?
$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit
, false):0);
24274 $w = abs($x2 - $x1);
24275 $h = abs($y2 - $y1);
24277 $this->StartTransform();
24278 $this->SVGTransform($tm);
24279 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
24280 $this->Line($x1, $y1, $x2, $y2);
24281 $this->StopTransform();
24290 $points = (isset($attribs['points'])?
$attribs['points']:'0 0');
24291 $points = trim($points);
24292 // note that point may use a complex syntax not covered here
24293 $points = preg_split('/[\,\s]+/si', $points);
24294 if (count($points) < 4) {
24298 $xmin = 2147483647;
24300 $ymin = 2147483647;
24302 foreach ($points as $key => $val) {
24303 $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit
, false);
24304 if (($key %
2) == 0) {
24306 $xmin = min($xmin, $p[$key]);
24307 $xmax = max($xmax, $p[$key]);
24310 $ymin = min($ymin, $p[$key]);
24311 $ymax = max($ymax, $p[$key]);
24316 $w = ($xmax - $xmin);
24317 $h = ($ymax - $ymin);
24318 if ($name == 'polyline') {
24319 $this->StartTransform();
24320 $this->SVGTransform($tm);
24321 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
24322 if (!empty($obstyle)) {
24323 $this->PolyLine($p, $obstyle, array(), array());
24325 $this->StopTransform();
24326 } else { // polygon
24328 $this->SVGTransform($tm);
24329 $this->Polygon($p, 'CNZ', array(), array(), true);
24331 $this->StartTransform();
24332 $this->SVGTransform($tm);
24333 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
24334 if (!empty($obstyle)) {
24335 $this->Polygon($p, $obstyle, array(), array(), true);
24337 $this->StopTransform();
24347 if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
24350 $x = (isset($attribs['x'])?
$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false):0);
24351 $y = (isset($attribs['y'])?
$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false):0);
24352 $w = (isset($attribs['width'])?
$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit
, false):0);
24353 $h = (isset($attribs['height'])?
$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit
, false):0);
24354 $img = $attribs['xlink:href'];
24356 $this->StartTransform();
24357 $this->SVGTransform($tm);
24358 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
24359 if (preg_match('/^data:image\/[^;]+;base64,/', $img, $m) > 0) {
24360 // embedded image encoded as base64
24361 $img = '@'.base64_decode(substr($img, strlen($m[0])));
24364 if (!TCPDF_STATIC
::empty_string($this->svgdir
) AND (($img[0] == '.') OR (basename($img) == $img))) {
24365 // replace relative path with full server path
24366 $img = $this->svgdir
.'/'.$img;
24368 if (($img[0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
24369 $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
24370 if (($findroot === false) OR ($findroot > 1)) {
24371 if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
24372 $img = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$img;
24374 $img = $_SERVER['DOCUMENT_ROOT'].$img;
24378 $img = urldecode($img);
24379 $testscrtype = @parse_url
($img);
24380 if (empty($testscrtype['query'])) {
24381 // convert URL to server path
24382 $img = str_replace(K_PATH_URL
, K_PATH_MAIN
, $img);
24383 } elseif (preg_match('|^https?://|', $img) !== 1) {
24384 // convert server path to URL
24385 $img = str_replace(K_PATH_MAIN
, K_PATH_URL
, $img);
24389 $imgtype = TCPDF_IMAGES
::getImageFileType($img);
24390 if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
24391 $this->ImageEps($img, $x, $y, $w, $h);
24392 } elseif ($imgtype == 'svg') {
24394 $svggradients = $this->svggradients
;
24395 $svggradientid = $this->svggradientid
;
24396 $svgdefsmode = $this->svgdefsmode
;
24397 $svgdefs = $this->svgdefs
;
24398 $svgclipmode = $this->svgclipmode
;
24399 $svgclippaths = $this->svgclippaths
;
24400 $svgcliptm = $this->svgcliptm
;
24401 $svgclipid = $this->svgclipid
;
24402 $svgtext = $this->svgtext
;
24403 $svgtextmode = $this->svgtextmode
;
24404 $this->ImageSVG($img, $x, $y, $w, $h);
24405 // restore SVG vars
24406 $this->svggradients
= $svggradients;
24407 $this->svggradientid
= $svggradientid;
24408 $this->svgdefsmode
= $svgdefsmode;
24409 $this->svgdefs
= $svgdefs;
24410 $this->svgclipmode
= $svgclipmode;
24411 $this->svgclippaths
= $svgclippaths;
24412 $this->svgcliptm
= $svgcliptm;
24413 $this->svgclipid
= $svgclipid;
24414 $this->svgtext
= $svgtext;
24415 $this->svgtextmode
= $svgtextmode;
24417 $this->Image($img, $x, $y, $w, $h);
24419 $this->StopTransform();
24426 if (isset($this->svgtextmode
['text-anchor']) AND !empty($this->svgtext
)) {
24427 // @TODO: unsupported feature
24429 // only basic support - advanced features must be implemented
24430 $this->svgtextmode
['invisible'] = $invisible;
24434 array_push($this->svgstyles
, $svgstyle);
24435 if (isset($attribs['x'])) {
24436 $x = $this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false);
24437 } elseif ($name == 'tspan') {
24442 if (isset($attribs['dx'])) {
24443 $x +
= $this->getHTMLUnitToUnits($attribs['dx'], 0, $this->svgunit
, false);
24445 if (isset($attribs['y'])) {
24446 $y = $this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false);
24447 } elseif ($name == 'tspan') {
24452 if (isset($attribs['dy'])) {
24453 $y +
= $this->getHTMLUnitToUnits($attribs['dy'], 0, $this->svgunit
, false);
24455 $svgstyle['text-color'] = $svgstyle['fill'];
24456 $this->svgtext
= '';
24457 if (isset($svgstyle['text-anchor'])) {
24458 $this->svgtextmode
['text-anchor'] = $svgstyle['text-anchor'];
24460 $this->svgtextmode
['text-anchor'] = 'start';
24462 if (isset($svgstyle['direction'])) {
24463 if ($svgstyle['direction'] == 'rtl') {
24464 $this->svgtextmode
['rtl'] = true;
24466 $this->svgtextmode
['rtl'] = false;
24469 $this->svgtextmode
['rtl'] = false;
24471 if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
24472 $this->svgtextmode
['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit
, false);
24474 $this->svgtextmode
['stroke'] = false;
24476 $this->StartTransform();
24477 $this->SVGTransform($tm);
24478 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
24485 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
24486 $svgdefid = substr($attribs['xlink:href'], 1);
24487 if (isset($this->svgdefs
[$svgdefid])) {
24488 $use = $this->svgdefs
[$svgdefid];
24489 if (isset($attribs['xlink:href'])) {
24490 unset($attribs['xlink:href']);
24492 if (isset($attribs['id'])) {
24493 unset($attribs['id']);
24495 if (isset($use['attribs']['x']) AND isset($attribs['x'])) {
24496 $attribs['x'] +
= $use['attribs']['x'];
24498 if (isset($use['attribs']['y']) AND isset($attribs['y'])) {
24499 $attribs['y'] +
= $use['attribs']['y'];
24501 if (empty($attribs['style'])) {
24502 $attribs['style'] = '';
24504 if (!empty($use['attribs']['style'])) {
24506 $attribs['style'] = str_replace(';;',';',';'.$use['attribs']['style'].$attribs['style']);
24508 $attribs = array_merge($use['attribs'], $attribs);
24509 $this->startSVGElementHandler($parser, $use['name'], $attribs);
24519 // process child elements
24520 if (!empty($attribs['child_elements'])) {
24521 $child_elements = $attribs['child_elements'];
24522 unset($attribs['child_elements']);
24523 foreach($child_elements as $child_element) {
24524 if (empty($child_element['attribs']['closing_tag'])) {
24525 $this->startSVGElementHandler('child-tag', $child_element['name'], $child_element['attribs']);
24527 if (isset($child_element['attribs']['content'])) {
24528 $this->svgtext
= $child_element['attribs']['content'];
24530 $this->endSVGElementHandler('child-tag', $child_element['name']);
24537 * Sets the closing SVG element handler function for the XML parser.
24538 * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
24539 * @param $name (string) The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters.
24540 * @author Nicola Asuni
24541 * @since 5.0.000 (2010-05-02)
24544 protected function endSVGElementHandler($parser, $name) {
24545 $name = $this->removeTagNamespace($name);
24546 if ($this->svgdefsmode
AND !in_array($name, array('defs', 'clipPath', 'linearGradient', 'radialGradient', 'stop'))) {;
24547 if (end($this->svgdefs
) !== FALSE) {
24548 $last_svgdefs_id = key($this->svgdefs
);
24549 if (isset($this->svgdefs
[$last_svgdefs_id]['attribs']['child_elements'])) {
24550 foreach($this->svgdefs
[$last_svgdefs_id]['attribs']['child_elements'] as $child_element) {
24551 if (isset($child_element['attribs']['id']) AND ($child_element['name'] == $name)) {
24552 $this->svgdefs
[$last_svgdefs_id]['attribs']['child_elements'][$child_element['attribs']['id'].'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext
));
24556 if ($this->svgdefs
[$last_svgdefs_id]['name'] == $name) {
24557 $this->svgdefs
[$last_svgdefs_id]['attribs']['child_elements'][$last_svgdefs_id.'_CLOSE'] = array('name' => $name, 'attribs' => array('closing_tag' => TRUE, 'content' => $this->svgtext
));
24566 $this->svgdefsmode
= false;
24571 $this->svgclipmode
= false;
24575 if (--$this->svg_tag_depth
<= 0) {
24580 // ungroup: remove last style from array
24581 array_pop($this->svgstyles
);
24582 $this->StopTransform();
24587 if ($this->svgtextmode
['invisible']) {
24588 // This implementation must be fixed to following the rule:
24589 // If the 'visibility' property is set to hidden on a 'tspan', 'tref' or 'altGlyph' element, then the text is invisible but still takes up space in text layout calculations.
24593 $text = $this->svgtext
;
24594 //$text = $this->stringTrim($text);
24595 $textlen = $this->GetStringWidth($text);
24596 if ($this->svgtextmode
['text-anchor'] != 'start') {
24597 // check if string is RTL text
24598 if ($this->svgtextmode
['text-anchor'] == 'end') {
24599 if ($this->svgtextmode
['rtl']) {
24600 $this->x +
= $textlen;
24602 $this->x
-= $textlen;
24604 } elseif ($this->svgtextmode
['text-anchor'] == 'middle') {
24605 if ($this->svgtextmode
['rtl']) {
24606 $this->x +
= ($textlen / 2);
24608 $this->x
-= ($textlen / 2);
24612 $textrendermode = $this->textrendermode
;
24613 $textstrokewidth = $this->textstrokewidth
;
24614 $this->setTextRenderingMode($this->svgtextmode
['stroke'], true, false);
24615 if ($name == 'text') {
24616 // store current coordinates
24621 $this->Cell($textlen, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
24622 if ($name == 'text') {
24623 // restore coordinates
24627 // restore previous rendering mode
24628 $this->textrendermode
= $textrendermode;
24629 $this->textstrokewidth
= $textstrokewidth;
24630 $this->svgtext
= '';
24631 $this->StopTransform();
24632 if (!$this->svgdefsmode
) {
24633 array_pop($this->svgstyles
);
24644 * Sets the character data handler function for the XML parser.
24645 * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
24646 * @param $data (string) The second parameter, data, contains the character data as a string.
24647 * @author Nicola Asuni
24648 * @since 5.0.000 (2010-05-02)
24651 protected function segSVGContentHandler($parser, $data) {
24652 $this->svgtext
.= $data;
24655 // --- END SVG METHODS -----------------------------------------------------
24658 * Keeps files in memory, so it doesn't need to downloaded everytime in a loop
24659 * @param string $file
24662 protected function getCachedFileContents($file)
24664 if (!isset($this->fileContentCache
[$file])) {
24665 $this->fileContentCache
[$file] = TCPDF_STATIC
::fileGetContents($file);
24667 return $this->fileContentCache
[$file];
24671 * Avoid multiple calls to an external server to see if a file exists
24672 * @param string $file
24675 protected function fileExists($file)
24677 if (isset($this->fileContentCache
[$file]) ||
false !== $this->getImageBuffer($file)) {
24681 return TCPDF_STATIC
::file_exists($file);
24684 } // END OF TCPDF CLASS
24686 //============================================================+
24688 //============================================================+