2 //============================================================+
3 // File name : tcpdf.php
6 // Last Update : 2011-01-12
7 // Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
8 // License : http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT GNU-LGPLv3 + YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE GENERATED PDF DOCUMENTS.
9 // -------------------------------------------------------------------
10 // Copyright (C) 2002-2011 Nicola Asuni - Tecnick.com S.r.l.
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. Additionally,
18 // YOU CAN'T REMOVE ANY TCPDF COPYRIGHT NOTICE OR LINK FROM THE
19 // GENERATED PDF DOCUMENTS.
21 // TCPDF is distributed in the hope that it will be useful, but
22 // WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 // See the GNU Lesser General Public License for more details.
26 // You should have received a copy of the License
27 // along with TCPDF. If not, see
28 // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
30 // See LICENSE.TXT file for more information.
31 // -------------------------------------------------------------------
33 // Description : This is a PHP class for generating PDF documents without
34 // requiring external extensions.
37 // This class was originally derived in 2002 from the Public
38 // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
39 // but now is almost entirely rewritten and contains thousands of
40 // new lines of code and hundreds new features.
43 // * no external libraries are required for the basic functions;
44 // * all standard page formats, custom page formats, custom margins and units of measure;
45 // * UTF-8 Unicode and Right-To-Left languages;
46 // * TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
48 // * methods to publish some XHTML + CSS code, Javascript and Forms;
49 // * images, graphic (geometric figures) and transformation methods;
50 // * 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 ImagMagick (http://www.imagemagick.org/www/formats.html)
51 // * 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 Extention, 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, QR-Code, PDF417;
52 // * Grayscale, RGB, CMYK, Spot Colors and Transparencies;
53 // * automatic page header and footer management;
54 // * document encryption up to 256 bit and digital signature certifications;
55 // * transactions to UNDO commands;
56 // * PDF annotations, including links, text and file attachments;
57 // * text rendering modes (fill, stroke and clipping);
58 // * multiple columns mode;
59 // * no-write page regions;
60 // * bookmarks and table of content;
61 // * text hyphenation;
62 // * text stretching and spacing (tracking/kerning);
63 // * automatic page break, line break and text alignments including justification;
64 // * automatic page numbering and page groups;
65 // * move and delete pages;
66 // * page compression (requires php-zlib extension);
67 // * XOBject Templates;
69 // -----------------------------------------------------------
72 // Olivier Plathey (http://www.fpdf.org) for original FPDF.
73 // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
74 // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
75 // Warren Sherliker (wsherliker@gmail.com) for better image handling.
76 // dullus for text Justification.
77 // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
78 // Patrick Benny for text stretch suggestion on Cell().
79 // Johannes Güntert for JavaScript support.
80 // Denis Van Nuffelen for Dynamic Form.
81 // Jacek Czekaj for multibyte justification
82 // Anthony Ferrara for the reintroduction of legacy image methods.
83 // Sourceforge user 1707880 (hucste) for line-trough mode.
84 // Larry Stanbery for page groups.
85 // Martin Hall-May for transparency.
86 // Aaron C. Spike for Polycurve method.
87 // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
88 // Moritz Wagner and Andreas Wurmser for graphic functions.
89 // Andrew Whitehead for core fonts support.
90 // Esteban Joël Marín for OpenType font conversion.
91 // Teus Hagen for several suggestions and fixes.
92 // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
93 // Kosmas Papachristos for some CSS improvements.
94 // Marcel Partap for some fixes.
95 // Won Kyu Park for several suggestions, fixes and patches.
96 // Dominik Dzienia for QR-code support.
97 // Laurent Minguet for some suggestions.
98 // Christian Deligant for some suggestions and fixes.
99 // Anyone that has reported a bug or sent a suggestion.
100 //============================================================+
104 * This is a PHP class for generating PDF documents without requiring external extensions.<br>
105 * 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>
106 * <h3>TCPDF main features are:</h3>
108 * <li>no external libraries are required for the basic functions;</li>
109 * <li>all standard page formats, custom page formats, custom margins and units of measure;</li>
110 * <li>UTF-8 Unicode and Right-To-Left languages;</li>
111 * <li>TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
112 * <li>font subsetting;</li>
113 * <li>methods to publish some XHTML + CSS code, Javascript and Forms;</li>
114 * <li>images, graphic (geometric figures) and transformation methods;
115 * <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 ImagMagick (http://www.imagemagick.org/www/formats.html)</li>
116 * <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 Extention, 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, QR-Code, PDF417;</li>
117 * <li>Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
118 * <li>automatic page header and footer management;</li>
119 * <li>document encryption up to 256 bit and digital signature certifications;</li>
120 * <li>transactions to UNDO commands;</li>
121 * <li>PDF annotations, including links, text and file attachments;</li>
122 * <li>text rendering modes (fill, stroke and clipping);</li>
123 * <li>multiple columns mode;</li>
124 * <li>no-write page regions;</li>
125 * <li>bookmarks and table of content;</li>
126 * <li>text hyphenation;</li>
127 * <li>text stretching and spacing (tracking/kerning);</li>
128 * <li>automatic page break, line break and text alignments including justification;</li>
129 * <li>automatic page numbering and page groups;</li>
130 * <li>move and delete pages;</li>
131 * <li>page compression (requires php-zlib extension);</li>
132 * <li>XOBject Templates;</li>
134 * Tools to encode your unicode fonts are on fonts/utils directory.</p>
135 * @package com.tecnick.tcpdf
136 * @author Nicola Asuni
140 // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file.
141 require_once(dirname(__FILE__
).'/config/tcpdf_config.php');
145 * PHP class for generating PDF documents without requiring external extensions.
146 * 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>
147 * @package com.tecnick.tcpdf
148 * @brief PHP class for generating PDF documents without requiring external extensions.
150 * @author Nicola Asuni - info@tecnick.com
154 // private properties
157 * Current TCPDF version.
160 private $tcpdf_version = '5.9.039';
162 // Protected properties
165 * Current page number.
171 * Current object number.
177 * Array of object offsets.
183 * Buffer holding in-memory PDF.
189 * Array containing pages.
192 protected $pages = array();
195 * Current document state.
207 * Current page orientation (P = Portrait, L = Landscape).
210 protected $CurOrientation;
216 protected $pagedim = array();
219 * Scale factor (number of points in user unit).
225 * Width of page format in points.
231 * Height of page format in points.
237 * Current width of page in points.
243 * Current height of page in points.
249 * Current width of page in user unit.
255 * Current height of page in user unit.
285 * Array of cell internal paddings ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
286 * @since 5.9.000 (2010-10-03)
289 protected $cell_padding = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
292 * Array of cell margins ('T' => top, 'R' => right, 'B' => bottom, 'L' => left).
293 * @since 5.9.000 (2010-10-04)
296 protected $cell_margin = array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0);
299 * Current horizontal position in user unit for cell positioning.
305 * Current vertical position in user unit for cell positioning.
311 * Height of last cell printed.
317 * Line width in user unit.
320 protected $LineWidth;
323 * Array of standard font names.
326 protected $CoreFonts;
329 * Array of used fonts.
332 protected $fonts = array();
335 * Array of font files.
338 protected $FontFiles = array();
341 * Array of encoding differences.
344 protected $diffs = array();
347 * Array of used images.
350 protected $images = array();
353 * Array of Annotations in pages.
356 protected $PageAnnots = array();
359 * Array of internal links.
362 protected $links = array();
365 * Current font family.
368 protected $FontFamily;
371 * Current font style.
374 protected $FontStyle;
377 * Current font ascent (distance between font top and baseline).
379 * @since 2.8.000 (2007-03-29)
381 protected $FontAscent;
384 * Current font descent (distance between font bottom and baseline).
386 * @since 2.8.000 (2007-03-29)
388 protected $FontDescent;
394 protected $underline;
406 protected $CurrentFont;
409 * Current font size in points.
412 protected $FontSizePt;
415 * Current font size in user unit.
421 * Commands for drawing color.
424 protected $DrawColor;
427 * Commands for filling color.
430 protected $FillColor;
433 * Commands for text color.
436 protected $TextColor;
439 * Indicates whether fill and text colors are different.
442 protected $ColorFlag;
445 * Automatic page breaking.
448 protected $AutoPageBreak;
451 * Threshold used to trigger page breaks.
454 protected $PageBreakTrigger;
457 * Flag set when processing footer.
460 protected $InFooter = false;
469 * Layout display mode.
472 protected $LayoutMode;
475 * If true set the document information dictionary in Unicode.
478 protected $docinfounicode = true;
484 protected $title = '';
490 protected $subject = '';
496 protected $author = '';
502 protected $keywords = '';
508 protected $creator = '';
511 * String alias for total number of pages.
514 protected $AliasNbPages = '{nb}';
517 * String alias for page number.
520 protected $AliasNumPage = '{pnb}';
523 * The right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image.
525 * @author Nicola Asuni
531 * The right-bottom corner Y coordinate of last inserted image.
533 * @author Nicola Asuni
539 * Adjusting factor to convert pixels to user units.
541 * @author Nicola Asuni
544 protected $imgscale = 1;
547 * Boolean flag set to true when the input text is unicode (require unicode fonts).
549 * @author Nicola Asuni
552 protected $isunicode = false;
555 * Object containing unicode data.
556 * @since 5.9.004 (2010-10-18)
557 * @author Nicola Asuni
567 protected $PDFVersion = '1.7';
570 * Minimum distance between header and top page margin.
573 protected $header_margin;
576 * Minimum distance between footer and bottom page margin.
579 protected $footer_margin;
582 * Original left margin value.
584 * @since 1.53.0.TC013
586 protected $original_lMargin;
589 * Original right margin value.
591 * @since 1.53.0.TC013
593 protected $original_rMargin;
596 * Default font used on page header.
599 protected $header_font;
602 * Default font used on page footer.
605 protected $footer_font;
608 * Language templates.
614 * Barcode to print on page footer (only if set).
617 protected $barcode = false;
620 * Boolean flag to print/hide page header.
623 protected $print_header = true;
626 * Boolean flag to print/hide page footer.
629 protected $print_footer = true;
635 protected $header_logo = '';
638 * Width of header image logo in user units.
641 protected $header_logo_width = 30;
644 * Title to be printed on default page header.
647 protected $header_title = '';
650 * String to pring on page header after title.
653 protected $header_string = '';
656 * Default number of columns for html table.
659 protected $default_table_columns = 4;
661 // variables for html parser
664 * HTML PARSER: array to store current link and rendering styles.
667 protected $HREF = array();
670 * List of available fonts on filesystem.
673 protected $fontlist = array();
676 * Current foreground color.
682 * HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
685 protected $listordered = array();
688 * HTML PARSER: array count list items on nested lists.
691 protected $listcount = array();
694 * HTML PARSER: current list nesting level.
697 protected $listnum = 0;
700 * HTML PARSER: indent amount for lists.
703 protected $listindent = 0;
706 * HTML PARSER: current list indententation level.
709 protected $listindentlevel = 0;
712 * Current background color.
718 * Temporary font size in points.
721 protected $tempfontsize = 10;
724 * Spacer string for LI tags.
727 protected $lispacer = '';
732 * @since 1.53.0.TC010
734 protected $encoding = 'UTF-8';
737 * PHP internal encoding.
739 * @since 1.53.0.TC016
741 protected $internal_encoding;
744 * Boolean flag to indicate if the document language is Right-To-Left.
748 protected $rtl = false;
751 * Boolean flag used to force RTL or LTR string direction.
755 protected $tmprtl = false;
757 // --- Variables used for document encryption:
760 * IBoolean flag indicating whether document is protected.
762 * @since 2.0.000 (2008-01-02)
764 protected $encrypted;
767 * Array containing encryption settings.
769 * @since 5.0.005 (2010-05-11)
771 protected $encryptdata = array();
774 * Last RC4 key encrypted (cached for optimisation).
776 * @since 2.0.000 (2008-01-02)
778 protected $last_enc_key;
781 * Last RC4 computed key.
783 * @since 2.0.000 (2008-01-02)
785 protected $last_enc_key_c;
788 * Encryption padding string.
791 protected $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
794 * File ID (used on document trailer).
796 * @since 5.0.005 (2010-05-12)
803 * Outlines for bookmark.
805 * @since 2.1.002 (2008-02-12)
807 protected $outlines = array();
810 * Outline root for bookmark.
812 * @since 2.1.002 (2008-02-12)
814 protected $OutlineRoot;
816 // --- javascript and form ---
821 * @since 2.1.002 (2008-02-12)
823 protected $javascript = '';
826 * Javascript counter.
828 * @since 2.1.002 (2008-02-12)
835 * @since 2.8.000 (2008-03-19)
837 protected $linethrough;
840 * Array with additional document-wide usage rights for the document.
842 * @since 5.8.014 (2010-08-23)
844 protected $ur = array();
847 * DPI (Dot Per Inch) Document Resolution (do not change).
849 * @since 3.0.000 (2008-03-27)
854 * Array of page numbers were a new page group was started.
856 * @since 3.0.000 (2008-03-27)
858 protected $newpagegroup = array();
861 * Contains the number of pages of the groups.
863 * @since 3.0.000 (2008-03-27)
865 protected $pagegroups;
868 * Contains the alias of the current page group.
870 * @since 3.0.000 (2008-03-27)
872 protected $currpagegroup;
875 * Restrict the rendering of some elements to screen or printout.
877 * @since 3.0.000 (2008-03-27)
879 protected $visibility = 'all';
884 * @since 3.0.000 (2008-03-27)
886 protected $n_ocg_print;
891 * @since 3.0.000 (2008-03-27)
893 protected $n_ocg_view;
896 * Array of transparency objects and parameters.
898 * @since 3.0.000 (2008-03-27)
900 protected $extgstates;
903 * Set the default JPEG compression quality (1-100).
905 * @since 3.0.000 (2008-03-27)
907 protected $jpeg_quality;
910 * Default cell height ratio.
912 * @since 3.0.014 (2008-05-23)
914 protected $cell_height_ratio = K_CELL_HEIGHT_RATIO
;
917 * PDF viewer preferences.
919 * @since 3.1.000 (2008-06-09)
921 protected $viewer_preferences;
924 * A name object specifying how the document should be displayed when opened.
926 * @since 3.1.000 (2008-06-09)
931 * Array for storing gradient information.
933 * @since 3.1.000 (2008-06-09)
935 protected $gradients = array();
938 * Array used to store positions inside the pages buffer (keys are the page numbers).
940 * @since 3.2.000 (2008-06-26)
942 protected $intmrk = array();
945 * Array used to store positions inside the pages buffer (keys are the page numbers).
947 * @since 5.7.000 (2010-08-03)
949 protected $bordermrk = array();
952 * Array used to store page positions to track empty pages (keys are the page numbers).
954 * @since 5.8.007 (2010-08-18)
956 protected $emptypagemrk = array();
959 * Array used to store content positions inside the pages buffer (keys are the page numbers).
961 * @since 4.6.021 (2009-07-20)
963 protected $cntmrk = array();
966 * Array used to store footer positions of each page.
968 * @since 3.2.000 (2008-07-01)
970 protected $footerpos = array();
973 * Array used to store footer length of each page.
975 * @since 4.0.014 (2008-07-29)
977 protected $footerlen = array();
980 * Boolean flag to indicate if a new line is created.
982 * @since 3.2.000 (2008-07-01)
984 protected $newline = true;
987 * End position of the latest inserted line.
989 * @since 3.2.000 (2008-07-01)
991 protected $endlinex = 0;
994 * PDF string for width value of the last line.
996 * @since 4.0.006 (2008-07-16)
998 protected $linestyleWidth = '';
1001 * PDF string for CAP value of the last line.
1003 * @since 4.0.006 (2008-07-16)
1005 protected $linestyleCap = '0 J';
1008 * PDF string for join value of the last line.
1010 * @since 4.0.006 (2008-07-16)
1012 protected $linestyleJoin = '0 j';
1015 * PDF string for dash value of the last line.
1017 * @since 4.0.006 (2008-07-16)
1019 protected $linestyleDash = '[] 0 d';
1022 * Boolean flag to indicate if marked-content sequence is open.
1024 * @since 4.0.013 (2008-07-28)
1026 protected $openMarkedContent = false;
1029 * Count the latest inserted vertical spaces on HTML.
1031 * @since 4.0.021 (2008-08-24)
1033 protected $htmlvspace = 0;
1036 * Array of Spot colors.
1038 * @since 4.0.024 (2008-09-12)
1040 protected $spot_colors = array();
1043 * Symbol used for HTML unordered list items.
1045 * @since 4.0.028 (2008-09-26)
1047 protected $lisymbol = '';
1050 * String used to mark the beginning and end of EPS image blocks.
1052 * @since 4.1.000 (2008-10-18)
1054 protected $epsmarker = 'x#!#EPS#!#x';
1057 * Array of transformation matrix.
1059 * @since 4.2.000 (2008-10-29)
1061 protected $transfmatrix = array();
1064 * Current key for transformation matrix.
1066 * @since 4.8.005 (2009-09-17)
1068 protected $transfmatrix_key = 0;
1071 * Booklet mode for double-sided pages.
1073 * @since 4.2.000 (2008-10-29)
1075 protected $booklet = false;
1078 * Epsilon value used for float calculations.
1080 * @since 4.2.000 (2008-10-29)
1082 protected $feps = 0.005;
1085 * Array used for custom vertical spaces for HTML tags.
1087 * @since 4.2.001 (2008-10-30)
1089 protected $tagvspaces = array();
1092 * HTML PARSER: custom indent amount for lists. Negative value means disabled.
1094 * @since 4.2.007 (2008-11-12)
1096 protected $customlistindent = -1;
1099 * Boolean flag to indicate if the border of the cell sides that cross the page should be removed.
1101 * @since 4.2.010 (2008-11-14)
1103 protected $opencell = true;
1106 * Array of files to embedd.
1108 * @since 4.4.000 (2008-12-07)
1110 protected $embeddedfiles = array();
1113 * Boolean flag to indicate if we are inside a PRE tag.
1115 * @since 4.4.001 (2008-12-08)
1117 protected $premode = false;
1120 * Array used to store positions of graphics transformation blocks inside the page buffer.
1121 * keys are the page numbers
1123 * @since 4.4.002 (2008-12-09)
1125 protected $transfmrk = array();
1128 * Default color for html links.
1130 * @since 4.4.003 (2008-12-09)
1132 protected $htmlLinkColorArray = array(0, 0, 255);
1135 * Default font style to add to html links.
1137 * @since 4.4.003 (2008-12-09)
1139 protected $htmlLinkFontStyle = 'U';
1142 * Counts the number of pages.
1144 * @since 4.5.000 (2008-12-31)
1146 protected $numpages = 0;
1149 * Array containing page lengths in bytes.
1151 * @since 4.5.000 (2008-12-31)
1153 protected $pagelen = array();
1156 * Counts the number of pages.
1158 * @since 4.5.000 (2008-12-31)
1160 protected $numimages = 0;
1163 * Store the image keys.
1165 * @since 4.5.000 (2008-12-31)
1167 protected $imagekeys = array();
1170 * Length of the buffer in bytes.
1172 * @since 4.5.000 (2008-12-31)
1174 protected $bufferlen = 0;
1177 * If true enables disk caching.
1179 * @since 4.5.000 (2008-12-31)
1181 protected $diskcache = false;
1184 * Counts the number of fonts.
1186 * @since 4.5.000 (2009-01-02)
1188 protected $numfonts = 0;
1191 * Store the font keys.
1193 * @since 4.5.000 (2009-01-02)
1195 protected $fontkeys = array();
1198 * Store the font object IDs.
1200 * @since 4.8.001 (2009-09-09)
1202 protected $font_obj_ids = array();
1205 * Store the fage status (true when opened, false when closed).
1207 * @since 4.5.000 (2009-01-02)
1209 protected $pageopen = array();
1212 * Default monospace font.
1214 * @since 4.5.025 (2009-03-10)
1216 protected $default_monospaced_font = 'courier';
1219 * Cloned copy of the current class object.
1221 * @since 4.5.029 (2009-03-19)
1226 * Array used to store the lengths of cache files.
1228 * @since 4.5.029 (2009-03-19)
1230 protected $cache_file_length = array();
1233 * Table header content to be repeated on each new page.
1235 * @since 4.5.030 (2009-03-20)
1237 protected $thead = '';
1240 * Margins used for table header.
1242 * @since 4.5.030 (2009-03-20)
1244 protected $theadMargins = array();
1247 * Cache array for UTF8StringToArray() method.
1249 * @since 4.5.037 (2009-04-07)
1251 protected $cache_UTF8StringToArray = array();
1254 * Maximum size of cache array used for UTF8StringToArray() method.
1256 * @since 4.5.037 (2009-04-07)
1258 protected $cache_maxsize_UTF8StringToArray = 8;
1261 * Current size of cache array used for UTF8StringToArray() method.
1263 * @since 4.5.037 (2009-04-07)
1265 protected $cache_size_UTF8StringToArray = 0;
1268 * Boolean flag to enable document digital signature.
1270 * @since 4.6.005 (2009-04-24)
1272 protected $sign = false;
1275 * Digital signature data.
1277 * @since 4.6.005 (2009-04-24)
1279 protected $signature_data = array();
1282 * Digital signature max length.
1284 * @since 4.6.005 (2009-04-24)
1286 protected $signature_max_length = 11742;
1289 * Data for digital signature appearance.
1291 * @since 5.3.011 (2010-06-16)
1293 protected $signature_appearance = array('page' => 1, 'rect' => '0 0 0 0');
1296 * Regular expression used to find blank characters (required for word-wrapping).
1298 * @since 4.6.006 (2009-04-28)
1300 protected $re_spaces = '/[^\S\xa0]/';
1303 * Array of $re_spaces parts.
1305 * @since 5.5.011 (2010-07-09)
1307 protected $re_space = array('p' => '[^\S\xa0]', 'm' => '');
1310 * Digital signature object ID.
1312 * @since 4.6.022 (2009-06-23)
1314 protected $sig_obj_id = 0;
1317 * ByteRange placemark used during digital signature process.
1319 * @since 4.6.028 (2009-08-25)
1321 protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
1324 * Placemark used during digital signature process.
1326 * @since 4.6.028 (2009-08-25)
1328 protected $sig_annot_ref = '***SIGANNREF*** 0 R';
1331 * ID of page objects.
1333 * @since 4.7.000 (2009-08-29)
1335 protected $page_obj_id = array();
1338 * List of form annotations IDs.
1340 * @since 4.8.000 (2009-09-07)
1342 protected $form_obj_id = array();
1345 * 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.
1347 * @since 4.8.000 (2009-09-07)
1349 protected $default_form_prop = array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
1352 * Javascript objects array.
1354 * @since 4.8.000 (2009-09-07)
1356 protected $js_objects = array();
1359 * Current form action (used during XHTML rendering).
1361 * @since 4.8.000 (2009-09-07)
1363 protected $form_action = '';
1366 * Current form encryption type (used during XHTML rendering).
1368 * @since 4.8.000 (2009-09-07)
1370 protected $form_enctype = 'application/x-www-form-urlencoded';
1373 * Current method to submit forms.
1375 * @since 4.8.000 (2009-09-07)
1377 protected $form_mode = 'post';
1380 * List of fonts used on form fields (fontname => fontkey).
1382 * @since 4.8.001 (2009-09-09)
1384 protected $annotation_fonts = array();
1387 * List of radio buttons parent objects.
1389 * @since 4.8.001 (2009-09-09)
1391 protected $radiobutton_groups = array();
1394 * List of radio group objects IDs.
1396 * @since 4.8.001 (2009-09-09)
1398 protected $radio_groups = array();
1401 * Text indentation value (used for text-indent CSS attribute).
1403 * @since 4.8.006 (2009-09-23)
1405 protected $textindent = 0;
1408 * Store page number when startTransaction() is called.
1410 * @since 4.8.006 (2009-09-23)
1412 protected $start_transaction_page = 0;
1415 * Store Y position when startTransaction() is called.
1417 * @since 4.9.001 (2010-03-28)
1419 protected $start_transaction_y = 0;
1422 * True when we are printing the thead section on a new page.
1424 * @since 4.8.027 (2010-01-25)
1426 protected $inthead = false;
1429 * Array of column measures (width, space, starting Y position).
1431 * @since 4.9.001 (2010-03-28)
1433 protected $columns = array();
1438 * @since 4.9.001 (2010-03-28)
1440 protected $num_columns = 1;
1443 * Current column number.
1445 * @since 4.9.001 (2010-03-28)
1447 protected $current_column = 0;
1450 * Starting page for columns.
1452 * @since 4.9.001 (2010-03-28)
1454 protected $column_start_page = 0;
1457 * Maximum page and column selected.
1459 * @since 5.8.000 (2010-08-11)
1461 protected $maxselcol = array('page' => 0, 'column' => 0);
1464 * Array of: X difference between table cell x start and starting page margin, cellspacing, cellpadding.
1466 * @since 5.8.000 (2010-08-11)
1468 protected $colxshift = array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
1471 * 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.
1473 * @since 4.9.008 (2010-04-03)
1475 protected $textrendermode = 0;
1478 * Text stroke width in doc units.
1480 * @since 4.9.008 (2010-04-03)
1482 protected $textstrokewidth = 0;
1485 * Current stroke color.
1487 * @since 4.9.008 (2010-04-03)
1489 protected $strokecolor;
1492 * Default unit of measure for document.
1494 * @since 5.0.000 (2010-04-22)
1496 protected $pdfunit = 'mm';
1499 * Boolean flag true when we are on TOC (Table Of Content) page.
1502 protected $tocpage = false;
1505 * Boolean flag: if true convert vector images (SVG, EPS) to raster image using GD or ImageMagick library.
1507 * @since 5.0.000 (2010-04-26)
1509 protected $rasterize_vector_images = false;
1512 * Boolean flag: if true enables font subsetting by default.
1514 * @since 5.3.002 (2010-06-07)
1516 protected $font_subsetting = true;
1519 * Array of default graphic settings.
1521 * @since 5.5.008 (2010-07-02)
1523 protected $default_graphic_vars = array();
1526 * Array of XObjects.
1528 * @since 5.8.014 (2010-08-23)
1530 protected $xobjects = array();
1533 * Boolean value true when we are inside an XObject.
1535 * @since 5.8.017 (2010-08-24)
1537 protected $inxobj = false;
1540 * Current XObject ID.
1542 * @since 5.8.017 (2010-08-24)
1544 protected $xobjid = '';
1547 * Percentage of character stretching.
1549 * @since 5.9.000 (2010-09-29)
1551 protected $font_stretching = 100;
1554 * Increases or decreases the space between characters in a text by the specified amount (tracking/kerning).
1556 * @since 5.9.000 (2010-09-29)
1558 protected $font_spacing = 0;
1561 * Array of no-write regions.
1562 * ('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)
1564 * @since 5.9.003 (2010-10-14)
1566 protected $page_regions = array();
1569 * Array containing HTML color names and values.
1571 * @since 5.9.004 (2010-10-18)
1573 protected $webcolor = array();
1576 * Array containing spot color names and values.
1578 * @since 5.9.012 (2010-11-11)
1580 protected $spotcolor = array();
1583 * Directory used for the last SVG image.
1585 * @since 5.0.000 (2010-05-05)
1587 protected $svgdir = '';
1590 * Deafult unit of measure for SVG.
1592 * @since 5.0.000 (2010-05-02)
1594 protected $svgunit = 'px';
1597 * Array of SVG gradients.
1599 * @since 5.0.000 (2010-05-02)
1601 protected $svggradients = array();
1604 * ID of last SVG gradient.
1606 * @since 5.0.000 (2010-05-02)
1608 protected $svggradientid = 0;
1611 * Boolean value true when in SVG defs group.
1613 * @since 5.0.000 (2010-05-02)
1615 protected $svgdefsmode = false;
1618 * Array of SVG defs.
1620 * @since 5.0.000 (2010-05-02)
1622 protected $svgdefs = array();
1625 * Boolean value true when in SVG clipPath tag.
1627 * @since 5.0.000 (2010-04-26)
1629 protected $svgclipmode = false;
1632 * Array of SVG clipPath commands.
1634 * @since 5.0.000 (2010-05-02)
1636 protected $svgclippaths = array();
1639 * Array of SVG clipPath tranformation matrix.
1641 * @since 5.8.022 (2010-08-31)
1643 protected $svgcliptm = array();
1646 * ID of last SVG clipPath.
1648 * @since 5.0.000 (2010-05-02)
1650 protected $svgclipid = 0;
1655 * @since 5.0.000 (2010-05-02)
1657 protected $svgtext = '';
1660 * SVG text properties.
1662 * @since 5.8.013 (2010-08-23)
1664 protected $svgtextmode = array();
1667 * Array of hinheritable SVG properties.
1669 * @since 5.0.000 (2010-05-02)
1671 protected $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode');
1674 * Array of SVG properties.
1676 * @since 5.0.000 (2010-05-02)
1678 protected $svgstyles = array(array(
1679 'alignment-baseline' => 'auto',
1680 'baseline-shift' => 'baseline',
1682 'clip-path' => 'none',
1683 'clip-rule' => 'nonzero',
1685 'color-interpolation' => 'sRGB',
1686 'color-interpolation-filters' => 'linearRGB',
1687 'color-profile' => 'auto',
1688 'color-rendering' => 'auto',
1690 'direction' => 'ltr',
1691 'display' => 'inline',
1692 'dominant-baseline' => 'auto',
1693 'enable-background' => 'accumulate',
1695 'fill-opacity' => 1,
1696 'fill-rule' => 'nonzero',
1698 'flood-color' => 'black',
1699 'flood-opacity' => 1,
1701 'font-family' => 'helvetica',
1702 'font-size' => 'medium',
1703 'font-size-adjust' => 'none',
1704 'font-stretch' => 'normal',
1705 'font-style' => 'normal',
1706 'font-variant' => 'normal',
1707 'font-weight' => 'normal',
1708 'glyph-orientation-horizontal' => '0deg',
1709 'glyph-orientation-vertical' => 'auto',
1710 'image-rendering' => 'auto',
1711 'kerning' => 'auto',
1712 'letter-spacing' => 'normal',
1713 'lighting-color' => 'white',
1715 'marker-end' => 'none',
1716 'marker-mid' => 'none',
1717 'marker-start' => 'none',
1720 'overflow' => 'auto',
1721 'pointer-events' => 'visiblePainted',
1722 'shape-rendering' => 'auto',
1723 'stop-color' => 'black',
1724 'stop-opacity' => 1,
1726 'stroke-dasharray' => 'none',
1727 'stroke-dashoffset' => 0,
1728 'stroke-linecap' => 'butt',
1729 'stroke-linejoin' => 'miter',
1730 'stroke-miterlimit' => 4,
1731 'stroke-opacity' => 1,
1732 'stroke-width' => 1,
1733 'text-anchor' => 'start',
1734 'text-decoration' => 'none',
1735 'text-rendering' => 'auto',
1736 'unicode-bidi' => 'normal',
1737 'visibility' => 'visible',
1738 'word-spacing' => 'normal',
1739 'writing-mode' => 'lr-tb',
1740 'text-color' => 'black',
1741 'transfmatrix' => array(1, 0, 0, 1, 0, 0)
1744 //------------------------------------------------------------
1746 //------------------------------------------------------------
1749 * This is the class constructor.
1750 * It allows to set up the page format, the orientation and the measure unit used in all the methods (except for the font sizes).
1751 * @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>
1752 * @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.
1753 * @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().
1754 * @param $unicode (boolean) TRUE means that the input text is unicode (default = true)
1755 * @param $diskcache (boolean) if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
1756 * @param $encoding (string) charset encoding; default is UTF-8
1758 * @see getPageSizeFromFormat(), setPageFormat()
1760 public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false) {
1761 /* Set internal character encoding to ASCII */
1762 if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
1763 $this->internal_encoding
= mb_internal_encoding();
1764 mb_internal_encoding('ASCII');
1766 // get array of HTML colors
1767 require(dirname(__FILE__
).'/htmlcolors.php');
1768 $this->webcolor
= $webcolor;
1769 // get array of custom spot colors
1770 if (file_exists(dirname(__FILE__
).'/spotcolors.php')) {
1771 require(dirname(__FILE__
).'/spotcolors.php');
1772 $this->spotcolor
= $spotcolor;
1774 $this->spotcolor
= array();
1776 require_once(dirname(__FILE__
).'/unicode_data.php');
1777 $this->unicode
= new TCPDF_UNICODE_DATA();
1778 $this->font_obj_ids
= array();
1779 $this->page_obj_id
= array();
1780 $this->form_obj_id
= array();
1782 $this->diskcache
= $diskcache ?
true : false;
1783 // set language direction
1785 $this->tmprtl
= false;
1788 // initialization of properties
1789 $this->isunicode
= $unicode;
1791 $this->transfmrk
[0] = array();
1792 $this->pagedim
= array();
1795 $this->pages
= array();
1797 $this->fonts
= array();
1798 $this->FontFiles
= array();
1799 $this->diffs
= array();
1800 $this->images
= array();
1801 $this->links
= array();
1802 $this->gradients
= array();
1803 $this->InFooter
= false;
1805 $this->FontFamily
= 'helvetica';
1806 $this->FontStyle
= '';
1807 $this->FontSizePt
= 12;
1808 $this->underline
= false;
1809 $this->overline
= false;
1810 $this->linethrough
= false;
1811 $this->DrawColor
= '0 G';
1812 $this->FillColor
= '0 g';
1813 $this->TextColor
= '0 g';
1814 $this->ColorFlag
= false;
1815 // encryption values
1816 $this->encrypted
= false;
1817 $this->last_enc_key
= '';
1818 // standard Unicode fonts
1819 $this->CoreFonts
= array(
1820 'courier'=>'Courier',
1821 'courierB'=>'Courier-Bold',
1822 'courierI'=>'Courier-Oblique',
1823 'courierBI'=>'Courier-BoldOblique',
1824 'helvetica'=>'Helvetica',
1825 'helveticaB'=>'Helvetica-Bold',
1826 'helveticaI'=>'Helvetica-Oblique',
1827 'helveticaBI'=>'Helvetica-BoldOblique',
1828 'times'=>'Times-Roman',
1829 'timesB'=>'Times-Bold',
1830 'timesI'=>'Times-Italic',
1831 'timesBI'=>'Times-BoldItalic',
1833 'zapfdingbats'=>'ZapfDingbats'
1836 $this->setPageUnit($unit);
1837 // set page format and orientation
1838 $this->setPageFormat($format, $orientation);
1839 // page margins (1 cm)
1840 $margin = 28.35 / $this->k
;
1841 $this->SetMargins($margin, $margin);
1842 // internal cell padding
1843 $cpadding = $margin / 10;
1844 $this->setCellPaddings($cpadding, 0, $cpadding, 0);
1846 $this->setCellMargins(0, 0, 0, 0);
1847 // line width (0.2 mm)
1848 $this->LineWidth
= 0.57 / $this->k
;
1849 $this->linestyleWidth
= sprintf('%.2F w', ($this->LineWidth
* $this->k
));
1850 $this->linestyleCap
= '0 J';
1851 $this->linestyleJoin
= '0 j';
1852 $this->linestyleDash
= '[] 0 d';
1853 // automatic page break
1854 $this->SetAutoPageBreak(true, (2 * $margin));
1855 // full width display mode
1856 $this->SetDisplayMode('fullwidth');
1858 $this->SetCompression(true);
1859 // set default PDF version number
1860 $this->PDFVersion
= '1.7';
1861 $this->encoding
= $encoding;
1862 $this->HREF
= array();
1863 $this->getFontsList();
1864 $this->fgcolor
= array('R' => 0, 'G' => 0, 'B' => 0);
1865 $this->strokecolor
= array('R' => 0, 'G' => 0, 'B' => 0);
1866 $this->bgcolor
= array('R' => 255, 'G' => 255, 'B' => 255);
1867 $this->extgstates
= array();
1869 $this->sign
= false;
1870 $this->ur
['enabled'] = false;
1871 $this->ur
['document'] = '/FullSave';
1872 $this->ur
['annots'] = '/Create/Delete/Modify/Copy/Import/Export';
1873 $this->ur
['form'] = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
1874 $this->ur
['signature'] = '/Modify';
1875 $this->ur
['ef'] = '/Create/Delete/Modify/Import';
1876 $this->ur
['formex'] = '';
1877 $this->signature_appearance
= array('page' => 1, 'rect' => '0 0 0 0');
1878 // set default JPEG quality
1879 $this->jpeg_quality
= 75;
1880 // initialize some settings
1881 $this->utf8Bidi(array(''), '');
1883 $this->SetFont($this->FontFamily
, $this->FontStyle
, $this->FontSizePt
);
1884 // check if PCRE Unicode support is enabled
1885 if ($this->isunicode
AND (@preg_match
('/\pL/u', 'a') == 1)) {
1886 // PCRE unicode support is turned ON
1887 // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
1888 // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
1889 // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
1890 //$this->setSpacesRE('/[^\S\P{Z}\P{Lo}\xa0]/u');
1891 $this->setSpacesRE('/[^\S\P{Z}\xa0]/u');
1893 // PCRE unicode support is turned OFF
1894 $this->setSpacesRE('/[^\S\xa0]/');
1896 $this->default_form_prop
= array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 255), 'strokeColor'=>array(128, 128, 128));
1897 // set file ID for trailer
1898 $this->file_id
= md5($this->getRandomSeed('TCPDF'.$orientation.$unit.$format.$encoding));
1899 // get default graphic vars
1900 $this->default_graphic_vars
= $this->getGraphicVars();
1904 * Default destructor.
1906 * @since 1.53.0.TC016
1908 public function __destruct() {
1909 // restore internal encoding
1910 if (isset($this->internal_encoding
) AND !empty($this->internal_encoding
)) {
1911 mb_internal_encoding($this->internal_encoding
);
1913 // unset all class variables
1914 $this->_destroy(true);
1918 * Return the current TCPDF version.
1919 * @return TCPDF version string
1921 * @since 5.9.012 (2010-11-10)
1923 public function getTCPDFVersion() {
1924 return $this->tcpdf_version
;
1928 * Set the units of measure for the document.
1929 * @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.
1931 * @since 3.0.015 (2008-06-06)
1933 public function setPageUnit($unit) {
1934 $unit = strtolower($unit);
1945 $this->k
= $this->dpi
/ 25.4;
1950 $this->k
= $this->dpi
/ 2.54;
1955 $this->k
= $this->dpi
;
1960 $this->Error('Incorrect unit: '.$unit);
1964 $this->pdfunit
= $unit;
1965 if (isset($this->CurOrientation
)) {
1966 $this->setPageOrientation($this->CurOrientation
);
1971 * Get page dimensions from format name.
1972 * @param $format (mixed) The format name. It can be: <ul>
1973 * <li><b>ISO 216 A Series + 2 SIS 014711 extensions</b></li>
1974 * <li>A0 (841x1189 mm ; 33.11x46.81 in)</li>
1975 * <li>A1 (594x841 mm ; 23.39x33.11 in)</li>
1976 * <li>A2 (420x594 mm ; 16.54x23.39 in)</li>
1977 * <li>A3 (297x420 mm ; 11.69x16.54 in)</li>
1978 * <li>A4 (210x297 mm ; 8.27x11.69 in)</li>
1979 * <li>A5 (148x210 mm ; 5.83x8.27 in)</li>
1980 * <li>A6 (105x148 mm ; 4.13x5.83 in)</li>
1981 * <li>A7 (74x105 mm ; 2.91x4.13 in)</li>
1982 * <li>A8 (52x74 mm ; 2.05x2.91 in)</li>
1983 * <li>A9 (37x52 mm ; 1.46x2.05 in)</li>
1984 * <li>A10 (26x37 mm ; 1.02x1.46 in)</li>
1985 * <li>A11 (18x26 mm ; 0.71x1.02 in)</li>
1986 * <li>A12 (13x18 mm ; 0.51x0.71 in)</li>
1987 * <li><b>ISO 216 B Series + 2 SIS 014711 extensions</b></li>
1988 * <li>B0 (1000x1414 mm ; 39.37x55.67 in)</li>
1989 * <li>B1 (707x1000 mm ; 27.83x39.37 in)</li>
1990 * <li>B2 (500x707 mm ; 19.69x27.83 in)</li>
1991 * <li>B3 (353x500 mm ; 13.90x19.69 in)</li>
1992 * <li>B4 (250x353 mm ; 9.84x13.90 in)</li>
1993 * <li>B5 (176x250 mm ; 6.93x9.84 in)</li>
1994 * <li>B6 (125x176 mm ; 4.92x6.93 in)</li>
1995 * <li>B7 (88x125 mm ; 3.46x4.92 in)</li>
1996 * <li>B8 (62x88 mm ; 2.44x3.46 in)</li>
1997 * <li>B9 (44x62 mm ; 1.73x2.44 in)</li>
1998 * <li>B10 (31x44 mm ; 1.22x1.73 in)</li>
1999 * <li>B11 (22x31 mm ; 0.87x1.22 in)</li>
2000 * <li>B12 (15x22 mm ; 0.59x0.87 in)</li>
2001 * <li><b>ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION</b></li>
2002 * <li>C0 (917x1297 mm ; 36.10x51.06 in)</li>
2003 * <li>C1 (648x917 mm ; 25.51x36.10 in)</li>
2004 * <li>C2 (458x648 mm ; 18.03x25.51 in)</li>
2005 * <li>C3 (324x458 mm ; 12.76x18.03 in)</li>
2006 * <li>C4 (229x324 mm ; 9.02x12.76 in)</li>
2007 * <li>C5 (162x229 mm ; 6.38x9.02 in)</li>
2008 * <li>C6 (114x162 mm ; 4.49x6.38 in)</li>
2009 * <li>C7 (81x114 mm ; 3.19x4.49 in)</li>
2010 * <li>C8 (57x81 mm ; 2.24x3.19 in)</li>
2011 * <li>C9 (40x57 mm ; 1.57x2.24 in)</li>
2012 * <li>C10 (28x40 mm ; 1.10x1.57 in)</li>
2013 * <li>C11 (20x28 mm ; 0.79x1.10 in)</li>
2014 * <li>C12 (14x20 mm ; 0.55x0.79 in)</li>
2015 * <li>C76 (81x162 mm ; 3.19x6.38 in)</li>
2016 * <li>DL (110x220 mm ; 4.33x8.66 in)</li>
2017 * <li><b>SIS 014711 E Series</b></li>
2018 * <li>E0 (879x1241 mm ; 34.61x48.86 in)</li>
2019 * <li>E1 (620x879 mm ; 24.41x34.61 in)</li>
2020 * <li>E2 (440x620 mm ; 17.32x24.41 in)</li>
2021 * <li>E3 (310x440 mm ; 12.20x17.32 in)</li>
2022 * <li>E4 (220x310 mm ; 8.66x12.20 in)</li>
2023 * <li>E5 (155x220 mm ; 6.10x8.66 in)</li>
2024 * <li>E6 (110x155 mm ; 4.33x6.10 in)</li>
2025 * <li>E7 (78x110 mm ; 3.07x4.33 in)</li>
2026 * <li>E8 (55x78 mm ; 2.17x3.07 in)</li>
2027 * <li>E9 (39x55 mm ; 1.54x2.17 in)</li>
2028 * <li>E10 (27x39 mm ; 1.06x1.54 in)</li>
2029 * <li>E11 (19x27 mm ; 0.75x1.06 in)</li>
2030 * <li>E12 (13x19 mm ; 0.51x0.75 in)</li>
2031 * <li><b>SIS 014711 G Series</b></li>
2032 * <li>G0 (958x1354 mm ; 37.72x53.31 in)</li>
2033 * <li>G1 (677x958 mm ; 26.65x37.72 in)</li>
2034 * <li>G2 (479x677 mm ; 18.86x26.65 in)</li>
2035 * <li>G3 (338x479 mm ; 13.31x18.86 in)</li>
2036 * <li>G4 (239x338 mm ; 9.41x13.31 in)</li>
2037 * <li>G5 (169x239 mm ; 6.65x9.41 in)</li>
2038 * <li>G6 (119x169 mm ; 4.69x6.65 in)</li>
2039 * <li>G7 (84x119 mm ; 3.31x4.69 in)</li>
2040 * <li>G8 (59x84 mm ; 2.32x3.31 in)</li>
2041 * <li>G9 (42x59 mm ; 1.65x2.32 in)</li>
2042 * <li>G10 (29x42 mm ; 1.14x1.65 in)</li>
2043 * <li>G11 (21x29 mm ; 0.83x1.14 in)</li>
2044 * <li>G12 (14x21 mm ; 0.55x0.83 in)</li>
2045 * <li><b>ISO Press</b></li>
2046 * <li>RA0 (860x1220 mm ; 33.86x48.03 in)</li>
2047 * <li>RA1 (610x860 mm ; 24.02x33.86 in)</li>
2048 * <li>RA2 (430x610 mm ; 16.93x24.02 in)</li>
2049 * <li>RA3 (305x430 mm ; 12.01x16.93 in)</li>
2050 * <li>RA4 (215x305 mm ; 8.46x12.01 in)</li>
2051 * <li>SRA0 (900x1280 mm ; 35.43x50.39 in)</li>
2052 * <li>SRA1 (640x900 mm ; 25.20x35.43 in)</li>
2053 * <li>SRA2 (450x640 mm ; 17.72x25.20 in)</li>
2054 * <li>SRA3 (320x450 mm ; 12.60x17.72 in)</li>
2055 * <li>SRA4 (225x320 mm ; 8.86x12.60 in)</li>
2056 * <li><b>German DIN 476</b></li>
2057 * <li>4A0 (1682x2378 mm ; 66.22x93.62 in)</li>
2058 * <li>2A0 (1189x1682 mm ; 46.81x66.22 in)</li>
2059 * <li><b>Variations on the ISO Standard</b></li>
2060 * <li>A2_EXTRA (445x619 mm ; 17.52x24.37 in)</li>
2061 * <li>A3+ (329x483 mm ; 12.95x19.02 in)</li>
2062 * <li>A3_EXTRA (322x445 mm ; 12.68x17.52 in)</li>
2063 * <li>A3_SUPER (305x508 mm ; 12.01x20.00 in)</li>
2064 * <li>SUPER_A3 (305x487 mm ; 12.01x19.17 in)</li>
2065 * <li>A4_EXTRA (235x322 mm ; 9.25x12.68 in)</li>
2066 * <li>A4_SUPER (229x322 mm ; 9.02x12.68 in)</li>
2067 * <li>SUPER_A4 (227x356 mm ; 8.94x14.02 in)</li>
2068 * <li>A4_LONG (210x348 mm ; 8.27x13.70 in)</li>
2069 * <li>F4 (210x330 mm ; 8.27x12.99 in)</li>
2070 * <li>SO_B5_EXTRA (202x276 mm ; 7.95x10.87 in)</li>
2071 * <li>A5_EXTRA (173x235 mm ; 6.81x9.25 in)</li>
2072 * <li><b>ANSI Series</b></li>
2073 * <li>ANSI_E (864x1118 mm ; 34.00x44.00 in)</li>
2074 * <li>ANSI_D (559x864 mm ; 22.00x34.00 in)</li>
2075 * <li>ANSI_C (432x559 mm ; 17.00x22.00 in)</li>
2076 * <li>ANSI_B (279x432 mm ; 11.00x17.00 in)</li>
2077 * <li>ANSI_A (216x279 mm ; 8.50x11.00 in)</li>
2078 * <li><b>Traditional 'Loose' North American Paper Sizes</b></li>
2079 * <li>LEDGER, USLEDGER (432x279 mm ; 17.00x11.00 in)</li>
2080 * <li>TABLOID, USTABLOID, BIBLE, ORGANIZERK (279x432 mm ; 11.00x17.00 in)</li>
2081 * <li>LETTER, USLETTER, ORGANIZERM (216x279 mm ; 8.50x11.00 in)</li>
2082 * <li>LEGAL, USLEGAL (216x356 mm ; 8.50x14.00 in)</li>
2083 * <li>GLETTER, GOVERNMENTLETTER (203x267 mm ; 8.00x10.50 in)</li>
2084 * <li>JLEGAL, JUNIORLEGAL (203x127 mm ; 8.00x5.00 in)</li>
2085 * <li><b>Other North American Paper Sizes</b></li>
2086 * <li>QUADDEMY (889x1143 mm ; 35.00x45.00 in)</li>
2087 * <li>SUPER_B (330x483 mm ; 13.00x19.00 in)</li>
2088 * <li>QUARTO (229x279 mm ; 9.00x11.00 in)</li>
2089 * <li>FOLIO, GOVERNMENTLEGAL (216x330 mm ; 8.50x13.00 in)</li>
2090 * <li>EXECUTIVE, MONARCH (184x267 mm ; 7.25x10.50 in)</li>
2091 * <li>MEMO, STATEMENT, ORGANIZERL (140x216 mm ; 5.50x8.50 in)</li>
2092 * <li>FOOLSCAP (210x330 mm ; 8.27x13.00 in)</li>
2093 * <li>COMPACT (108x171 mm ; 4.25x6.75 in)</li>
2094 * <li>ORGANIZERJ (70x127 mm ; 2.75x5.00 in)</li>
2095 * <li><b>Canadian standard CAN 2-9.60M</b></li>
2096 * <li>P1 (560x860 mm ; 22.05x33.86 in)</li>
2097 * <li>P2 (430x560 mm ; 16.93x22.05 in)</li>
2098 * <li>P3 (280x430 mm ; 11.02x16.93 in)</li>
2099 * <li>P4 (215x280 mm ; 8.46x11.02 in)</li>
2100 * <li>P5 (140x215 mm ; 5.51x8.46 in)</li>
2101 * <li>P6 (107x140 mm ; 4.21x5.51 in)</li>
2102 * <li><b>North American Architectural Sizes</b></li>
2103 * <li>ARCH_E (914x1219 mm ; 36.00x48.00 in)</li>
2104 * <li>ARCH_E1 (762x1067 mm ; 30.00x42.00 in)</li>
2105 * <li>ARCH_D (610x914 mm ; 24.00x36.00 in)</li>
2106 * <li>ARCH_C, BROADSHEET (457x610 mm ; 18.00x24.00 in)</li>
2107 * <li>ARCH_B (305x457 mm ; 12.00x18.00 in)</li>
2108 * <li>ARCH_A (229x305 mm ; 9.00x12.00 in)</li>
2109 * <li><b>Announcement Envelopes</b></li>
2110 * <li>ANNENV_A2 (111x146 mm ; 4.37x5.75 in)</li>
2111 * <li>ANNENV_A6 (121x165 mm ; 4.75x6.50 in)</li>
2112 * <li>ANNENV_A7 (133x184 mm ; 5.25x7.25 in)</li>
2113 * <li>ANNENV_A8 (140x206 mm ; 5.50x8.12 in)</li>
2114 * <li>ANNENV_A10 (159x244 mm ; 6.25x9.62 in)</li>
2115 * <li>ANNENV_SLIM (98x225 mm ; 3.87x8.87 in)</li>
2116 * <li><b>Commercial Envelopes</b></li>
2117 * <li>COMMENV_N6_1/4 (89x152 mm ; 3.50x6.00 in)</li>
2118 * <li>COMMENV_N6_3/4 (92x165 mm ; 3.62x6.50 in)</li>
2119 * <li>COMMENV_N8 (98x191 mm ; 3.87x7.50 in)</li>
2120 * <li>COMMENV_N9 (98x225 mm ; 3.87x8.87 in)</li>
2121 * <li>COMMENV_N10 (105x241 mm ; 4.12x9.50 in)</li>
2122 * <li>COMMENV_N11 (114x263 mm ; 4.50x10.37 in)</li>
2123 * <li>COMMENV_N12 (121x279 mm ; 4.75x11.00 in)</li>
2124 * <li>COMMENV_N14 (127x292 mm ; 5.00x11.50 in)</li>
2125 * <li><b>Catalogue Envelopes</b></li>
2126 * <li>CATENV_N1 (152x229 mm ; 6.00x9.00 in)</li>
2127 * <li>CATENV_N1_3/4 (165x241 mm ; 6.50x9.50 in)</li>
2128 * <li>CATENV_N2 (165x254 mm ; 6.50x10.00 in)</li>
2129 * <li>CATENV_N3 (178x254 mm ; 7.00x10.00 in)</li>
2130 * <li>CATENV_N6 (191x267 mm ; 7.50x10.50 in)</li>
2131 * <li>CATENV_N7 (203x279 mm ; 8.00x11.00 in)</li>
2132 * <li>CATENV_N8 (210x286 mm ; 8.25x11.25 in)</li>
2133 * <li>CATENV_N9_1/2 (216x267 mm ; 8.50x10.50 in)</li>
2134 * <li>CATENV_N9_3/4 (222x286 mm ; 8.75x11.25 in)</li>
2135 * <li>CATENV_N10_1/2 (229x305 mm ; 9.00x12.00 in)</li>
2136 * <li>CATENV_N12_1/2 (241x318 mm ; 9.50x12.50 in)</li>
2137 * <li>CATENV_N13_1/2 (254x330 mm ; 10.00x13.00 in)</li>
2138 * <li>CATENV_N14_1/4 (286x311 mm ; 11.25x12.25 in)</li>
2139 * <li>CATENV_N14_1/2 (292x368 mm ; 11.50x14.50 in)</li>
2140 * <li><b>Japanese (JIS P 0138-61) Standard B-Series</b></li>
2141 * <li>JIS_B0 (1030x1456 mm ; 40.55x57.32 in)</li>
2142 * <li>JIS_B1 (728x1030 mm ; 28.66x40.55 in)</li>
2143 * <li>JIS_B2 (515x728 mm ; 20.28x28.66 in)</li>
2144 * <li>JIS_B3 (364x515 mm ; 14.33x20.28 in)</li>
2145 * <li>JIS_B4 (257x364 mm ; 10.12x14.33 in)</li>
2146 * <li>JIS_B5 (182x257 mm ; 7.17x10.12 in)</li>
2147 * <li>JIS_B6 (128x182 mm ; 5.04x7.17 in)</li>
2148 * <li>JIS_B7 (91x128 mm ; 3.58x5.04 in)</li>
2149 * <li>JIS_B8 (64x91 mm ; 2.52x3.58 in)</li>
2150 * <li>JIS_B9 (45x64 mm ; 1.77x2.52 in)</li>
2151 * <li>JIS_B10 (32x45 mm ; 1.26x1.77 in)</li>
2152 * <li>JIS_B11 (22x32 mm ; 0.87x1.26 in)</li>
2153 * <li>JIS_B12 (16x22 mm ; 0.63x0.87 in)</li>
2154 * <li><b>PA Series</b></li>
2155 * <li>PA0 (840x1120 mm ; 33.07x44.09 in)</li>
2156 * <li>PA1 (560x840 mm ; 22.05x33.07 in)</li>
2157 * <li>PA2 (420x560 mm ; 16.54x22.05 in)</li>
2158 * <li>PA3 (280x420 mm ; 11.02x16.54 in)</li>
2159 * <li>PA4 (210x280 mm ; 8.27x11.02 in)</li>
2160 * <li>PA5 (140x210 mm ; 5.51x8.27 in)</li>
2161 * <li>PA6 (105x140 mm ; 4.13x5.51 in)</li>
2162 * <li>PA7 (70x105 mm ; 2.76x4.13 in)</li>
2163 * <li>PA8 (52x70 mm ; 2.05x2.76 in)</li>
2164 * <li>PA9 (35x52 mm ; 1.38x2.05 in)</li>
2165 * <li>PA10 (26x35 mm ; 1.02x1.38 in)</li>
2166 * <li><b>Standard Photographic Print Sizes</b></li>
2167 * <li>PASSPORT_PHOTO (35x45 mm ; 1.38x1.77 in)</li>
2168 * <li>E (82x120 mm ; 3.25x4.72 in)</li>
2169 * <li>3R, L (89x127 mm ; 3.50x5.00 in)</li>
2170 * <li>4R, KG (102x152 mm ; 4.02x5.98 in)</li>
2171 * <li>4D (120x152 mm ; 4.72x5.98 in)</li>
2172 * <li>5R, 2L (127x178 mm ; 5.00x7.01 in)</li>
2173 * <li>6R, 8P (152x203 mm ; 5.98x7.99 in)</li>
2174 * <li>8R, 6P (203x254 mm ; 7.99x10.00 in)</li>
2175 * <li>S8R, 6PW (203x305 mm ; 7.99x12.01 in)</li>
2176 * <li>10R, 4P (254x305 mm ; 10.00x12.01 in)</li>
2177 * <li>S10R, 4PW (254x381 mm ; 10.00x15.00 in)</li>
2178 * <li>11R (279x356 mm ; 10.98x14.02 in)</li>
2179 * <li>S11R (279x432 mm ; 10.98x17.01 in)</li>
2180 * <li>12R (305x381 mm ; 12.01x15.00 in)</li>
2181 * <li>S12R (305x456 mm ; 12.01x17.95 in)</li>
2182 * <li><b>Common Newspaper Sizes</b></li>
2183 * <li>NEWSPAPER_BROADSHEET (750x600 mm ; 29.53x23.62 in)</li>
2184 * <li>NEWSPAPER_BERLINER (470x315 mm ; 18.50x12.40 in)</li>
2185 * <li>NEWSPAPER_COMPACT, NEWSPAPER_TABLOID (430x280 mm ; 16.93x11.02 in)</li>
2186 * <li><b>Business Cards</b></li>
2187 * <li>CREDIT_CARD, BUSINESS_CARD, BUSINESS_CARD_ISO7810 (54x86 mm ; 2.13x3.37 in)</li>
2188 * <li>BUSINESS_CARD_ISO216 (52x74 mm ; 2.05x2.91 in)</li>
2189 * <li>BUSINESS_CARD_IT, BUSINESS_CARD_UK, BUSINESS_CARD_FR, BUSINESS_CARD_DE, BUSINESS_CARD_ES (55x85 mm ; 2.17x3.35 in)</li>
2190 * <li>BUSINESS_CARD_US, BUSINESS_CARD_CA (51x89 mm ; 2.01x3.50 in)</li>
2191 * <li>BUSINESS_CARD_JP (55x91 mm ; 2.17x3.58 in)</li>
2192 * <li>BUSINESS_CARD_HK (54x90 mm ; 2.13x3.54 in)</li>
2193 * <li>BUSINESS_CARD_AU, BUSINESS_CARD_DK, BUSINESS_CARD_SE (55x90 mm ; 2.17x3.54 in)</li>
2194 * <li>BUSINESS_CARD_RU, BUSINESS_CARD_CZ, BUSINESS_CARD_FI, BUSINESS_CARD_HU, BUSINESS_CARD_IL (50x90 mm ; 1.97x3.54 in)</li>
2195 * <li><b>Billboards</b></li>
2196 * <li>4SHEET (1016x1524 mm ; 40.00x60.00 in)</li>
2197 * <li>6SHEET (1200x1800 mm ; 47.24x70.87 in)</li>
2198 * <li>12SHEET (3048x1524 mm ; 120.00x60.00 in)</li>
2199 * <li>16SHEET (2032x3048 mm ; 80.00x120.00 in)</li>
2200 * <li>32SHEET (4064x3048 mm ; 160.00x120.00 in)</li>
2201 * <li>48SHEET (6096x3048 mm ; 240.00x120.00 in)</li>
2202 * <li>64SHEET (8128x3048 mm ; 320.00x120.00 in)</li>
2203 * <li>96SHEET (12192x3048 mm ; 480.00x120.00 in)</li>
2204 * <li><b>Old Imperial English (some are still used in USA)</b></li>
2205 * <li>EN_EMPEROR (1219x1829 mm ; 48.00x72.00 in)</li>
2206 * <li>EN_ANTIQUARIAN (787x1346 mm ; 31.00x53.00 in)</li>
2207 * <li>EN_GRAND_EAGLE (730x1067 mm ; 28.75x42.00 in)</li>
2208 * <li>EN_DOUBLE_ELEPHANT (679x1016 mm ; 26.75x40.00 in)</li>
2209 * <li>EN_ATLAS (660x864 mm ; 26.00x34.00 in)</li>
2210 * <li>EN_COLOMBIER (597x876 mm ; 23.50x34.50 in)</li>
2211 * <li>EN_ELEPHANT (584x711 mm ; 23.00x28.00 in)</li>
2212 * <li>EN_DOUBLE_DEMY (572x902 mm ; 22.50x35.50 in)</li>
2213 * <li>EN_IMPERIAL (559x762 mm ; 22.00x30.00 in)</li>
2214 * <li>EN_PRINCESS (546x711 mm ; 21.50x28.00 in)</li>
2215 * <li>EN_CARTRIDGE (533x660 mm ; 21.00x26.00 in)</li>
2216 * <li>EN_DOUBLE_LARGE_POST (533x838 mm ; 21.00x33.00 in)</li>
2217 * <li>EN_ROYAL (508x635 mm ; 20.00x25.00 in)</li>
2218 * <li>EN_SHEET, EN_HALF_POST (495x597 mm ; 19.50x23.50 in)</li>
2219 * <li>EN_SUPER_ROYAL (483x686 mm ; 19.00x27.00 in)</li>
2220 * <li>EN_DOUBLE_POST (483x775 mm ; 19.00x30.50 in)</li>
2221 * <li>EN_MEDIUM (445x584 mm ; 17.50x23.00 in)</li>
2222 * <li>EN_DEMY (445x572 mm ; 17.50x22.50 in)</li>
2223 * <li>EN_LARGE_POST (419x533 mm ; 16.50x21.00 in)</li>
2224 * <li>EN_COPY_DRAUGHT (406x508 mm ; 16.00x20.00 in)</li>
2225 * <li>EN_POST (394x489 mm ; 15.50x19.25 in)</li>
2226 * <li>EN_CROWN (381x508 mm ; 15.00x20.00 in)</li>
2227 * <li>EN_PINCHED_POST (375x470 mm ; 14.75x18.50 in)</li>
2228 * <li>EN_BRIEF (343x406 mm ; 13.50x16.00 in)</li>
2229 * <li>EN_FOOLSCAP (343x432 mm ; 13.50x17.00 in)</li>
2230 * <li>EN_SMALL_FOOLSCAP (337x419 mm ; 13.25x16.50 in)</li>
2231 * <li>EN_POTT (318x381 mm ; 12.50x15.00 in)</li>
2232 * <li><b>Old Imperial Belgian</b></li>
2233 * <li>BE_GRAND_AIGLE (700x1040 mm ; 27.56x40.94 in)</li>
2234 * <li>BE_COLOMBIER (620x850 mm ; 24.41x33.46 in)</li>
2235 * <li>BE_DOUBLE_CARRE (620x920 mm ; 24.41x36.22 in)</li>
2236 * <li>BE_ELEPHANT (616x770 mm ; 24.25x30.31 in)</li>
2237 * <li>BE_PETIT_AIGLE (600x840 mm ; 23.62x33.07 in)</li>
2238 * <li>BE_GRAND_JESUS (550x730 mm ; 21.65x28.74 in)</li>
2239 * <li>BE_JESUS (540x730 mm ; 21.26x28.74 in)</li>
2240 * <li>BE_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
2241 * <li>BE_GRAND_MEDIAN (460x605 mm ; 18.11x23.82 in)</li>
2242 * <li>BE_DOUBLE_POSTE (435x565 mm ; 17.13x22.24 in)</li>
2243 * <li>BE_COQUILLE (430x560 mm ; 16.93x22.05 in)</li>
2244 * <li>BE_PETIT_MEDIAN (415x530 mm ; 16.34x20.87 in)</li>
2245 * <li>BE_RUCHE (360x460 mm ; 14.17x18.11 in)</li>
2246 * <li>BE_PROPATRIA (345x430 mm ; 13.58x16.93 in)</li>
2247 * <li>BE_LYS (317x397 mm ; 12.48x15.63 in)</li>
2248 * <li>BE_POT (307x384 mm ; 12.09x15.12 in)</li>
2249 * <li>BE_ROSETTE (270x347 mm ; 10.63x13.66 in)</li>
2250 * <li><b>Old Imperial French</b></li>
2251 * <li>FR_UNIVERS (1000x1300 mm ; 39.37x51.18 in)</li>
2252 * <li>FR_DOUBLE_COLOMBIER (900x1260 mm ; 35.43x49.61 in)</li>
2253 * <li>FR_GRANDE_MONDE (900x1260 mm ; 35.43x49.61 in)</li>
2254 * <li>FR_DOUBLE_SOLEIL (800x1200 mm ; 31.50x47.24 in)</li>
2255 * <li>FR_DOUBLE_JESUS (760x1120 mm ; 29.92x44.09 in)</li>
2256 * <li>FR_GRAND_AIGLE (750x1060 mm ; 29.53x41.73 in)</li>
2257 * <li>FR_PETIT_AIGLE (700x940 mm ; 27.56x37.01 in)</li>
2258 * <li>FR_DOUBLE_RAISIN (650x1000 mm ; 25.59x39.37 in)</li>
2259 * <li>FR_JOURNAL (650x940 mm ; 25.59x37.01 in)</li>
2260 * <li>FR_COLOMBIER_AFFICHE (630x900 mm ; 24.80x35.43 in)</li>
2261 * <li>FR_DOUBLE_CAVALIER (620x920 mm ; 24.41x36.22 in)</li>
2262 * <li>FR_CLOCHE (600x800 mm ; 23.62x31.50 in)</li>
2263 * <li>FR_SOLEIL (600x800 mm ; 23.62x31.50 in)</li>
2264 * <li>FR_DOUBLE_CARRE (560x900 mm ; 22.05x35.43 in)</li>
2265 * <li>FR_DOUBLE_COQUILLE (560x880 mm ; 22.05x34.65 in)</li>
2266 * <li>FR_JESUS (560x760 mm ; 22.05x29.92 in)</li>
2267 * <li>FR_RAISIN (500x650 mm ; 19.69x25.59 in)</li>
2268 * <li>FR_CAVALIER (460x620 mm ; 18.11x24.41 in)</li>
2269 * <li>FR_DOUBLE_COURONNE (460x720 mm ; 18.11x28.35 in)</li>
2270 * <li>FR_CARRE (450x560 mm ; 17.72x22.05 in)</li>
2271 * <li>FR_COQUILLE (440x560 mm ; 17.32x22.05 in)</li>
2272 * <li>FR_DOUBLE_TELLIERE (440x680 mm ; 17.32x26.77 in)</li>
2273 * <li>FR_DOUBLE_CLOCHE (400x600 mm ; 15.75x23.62 in)</li>
2274 * <li>FR_DOUBLE_POT (400x620 mm ; 15.75x24.41 in)</li>
2275 * <li>FR_ECU (400x520 mm ; 15.75x20.47 in)</li>
2276 * <li>FR_COURONNE (360x460 mm ; 14.17x18.11 in)</li>
2277 * <li>FR_TELLIERE (340x440 mm ; 13.39x17.32 in)</li>
2278 * <li>FR_POT (310x400 mm ; 12.20x15.75 in)</li>
2280 * @return array containing page width and height in points
2282 * @since 5.0.010 (2010-05-17)
2284 public function getPageSizeFromFormat($format) {
2285 // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 25.4 mm)
2286 switch (strtoupper($format)) {
2287 // ISO 216 A Series + 2 SIS 014711 extensions
2288 case 'A0' : {$pf = array( 2383.937, 3370.394); break;}
2289 case 'A1' : {$pf = array( 1683.780, 2383.937); break;}
2290 case 'A2' : {$pf = array( 1190.551, 1683.780); break;}
2291 case 'A3' : {$pf = array( 841.890, 1190.551); break;}
2292 case 'A4' : {$pf = array( 595.276, 841.890); break;}
2293 case 'A5' : {$pf = array( 419.528, 595.276); break;}
2294 case 'A6' : {$pf = array( 297.638, 419.528); break;}
2295 case 'A7' : {$pf = array( 209.764, 297.638); break;}
2296 case 'A8' : {$pf = array( 147.402, 209.764); break;}
2297 case 'A9' : {$pf = array( 104.882, 147.402); break;}
2298 case 'A10': {$pf = array( 73.701, 104.882); break;}
2299 case 'A11': {$pf = array( 51.024, 73.701); break;}
2300 case 'A12': {$pf = array( 36.850, 51.024); break;}
2301 // ISO 216 B Series + 2 SIS 014711 extensions
2302 case 'B0' : {$pf = array( 2834.646, 4008.189); break;}
2303 case 'B1' : {$pf = array( 2004.094, 2834.646); break;}
2304 case 'B2' : {$pf = array( 1417.323, 2004.094); break;}
2305 case 'B3' : {$pf = array( 1000.630, 1417.323); break;}
2306 case 'B4' : {$pf = array( 708.661, 1000.630); break;}
2307 case 'B5' : {$pf = array( 498.898, 708.661); break;}
2308 case 'B6' : {$pf = array( 354.331, 498.898); break;}
2309 case 'B7' : {$pf = array( 249.449, 354.331); break;}
2310 case 'B8' : {$pf = array( 175.748, 249.449); break;}
2311 case 'B9' : {$pf = array( 124.724, 175.748); break;}
2312 case 'B10': {$pf = array( 87.874, 124.724); break;}
2313 case 'B11': {$pf = array( 62.362, 87.874); break;}
2314 case 'B12': {$pf = array( 42.520, 62.362); break;}
2315 // ISO 216 C Series + 2 SIS 014711 extensions + 2 EXTENSION
2316 case 'C0' : {$pf = array( 2599.370, 3676.535); break;}
2317 case 'C1' : {$pf = array( 1836.850, 2599.370); break;}
2318 case 'C2' : {$pf = array( 1298.268, 1836.850); break;}
2319 case 'C3' : {$pf = array( 918.425, 1298.268); break;}
2320 case 'C4' : {$pf = array( 649.134, 918.425); break;}
2321 case 'C5' : {$pf = array( 459.213, 649.134); break;}
2322 case 'C6' : {$pf = array( 323.150, 459.213); break;}
2323 case 'C7' : {$pf = array( 229.606, 323.150); break;}
2324 case 'C8' : {$pf = array( 161.575, 229.606); break;}
2325 case 'C9' : {$pf = array( 113.386, 161.575); break;}
2326 case 'C10': {$pf = array( 79.370, 113.386); break;}
2327 case 'C11': {$pf = array( 56.693, 79.370); break;}
2328 case 'C12': {$pf = array( 39.685, 56.693); break;}
2329 case 'C76': {$pf = array( 229.606, 459.213); break;}
2330 case 'DL' : {$pf = array( 311.811, 623.622); break;}
2331 // SIS 014711 E Series
2332 case 'E0' : {$pf = array( 2491.654, 3517.795); break;}
2333 case 'E1' : {$pf = array( 1757.480, 2491.654); break;}
2334 case 'E2' : {$pf = array( 1247.244, 1757.480); break;}
2335 case 'E3' : {$pf = array( 878.740, 1247.244); break;}
2336 case 'E4' : {$pf = array( 623.622, 878.740); break;}
2337 case 'E5' : {$pf = array( 439.370, 623.622); break;}
2338 case 'E6' : {$pf = array( 311.811, 439.370); break;}
2339 case 'E7' : {$pf = array( 221.102, 311.811); break;}
2340 case 'E8' : {$pf = array( 155.906, 221.102); break;}
2341 case 'E9' : {$pf = array( 110.551, 155.906); break;}
2342 case 'E10': {$pf = array( 76.535, 110.551); break;}
2343 case 'E11': {$pf = array( 53.858, 76.535); break;}
2344 case 'E12': {$pf = array( 36.850, 53.858); break;}
2345 // SIS 014711 G Series
2346 case 'G0' : {$pf = array( 2715.591, 3838.110); break;}
2347 case 'G1' : {$pf = array( 1919.055, 2715.591); break;}
2348 case 'G2' : {$pf = array( 1357.795, 1919.055); break;}
2349 case 'G3' : {$pf = array( 958.110, 1357.795); break;}
2350 case 'G4' : {$pf = array( 677.480, 958.110); break;}
2351 case 'G5' : {$pf = array( 479.055, 677.480); break;}
2352 case 'G6' : {$pf = array( 337.323, 479.055); break;}
2353 case 'G7' : {$pf = array( 238.110, 337.323); break;}
2354 case 'G8' : {$pf = array( 167.244, 238.110); break;}
2355 case 'G9' : {$pf = array( 119.055, 167.244); break;}
2356 case 'G10': {$pf = array( 82.205, 119.055); break;}
2357 case 'G11': {$pf = array( 59.528, 82.205); break;}
2358 case 'G12': {$pf = array( 39.685, 59.528); break;}
2360 case 'RA0': {$pf = array( 2437.795, 3458.268); break;}
2361 case 'RA1': {$pf = array( 1729.134, 2437.795); break;}
2362 case 'RA2': {$pf = array( 1218.898, 1729.134); break;}
2363 case 'RA3': {$pf = array( 864.567, 1218.898); break;}
2364 case 'RA4': {$pf = array( 609.449, 864.567); break;}
2365 case 'SRA0': {$pf = array( 2551.181, 3628.346); break;}
2366 case 'SRA1': {$pf = array( 1814.173, 2551.181); break;}
2367 case 'SRA2': {$pf = array( 1275.591, 1814.173); break;}
2368 case 'SRA3': {$pf = array( 907.087, 1275.591); break;}
2369 case 'SRA4': {$pf = array( 637.795, 907.087); break;}
2371 case '4A0': {$pf = array( 4767.874, 6740.787); break;}
2372 case '2A0': {$pf = array( 3370.394, 4767.874); break;}
2373 // Variations on the ISO Standard
2374 case 'A2_EXTRA' : {$pf = array( 1261.417, 1754.646); break;}
2375 case 'A3+' : {$pf = array( 932.598, 1369.134); break;}
2376 case 'A3_EXTRA' : {$pf = array( 912.756, 1261.417); break;}
2377 case 'A3_SUPER' : {$pf = array( 864.567, 1440.000); break;}
2378 case 'SUPER_A3' : {$pf = array( 864.567, 1380.472); break;}
2379 case 'A4_EXTRA' : {$pf = array( 666.142, 912.756); break;}
2380 case 'A4_SUPER' : {$pf = array( 649.134, 912.756); break;}
2381 case 'SUPER_A4' : {$pf = array( 643.465, 1009.134); break;}
2382 case 'A4_LONG' : {$pf = array( 595.276, 986.457); break;}
2383 case 'F4' : {$pf = array( 595.276, 935.433); break;}
2384 case 'SO_B5_EXTRA': {$pf = array( 572.598, 782.362); break;}
2385 case 'A5_EXTRA' : {$pf = array( 490.394, 666.142); break;}
2387 case 'ANSI_E': {$pf = array( 2448.000, 3168.000); break;}
2388 case 'ANSI_D': {$pf = array( 1584.000, 2448.000); break;}
2389 case 'ANSI_C': {$pf = array( 1224.000, 1584.000); break;}
2390 case 'ANSI_B': {$pf = array( 792.000, 1224.000); break;}
2391 case 'ANSI_A': {$pf = array( 612.000, 792.000); break;}
2392 // Traditional 'Loose' North American Paper Sizes
2394 case 'LEDGER' : {$pf = array( 1224.000, 792.000); break;}
2398 case 'TABLOID': {$pf = array( 792.000, 1224.000); break;}
2401 case 'LETTER' : {$pf = array( 612.000, 792.000); break;}
2403 case 'LEGAL' : {$pf = array( 612.000, 1008.000); break;}
2404 case 'GOVERNMENTLETTER':
2405 case 'GLETTER': {$pf = array( 576.000, 756.000); break;}
2407 case 'JLEGAL' : {$pf = array( 576.000, 360.000); break;}
2408 // Other North American Paper Sizes
2409 case 'QUADDEMY': {$pf = array( 2520.000, 3240.000); break;}
2410 case 'SUPER_B': {$pf = array( 936.000, 1368.000); break;}
2411 case 'QUARTO': {$pf = array( 648.000, 792.000); break;}
2412 case 'GOVERNMENTLEGAL':
2413 case 'FOLIO': {$pf = array( 612.000, 936.000); break;}
2415 case 'EXECUTIVE': {$pf = array( 522.000, 756.000); break;}
2418 case 'MEMO': {$pf = array( 396.000, 612.000); break;}
2419 case 'FOOLSCAP': {$pf = array( 595.440, 936.000); break;}
2420 case 'COMPACT': {$pf = array( 306.000, 486.000); break;}
2421 case 'ORGANIZERJ': {$pf = array( 198.000, 360.000); break;}
2422 // Canadian standard CAN 2-9.60M
2423 case 'P1': {$pf = array( 1587.402, 2437.795); break;}
2424 case 'P2': {$pf = array( 1218.898, 1587.402); break;}
2425 case 'P3': {$pf = array( 793.701, 1218.898); break;}
2426 case 'P4': {$pf = array( 609.449, 793.701); break;}
2427 case 'P5': {$pf = array( 396.850, 609.449); break;}
2428 case 'P6': {$pf = array( 303.307, 396.850); break;}
2429 // North American Architectural Sizes
2430 case 'ARCH_E' : {$pf = array( 2592.000, 3456.000); break;}
2431 case 'ARCH_E1': {$pf = array( 2160.000, 3024.000); break;}
2432 case 'ARCH_D' : {$pf = array( 1728.000, 2592.000); break;}
2434 case 'ARCH_C' : {$pf = array( 1296.000, 1728.000); break;}
2435 case 'ARCH_B' : {$pf = array( 864.000, 1296.000); break;}
2436 case 'ARCH_A' : {$pf = array( 648.000, 864.000); break;}
2437 // --- North American Envelope Sizes ---
2438 // - Announcement Envelopes
2439 case 'ANNENV_A2' : {$pf = array( 314.640, 414.000); break;}
2440 case 'ANNENV_A6' : {$pf = array( 342.000, 468.000); break;}
2441 case 'ANNENV_A7' : {$pf = array( 378.000, 522.000); break;}
2442 case 'ANNENV_A8' : {$pf = array( 396.000, 584.640); break;}
2443 case 'ANNENV_A10' : {$pf = array( 450.000, 692.640); break;}
2444 case 'ANNENV_SLIM': {$pf = array( 278.640, 638.640); break;}
2445 // - Commercial Envelopes
2446 case 'COMMENV_N6_1/4': {$pf = array( 252.000, 432.000); break;}
2447 case 'COMMENV_N6_3/4': {$pf = array( 260.640, 468.000); break;}
2448 case 'COMMENV_N8' : {$pf = array( 278.640, 540.000); break;}
2449 case 'COMMENV_N9' : {$pf = array( 278.640, 638.640); break;}
2450 case 'COMMENV_N10' : {$pf = array( 296.640, 684.000); break;}
2451 case 'COMMENV_N11' : {$pf = array( 324.000, 746.640); break;}
2452 case 'COMMENV_N12' : {$pf = array( 342.000, 792.000); break;}
2453 case 'COMMENV_N14' : {$pf = array( 360.000, 828.000); break;}
2454 // - Catalogue Envelopes
2455 case 'CATENV_N1' : {$pf = array( 432.000, 648.000); break;}
2456 case 'CATENV_N1_3/4' : {$pf = array( 468.000, 684.000); break;}
2457 case 'CATENV_N2' : {$pf = array( 468.000, 720.000); break;}
2458 case 'CATENV_N3' : {$pf = array( 504.000, 720.000); break;}
2459 case 'CATENV_N6' : {$pf = array( 540.000, 756.000); break;}
2460 case 'CATENV_N7' : {$pf = array( 576.000, 792.000); break;}
2461 case 'CATENV_N8' : {$pf = array( 594.000, 810.000); break;}
2462 case 'CATENV_N9_1/2' : {$pf = array( 612.000, 756.000); break;}
2463 case 'CATENV_N9_3/4' : {$pf = array( 630.000, 810.000); break;}
2464 case 'CATENV_N10_1/2': {$pf = array( 648.000, 864.000); break;}
2465 case 'CATENV_N12_1/2': {$pf = array( 684.000, 900.000); break;}
2466 case 'CATENV_N13_1/2': {$pf = array( 720.000, 936.000); break;}
2467 case 'CATENV_N14_1/4': {$pf = array( 810.000, 882.000); break;}
2468 case 'CATENV_N14_1/2': {$pf = array( 828.000, 1044.000); break;}
2469 // Japanese (JIS P 0138-61) Standard B-Series
2470 case 'JIS_B0' : {$pf = array( 2919.685, 4127.244); break;}
2471 case 'JIS_B1' : {$pf = array( 2063.622, 2919.685); break;}
2472 case 'JIS_B2' : {$pf = array( 1459.843, 2063.622); break;}
2473 case 'JIS_B3' : {$pf = array( 1031.811, 1459.843); break;}
2474 case 'JIS_B4' : {$pf = array( 728.504, 1031.811); break;}
2475 case 'JIS_B5' : {$pf = array( 515.906, 728.504); break;}
2476 case 'JIS_B6' : {$pf = array( 362.835, 515.906); break;}
2477 case 'JIS_B7' : {$pf = array( 257.953, 362.835); break;}
2478 case 'JIS_B8' : {$pf = array( 181.417, 257.953); break;}
2479 case 'JIS_B9' : {$pf = array( 127.559, 181.417); break;}
2480 case 'JIS_B10': {$pf = array( 90.709, 127.559); break;}
2481 case 'JIS_B11': {$pf = array( 62.362, 90.709); break;}
2482 case 'JIS_B12': {$pf = array( 45.354, 62.362); break;}
2484 case 'PA0' : {$pf = array( 2381.102, 3174.803,); break;}
2485 case 'PA1' : {$pf = array( 1587.402, 2381.102); break;}
2486 case 'PA2' : {$pf = array( 1190.551, 1587.402); break;}
2487 case 'PA3' : {$pf = array( 793.701, 1190.551); break;}
2488 case 'PA4' : {$pf = array( 595.276, 793.701); break;}
2489 case 'PA5' : {$pf = array( 396.850, 595.276); break;}
2490 case 'PA6' : {$pf = array( 297.638, 396.850); break;}
2491 case 'PA7' : {$pf = array( 198.425, 297.638); break;}
2492 case 'PA8' : {$pf = array( 147.402, 198.425); break;}
2493 case 'PA9' : {$pf = array( 99.213, 147.402); break;}
2494 case 'PA10': {$pf = array( 73.701, 99.213); break;}
2495 // Standard Photographic Print Sizes
2496 case 'PASSPORT_PHOTO': {$pf = array( 99.213, 127.559); break;}
2497 case 'E' : {$pf = array( 233.858, 340.157); break;}
2499 case '3R' : {$pf = array( 252.283, 360.000); break;}
2501 case '4R' : {$pf = array( 289.134, 430.866); break;}
2502 case '4D' : {$pf = array( 340.157, 430.866); break;}
2504 case '5R' : {$pf = array( 360.000, 504.567); break;}
2506 case '6R' : {$pf = array( 430.866, 575.433); break;}
2508 case '8R' : {$pf = array( 575.433, 720.000); break;}
2510 case 'S8R' : {$pf = array( 575.433, 864.567); break;}
2512 case '10R' : {$pf = array( 720.000, 864.567); break;}
2514 case 'S10R': {$pf = array( 720.000, 1080.000); break;}
2515 case '11R' : {$pf = array( 790.866, 1009.134); break;}
2516 case 'S11R': {$pf = array( 790.866, 1224.567); break;}
2517 case '12R' : {$pf = array( 864.567, 1080.000); break;}
2518 case 'S12R': {$pf = array( 864.567, 1292.598); break;}
2519 // Common Newspaper Sizes
2520 case 'NEWSPAPER_BROADSHEET': {$pf = array( 2125.984, 1700.787); break;}
2521 case 'NEWSPAPER_BERLINER' : {$pf = array( 1332.283, 892.913); break;}
2522 case 'NEWSPAPER_TABLOID':
2523 case 'NEWSPAPER_COMPACT' : {$pf = array( 1218.898, 793.701); break;}
2526 case 'BUSINESS_CARD':
2527 case 'BUSINESS_CARD_ISO7810': {$pf = array( 153.014, 242.646); break;}
2528 case 'BUSINESS_CARD_ISO216' : {$pf = array( 147.402, 209.764); break;}
2529 case 'BUSINESS_CARD_IT':
2530 case 'BUSINESS_CARD_UK':
2531 case 'BUSINESS_CARD_FR':
2532 case 'BUSINESS_CARD_DE':
2533 case 'BUSINESS_CARD_ES' : {$pf = array( 155.906, 240.945); break;}
2534 case 'BUSINESS_CARD_CA':
2535 case 'BUSINESS_CARD_US' : {$pf = array( 144.567, 252.283); break;}
2536 case 'BUSINESS_CARD_JP' : {$pf = array( 155.906, 257.953); break;}
2537 case 'BUSINESS_CARD_HK' : {$pf = array( 153.071, 255.118); break;}
2538 case 'BUSINESS_CARD_AU':
2539 case 'BUSINESS_CARD_DK':
2540 case 'BUSINESS_CARD_SE' : {$pf = array( 155.906, 255.118); break;}
2541 case 'BUSINESS_CARD_RU':
2542 case 'BUSINESS_CARD_CZ':
2543 case 'BUSINESS_CARD_FI':
2544 case 'BUSINESS_CARD_HU':
2545 case 'BUSINESS_CARD_IL' : {$pf = array( 141.732, 255.118); break;}
2547 case '4SHEET' : {$pf = array( 2880.000, 4320.000); break;}
2548 case '6SHEET' : {$pf = array( 3401.575, 5102.362); break;}
2549 case '12SHEET': {$pf = array( 8640.000, 4320.000); break;}
2550 case '16SHEET': {$pf = array( 5760.000, 8640.000); break;}
2551 case '32SHEET': {$pf = array(11520.000, 8640.000); break;}
2552 case '48SHEET': {$pf = array(17280.000, 8640.000); break;}
2553 case '64SHEET': {$pf = array(23040.000, 8640.000); break;}
2554 case '96SHEET': {$pf = array(34560.000, 8640.000); break;}
2555 // Old European Sizes
2556 // - Old Imperial English Sizes
2557 case 'EN_EMPEROR' : {$pf = array( 3456.000, 5184.000); break;}
2558 case 'EN_ANTIQUARIAN' : {$pf = array( 2232.000, 3816.000); break;}
2559 case 'EN_GRAND_EAGLE' : {$pf = array( 2070.000, 3024.000); break;}
2560 case 'EN_DOUBLE_ELEPHANT' : {$pf = array( 1926.000, 2880.000); break;}
2561 case 'EN_ATLAS' : {$pf = array( 1872.000, 2448.000); break;}
2562 case 'EN_COLOMBIER' : {$pf = array( 1692.000, 2484.000); break;}
2563 case 'EN_ELEPHANT' : {$pf = array( 1656.000, 2016.000); break;}
2564 case 'EN_DOUBLE_DEMY' : {$pf = array( 1620.000, 2556.000); break;}
2565 case 'EN_IMPERIAL' : {$pf = array( 1584.000, 2160.000); break;}
2566 case 'EN_PRINCESS' : {$pf = array( 1548.000, 2016.000); break;}
2567 case 'EN_CARTRIDGE' : {$pf = array( 1512.000, 1872.000); break;}
2568 case 'EN_DOUBLE_LARGE_POST': {$pf = array( 1512.000, 2376.000); break;}
2569 case 'EN_ROYAL' : {$pf = array( 1440.000, 1800.000); break;}
2571 case 'EN_HALF_POST' : {$pf = array( 1404.000, 1692.000); break;}
2572 case 'EN_SUPER_ROYAL' : {$pf = array( 1368.000, 1944.000); break;}
2573 case 'EN_DOUBLE_POST' : {$pf = array( 1368.000, 2196.000); break;}
2574 case 'EN_MEDIUM' : {$pf = array( 1260.000, 1656.000); break;}
2575 case 'EN_DEMY' : {$pf = array( 1260.000, 1620.000); break;}
2576 case 'EN_LARGE_POST' : {$pf = array( 1188.000, 1512.000); break;}
2577 case 'EN_COPY_DRAUGHT' : {$pf = array( 1152.000, 1440.000); break;}
2578 case 'EN_POST' : {$pf = array( 1116.000, 1386.000); break;}
2579 case 'EN_CROWN' : {$pf = array( 1080.000, 1440.000); break;}
2580 case 'EN_PINCHED_POST' : {$pf = array( 1062.000, 1332.000); break;}
2581 case 'EN_BRIEF' : {$pf = array( 972.000, 1152.000); break;}
2582 case 'EN_FOOLSCAP' : {$pf = array( 972.000, 1224.000); break;}
2583 case 'EN_SMALL_FOOLSCAP' : {$pf = array( 954.000, 1188.000); break;}
2584 case 'EN_POTT' : {$pf = array( 900.000, 1080.000); break;}
2585 // - Old Imperial Belgian Sizes
2586 case 'BE_GRAND_AIGLE' : {$pf = array( 1984.252, 2948.031); break;}
2587 case 'BE_COLOMBIER' : {$pf = array( 1757.480, 2409.449); break;}
2588 case 'BE_DOUBLE_CARRE': {$pf = array( 1757.480, 2607.874); break;}
2589 case 'BE_ELEPHANT' : {$pf = array( 1746.142, 2182.677); break;}
2590 case 'BE_PETIT_AIGLE' : {$pf = array( 1700.787, 2381.102); break;}
2591 case 'BE_GRAND_JESUS' : {$pf = array( 1559.055, 2069.291); break;}
2592 case 'BE_JESUS' : {$pf = array( 1530.709, 2069.291); break;}
2593 case 'BE_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
2594 case 'BE_GRAND_MEDIAN': {$pf = array( 1303.937, 1714.961); break;}
2595 case 'BE_DOUBLE_POSTE': {$pf = array( 1233.071, 1601.575); break;}
2596 case 'BE_COQUILLE' : {$pf = array( 1218.898, 1587.402); break;}
2597 case 'BE_PETIT_MEDIAN': {$pf = array( 1176.378, 1502.362); break;}
2598 case 'BE_RUCHE' : {$pf = array( 1020.472, 1303.937); break;}
2599 case 'BE_PROPATRIA' : {$pf = array( 977.953, 1218.898); break;}
2600 case 'BE_LYS' : {$pf = array( 898.583, 1125.354); break;}
2601 case 'BE_POT' : {$pf = array( 870.236, 1088.504); break;}
2602 case 'BE_ROSETTE' : {$pf = array( 765.354, 983.622); break;}
2603 // - Old Imperial French Sizes
2604 case 'FR_UNIVERS' : {$pf = array( 2834.646, 3685.039); break;}
2605 case 'FR_DOUBLE_COLOMBIER' : {$pf = array( 2551.181, 3571.654); break;}
2606 case 'FR_GRANDE_MONDE' : {$pf = array( 2551.181, 3571.654); break;}
2607 case 'FR_DOUBLE_SOLEIL' : {$pf = array( 2267.717, 3401.575); break;}
2608 case 'FR_DOUBLE_JESUS' : {$pf = array( 2154.331, 3174.803); break;}
2609 case 'FR_GRAND_AIGLE' : {$pf = array( 2125.984, 3004.724); break;}
2610 case 'FR_PETIT_AIGLE' : {$pf = array( 1984.252, 2664.567); break;}
2611 case 'FR_DOUBLE_RAISIN' : {$pf = array( 1842.520, 2834.646); break;}
2612 case 'FR_JOURNAL' : {$pf = array( 1842.520, 2664.567); break;}
2613 case 'FR_COLOMBIER_AFFICHE': {$pf = array( 1785.827, 2551.181); break;}
2614 case 'FR_DOUBLE_CAVALIER' : {$pf = array( 1757.480, 2607.874); break;}
2615 case 'FR_CLOCHE' : {$pf = array( 1700.787, 2267.717); break;}
2616 case 'FR_SOLEIL' : {$pf = array( 1700.787, 2267.717); break;}
2617 case 'FR_DOUBLE_CARRE' : {$pf = array( 1587.402, 2551.181); break;}
2618 case 'FR_DOUBLE_COQUILLE' : {$pf = array( 1587.402, 2494.488); break;}
2619 case 'FR_JESUS' : {$pf = array( 1587.402, 2154.331); break;}
2620 case 'FR_RAISIN' : {$pf = array( 1417.323, 1842.520); break;}
2621 case 'FR_CAVALIER' : {$pf = array( 1303.937, 1757.480); break;}
2622 case 'FR_DOUBLE_COURONNE' : {$pf = array( 1303.937, 2040.945); break;}
2623 case 'FR_CARRE' : {$pf = array( 1275.591, 1587.402); break;}
2624 case 'FR_COQUILLE' : {$pf = array( 1247.244, 1587.402); break;}
2625 case 'FR_DOUBLE_TELLIERE' : {$pf = array( 1247.244, 1927.559); break;}
2626 case 'FR_DOUBLE_CLOCHE' : {$pf = array( 1133.858, 1700.787); break;}
2627 case 'FR_DOUBLE_POT' : {$pf = array( 1133.858, 1757.480); break;}
2628 case 'FR_ECU' : {$pf = array( 1133.858, 1474.016); break;}
2629 case 'FR_COURONNE' : {$pf = array( 1020.472, 1303.937); break;}
2630 case 'FR_TELLIERE' : {$pf = array( 963.780, 1247.244); break;}
2631 case 'FR_POT' : {$pf = array( 878.740, 1133.858); break;}
2633 default: {$pf = array( 595.276, 841.890); break;}
2639 * Change the format of the current page
2640 * @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 numners (width, height) or an array containing the following measures and options:<ul>
2641 * <li>['format'] = page format name (one of the above);</li>
2642 * <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>
2643 * <li>['PZ'] : The page's preferred zoom (magnification) factor.</li>
2644 * <li>['MediaBox'] : the boundaries of the physical medium on which the page shall be displayed or printed:</li>
2645 * <li>['MediaBox']['llx'] : lower-left x coordinate in points</li>
2646 * <li>['MediaBox']['lly'] : lower-left y coordinate in points</li>
2647 * <li>['MediaBox']['urx'] : upper-right x coordinate in points</li>
2648 * <li>['MediaBox']['ury'] : upper-right y coordinate in points</li>
2649 * <li>['CropBox'] : the visible region of default user space:</li>
2650 * <li>['CropBox']['llx'] : lower-left x coordinate in points</li>
2651 * <li>['CropBox']['lly'] : lower-left y coordinate in points</li>
2652 * <li>['CropBox']['urx'] : upper-right x coordinate in points</li>
2653 * <li>['CropBox']['ury'] : upper-right y coordinate in points</li>
2654 * <li>['BleedBox'] : the region to which the contents of the page shall be clipped when output in a production environment:</li>
2655 * <li>['BleedBox']['llx'] : lower-left x coordinate in points</li>
2656 * <li>['BleedBox']['lly'] : lower-left y coordinate in points</li>
2657 * <li>['BleedBox']['urx'] : upper-right x coordinate in points</li>
2658 * <li>['BleedBox']['ury'] : upper-right y coordinate in points</li>
2659 * <li>['TrimBox'] : the intended dimensions of the finished page after trimming:</li>
2660 * <li>['TrimBox']['llx'] : lower-left x coordinate in points</li>
2661 * <li>['TrimBox']['lly'] : lower-left y coordinate in points</li>
2662 * <li>['TrimBox']['urx'] : upper-right x coordinate in points</li>
2663 * <li>['TrimBox']['ury'] : upper-right y coordinate in points</li>
2664 * <li>['ArtBox'] : the extent of the page's meaningful content:</li>
2665 * <li>['ArtBox']['llx'] : lower-left x coordinate in points</li>
2666 * <li>['ArtBox']['lly'] : lower-left y coordinate in points</li>
2667 * <li>['ArtBox']['urx'] : upper-right x coordinate in points</li>
2668 * <li>['ArtBox']['ury'] : upper-right y coordinate in points</li>
2669 * <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>
2670 * <li>['BoxColorInfo'][BOXTYPE]['C'] : an array of three numbers in the range 0-255, representing the components in the DeviceRGB colour space.</li>
2671 * <li>['BoxColorInfo'][BOXTYPE]['W'] : the guideline width in default user units</li>
2672 * <li>['BoxColorInfo'][BOXTYPE]['S'] : the guideline style: S = Solid; D = Dashed</li>
2673 * <li>['BoxColorInfo'][BOXTYPE]['D'] : dash array defining a pattern of dashes and gaps to be used in drawing dashed guidelines</li>
2674 * <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>
2675 * <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>
2676 * <li>['trans']['S'] : transition style : Split, Blinds, Box, Wipe, Dissolve, Glitter, R, Fly, Push, Cover, Uncover, Fade</li>
2677 * <li>['trans']['D'] : The duration of the transition effect, in seconds.</li>
2678 * <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>
2679 * <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>
2680 * <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>
2681 * <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>
2682 * <li>['trans']['B'] : (Fly transition style only) If true, the area that shall be flown in is rectangular and opaque. Default: false.</li>
2684 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul>
2685 * <li>P or Portrait (default)</li>
2686 * <li>L or Landscape</li>
2687 * <li>'' (empty string) for automatic orientation</li>
2690 * @since 3.0.015 (2008-06-06)
2691 * @see getPageSizeFromFormat()
2693 protected function setPageFormat($format, $orientation='P') {
2694 if (!empty($format) AND isset($this->pagedim
[$this->page
])) {
2695 // remove inherited values
2696 unset($this->pagedim
[$this->page
]);
2698 if (is_string($format)) {
2699 // get page measures from format name
2700 $pf = $this->getPageSizeFromFormat($format);
2701 $this->fwPt
= $pf[0];
2702 $this->fhPt
= $pf[1];
2704 // the boundaries of the physical medium on which the page shall be displayed or printed
2705 if (isset($format['MediaBox'])) {
2706 $this->setPageBoxes($this->page
, 'MediaBox', $format['MediaBox']['llx'], $format['MediaBox']['lly'], $format['MediaBox']['urx'], $format['MediaBox']['ury'], false);
2707 $this->fwPt
= (($format['MediaBox']['urx'] - $format['MediaBox']['llx']) * $this->k
);
2708 $this->fhPt
= (($format['MediaBox']['ury'] - $format['MediaBox']['lly']) * $this->k
);
2710 if (isset($format[0]) AND is_numeric($format[0]) AND isset($format[1]) AND is_numeric($format[1])) {
2711 $pf = array(($format[0] * $this->k
), ($format[1] * $this->k
));
2713 if (!isset($format['format'])) {
2715 $format['format'] = 'A4';
2717 $pf = $this->getPageSizeFromFormat($format['format']);
2719 $this->fwPt
= $pf[0];
2720 $this->fhPt
= $pf[1];
2721 $this->setPageBoxes($this->page
, 'MediaBox', 0, 0, $this->fwPt
, $this->fhPt
, true);
2723 // the visible region of default user space
2724 if (isset($format['CropBox'])) {
2725 $this->setPageBoxes($this->page
, 'CropBox', $format['CropBox']['llx'], $format['CropBox']['lly'], $format['CropBox']['urx'], $format['CropBox']['ury'], false);
2727 // the region to which the contents of the page shall be clipped when output in a production environment
2728 if (isset($format['BleedBox'])) {
2729 $this->setPageBoxes($this->page
, 'BleedBox', $format['BleedBox']['llx'], $format['BleedBox']['lly'], $format['BleedBox']['urx'], $format['BleedBox']['ury'], false);
2731 // the intended dimensions of the finished page after trimming
2732 if (isset($format['TrimBox'])) {
2733 $this->setPageBoxes($this->page
, 'TrimBox', $format['TrimBox']['llx'], $format['TrimBox']['lly'], $format['TrimBox']['urx'], $format['TrimBox']['ury'], false);
2735 // the page's meaningful content (including potential white space)
2736 if (isset($format['ArtBox'])) {
2737 $this->setPageBoxes($this->page
, 'ArtBox', $format['ArtBox']['llx'], $format['ArtBox']['lly'], $format['ArtBox']['urx'], $format['ArtBox']['ury'], false);
2739 // specify the colours and other visual characteristics that should be used in displaying guidelines on the screen for the various page boundaries
2740 if (isset($format['BoxColorInfo'])) {
2741 $this->pagedim
[$this->page
]['BoxColorInfo'] = $format['BoxColorInfo'];
2743 if (isset($format['Rotate']) AND (($format['Rotate'] %
90) == 0)) {
2744 // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
2745 $this->pagedim
[$this->page
]['Rotate'] = intval($format['Rotate']);
2747 if (isset($format['PZ'])) {
2748 // The page's preferred zoom (magnification) factor
2749 $this->pagedim
[$this->page
]['PZ'] = floatval($format['PZ']);
2751 if (isset($format['trans'])) {
2752 // The style and duration of the visual transition to use when moving from another page to the given page during a presentation
2753 if (isset($format['trans']['Dur'])) {
2754 // The page's display duration
2755 $this->pagedim
[$this->page
]['trans']['Dur'] = floatval($format['trans']['Dur']);
2757 $stansition_styles = array('Split', 'Blinds', 'Box', 'Wipe', 'Dissolve', 'Glitter', 'R', 'Fly', 'Push', 'Cover', 'Uncover', 'Fade');
2758 if (isset($format['trans']['S']) AND in_array($format['trans']['S'], $stansition_styles)) {
2759 // The transition style that shall be used when moving to this page from another during a presentation
2760 $this->pagedim
[$this->page
]['trans']['S'] = $format['trans']['S'];
2761 $valid_effect = array('Split', 'Blinds');
2762 $valid_vals = array('H', 'V');
2763 if (isset($format['trans']['Dm']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['Dm'], $valid_vals)) {
2764 $this->pagedim
[$this->page
]['trans']['Dm'] = $format['trans']['Dm'];
2766 $valid_effect = array('Split', 'Box', 'Fly');
2767 $valid_vals = array('I', 'O');
2768 if (isset($format['trans']['M']) AND in_array($format['trans']['S'], $valid_effect) AND in_array($format['trans']['M'], $valid_vals)) {
2769 $this->pagedim
[$this->page
]['trans']['M'] = $format['trans']['M'];
2771 $valid_effect = array('Wipe', 'Glitter', 'Fly', 'Cover', 'Uncover', 'Push');
2772 if (isset($format['trans']['Di']) AND in_array($format['trans']['S'], $valid_effect)) {
2773 if (((($format['trans']['Di'] == 90) OR ($format['trans']['Di'] == 180)) AND ($format['trans']['S'] == 'Wipe'))
2774 OR (($format['trans']['Di'] == 315) AND ($format['trans']['S'] == 'Glitter'))
2775 OR (($format['trans']['Di'] == 0) OR ($format['trans']['Di'] == 270))) {
2776 $this->pagedim
[$this->page
]['trans']['Di'] = intval($format['trans']['Di']);
2779 if (isset($format['trans']['SS']) AND ($format['trans']['S'] == 'Fly')) {
2780 $this->pagedim
[$this->page
]['trans']['SS'] = floatval($format['trans']['SS']);
2782 if (isset($format['trans']['B']) AND ($format['trans']['B'] === true) AND ($format['trans']['S'] == 'Fly')) {
2783 $this->pagedim
[$this->page
]['trans']['B'] = 'true';
2786 $this->pagedim
[$this->page
]['trans']['S'] = 'R';
2788 if (isset($format['trans']['D'])) {
2789 // The duration of the transition effect, in seconds
2790 $this->pagedim
[$this->page
]['trans']['D'] = floatval($format['trans']['D']);
2792 $this->pagedim
[$this->page
]['trans']['D'] = 1;
2796 $this->setPageOrientation($orientation);
2800 * Set page boundaries.
2801 * @param $page (int) page number
2802 * @param $type (string) valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
2803 * @param $llx (float) lower-left x coordinate in user units
2804 * @param $lly (float) lower-left y coordinate in user units
2805 * @param $urx (float) upper-right x coordinate in user units
2806 * @param $ury (float) upper-right y coordinate in user units
2807 * @param $points (boolean) if true uses user units as unit of measure, otherwise uses PDF points
2809 * @since 5.0.010 (2010-05-17)
2811 public function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false) {
2812 if (!isset($this->pagedim
[$page])) {
2814 $this->pagedim
[$page] = array();
2816 $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
2817 if (!in_array($type, $pageboxes)) {
2825 $this->pagedim
[$page][$type]['llx'] = ($llx * $k);
2826 $this->pagedim
[$page][$type]['lly'] = ($lly * $k);
2827 $this->pagedim
[$page][$type]['urx'] = ($urx * $k);
2828 $this->pagedim
[$page][$type]['ury'] = ($ury * $k);
2832 * Swap X and Y coordinates of page boxes (change page boxes orientation).
2833 * @param $page (int) page number
2835 * @since 5.0.010 (2010-05-17)
2837 protected function swapPageBoxCoordinates($page) {
2838 $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
2839 foreach ($pageboxes as $type) {
2840 // swap X and Y coordinates
2841 if (isset($this->pagedim
[$page][$type])) {
2842 $tmp = $this->pagedim
[$page][$type]['llx'];
2843 $this->pagedim
[$page][$type]['llx'] = $this->pagedim
[$page][$type]['lly'];
2844 $this->pagedim
[$page][$type]['lly'] = $tmp;
2845 $tmp = $this->pagedim
[$page][$type]['urx'];
2846 $this->pagedim
[$page][$type]['urx'] = $this->pagedim
[$page][$type]['ury'];
2847 $this->pagedim
[$page][$type]['ury'] = $tmp;
2853 * Set page orientation.
2854 * @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>
2855 * @param $autopagebreak (boolean) Boolean indicating if auto-page-break mode should be on or off.
2856 * @param $bottommargin (float) bottom margin of the page.
2858 * @since 3.0.015 (2008-06-06)
2860 public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
2861 if (!isset($this->pagedim
[$this->page
]['MediaBox'])) {
2862 // the boundaries of the physical medium on which the page shall be displayed or printed
2863 $this->setPageBoxes($this->page
, 'MediaBox', 0, 0, $this->fwPt
, $this->fhPt
, true);
2865 if (!isset($this->pagedim
[$this->page
]['CropBox'])) {
2866 // the visible region of default user space
2867 $this->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);
2869 if (!isset($this->pagedim
[$this->page
]['BleedBox'])) {
2870 // the region to which the contents of the page shall be clipped when output in a production environment
2871 $this->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);
2873 if (!isset($this->pagedim
[$this->page
]['TrimBox'])) {
2874 // the intended dimensions of the finished page after trimming
2875 $this->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);
2877 if (!isset($this->pagedim
[$this->page
]['ArtBox'])) {
2878 // the page's meaningful content (including potential white space)
2879 $this->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);
2881 if (!isset($this->pagedim
[$this->page
]['Rotate'])) {
2882 // The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90.
2883 $this->pagedim
[$this->page
]['Rotate'] = 0;
2885 if (!isset($this->pagedim
[$this->page
]['PZ'])) {
2886 // The page's preferred zoom (magnification) factor
2887 $this->pagedim
[$this->page
]['PZ'] = 1;
2889 if ($this->fwPt
> $this->fhPt
) {
2891 $default_orientation = 'L';
2894 $default_orientation = 'P';
2896 $valid_orientations = array('P', 'L');
2897 if (empty($orientation)) {
2898 $orientation = $default_orientation;
2900 $orientation = strtoupper($orientation{0});
2902 if (in_array($orientation, $valid_orientations) AND ($orientation != $default_orientation)) {
2903 $this->CurOrientation
= $orientation;
2904 $this->wPt
= $this->fhPt
;
2905 $this->hPt
= $this->fwPt
;
2907 $this->CurOrientation
= $default_orientation;
2908 $this->wPt
= $this->fwPt
;
2909 $this->hPt
= $this->fhPt
;
2911 if ((abs($this->pagedim
[$this->page
]['MediaBox']['urx'] - $this->hPt
) < $this->feps
) AND (abs($this->pagedim
[$this->page
]['MediaBox']['ury'] - $this->wPt
) < $this->feps
)){
2912 // swap X and Y coordinates (change page orientation)
2913 $this->swapPageBoxCoordinates($this->page
);
2915 $this->w
= $this->wPt
/ $this->k
;
2916 $this->h
= $this->hPt
/ $this->k
;
2917 if ($this->empty_string($autopagebreak)) {
2918 if (isset($this->AutoPageBreak
)) {
2919 $autopagebreak = $this->AutoPageBreak
;
2921 $autopagebreak = true;
2924 if ($this->empty_string($bottommargin)) {
2925 if (isset($this->bMargin
)) {
2926 $bottommargin = $this->bMargin
;
2928 // default value = 2 cm
2929 $bottommargin = 2 * 28.35 / $this->k
;
2932 $this->SetAutoPageBreak($autopagebreak, $bottommargin);
2933 // store page dimensions
2934 $this->pagedim
[$this->page
]['w'] = $this->wPt
;
2935 $this->pagedim
[$this->page
]['h'] = $this->hPt
;
2936 $this->pagedim
[$this->page
]['wk'] = $this->w
;
2937 $this->pagedim
[$this->page
]['hk'] = $this->h
;
2938 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
2939 $this->pagedim
[$this->page
]['bm'] = $bottommargin;
2940 $this->pagedim
[$this->page
]['lm'] = $this->lMargin
;
2941 $this->pagedim
[$this->page
]['rm'] = $this->rMargin
;
2942 $this->pagedim
[$this->page
]['pb'] = $autopagebreak;
2943 $this->pagedim
[$this->page
]['or'] = $this->CurOrientation
;
2944 $this->pagedim
[$this->page
]['olm'] = $this->original_lMargin
;
2945 $this->pagedim
[$this->page
]['orm'] = $this->original_rMargin
;
2949 * Set regular expression to detect withespaces or word separators.
2950 * The pattern delimiter must be the forward-slash character "/".
2951 * Some example patterns are:
2953 * Non-Unicode or missing PCRE unicode support: "/[^\S\xa0]/"
2954 * Unicode and PCRE unicode support: "/[^\S\P{Z}\xa0]/u"
2955 * Unicode and PCRE unicode support in Chinese mode: "/[^\S\P{Z}\P{Lo}\xa0]/u"
2956 * if PCRE unicode support is turned ON ("\P" is the negate class of "\p"):
2957 * "\p{Z}" or "\p{Separator}": any kind of Unicode whitespace or invisible separator.
2958 * "\p{Lo}" or "\p{Other_Letter}": a Unicode letter or ideograph that does not have lowercase and uppercase variants.
2959 * "\p{Lo}" is needed for Chinese characters because are packed next to each other without spaces in between.
2961 * @param $re (string) regular expression (leave empty for default).
2963 * @since 4.6.016 (2009-06-15)
2965 public function setSpacesRE($re='/[^\S\xa0]/') {
2966 $this->re_spaces
= $re;
2967 $re_parts = explode('/', $re);
2968 // get pattern parts
2969 $this->re_space
= array();
2970 if (isset($re_parts[1]) AND !empty($re_parts[1])) {
2971 $this->re_space
['p'] = $re_parts[1];
2973 $this->re_space
['p'] = '[\s]';
2975 // set pattern modifiers
2976 if (isset($re_parts[2]) AND !empty($re_parts[2])) {
2977 $this->re_space
['m'] = $re_parts[2];
2979 $this->re_space
['m'] = '';
2984 * Enable or disable Right-To-Left language mode
2985 * @param $enable (Boolean) if true enable Right-To-Left language mode.
2986 * @param $resetx (Boolean) if true reset the X position on direction change.
2988 * @since 2.0.000 (2008-01-03)
2990 public function setRTL($enable, $resetx=true) {
2991 $enable = $enable ?
true : false;
2992 $resetx = ($resetx AND ($enable != $this->rtl
));
2993 $this->rtl
= $enable;
2994 $this->tmprtl
= false;
3001 * Return the RTL status
3004 * @since 4.0.012 (2008-07-24)
3006 public function getRTL() {
3011 * Force temporary RTL language direction
3012 * @param $mode (mixed) can be false, 'L' for LTR or 'R' for RTL
3014 * @since 2.1.000 (2008-01-09)
3016 public function setTempRTL($mode) {
3018 switch (strtoupper($mode)) {
3039 $this->tmprtl
= $newmode;
3043 * Return the current temporary RTL status
3046 * @since 4.8.014 (2009-11-04)
3048 public function isRTLTextDir() {
3049 return ($this->rtl
OR ($this->tmprtl
== 'R'));
3053 * Set the last cell height.
3054 * @param $h (float) cell height.
3055 * @author Nicola Asuni
3057 * @since 1.53.0.TC034
3059 public function setLastH($h) {
3064 * Reset the last cell height.
3066 * @since 5.9.000 (2010-10-03)
3068 public function resetLastH() {
3069 $this->lasth
= ($this->FontSize
* $this->cell_height_ratio
) +
$this->cell_padding
['T'] +
$this->cell_padding
['B'];
3073 * Get the last cell height.
3074 * @return last cell height
3076 * @since 4.0.017 (2008-08-05)
3078 public function getLastH() {
3079 return $this->lasth
;
3083 * Set the adjusting factor to convert pixels to user units.
3084 * @param $scale (float) adjusting factor to convert pixels to user units.
3085 * @author Nicola Asuni
3089 public function setImageScale($scale) {
3090 $this->imgscale
= $scale;
3094 * Returns the adjusting factor to convert pixels to user units.
3095 * @return float adjusting factor to convert pixels to user units.
3096 * @author Nicola Asuni
3100 public function getImageScale() {
3101 return $this->imgscale
;
3105 * Returns an array of page dimensions:
3106 * <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>
3107 * @param $pagenum (int) page number (empty = current page)
3108 * @return array of page dimensions.
3109 * @author Nicola Asuni
3111 * @since 4.5.027 (2009-03-16)
3113 public function getPageDimensions($pagenum='') {
3114 if (empty($pagenum)) {
3115 $pagenum = $this->page
;
3117 return $this->pagedim
[$pagenum];
3121 * Returns the page width in units.
3122 * @param $pagenum (int) page number (empty = current page)
3123 * @return int page width.
3124 * @author Nicola Asuni
3127 * @see getPageDimensions()
3129 public function getPageWidth($pagenum='') {
3130 if (empty($pagenum)) {
3133 return $this->pagedim
[$pagenum]['w'];
3137 * Returns the page height in units.
3138 * @param $pagenum (int) page number (empty = current page)
3139 * @return int page height.
3140 * @author Nicola Asuni
3143 * @see getPageDimensions()
3145 public function getPageHeight($pagenum='') {
3146 if (empty($pagenum)) {
3149 return $this->pagedim
[$pagenum]['h'];
3153 * Returns the page break margin.
3154 * @param $pagenum (int) page number (empty = current page)
3155 * @return int page break margin.
3156 * @author Nicola Asuni
3159 * @see getPageDimensions()
3161 public function getBreakMargin($pagenum='') {
3162 if (empty($pagenum)) {
3163 return $this->bMargin
;
3165 return $this->pagedim
[$pagenum]['bm'];
3169 * Returns the scale factor (number of points in user unit).
3170 * @return int scale factor.
3171 * @author Nicola Asuni
3175 public function getScaleFactor() {
3180 * Defines the left, top and right margins.
3181 * @param $left (float) Left margin.
3182 * @param $top (float) Top margin.
3183 * @param $right (float) Right margin. Default value is the left one.
3184 * @param $keepmargins (boolean) if true overwrites the default page margins
3187 * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
3189 public function SetMargins($left, $top, $right=-1, $keepmargins=false) {
3190 //Set left, top and right margins
3191 $this->lMargin
= $left;
3192 $this->tMargin
= $top;
3196 $this->rMargin
= $right;
3198 // overwrite original values
3199 $this->original_lMargin
= $this->lMargin
;
3200 $this->original_rMargin
= $this->rMargin
;
3205 * 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.
3206 * @param $margin (float) The margin.
3209 * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
3211 public function SetLeftMargin($margin) {
3213 $this->lMargin
= $margin;
3214 if (($this->page
> 0) AND ($this->x
< $margin)) {
3220 * Defines the top margin. The method can be called before creating the first page.
3221 * @param $margin (float) The margin.
3224 * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
3226 public function SetTopMargin($margin) {
3228 $this->tMargin
= $margin;
3229 if (($this->page
> 0) AND ($this->y
< $margin)) {
3235 * Defines the right margin. The method can be called before creating the first page.
3236 * @param $margin (float) The margin.
3239 * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
3241 public function SetRightMargin($margin) {
3242 $this->rMargin
= $margin;
3243 if (($this->page
> 0) AND ($this->x
> ($this->w
- $margin))) {
3244 $this->x
= $this->w
- $margin;
3249 * Set the same internal Cell padding for top, right, bottom, left-
3250 * @param $pad (float) internal padding.
3252 * @since 2.1.000 (2008-01-09)
3253 * @see getCellPaddings(), setCellPaddings()
3255 public function SetCellPadding($pad) {
3257 $this->cell_padding
['L'] = $pad;
3258 $this->cell_padding
['T'] = $pad;
3259 $this->cell_padding
['R'] = $pad;
3260 $this->cell_padding
['B'] = $pad;
3265 * Set the internal Cell paddings.
3266 * @param $left (float) left padding
3267 * @param $top (float) top padding
3268 * @param $right (float) right padding
3269 * @param $bottom (float) bottom padding
3271 * @since 5.9.000 (2010-10-03)
3272 * @see getCellPaddings(), SetCellPadding()
3274 public function setCellPaddings($left='', $top='', $right='', $bottom='') {
3275 if (($left !== '') AND ($left >= 0)) {
3276 $this->cell_padding
['L'] = $left;
3278 if (($top !== '') AND ($top >= 0)) {
3279 $this->cell_padding
['T'] = $top;
3281 if (($right !== '') AND ($right >= 0)) {
3282 $this->cell_padding
['R'] = $right;
3284 if (($bottom !== '') AND ($bottom >= 0)) {
3285 $this->cell_padding
['B'] = $bottom;
3290 * Get the internal Cell padding array.
3291 * @return array of padding values
3293 * @since 5.9.000 (2010-10-03)
3294 * @see setCellPaddings(), SetCellPadding()
3296 public function getCellPaddings() {
3297 return $this->cell_padding
;
3301 * Set the internal Cell margins.
3302 * @param $left (float) left margin
3303 * @param $top (float) top margin
3304 * @param $right (float) right margin
3305 * @param $bottom (float) bottom margin
3307 * @since 5.9.000 (2010-10-03)
3308 * @see getCellMargins()
3310 public function setCellMargins($left='', $top='', $right='', $bottom='') {
3311 if (($left !== '') AND ($left >= 0)) {
3312 $this->cell_margin
['L'] = $left;
3314 if (($top !== '') AND ($top >= 0)) {
3315 $this->cell_margin
['T'] = $top;
3317 if (($right !== '') AND ($right >= 0)) {
3318 $this->cell_margin
['R'] = $right;
3320 if (($bottom !== '') AND ($bottom >= 0)) {
3321 $this->cell_margin
['B'] = $bottom;
3326 * Get the internal Cell margin array.
3327 * @return array of margin values
3329 * @since 5.9.000 (2010-10-03)
3330 * @see setCellMargins()
3332 public function getCellMargins() {
3333 return $this->cell_margin
;
3337 * Adjust the internal Cell padding array to take account of the line width.
3338 * @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)))
3339 * @return array of adjustments
3341 * @since 5.9.000 (2010-10-03)
3343 protected function adjustCellPadding($brd=0) {
3347 if (is_string($brd)) {
3348 // convert string to array
3349 $slen = strlen($brd);
3351 for ($i = 0; $i < $slen; ++
$i) {
3352 $newbrd[$brd{$i}] = true;
3355 } elseif (($brd === 1) OR ($brd === true) OR (is_numeric($brd) AND (intval($brd) > 0))) {
3356 $brd = array('LRTB' => true);
3358 if (!is_array($brd)) {
3361 // store current cell padding
3362 $cp = $this->cell_padding
;
3363 // select border mode
3364 if (isset($brd['mode'])) {
3365 $mode = $brd['mode'];
3366 unset($brd['mode']);
3371 foreach ($brd as $border => $style) {
3372 $line_width = $this->LineWidth
;
3373 if (is_array($style) AND isset($style['width'])) {
3375 $line_width = $style['width'];
3377 $adj = 0; // line width inside the cell
3389 $adj = ($line_width / 2);
3393 // correct internal cell padding if required to avoid overlap between text and lines
3394 if ((strpos($border,'T') !== false) AND ($this->cell_padding
['T'] < $adj)) {
3395 $this->cell_padding
['T'] = $adj;
3397 if ((strpos($border,'R') !== false) AND ($this->cell_padding
['R'] < $adj)) {
3398 $this->cell_padding
['R'] = $adj;
3400 if ((strpos($border,'B') !== false) AND ($this->cell_padding
['B'] < $adj)) {
3401 $this->cell_padding
['B'] = $adj;
3403 if ((strpos($border,'L') !== false) AND ($this->cell_padding
['L'] < $adj)) {
3404 $this->cell_padding
['L'] = $adj;
3407 return array('T' => ($this->cell_padding
['T'] - $cp['T']), 'R' => ($this->cell_padding
['R'] - $cp['R']), 'B' => ($this->cell_padding
['B'] - $cp['B']), 'L' => ($this->cell_padding
['L'] - $cp['L']));
3411 * 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.
3412 * @param $auto (boolean) Boolean indicating if mode should be on or off.
3413 * @param $margin (float) Distance from the bottom of the page.
3416 * @see Cell(), MultiCell(), AcceptPageBreak()
3418 public function SetAutoPageBreak($auto, $margin=0) {
3419 $this->AutoPageBreak
= $auto;
3420 $this->bMargin
= $margin;
3421 $this->PageBreakTrigger
= $this->h
- $margin;
3425 * Defines the way the document is to be displayed by the viewer.
3426 * @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>
3427 * @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>
3428 * @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>
3432 public function SetDisplayMode($zoom, $layout='SinglePage', $mode='UseNone') {
3433 if (($zoom == 'fullpage') OR ($zoom == 'fullwidth') OR ($zoom == 'real') OR ($zoom == 'default') OR (!is_string($zoom))) {
3434 $this->ZoomMode
= $zoom;
3436 $this->Error('Incorrect zoom display mode: '.$zoom);
3441 case 'SinglePage': {
3442 $this->LayoutMode
= 'SinglePage';
3447 $this->LayoutMode
= 'OneColumn';
3451 case 'TwoColumnLeft': {
3452 $this->LayoutMode
= 'TwoColumnLeft';
3455 case 'TwoColumnRight': {
3456 $this->LayoutMode
= 'TwoColumnRight';
3459 case 'TwoPageLeft': {
3460 $this->LayoutMode
= 'TwoPageLeft';
3463 case 'TwoPageRight': {
3464 $this->LayoutMode
= 'TwoPageRight';
3468 $this->LayoutMode
= 'SinglePage';
3473 $this->PageMode
= 'UseNone';
3476 case 'UseOutlines': {
3477 $this->PageMode
= 'UseOutlines';
3481 $this->PageMode
= 'UseThumbs';
3484 case 'FullScreen': {
3485 $this->PageMode
= 'FullScreen';
3489 $this->PageMode
= 'UseOC';
3493 $this->PageMode
= 'UseAttachments';
3497 $this->PageMode
= 'UseNone';
3503 * 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.
3504 * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
3505 * @param $compress (boolean) Boolean indicating if compression must be enabled.
3509 public function SetCompression($compress) {
3510 if (function_exists('gzcompress')) {
3511 $this->compress
= $compress ?
true : false;
3513 $this->compress
= false;
3518 * Turn on/off Unicode mode for document information dictionary (meta tags).
3519 * This has effect only when unicode mode is set to false.
3520 * @param $unicode (boolean) if true set the meta information in Unicode
3521 * @since 5.9.027 (2010-12-01)
3524 public function SetDocInfoUnicode($unicode=true) {
3525 $this->docinfounicode
= $unicode ?
true : false;
3529 * Defines the title of the document.
3530 * @param $title (string) The title.
3533 * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
3535 public function SetTitle($title) {
3536 $this->title
= $title;
3540 * Defines the subject of the document.
3541 * @param $subject (string) The subject.
3544 * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
3546 public function SetSubject($subject) {
3547 $this->subject
= $subject;
3551 * Defines the author of the document.
3552 * @param $author (string) The name of the author.
3555 * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
3557 public function SetAuthor($author) {
3558 $this->author
= $author;
3562 * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
3563 * @param $keywords (string) The list of keywords.
3566 * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
3568 public function SetKeywords($keywords) {
3569 $this->keywords
= $keywords;
3573 * Defines the creator of the document. This is typically the name of the application that generates the PDF.
3574 * @param $creator (string) The name of the creator.
3577 * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
3579 public function SetCreator($creator) {
3580 $this->creator
= $creator;
3584 * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
3585 * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
3586 * @param $msg (string) The error message
3590 public function Error($msg) {
3591 // unset all class variables
3592 $this->_destroy(true);
3593 // exit program and print error
3594 die('<strong>TCPDF ERROR: </strong>'.$msg);
3598 * This method begins the generation of the PDF document.
3599 * It is not necessary to call it explicitly because AddPage() does it automatically.
3600 * Note: no page is created by this method
3603 * @see AddPage(), Close()
3605 public function Open() {
3610 * Terminates the PDF document.
3611 * It is not necessary to call this method explicitly because Output() does it automatically.
3612 * If the document contains no page, AddPage() is called to prevent from getting an invalid document.
3615 * @see Open(), Output()
3617 public function Close() {
3618 if ($this->state
== 3) {
3621 if ($this->page
== 0) {
3624 // save current graphic settings
3625 $gvars = $this->getGraphicVars();
3626 $this->setEqualColumns();
3627 $this->lastpage(true);
3628 $this->SetAutoPageBreak(false);
3630 $this->y
= $this->h
- (1 / $this->k
);
3633 $this->SetFont('helvetica', '', 1);
3634 $this->setTextRenderingMode(0, false, false);
3635 $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";
3636 $lnk = "\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67";
3637 $this->Cell(0, 0, $msg, 0, 0, 'L', 0, $lnk, 0, false, 'D', 'B');
3639 // restore graphic settings
3640 $this->setGraphicVars($gvars);
3645 // unset all class variables (except critical ones)
3646 $this->_destroy(false);
3650 * Move pointer at the specified document page and update page dimensions.
3651 * @param $pnum (int) page number (1 ... numpages)
3652 * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
3654 * @since 2.1.000 (2008-01-07)
3655 * @see getPage(), lastpage(), getNumPages()
3657 public function setPage($pnum, $resetmargins=false) {
3658 if (($pnum == $this->page
) AND ($this->state
== 2)) {
3661 if (($pnum > 0) AND ($pnum <= $this->numpages
)) {
3663 // save current graphic settings
3664 //$gvars = $this->getGraphicVars();
3665 $oldpage = $this->page
;
3666 $this->page
= $pnum;
3667 $this->wPt
= $this->pagedim
[$this->page
]['w'];
3668 $this->hPt
= $this->pagedim
[$this->page
]['h'];
3669 $this->w
= $this->pagedim
[$this->page
]['wk'];
3670 $this->h
= $this->pagedim
[$this->page
]['hk'];
3671 $this->tMargin
= $this->pagedim
[$this->page
]['tm'];
3672 $this->bMargin
= $this->pagedim
[$this->page
]['bm'];
3673 $this->original_lMargin
= $this->pagedim
[$this->page
]['olm'];
3674 $this->original_rMargin
= $this->pagedim
[$this->page
]['orm'];
3675 $this->AutoPageBreak
= $this->pagedim
[$this->page
]['pb'];
3676 $this->CurOrientation
= $this->pagedim
[$this->page
]['or'];
3677 $this->SetAutoPageBreak($this->AutoPageBreak
, $this->bMargin
);
3678 // restore graphic settings
3679 //$this->setGraphicVars($gvars);
3680 if ($resetmargins) {
3681 $this->lMargin
= $this->pagedim
[$this->page
]['olm'];
3682 $this->rMargin
= $this->pagedim
[$this->page
]['orm'];
3683 $this->SetY($this->tMargin
);
3685 // account for booklet mode
3686 if ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$oldpage]['olm']) {
3687 $deltam = $this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$this->page
]['orm'];
3688 $this->lMargin +
= $deltam;
3689 $this->rMargin
-= $deltam;
3693 $this->Error('Wrong page number on setPage() function: '.$pnum);
3698 * Reset pointer to the last document page.
3699 * @param $resetmargins (boolean) if true reset left, right, top margins and Y position.
3701 * @since 2.0.000 (2008-01-04)
3702 * @see setPage(), getPage(), getNumPages()
3704 public function lastPage($resetmargins=false) {
3705 $this->setPage($this->getNumPages(), $resetmargins);
3709 * Get current document page number.
3710 * @return int page number
3712 * @since 2.1.000 (2008-01-07)
3713 * @see setPage(), lastpage(), getNumPages()
3715 public function getPage() {
3720 * Get the total number of insered pages.
3721 * @return int number of pages
3723 * @since 2.1.000 (2008-01-07)
3724 * @see setPage(), getPage(), lastpage()
3726 public function getNumPages() {
3727 return $this->numpages
;
3731 * Adds a new TOC (Table Of Content) page to the document.
3732 * @param $orientation (string) page orientation.
3733 * @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().
3734 * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
3736 * @since 5.0.001 (2010-05-06)
3737 * @see AddPage(), startPage(), endPage(), endTOCPage()
3739 public function addTOCPage($orientation='', $format='', $keepmargins=false) {
3740 $this->AddPage($orientation, $format, $keepmargins, true);
3744 * Terminate the current TOC (Table Of Content) page
3746 * @since 5.0.001 (2010-05-06)
3747 * @see AddPage(), startPage(), endPage(), addTOCPage()
3749 public function endTOCPage() {
3750 $this->endPage(true);
3754 * 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).
3755 * The origin of the coordinate system is at the top-left corner (or top-right for RTL) and increasing ordinates go downwards.
3756 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
3757 * @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().
3758 * @param $keepmargins (boolean) if true overwrites the default page margins with the current margins
3759 * @param $tocpage (boolean) if true set the tocpage state to true (the added page will be used to display Table Of Content).
3762 * @see startPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
3764 public function AddPage($orientation='', $format='', $keepmargins=false, $tocpage=false) {
3765 if ($this->inxobj
) {
3766 // we are inside an XObject template
3769 if (!isset($this->original_lMargin
) OR $keepmargins) {
3770 $this->original_lMargin
= $this->lMargin
;
3772 if (!isset($this->original_rMargin
) OR $keepmargins) {
3773 $this->original_rMargin
= $this->rMargin
;
3775 // terminate previous page
3778 $this->startPage($orientation, $format, $tocpage);
3782 * Terminate the current page
3783 * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
3785 * @since 4.2.010 (2008-11-14)
3786 * @see AddPage(), startPage(), addTOCPage(), endTOCPage()
3788 public function endPage($tocpage=false) {
3789 // check if page is already closed
3790 if (($this->page
== 0) OR ($this->numpages
> $this->page
) OR (!$this->pageopen
[$this->page
])) {
3793 $this->InFooter
= true;
3794 // print page footer
3798 // mark page as closed
3799 $this->pageopen
[$this->page
] = false;
3800 $this->InFooter
= false;
3802 $this->tocpage
= false;
3807 * Starts a new page to the document. The page must be closed using the endPage() function.
3808 * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
3809 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
3810 * @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().
3811 * @param $tocpage (boolean) if true the page is designated to contain the Table-Of-Content.
3812 * @since 4.2.010 (2008-11-14)
3813 * @see AddPage(), endPage(), addTOCPage(), endTOCPage(), getPageSizeFromFormat(), setPageFormat()
3816 public function startPage($orientation='', $format='', $tocpage=false) {
3818 $this->tocpage
= true;
3820 if ($this->numpages
> $this->page
) {
3821 // this page has been already added
3822 $this->setPage($this->page +
1);
3823 $this->SetY($this->tMargin
);
3827 if ($this->state
== 0) {
3831 $this->swapMargins($this->booklet
);
3832 // save current graphic settings
3833 $gvars = $this->getGraphicVars();
3835 $this->_beginpage($orientation, $format);
3836 // mark page as open
3837 $this->pageopen
[$this->page
] = true;
3838 // restore graphic settings
3839 $this->setGraphicVars($gvars);
3841 $this->setPageMark();
3842 // print page header
3844 // restore graphic settings
3845 $this->setGraphicVars($gvars);
3847 $this->setPageMark();
3848 // print table header (if any)
3849 $this->setTableHeader();
3850 // set mark for empty page check
3851 $this->emptypagemrk
[$this->page
]= $this->pagelen
[$this->page
];
3855 * Set start-writing mark on current page stream used to put borders and fills.
3856 * Borders and fills are always created after content and inserted on the position marked by this method.
3857 * This function must be called after calling Image() function for a background image.
3858 * Background images must be always inserted before calling Multicell() or WriteHTMLCell() or WriteHTML() functions.
3860 * @since 4.0.016 (2008-07-30)
3862 public function setPageMark() {
3863 $this->intmrk
[$this->page
] = $this->pagelen
[$this->page
];
3864 $this->bordermrk
[$this->page
] = $this->intmrk
[$this->page
];
3865 $this->setContentMark();
3869 * Set start-writing mark on selected page.
3870 * Borders and fills are always created after content and inserted on the position marked by this method.
3871 * @param $page (int) page number (default is the current page)
3873 * @since 4.6.021 (2009-07-20)
3875 protected function setContentMark($page=0) {
3877 $page = $this->page
;
3879 if (isset($this->footerlen
[$page])) {
3880 $this->cntmrk
[$page] = $this->pagelen
[$page] - $this->footerlen
[$page];
3882 $this->cntmrk
[$page] = $this->pagelen
[$page];
3888 * @param $ln (string) header image logo
3889 * @param $lw (string) header image logo width in mm
3890 * @param $ht (string) string to print as title on document header
3891 * @param $hs (string) string to print on document header
3894 public function setHeaderData($ln='', $lw=0, $ht='', $hs='') {
3895 $this->header_logo
= $ln;
3896 $this->header_logo_width
= $lw;
3897 $this->header_title
= $ht;
3898 $this->header_string
= $hs;
3902 * Returns header data:
3903 * <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>
3906 * @since 4.0.012 (2008-07-24)
3908 public function getHeaderData() {
3910 $ret['logo'] = $this->header_logo
;
3911 $ret['logo_width'] = $this->header_logo_width
;
3912 $ret['title'] = $this->header_title
;
3913 $ret['string'] = $this->header_string
;
3918 * Set header margin.
3919 * (minimum distance between header and top page margin)
3920 * @param $hm (int) distance in user units
3923 public function setHeaderMargin($hm=10) {
3924 $this->header_margin
= $hm;
3928 * Returns header margin in user units.
3930 * @since 4.0.012 (2008-07-24)
3933 public function getHeaderMargin() {
3934 return $this->header_margin
;
3938 * Set footer margin.
3939 * (minimum distance between footer and bottom page margin)
3940 * @param $fm (int) distance in user units
3943 public function setFooterMargin($fm=10) {
3944 $this->footer_margin
= $fm;
3948 * Returns footer margin in user units.
3950 * @since 4.0.012 (2008-07-24)
3953 public function getFooterMargin() {
3954 return $this->footer_margin
;
3957 * Set a flag to print page header.
3958 * @param $val (boolean) set to true to print the page header (default), false otherwise.
3961 public function setPrintHeader($val=true) {
3962 $this->print_header
= $val;
3966 * Set a flag to print page footer.
3967 * @param $val (boolean) set to true to print the page footer (default), false otherwise.
3970 public function setPrintFooter($val=true) {
3971 $this->print_footer
= $val;
3975 * Return the right-bottom (or left-bottom for RTL) corner X coordinate of last inserted image
3979 public function getImageRBX() {
3980 return $this->img_rb_x
;
3984 * Return the right-bottom (or left-bottom for RTL) corner Y coordinate of last inserted image
3988 public function getImageRBY() {
3989 return $this->img_rb_y
;
3993 * This method is used to render the page header.
3994 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
3997 public function Header() {
3998 $ormargins = $this->getOriginalMargins();
3999 $headerfont = $this->getHeaderFont();
4000 $headerdata = $this->getHeaderData();
4001 if (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE
)) {
4002 $imgtype = $this->getImageFileType(K_PATH_IMAGES
.$headerdata['logo']);
4003 if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
4004 $this->ImageEps(K_PATH_IMAGES
.$headerdata['logo'], '', '', $headerdata['logo_width']);
4005 } elseif ($imgtype == 'svg') {
4006 $this->ImageSVG(K_PATH_IMAGES
.$headerdata['logo'], '', '', $headerdata['logo_width']);
4008 $this->Image(K_PATH_IMAGES
.$headerdata['logo'], '', '', $headerdata['logo_width']);
4010 $imgy = $this->getImageRBY();
4012 $imgy = $this->GetY();
4014 $cell_height = round(($this->getCellHeightRatio() * $headerfont[2]) / $this->getScaleFactor(), 2);
4015 // set starting margin for text data cell
4016 if ($this->getRTL()) {
4017 $header_x = $ormargins['right'] +
($headerdata['logo_width'] * 1.1);
4019 $header_x = $ormargins['left'] +
($headerdata['logo_width'] * 1.1);
4021 $this->SetTextColor(0, 0, 0);
4023 $this->SetFont($headerfont[0], 'B', $headerfont[2] +
1);
4024 $this->SetX($header_x);
4025 $this->Cell(0, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
4027 $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
4028 $this->SetX($header_x);
4029 $this->MultiCell(0, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
4030 // print an ending header line
4031 $this->SetLineStyle(array('width' => 0.85 / $this->getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
4032 $this->SetY((2.835 / $this->getScaleFactor()) +
max($imgy, $this->GetY()));
4033 if ($this->getRTL()) {
4034 $this->SetX($ormargins['right']);
4036 $this->SetX($ormargins['left']);
4038 $this->Cell(0, 0, '', 'T', 0, 'C');
4042 * This method is used to render the page footer.
4043 * It is automatically called by AddPage() and could be overwritten in your own inherited class.
4046 public function Footer() {
4047 $cur_y = $this->GetY();
4048 $ormargins = $this->getOriginalMargins();
4049 $this->SetTextColor(0, 0, 0);
4050 //set style for cell border
4051 $line_width = 0.85 / $this->getScaleFactor();
4052 $this->SetLineStyle(array('width' => $line_width, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
4053 //print document barcode
4054 $barcode = $this->getBarcode();
4055 if (!empty($barcode)) {
4056 $this->Ln($line_width);
4057 $barcode_width = round(($this->getPageWidth() - $ormargins['left'] - $ormargins['right']) / 3);
4059 'position' => $this->rtl?
'R':'L',
4060 'align' => $this->rtl?
'R':'L',
4063 'cellfitalign' => '',
4066 'fgcolor' => array(0,0,0),
4070 $this->write1DBarcode($barcode, 'C128B', '', $cur_y +
$line_width, '', (($this->getFooterMargin() / 3) - $line_width), 0.3, $style, '');
4072 if (empty($this->pagegroups
)) {
4073 $pagenumtxt = $this->l
['w_page'].' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
4075 $pagenumtxt = $this->l
['w_page'].' '.$this->getPageNumGroupAlias().' / '.$this->getPageGroupAlias();
4077 $this->SetY($cur_y);
4079 if ($this->getRTL()) {
4080 $this->SetX($ormargins['right']);
4081 $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
4083 $this->SetX($ormargins['left']);
4084 $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'R');
4089 * This method is used to render the page header.
4091 * @since 4.0.012 (2008-07-24)
4093 protected function setHeader() {
4094 if ($this->print_header
) {
4095 $this->setGraphicVars($this->default_graphic_vars
);
4096 $temp_thead = $this->thead
;
4097 $temp_theadMargins = $this->theadMargins
;
4098 $lasth = $this->lasth
;
4100 $this->rMargin
= $this->original_rMargin
;
4101 $this->lMargin
= $this->original_lMargin
;
4102 $this->SetCellPadding(0);
4103 //set current position
4105 $this->SetXY($this->original_rMargin
, $this->header_margin
);
4107 $this->SetXY($this->original_lMargin
, $this->header_margin
);
4109 $this->SetFont($this->header_font
[0], $this->header_font
[1], $this->header_font
[2]);
4113 $this->SetXY($this->original_rMargin
, $this->tMargin
);
4115 $this->SetXY($this->original_lMargin
, $this->tMargin
);
4118 $this->lasth
= $lasth;
4119 $this->thead
= $temp_thead;
4120 $this->theadMargins
= $temp_theadMargins;
4121 $this->newline
= false;
4126 * This method is used to render the page footer.
4128 * @since 4.0.012 (2008-07-24)
4130 protected function setFooter() {
4132 // save current graphic settings
4133 $gvars = $this->getGraphicVars();
4135 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
4137 if ($this->print_footer
) {
4138 $this->setGraphicVars($this->default_graphic_vars
);
4139 $this->current_column
= 0;
4140 $this->num_columns
= 1;
4141 $temp_thead = $this->thead
;
4142 $temp_theadMargins = $this->theadMargins
;
4143 $lasth = $this->lasth
;
4145 $this->rMargin
= $this->original_rMargin
;
4146 $this->lMargin
= $this->original_lMargin
;
4147 $this->SetCellPadding(0);
4148 //set current position
4149 $footer_y = $this->h
- $this->footer_margin
;
4151 $this->SetXY($this->original_rMargin
, $footer_y);
4153 $this->SetXY($this->original_lMargin
, $footer_y);
4155 $this->SetFont($this->footer_font
[0], $this->footer_font
[1], $this->footer_font
[2]);
4159 $this->SetXY($this->original_rMargin
, $this->tMargin
);
4161 $this->SetXY($this->original_lMargin
, $this->tMargin
);
4164 $this->lasth
= $lasth;
4165 $this->thead
= $temp_thead;
4166 $this->theadMargins
= $temp_theadMargins;
4168 // restore graphic settings
4169 $this->setGraphicVars($gvars);
4170 $this->current_column
= $gvars['current_column'];
4171 $this->num_columns
= $gvars['num_columns'];
4172 // calculate footer length
4173 $this->footerlen
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerpos
[$this->page
] +
1;
4177 * This method is used to render the table header on new page (if any).
4179 * @since 4.5.030 (2009-03-25)
4181 protected function setTableHeader() {
4182 if ($this->num_columns
> 1) {
4183 // multi column mode
4186 if (isset($this->theadMargins
['top'])) {
4187 // restore the original top-margin
4188 $this->tMargin
= $this->theadMargins
['top'];
4189 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
4190 $this->y
= $this->tMargin
;
4192 if (!$this->empty_string($this->thead
) AND (!$this->inthead
)) {
4194 $prev_lMargin = $this->lMargin
;
4195 $prev_rMargin = $this->rMargin
;
4196 $prev_cell_padding = $this->cell_padding
;
4197 $this->lMargin
= $this->theadMargins
['lmargin'] +
($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$this->theadMargins
['page']]['olm']);
4198 $this->rMargin
= $this->theadMargins
['rmargin'] +
($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$this->theadMargins
['page']]['orm']);
4199 $this->cell_padding
= $this->theadMargins
['cell_padding'];
4201 $this->x
= $this->w
- $this->rMargin
;
4203 $this->x
= $this->lMargin
;
4205 // print table header
4206 $this->writeHTML($this->thead
, false, false, false, false, '');
4207 // set new top margin to skip the table headers
4208 if (!isset($this->theadMargins
['top'])) {
4209 $this->theadMargins
['top'] = $this->tMargin
;
4211 // store end of header position
4212 if (!isset($this->columns
[0]['th'])) {
4213 $this->columns
[0]['th'] = array();
4215 $this->columns
[0]['th']['\''.$this->page
.'\''] = $this->y
;
4216 $this->tMargin
= $this->y
;
4217 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
4219 $this->lMargin
= $prev_lMargin;
4220 $this->rMargin
= $prev_rMargin;
4221 $this->cell_padding
= $prev_cell_padding;
4226 * Returns the current page number.
4227 * @return int page number
4230 * @see AliasNbPages(), getAliasNbPages()
4232 public function PageNo() {
4237 * Defines a new spot color.
4238 * It can be expressed in RGB components or gray scale.
4239 * The method can be called before the first page is created and the value is retained from page to page.
4240 * @param $name (string) name of the spot color
4241 * @param $c (int) Cyan color for CMYK. Value between 0 and 100
4242 * @param $m (int) Magenta color for CMYK. Value between 0 and 100
4243 * @param $y (int) Yellow color for CMYK. Value between 0 and 100
4244 * @param $k (int) Key (Black) color for CMYK. Value between 0 and 100
4246 * @since 4.0.024 (2008-09-12)
4247 * @see SetDrawSpotColor(), SetFillSpotColor(), SetTextSpotColor()
4249 public function AddSpotColor($name, $c, $m, $y, $k) {
4250 if (!isset($this->spot_colors
[$name])) {
4251 $i = 1 +
count($this->spot_colors
);
4252 $this->spot_colors
[$name] = array('i' => $i, 'c' => $c, 'm' => $m, 'y' => $y, 'k' => $k);
4254 $color = preg_replace('/[\s]*/', '', $name); // remove extra spaces
4255 $color = strtolower($color);
4256 if (!isset($this->spotcolor
[$color])) {
4257 $this->spotcolor
[$color] = array($c, $m, $y, $k, $name);
4262 * Defines the color used for all drawing operations (lines, rectangles and cell borders).
4263 * It can be expressed in RGB, CMYK or GRAY SCALE components.
4264 * The method can be called before the first page is created and the value is retained from page to page.
4265 * @param $color (array) array of colors
4266 * @param $ret (boolean) if true do not send the PDF command.
4267 * @return string the PDF command
4269 * @since 3.1.000 (2008-06-11)
4270 * @see SetDrawColor()
4272 public function SetDrawColorArray($color, $ret=false) {
4273 if (is_array($color)) {
4274 $color = array_values($color);
4275 $r = isset($color[0]) ?
$color[0] : -1;
4276 $g = isset($color[1]) ?
$color[1] : -1;
4277 $b = isset($color[2]) ?
$color[2] : -1;
4278 $k = isset($color[3]) ?
$color[3] : -1;
4279 $name = isset($color[4]) ?
$color[4] : ''; // spot color name
4281 return $this->SetDrawColor($r, $g, $b, $k, $ret, $name);
4288 * 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.
4289 * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4290 * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4291 * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4292 * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
4293 * @param $ret (boolean) if true do not send the command.
4294 * @param $name (string) spot color name (if any)
4295 * @return string the PDF command
4298 * @see SetDrawColorArray(), SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
4300 public function SetDrawColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4301 // set default values
4302 if (!is_numeric($col1)) {
4305 if (!is_numeric($col2)) {
4308 if (!is_numeric($col3)) {
4311 if (!is_numeric($col4)) {
4314 //Set color for all stroking operations
4315 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
4317 $this->DrawColor
= sprintf('%.3F G', ($col1 / 255));
4318 $this->strokecolor
= array('G' => $col1);
4319 } elseif ($col4 == -1) {
4321 $this->DrawColor
= sprintf('%.3F %.3F %.3F RG', ($col1 / 255), ($col2 / 255), ($col3 / 255));
4322 $this->strokecolor
= array('R' => $col1, 'G' => $col2, 'B' => $col3);
4323 } elseif (empty($name)) {
4325 $this->DrawColor
= sprintf('%.3F %.3F %.3F %.3F K', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
4326 $this->strokecolor
= array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
4329 $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
4330 $this->DrawColor
= sprintf('/CS%d CS %.3F SCN', $this->spot_colors
[$name]['i'], 1);
4331 $this->strokecolor
= array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
4333 if ($this->page
> 0) {
4335 $this->_out($this->DrawColor
);
4337 return $this->DrawColor
;
4343 * Defines the spot color used for all drawing operations (lines, rectangles and cell borders).
4344 * @param $name (string) name of the spot color
4345 * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
4347 * @since 4.0.024 (2008-09-12)
4348 * @see AddSpotColor(), SetFillSpotColor(), SetTextSpotColor()
4350 public function SetDrawSpotColor($name, $tint=100) {
4351 if (!isset($this->spot_colors
[$name])) {
4352 $this->Error('Undefined spot color: '.$name);
4354 $this->DrawColor
= sprintf('/CS%d CS %.3F SCN', $this->spot_colors
[$name]['i'], ($tint / 100));
4355 $this->strokecolor
= array('C' => $this->spot_colors
[$name]['c'], 'M' => $this->spot_colors
[$name]['m'], 'Y' => $this->spot_colors
[$name]['y'], 'K' => $this->spot_colors
[$name]['k'], 'name' => $name);
4356 if ($this->page
> 0) {
4357 $this->_out($this->DrawColor
);
4362 * Defines the color used for all filling operations (filled rectangles and cell backgrounds).
4363 * It can be expressed in RGB, CMYK or GRAY SCALE components.
4364 * The method can be called before the first page is created and the value is retained from page to page.
4365 * @param $color (array) array of colors
4366 * @param $ret (boolean) if true do not send the PDF command.
4368 * @since 3.1.000 (2008-6-11)
4369 * @see SetFillColor()
4371 public function SetFillColorArray($color, $ret=false) {
4372 if (is_array($color)) {
4373 $color = array_values($color);
4374 $r = isset($color[0]) ?
$color[0] : -1;
4375 $g = isset($color[1]) ?
$color[1] : -1;
4376 $b = isset($color[2]) ?
$color[2] : -1;
4377 $k = isset($color[3]) ?
$color[3] : -1;
4378 $name = isset($color[4]) ?
$color[4] : ''; // spot color name
4380 $this->SetFillColor($r, $g, $b, $k, $ret, $name);
4386 * 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.
4387 * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4388 * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4389 * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4390 * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
4391 * @param $ret (boolean) if true do not send the command.
4392 * @param $name (string) spot color name (if any)
4393 * @return string the PDF command
4396 * @see SetFillColorArray(), SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
4398 public function SetFillColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4399 // set default values
4400 if (!is_numeric($col1)) {
4403 if (!is_numeric($col2)) {
4406 if (!is_numeric($col3)) {
4409 if (!is_numeric($col4)) {
4412 //Set color for all filling operations
4413 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
4415 $this->FillColor
= sprintf('%.3F g', ($col1 / 255));
4416 $this->bgcolor
= array('G' => $col1);
4417 } elseif ($col4 == -1) {
4419 $this->FillColor
= sprintf('%.3F %.3F %.3F rg', ($col1 / 255), ($col2 / 255), ($col3 / 255));
4420 $this->bgcolor
= array('R' => $col1, 'G' => $col2, 'B' => $col3);
4421 } elseif (empty($name)) {
4423 $this->FillColor
= sprintf('%.3F %.3F %.3F %.3F k', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
4424 $this->bgcolor
= array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
4427 $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
4428 $this->FillColor
= sprintf('/CS%d cs %.3F scn', $this->spot_colors
[$name]['i'], 1);
4429 $this->bgcolor
= array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
4431 $this->ColorFlag
= ($this->FillColor
!= $this->TextColor
);
4432 if ($this->page
> 0) {
4434 $this->_out($this->FillColor
);
4436 return $this->FillColor
;
4442 * Defines the spot color used for all filling operations (filled rectangles and cell backgrounds).
4443 * @param $name (string) name of the spot color
4444 * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
4446 * @since 4.0.024 (2008-09-12)
4447 * @see AddSpotColor(), SetDrawSpotColor(), SetTextSpotColor()
4449 public function SetFillSpotColor($name, $tint=100) {
4450 if (!isset($this->spot_colors
[$name])) {
4451 $this->Error('Undefined spot color: '.$name);
4453 $this->FillColor
= sprintf('/CS%d cs %.3F scn', $this->spot_colors
[$name]['i'], ($tint / 100));
4454 $this->bgcolor
= array('C' => $this->spot_colors
[$name]['c'], 'M' => $this->spot_colors
[$name]['m'], 'Y' => $this->spot_colors
[$name]['y'], 'K' => $this->spot_colors
[$name]['k'], 'name' => $name);
4455 $this->ColorFlag
= ($this->FillColor
!= $this->TextColor
);
4456 if ($this->page
> 0) {
4457 $this->_out($this->FillColor
);
4462 * Defines the color used for text. It can be expressed in RGB components or gray scale.
4463 * The method can be called before the first page is created and the value is retained from page to page.
4464 * @param $color (array) array of colors
4465 * @param $ret (boolean) if true do not send the PDF command.
4467 * @since 3.1.000 (2008-6-11)
4468 * @see SetFillColor()
4470 public function SetTextColorArray($color, $ret=false) {
4471 if (is_array($color)) {
4472 $color = array_values($color);
4473 $r = isset($color[0]) ?
$color[0] : -1;
4474 $g = isset($color[1]) ?
$color[1] : -1;
4475 $b = isset($color[2]) ?
$color[2] : -1;
4476 $k = isset($color[3]) ?
$color[3] : -1;
4477 $name = isset($color[4]) ?
$color[4] : ''; // spot color name
4479 $this->SetTextColor($r, $g, $b, $k, $ret, $name);
4485 * 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.
4486 * @param $col1 (int) GRAY level for single color, or Red color for RGB (0-255), or CYAN color for CMYK (0-100).
4487 * @param $col2 (int) GREEN color for RGB (0-255), or MAGENTA color for CMYK (0-100).
4488 * @param $col3 (int) BLUE color for RGB (0-255), or YELLOW color for CMYK (0-100).
4489 * @param $col4 (int) KEY (BLACK) color for CMYK (0-100).
4490 * @param $ret (boolean) if true do not send the command.
4491 * @param $name (string) spot color name (if any)
4494 * @see SetTextColorArray(), SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
4496 public function SetTextColor($col1=0, $col2=-1, $col3=-1, $col4=-1, $ret=false, $name='') {
4497 // set default values
4498 if (!is_numeric($col1)) {
4501 if (!is_numeric($col2)) {
4504 if (!is_numeric($col3)) {
4507 if (!is_numeric($col4)) {
4510 //Set color for text
4511 if (($col2 == -1) AND ($col3 == -1) AND ($col4 == -1)) {
4513 $this->TextColor
= sprintf('%.3F g', ($col1 / 255));
4514 $this->fgcolor
= array('G' => $col1);
4515 } elseif ($col4 == -1) {
4517 $this->TextColor
= sprintf('%.3F %.3F %.3F rg', ($col1 / 255), ($col2 / 255), ($col3 / 255));
4518 $this->fgcolor
= array('R' => $col1, 'G' => $col2, 'B' => $col3);
4519 } elseif (empty($name)) {
4521 $this->TextColor
= sprintf('%.3F %.3F %.3F %.3F k', ($col1 / 100), ($col2 / 100), ($col3 / 100), ($col4 / 100));
4522 $this->fgcolor
= array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4);
4525 $this->AddSpotColor($name, $col1, $col2, $col3, $col4);
4526 $this->TextColor
= sprintf('/CS%d cs %.3F scn', $this->spot_colors
[$name]['i'], 1);
4527 $this->fgcolor
= array('C' => $col1, 'M' => $col2, 'Y' => $col3, 'K' => $col4, 'name' => $name);
4529 $this->ColorFlag
= ($this->FillColor
!= $this->TextColor
);
4533 * Defines the spot color used for text.
4534 * @param $name (string) name of the spot color
4535 * @param $tint (int) the intensity of the color (from 0 to 100 ; 100 = full intensity by default).
4537 * @since 4.0.024 (2008-09-12)
4538 * @see AddSpotColor(), SetDrawSpotColor(), SetFillSpotColor()
4540 public function SetTextSpotColor($name, $tint=100) {
4541 if (!isset($this->spot_colors
[$name])) {
4542 $this->Error('Undefined spot color: '.$name);
4544 $this->TextColor
= sprintf('/CS%d cs %.3F scn', $this->spot_colors
[$name]['i'], ($tint / 100));
4545 $this->fgcolor
= array('C' => $this->spot_colors
[$name]['c'], 'M' => $this->spot_colors
[$name]['m'], 'Y' => $this->spot_colors
[$name]['y'], 'K' => $this->spot_colors
[$name]['k'], 'name' => $name);
4546 $this->ColorFlag
= ($this->FillColor
!= $this->TextColor
);
4547 if ($this->page
> 0) {
4548 $this->_out($this->TextColor
);
4553 * Returns the length of a string in user unit. A font must be selected.<br>
4554 * @param $s (string) The string whose length is to be computed
4555 * @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.
4556 * @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-trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
4557 * @param $fontsize (float) Font size in points. The default value is the current size.
4558 * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
4559 * @return mixed int total string length or array of characted widths
4560 * @author Nicola Asuni
4564 public function GetStringWidth($s, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
4565 return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $s, $this->tmprtl
), $fontname, $fontstyle, $fontsize, $getarray);
4569 * Returns the string length of an array of chars in user unit or an array of characters widths. A font must be selected.<br>
4570 * @param $sa (string) The array of chars whose total length is to be computed
4571 * @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.
4572 * @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 trough</li><li>O: overline</li></ul> or any combination. The default value is regular.
4573 * @param $fontsize (float) Font size in points. The default value is the current size.
4574 * @param $getarray (boolean) if true returns an array of characters widths, if false returns the total length.
4575 * @return mixed int total string length or array of characted widths
4576 * @author Nicola Asuni
4578 * @since 2.4.000 (2008-03-06)
4580 public function GetArrStringWidth($sa, $fontname='', $fontstyle='', $fontsize=0, $getarray=false) {
4581 // store current values
4582 if (!$this->empty_string($fontname)) {
4583 $prev_FontFamily = $this->FontFamily
;
4584 $prev_FontStyle = $this->FontStyle
;
4585 $prev_FontSizePt = $this->FontSizePt
;
4586 $this->SetFont($fontname, $fontstyle, $fontsize);
4588 // convert UTF-8 array to Latin1 if required
4589 $sa = $this->UTF8ArrToLatin1($sa);
4590 $w = 0; // total width
4591 $wa = array(); // array of characters widths
4592 foreach ($sa as $ck => $char) {
4594 $cw = $this->GetCharWidth($char, isset($sa[($ck +
1)]));
4598 // restore previous values
4599 if (!$this->empty_string($fontname)) {
4600 $this->SetFont($prev_FontFamily, $prev_FontStyle, $prev_FontSizePt);
4609 * Returns the length of the char in user unit for the current font considering current stretching and spacing (tracking/kerning).
4610 * @param $char (int) The char code whose length is to be returned
4611 * @param $notlast (boolean) set to false for the latest character on string, true otherwise (default)
4612 * @return float char width
4613 * @author Nicola Asuni
4615 * @since 2.4.000 (2008-03-06)
4617 public function GetCharWidth($char, $notlast=true) {
4619 $chw = $this->getRawCharWidth($char);
4620 if (($this->font_spacing
!= 0) AND $notlast) {
4621 // increase/decrease font spacing
4622 $chw +
= $this->font_spacing
;
4624 if ($this->font_stretching
!= 100) {
4625 // fixed stretching mode
4626 $chw *= ($this->font_stretching
/ 100);
4632 * Returns the length of the char in user unit for the current font.
4633 * @param $char (int) The char code whose length is to be returned
4634 * @return float char width
4635 * @author Nicola Asuni
4637 * @since 5.9.000 (2010-09-28)
4639 public function getRawCharWidth($char) {
4641 // SHY character will not be printed
4644 $cw = &$this->CurrentFont
['cw'];
4645 if (isset($cw[$char])) {
4647 } elseif (isset($this->CurrentFont
['dw'])) {
4649 $w = $this->CurrentFont
['dw'];
4650 } elseif (isset($cw[32])) {
4656 return ($w * $this->FontSize
/ 1000);
4660 * Returns the numbero of characters in a string.
4661 * @param $s (string) The input string.
4662 * @return int number of characters
4664 * @since 2.0.0001 (2008-01-07)
4666 public function GetNumChars($s) {
4667 if ($this->isUnicodeFont()) {
4668 return count($this->UTF8StringToArray($s));
4674 * Fill the list of available fonts ($this->fontlist).
4676 * @since 4.0.013 (2008-07-28)
4678 protected function getFontsList() {
4679 $fontsdir = opendir($this->_getfontpath());
4680 while (($file = readdir($fontsdir)) !== false) {
4681 if (substr($file, -4) == '.php') {
4682 array_push($this->fontlist
, strtolower(basename($file, '.php')));
4685 closedir($fontsdir);
4689 * Imports a TrueType, Type1, core, or CID0 font and makes it available.
4690 * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
4691 * 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.
4692 * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
4693 * @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>
4694 * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
4695 * @return array containing the font data, or false in case of error.
4696 * @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.
4699 * @see SetFont(), setFontSubsetting()
4701 public function AddFont($family, $style='', $fontfile='', $subset='default') {
4702 if ($subset === 'default') {
4703 $subset = $this->font_subsetting
;
4705 if ($this->empty_string($family)) {
4706 if (!$this->empty_string($this->FontFamily
)) {
4707 $family = $this->FontFamily
;
4709 $this->Error('Empty font family');
4712 // move embedded styles on $style
4713 if (substr($family, -1) == 'I') {
4715 $family = substr($family, 0, -1);
4717 if (substr($family, -1) == 'B') {
4719 $family = substr($family, 0, -1);
4721 // normalize family name
4722 $family = strtolower($family);
4723 if ((!$this->isunicode
) AND ($family == 'arial')) {
4724 $family = 'helvetica';
4726 if (($family == 'symbol') OR ($family == 'zapfdingbats')) {
4729 $tempstyle = strtoupper($style);
4732 if (strpos($tempstyle, 'U') !== false) {
4733 $this->underline
= true;
4735 $this->underline
= false;
4737 // line-through (deleted)
4738 if (strpos($tempstyle, 'D') !== false) {
4739 $this->linethrough
= true;
4741 $this->linethrough
= false;
4744 if (strpos($tempstyle, 'O') !== false) {
4745 $this->overline
= true;
4747 $this->overline
= false;
4750 if (strpos($tempstyle, 'B') !== false) {
4754 if (strpos($tempstyle, 'I') !== false) {
4758 $fontkey = $family.$style;
4759 $font_style = $style.($this->underline ?
'U' : '').($this->linethrough ?
'D' : '').($this->overline ?
'O' : '');
4760 $fontdata = array('fontkey' => $fontkey, 'family' => $family, 'style' => $font_style);
4761 // check if the font has been already added
4762 $fb = $this->getFontBuffer($fontkey);
4763 if ($fb !== false) {
4764 if ($this->inxobj
) {
4765 // we are inside an XObject template
4766 $this->xobjects
[$this->xobjid
]['fonts'][$fontkey] = $fb['i'];
4776 // get specified font directory (if any)
4778 if (!$this->empty_string($fontfile)) {
4779 $fontdir = dirname($fontfile);
4780 if ($this->empty_string($fontdir) OR ($fontdir == '.')) {
4786 // search and include font file
4787 if ($this->empty_string($fontfile) OR (!file_exists($fontfile))) {
4788 // build a standard filenames for specified font
4789 $fontfile1 = str_replace(' ', '', $family).strtolower($style).'.php';
4790 $fontfile2 = str_replace(' ', '', $family).'.php';
4791 // search files on various directories
4792 if (($fontdir !== false) AND file_exists($fontdir.$fontfile1)) {
4793 $fontfile = $fontdir.$fontfile1;
4794 } elseif (file_exists($this->_getfontpath().$fontfile1)) {
4795 $fontfile = $this->_getfontpath().$fontfile1;
4796 } elseif (file_exists($fontfile1)) {
4797 $fontfile = $fontfile1;
4798 } elseif (($fontdir !== false) AND file_exists($fontdir.$fontfile2)) {
4799 $fontfile = $fontdir.$fontfile2;
4800 } elseif (file_exists($this->_getfontpath().$fontfile2)) {
4801 $fontfile = $this->_getfontpath().$fontfile2;
4803 $fontfile = $fontfile2;
4806 // include font file
4807 if (file_exists($fontfile)) {
4810 $this->Error('Could not include font definition file: '.$family.'');
4812 // check font parameters
4813 if ((!isset($type)) OR (!isset($cw))) {
4814 $this->Error('The font definition file has a bad format: '.$fontfile.'');
4816 // SET default parameters
4817 if (!isset($file) OR $this->empty_string($file)) {
4820 if (!isset($enc) OR $this->empty_string($enc)) {
4823 if (!isset($cidinfo) OR $this->empty_string($cidinfo)) {
4824 $cidinfo = array('Registry'=>'Adobe','Ordering'=>'Identity','Supplement'=>0);
4825 $cidinfo['uni2cid'] = array();
4827 if (!isset($ctg) OR $this->empty_string($ctg)) {
4830 if (!isset($desc) OR $this->empty_string($desc)) {
4833 if (!isset($up) OR $this->empty_string($up)) {
4836 if (!isset($ut) OR $this->empty_string($ut)) {
4839 if (!isset($cw) OR $this->empty_string($cw)) {
4842 if (!isset($dw) OR $this->empty_string($dw)) {
4843 // set default width
4844 if (isset($desc['MissingWidth']) AND ($desc['MissingWidth'] > 0)) {
4845 $dw = $desc['MissingWidth'];
4846 } elseif (isset($cw[32])) {
4853 if ($type == 'cidfont0') {
4854 // register CID font (all styles at once)
4855 $styles = array('' => '', 'B' => ',Bold', 'I' => ',Italic', 'BI' => ',BoldItalic');
4856 $sname = $name.$styles[$bistyle];
4858 if (strpos($bistyle, 'B') !== false) {
4859 if (isset($desc['StemV'])) {
4860 $desc['StemV'] *= 2;
4862 $desc['StemV'] = 120;
4865 // artificial italic
4866 if (strpos($bistyle, 'I') !== false) {
4867 if (isset($desc['ItalicAngle'])) {
4868 $desc['ItalicAngle'] -= 11;
4870 $desc['ItalicAngle'] = -11;
4873 } elseif ($type == 'core') {
4874 $name = $this->CoreFonts
[$fontkey];
4876 } elseif (($type == 'TrueType') OR ($type == 'Type1')) {
4878 } elseif ($type == 'TrueTypeUnicode') {
4879 $enc = 'Identity-H';
4881 $this->Error('Unknow font type: '.$type.'');
4883 // initialize subsetchars to contain default ASCII values (0-255)
4884 $subsetchars = array_fill(0, 256, true);
4885 $this->setFontBuffer($fontkey, array('fontkey' => $fontkey, 'i' => $this->numfonts
, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'dw' => $dw, 'enc' => $enc, 'cidinfo' => $cidinfo, 'file' => $file, 'ctg' => $ctg, 'subset' => $subset, 'subsetchars' => $subsetchars));
4886 if ($this->inxobj
) {
4887 // we are inside an XObject template
4888 $this->xobjects
[$this->xobjid
]['fonts'][$fontkey] = $this->numfonts
;
4890 if (isset($diff) AND (!empty($diff))) {
4891 //Search existing encodings
4893 $nb = count($this->diffs
);
4894 for ($i=1; $i <= $nb; ++
$i) {
4895 if ($this->diffs
[$i] == $diff) {
4902 $this->diffs
[$d] = $diff;
4904 $this->setFontSubBuffer($fontkey, 'diff', $d);
4906 if (!$this->empty_string($file)) {
4907 if (!isset($this->FontFiles
[$file])) {
4908 if ((strcasecmp($type,'TrueType') == 0) OR (strcasecmp($type, 'TrueTypeUnicode') == 0)) {
4909 $this->FontFiles
[$file] = array('length1' => $originalsize, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
4910 } elseif ($type != 'core') {
4911 $this->FontFiles
[$file] = array('length1' => $size1, 'length2' => $size2, 'fontdir' => $fontdir, 'subset' => $subset, 'fontkeys' => array($fontkey));
4914 // update fontkeys that are sharing this font file
4915 $this->FontFiles
[$file]['subset'] = ($this->FontFiles
[$file]['subset'] AND $subset);
4916 if (!in_array($fontkey, $this->FontFiles
[$file]['fontkeys'])) {
4917 $this->FontFiles
[$file]['fontkeys'][] = $fontkey;
4925 * Sets the font used to print character strings.
4926 * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
4927 * The method can be called before the first page is created and the font is retained from page to page.
4928 * If you just wish to change the current font size, it is simpler to call SetFontSize().
4929 * 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 />
4930 * @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.
4931 * @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 trough</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.
4932 * @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
4933 * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
4934 * @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.
4935 * @author Nicola Asuni
4938 * @see AddFont(), SetFontSize()
4940 public function SetFont($family, $style='', $size=0, $fontfile='', $subset='default') {
4941 //Select a font; size given in points
4943 $size = $this->FontSizePt
;
4945 // try to add font (if not already added)
4946 $fontdata = $this->AddFont($family, $style, $fontfile, $subset);
4947 $this->FontFamily
= $fontdata['family'];
4948 $this->FontStyle
= $fontdata['style'];
4949 $this->CurrentFont
= $this->getFontBuffer($fontdata['fontkey']);
4950 $this->SetFontSize($size);
4954 * Defines the size of the current font.
4955 * @param $size (float) The size (in points)
4956 * @param $out (boolean) if true output the font size command, otherwise only set the font properties.
4961 public function SetFontSize($size, $out=true) {
4962 // font size in points
4963 $this->FontSizePt
= $size;
4964 // font size in user units
4965 $this->FontSize
= $size / $this->k
;
4966 // calculate some font metrics
4967 if (isset($this->CurrentFont
['desc']['FontBBox'])) {
4968 $bbox = explode(' ', substr($this->CurrentFont
['desc']['FontBBox'], 1, -1));
4969 $font_height = ((intval($bbox[3]) - intval($bbox[1])) * $size / 1000);
4971 $font_height = $size * 1.219;
4973 if (isset($this->CurrentFont
['desc']['Ascent']) AND ($this->CurrentFont
['desc']['Ascent'] > 0)) {
4974 $font_ascent = ($this->CurrentFont
['desc']['Ascent'] * $size / 1000);
4976 if (isset($this->CurrentFont
['desc']['Descent']) AND ($this->CurrentFont
['desc']['Descent'] <= 0)) {
4977 $font_descent = (- $this->CurrentFont
['desc']['Descent'] * $size / 1000);
4979 if (!isset($font_ascent) AND !isset($font_descent)) {
4981 $font_ascent = 0.76 * $font_height;
4982 $font_descent = $font_height - $font_ascent;
4983 } elseif (!isset($font_descent)) {
4984 $font_descent = $font_height - $font_ascent;
4985 } elseif (!isset($font_ascent)) {
4986 $font_ascent = $font_height - $font_descent;
4988 $this->FontAscent
= $font_ascent / $this->k
;
4989 $this->FontDescent
= $font_descent / $this->k
;
4990 if ($out AND ($this->page
> 0) AND (isset($this->CurrentFont
['i']))) {
4991 $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont
['i'], $this->FontSizePt
));
4996 * Return the font descent value
4997 * @param $font (string) font name
4998 * @param $style (string) font style
4999 * @param $size (float) The size (in points)
5000 * @return int font descent
5002 * @author Nicola Asuni
5003 * @since 4.9.003 (2010-03-30)
5005 public function getFontDescent($font, $style='', $size=0) {
5006 $fontdata = $this->AddFont($font, $style);
5007 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
5008 if (isset($fontinfo['desc']['Descent']) AND ($fontinfo['desc']['Descent'] <= 0)) {
5009 $descent = (- $fontinfo['desc']['Descent'] * $size / 1000);
5011 $descent = 1.219 * 0.24 * $size;
5013 return ($descent / $this->k
);
5017 * Return the font ascent value
5018 * @param $font (string) font name
5019 * @param $style (string) font style
5020 * @param $size (float) The size (in points)
5021 * @return int font ascent
5023 * @author Nicola Asuni
5024 * @since 4.9.003 (2010-03-30)
5026 public function getFontAscent($font, $style='', $size=0) {
5027 $fontdata = $this->AddFont($font, $style);
5028 $fontinfo = $this->getFontBuffer($fontdata['fontkey']);
5029 if (isset($fontinfo['desc']['Ascent']) AND ($fontinfo['desc']['Ascent'] > 0)) {
5030 $ascent = ($fontinfo['desc']['Ascent'] * $size / 1000);
5032 $ascent = 1.219 * 0.76 * $size;
5034 return ($ascent / $this->k
);
5038 * Defines the default monospaced font.
5039 * @param $font (string) Font name.
5043 public function SetDefaultMonospacedFont($font) {
5044 $this->default_monospaced_font
= $font;
5048 * 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 />
5049 * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
5052 * @see Cell(), Write(), Image(), Link(), SetLink()
5054 public function AddLink() {
5055 //Create a new internal link
5056 $n = count($this->links
) +
1;
5057 $this->links
[$n] = array(0, 0);
5062 * Defines the page and position a link points to.
5063 * @param $link (int) The link identifier returned by AddLink()
5064 * @param $y (float) Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
5065 * @param $page (int) Number of target page; -1 indicates the current page. This is the default value
5070 public function SetLink($link, $y=0, $page=-1) {
5075 $page = $this->page
;
5077 $this->links
[$link] = array($page, $y);
5081 * Puts a link on a rectangular area of the page.
5082 * 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.
5083 * @param $x (float) Abscissa of the upper-left corner of the rectangle
5084 * @param $y (float) Ordinate of the upper-left corner of the rectangle
5085 * @param $w (float) Width of the rectangle
5086 * @param $h (float) Height of the rectangle
5087 * @param $link (mixed) URL or identifier returned by AddLink()
5088 * @param $spaces (int) number of spaces on the text to link
5091 * @see AddLink(), Annotation(), Cell(), Write(), Image()
5093 public function Link($x, $y, $w, $h, $link, $spaces=0) {
5094 $this->Annotation($x, $y, $w, $h, $link, array('Subtype'=>'Link'), $spaces);
5098 * Puts a markup annotation on a rectangular area of the page.
5099 * !!!!THE ANNOTATION SUPPORT IS NOT YET FULLY IMPLEMENTED !!!!
5100 * @param $x (float) Abscissa of the upper-left corner of the rectangle
5101 * @param $y (float) Ordinate of the upper-left corner of the rectangle
5102 * @param $w (float) Width of the rectangle
5103 * @param $h (float) Height of the rectangle
5104 * @param $text (string) annotation text or alternate content
5105 * @param $opt (array) array of options (see section 8.4 of PDF reference 1.7).
5106 * @param $spaces (int) number of spaces on the text to link
5108 * @since 4.0.018 (2008-08-06)
5110 public function Annotation($x, $y, $w, $h, $text, $opt=array('Subtype'=>'Text'), $spaces=0) {
5111 if ($this->inxobj
) {
5112 // store parameters for later use on template
5113 $this->xobjects
[$this->xobjid
]['annotations'][] = array('x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'text' => $text, 'opt' => $opt, 'spaces' => $spaces);
5122 // check page for no-write regions and adapt page margins if necessary
5123 $this->checkPageRegions($h, $x, $y);
5124 // recalculate coordinates to account for graphic transformations
5125 if (isset($this->transfmatrix
) AND !empty($this->transfmatrix
)) {
5126 for ($i=$this->transfmatrix_key
; $i > 0; --$i) {
5127 $maxid = count($this->transfmatrix
[$i]) - 1;
5128 for ($j=$maxid; $j >= 0; --$j) {
5129 $ctm = $this->transfmatrix
[$i][$j];
5130 if (isset($ctm['a'])) {
5132 $y = ($this->h
- $y) * $this->k
;
5138 $x1 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
5139 $y1 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
5143 $x2 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
5144 $y2 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
5148 $x3 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
5149 $y3 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
5153 $x4 = ($ctm['a'] * $xt) +
($ctm['c'] * $yt) +
$ctm['e'];
5154 $y4 = ($ctm['b'] * $xt) +
($ctm['d'] * $yt) +
$ctm['f'];
5155 // new coordinates (rectangle area)
5156 $x = min($x1, $x2, $x3, $x4);
5157 $y = max($y1, $y2, $y3, $y4);
5158 $w = (max($x1, $x2, $x3, $x4) - $x) / $this->k
;
5159 $h = ($y - min($y1, $y2, $y3, $y4)) / $this->k
;
5161 $y = $this->h
- ($y / $this->k
);
5166 if ($this->page
<= 0) {
5169 $page = $this->page
;
5171 if (!isset($this->PageAnnots
[$page])) {
5172 $this->PageAnnots
[$page] = array();
5175 $this->PageAnnots
[$page][] = array('n' => $this->n
, 'x' => $x, 'y' => $y, 'w' => $w, 'h' => $h, 'txt' => $text, 'opt' => $opt, 'numspaces' => $spaces);
5176 if ((($opt['Subtype'] == 'FileAttachment') OR ($opt['Subtype'] == 'Sound')) AND (!$this->empty_string($opt['FS'])) AND file_exists($opt['FS']) AND (!isset($this->embeddedfiles
[basename($opt['FS'])]))) {
5178 $this->embeddedfiles
[basename($opt['FS'])] = array('n' => $this->n
, 'file' => $opt['FS']);
5180 // Add widgets annotation's icons
5181 if (isset($opt['mk']['i']) AND file_exists($opt['mk']['i'])) {
5182 $this->Image($opt['mk']['i'], '', '', 10, 10, '', '', '', false, 300, '', false, false, 0, false, true);
5184 if (isset($opt['mk']['ri']) AND file_exists($opt['mk']['ri'])) {
5185 $this->Image($opt['mk']['ri'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
5187 if (isset($opt['mk']['ix']) AND file_exists($opt['mk']['ix'])) {
5188 $this->Image($opt['mk']['ix'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, true);
5193 * Embedd the attached files.
5194 * @since 4.4.000 (2008-12-07)
5198 protected function _putEmbeddedFiles() {
5199 reset($this->embeddedfiles
);
5200 foreach ($this->embeddedfiles
as $filename => $filedata) {
5201 $data = file_get_contents($filedata['file']);
5203 if ($this->compress
) {
5204 $data = gzcompress($data);
5205 $filter = ' /Filter /FlateDecode';
5207 $stream = $this->_getrawstream($data, $filedata['n']);
5208 $out = $this->_getobj($filedata['n'])."\n";
5209 $out .= '<< /Type /EmbeddedFile'.$filter.' /Length '.strlen($stream).' >>';
5210 $out .= ' stream'."\n".$stream."\n".'endstream';
5211 $out .= "\n".'endobj';
5217 * Prints a text cell at the specified position.
5218 * This method allows to place a string precisely on the page.
5219 * @param $x (float) Abscissa of the cell origin
5220 * @param $y (float) Ordinate of the cell origin
5221 * @param $txt (string) String to print
5222 * @param $fstroke (int) outline size in user units (false = disable)
5223 * @param $fclip (boolean) if true activate clipping mode (you must call StartTransform() before this function and StopTransform() to stop the clipping tranformation).
5224 * @param $ffill (boolean) if true fills the text
5225 * @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)))
5226 * @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.
5227 * @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>
5228 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
5229 * @param $link (mixed) URL or identifier returned by AddLink().
5230 * @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.
5231 * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
5232 * @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>
5233 * @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>
5234 * @param $rtloff (boolean) if true uses the page top-left corner as origin of axis for $x and $y initial position.
5237 * @see Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell()
5239 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) {
5240 $textrendermode = $this->textrendermode
;
5241 $textstrokewidth = $this->textstrokewidth
;
5242 $this->setTextRenderingMode($fstroke, $ffill, $fclip);
5243 $this->SetXY($x, $y, $rtloff);
5244 $this->Cell(0, 0, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
5245 // restore previous rendering mode
5246 $this->textrendermode
= $textrendermode;
5247 $this->textstrokewidth
= $textstrokewidth;
5251 * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value.
5252 * The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
5253 * This method is called automatically and should not be called directly by the application.
5257 * @see SetAutoPageBreak()
5259 public function AcceptPageBreak() {
5260 if ($this->num_columns
> 1) {
5261 // multi column mode
5262 if($this->current_column
< ($this->num_columns
- 1)) {
5263 // go to next column
5264 $this->selectColumn($this->current_column +
1);
5269 $this->selectColumn(0);
5271 // avoid page breaking from checkPageBreak()
5274 return $this->AutoPageBreak
;
5278 * Add page if needed.
5279 * @param $h (float) Cell height. Default value: 0.
5280 * @param $y (mixed) starting y position, leave empty for current position.
5281 * @param $addpage (boolean) if true add a page, otherwise only return the true/false state
5282 * @return boolean true in case of page break, false otherwise.
5283 * @since 3.2.000 (2008-07-01)
5286 protected function checkPageBreak($h=0, $y='', $addpage=true) {
5287 if ($this->empty_string($y)) {
5290 $current_page = $this->page
;
5291 if ((($y +
$h) > $this->PageBreakTrigger
) AND (!$this->InFooter
) AND ($this->AcceptPageBreak())) {
5293 //Automatic page break
5295 $this->AddPage($this->CurOrientation
);
5296 $this->y
= $this->tMargin
;
5297 $oldpage = $this->page
- 1;
5299 if ($this->pagedim
[$this->page
]['orm'] != $this->pagedim
[$oldpage]['orm']) {
5300 $this->x
= $x - ($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$oldpage]['orm']);
5305 if ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$oldpage]['olm']) {
5306 $this->x
= $x +
($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$oldpage]['olm']);
5314 if ($current_page != $this->page
) {
5315 // account for columns mode
5322 * Removes SHY characters from text.
5324 * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
5325 * <li>HTML Entity (decimal): "&#173;"</li>
5326 * <li>HTML Entity (hex): "&#xad;"</li>
5327 * <li>HTML Entity (named): "&shy;"</li>
5328 * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
5329 * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
5330 * <li>UTF-8 character: chr(194).chr(173)</li>
5332 * @param $txt (string) input string
5333 * @return string without SHY characters.
5335 * @since (4.5.019) 2009-02-28
5337 public function removeSHY($txt='') {
5338 $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
5339 if (!$this->isunicode
) {
5340 $txt = preg_replace('/([\\xad]{1})/', '', $txt);
5346 * 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 />
5347 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
5348 * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
5349 * @param $h (float) Cell height. Default value: 0.
5350 * @param $txt (string) String to print. Default value: empty string.
5351 * @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)))
5352 * @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.
5353 * @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>
5354 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
5355 * @param $link (mixed) URL or identifier returned by AddLink().
5356 * @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.
5357 * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
5358 * @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>
5359 * @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>
5362 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
5364 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') {
5365 $prev_cell_margin = $this->cell_margin
;
5366 $prev_cell_padding = $this->cell_padding
;
5367 $this->adjustCellPadding($border);
5368 if (!$ignore_min_height) {
5369 $min_cell_height = ($this->FontSize
* $this->cell_height_ratio
) +
$this->cell_padding
['T'] +
$this->cell_padding
['B'];
5370 if ($h < $min_cell_height) {
5371 $h = $min_cell_height;
5374 $this->checkPageBreak($h +
$this->cell_margin
['T'] +
$this->cell_margin
['B']);
5375 $this->_out($this->getCellCode($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, true, $calign, $valign));
5376 $this->cell_padding
= $prev_cell_padding;
5377 $this->cell_margin
= $prev_cell_margin;
5381 * 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 />
5382 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
5383 * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
5384 * @param $h (float) Cell height. Default value: 0.
5385 * @param $txt (string) String to print. Default value: empty string.
5386 * @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)))
5387 * @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.
5388 * @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>
5389 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
5390 * @param $link (mixed) URL or identifier returned by AddLink().
5391 * @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.
5392 * @param $ignore_min_height (boolean) if true ignore automatic minimum height value.
5393 * @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>
5394 * @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>
5395 * @return string containing cell code
5400 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') {
5401 $prev_cell_margin = $this->cell_margin
;
5402 $prev_cell_padding = $this->cell_padding
;
5403 $txt = $this->removeSHY($txt);
5404 $rs = ''; //string to be returned
5405 $this->adjustCellPadding($border);
5406 if (!$ignore_min_height) {
5407 $min_cell_height = ($this->FontSize
* $this->cell_height_ratio
) +
$this->cell_padding
['T'] +
$this->cell_padding
['B'];
5408 if ($h < $min_cell_height) {
5409 $h = $min_cell_height;
5413 // check page for no-write regions and adapt page margins if necessary
5414 $this->checkPageRegions($h, $this->x
, $this->y
);
5416 $x = $this->x
- $this->cell_margin
['R'];
5418 $x = $this->x +
$this->cell_margin
['L'];
5420 $y = $this->y +
$this->cell_margin
['T'];
5421 $prev_font_stretching = $this->font_stretching
;
5422 $prev_font_spacing = $this->font_spacing
;
5423 // cell vertical alignment
5430 $y -= $this->cell_padding
['T'];
5435 $y -= ($h - $this->cell_padding
['B'] - $this->FontAscent
- $this->FontDescent
);
5442 $y -= (($h - $this->FontAscent
- $this->FontDescent
) / 2);
5453 $y -= ($this->cell_padding
['T'] +
$this->FontAscent
);
5458 $y -= ($h - $this->cell_padding
['B'] - $this->FontDescent
);
5465 $y -= (($h +
$this->FontAscent
- $this->FontDescent
) / 2);
5476 $y -= ($this->cell_padding
['T'] +
$this->FontAscent +
$this->FontDescent
);
5481 $y -= ($h - $this->cell_padding
['B']);
5488 $y -= (($h +
$this->FontAscent +
$this->FontDescent
) / 2);
5511 // text vertical alignment
5515 $yt = $y +
$this->cell_padding
['T'];
5520 $yt = $y +
$h - $this->cell_padding
['B'] - $this->FontAscent
- $this->FontDescent
;
5527 $yt = $y +
(($h - $this->FontAscent
- $this->FontDescent
) / 2);
5531 $basefonty = $yt +
$this->FontAscent
;
5532 if ($this->empty_string($w) OR ($w <= 0)) {
5534 $w = $x - $this->lMargin
;
5536 $w = $this->w
- $this->rMargin
- $x;
5541 if (is_string($border) AND (strlen($border) == 4)) {
5545 if ($fill OR ($border == 1)) {
5547 $op = ($border == 1) ?
'B' : 'f';
5552 $xk = (($x - $w) * $k);
5556 $s .= sprintf('%.2F %.2F %.2F %.2F re %s ', $xk, (($this->h
- $y) * $k), ($w * $k), (-$h * $k), $op);
5559 $s .= $this->getCellBorder($x, $y, $w, $h, $border);
5562 if ($this->isunicode
) {
5563 if (($this->CurrentFont
['type'] == 'core') OR ($this->CurrentFont
['type'] == 'TrueType') OR ($this->CurrentFont
['type'] == 'Type1')) {
5564 $txt2 = $this->UTF8ToLatin1($txt2);
5566 $unicode = $this->UTF8StringToArray($txt); // array of UTF-8 unicode values
5567 $unicode = $this->utf8Bidi($unicode, '', $this->tmprtl
);
5568 if (defined('K_THAI_TOPCHARS') AND (K_THAI_TOPCHARS
== true)) {
5569 // ---- Fix for bug #2977340 "Incorrect Thai characters position arrangement" ----
5570 // NOTE: this doesn't work with HTML justification
5571 // Symbols that could overlap on the font top (only works in LTR)
5572 $topchar = array(3611, 3613, 3615, 3650, 3651, 3652); // chars that extends on top
5573 $topsym = array(3633, 3636, 3637, 3638, 3639, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662); // symbols with top position
5574 $numchars = count($unicode); // number of chars
5576 $uniblock = array();
5577 $uniblock[$unik] = array();
5578 $uniblock[$unik][] = $unicode[0];
5579 // resolve overlapping conflicts by splitting the string in several parts
5580 for ($i = 1; $i < $numchars; ++
$i) {
5581 // check if symbols overlaps at top
5582 if (in_array($unicode[$i], $topsym) AND (in_array($unicode[($i - 1)], $topsym) OR in_array($unicode[($i - 1)], $topchar))) {
5583 // move symbols to another array
5585 $uniblock[$unik] = array();
5586 $uniblock[$unik][] = $unicode[$i];
5588 $uniblock[$unik] = array();
5589 $unicode[$i] = 0x200b; // Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
5591 $uniblock[$unik][] = $unicode[$i];
5594 // ---- END OF Fix for bug #2977340
5596 $txt2 = $this->arrUTF8ToUTF16BE($unicode, false);
5599 $txt2 = $this->_escape($txt2);
5600 // get current text width (considering general font stretching and spacing)
5601 $txwidth = $this->GetStringWidth($txt);
5603 // check for stretch mode
5605 // calculate ratio between cell width and text width
5609 $ratio = (($w - $this->cell_padding
['L'] - $this->cell_padding
['R']) / $width);
5611 // check if stretching is required
5612 if (($ratio < 1) OR (($ratio > 1) AND (($stretch %
2) == 0))) {
5613 // the text will be stretched to fit cell width
5615 // set new character spacing
5616 $this->font_spacing +
= ($w - $this->cell_padding
['L'] - $this->cell_padding
['R'] - $width) / (max(($this->GetNumChars($txt) - 1), 1) * ($this->font_stretching
/ 100));
5618 // set new horizontal stretching
5619 $this->font_stretching
*= $ratio;
5621 // recalculate text width (the text fills the entire cell)
5622 $width = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
5627 if ($this->font_stretching
!= 100) {
5628 // apply font stretching
5629 $rs .= sprintf('BT %.2F Tz ET ', $this->font_stretching
);
5631 if ($this->font_spacing
!= 0) {
5632 // increase/decrease font spacing
5633 $rs .= sprintf('BT %.2F Tc ET ', ($this->font_spacing
* $this->k
));
5635 if ($this->ColorFlag
) {
5636 $s .= 'q '.$this->TextColor
.' ';
5639 $s .= sprintf('BT %d Tr %.2F w ET ', $this->textrendermode
, $this->textstrokewidth
);
5640 // count number of spaces
5641 $ns = substr_count($txt, chr(32));
5644 if (($align == 'J') AND ($ns > 0)) {
5645 if ($this->isUnicodeFont()) {
5646 // get string width without spaces
5647 $width = $this->GetStringWidth(str_replace(' ', '', $txt));
5648 // calculate average space width
5649 $spacewidth = -1000 * ($w - $width - $this->cell_padding
['L'] - $this->cell_padding
['R']) / ($ns?
$ns:1) / $this->FontSize
;
5650 if ($this->font_stretching
!= 100) {
5651 // word spacing is affected by stretching
5652 $spacewidth /= ($this->font_stretching
/ 100);
5654 // set word position to be used with TJ operator
5655 $txt2 = str_replace(chr(0).chr(32), ') '.sprintf('%.3F', $spacewidth).' (', $txt2);
5656 $unicode_justification = true;
5661 $spacewidth = (($w - $width - $this->cell_padding
['L'] - $this->cell_padding
['R']) / ($ns?
$ns:1)) * $this->k
;
5662 if ($this->font_stretching
!= 100) {
5663 // word spacing (Tw) is affected by stretching
5664 $spacewidth /= ($this->font_stretching
/ 100);
5667 $rs .= sprintf('BT %.3F Tw ET ', $spacewidth);
5669 $width = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
5671 // replace carriage return characters
5672 $txt2 = str_replace("\r", ' ', $txt2);
5675 $dx = ($w - $width) / 2;
5680 $dx = $this->cell_padding
['R'];
5682 $dx = $w - $width - $this->cell_padding
['R'];
5688 $dx = $w - $width - $this->cell_padding
['L'];
5690 $dx = $this->cell_padding
['L'];
5697 $dx = $this->cell_padding
['R'];
5699 $dx = $this->cell_padding
['L'];
5705 $xdx = $x - $dx - $width;
5711 $s .= sprintf('BT %.2F %.2F Td [(%s)] TJ ET', $xdk, (($this->h
- $basefonty) * $k), $txt2);
5712 if (isset($uniblock)) {
5713 // print overlapping characters as separate string
5714 $xshift = 0; // horizontal shift
5715 $ty = (($this->h
- $basefonty +
(0.2 * $this->FontSize
)) * $k);
5716 $spw = (($w - $txwidth - $this->cell_padding
['L'] - $this->cell_padding
['R']) / ($ns?
$ns:1));
5717 foreach ($uniblock as $uk => $uniarr) {
5718 if (($uk %
2) == 0) {
5720 if ($spacewidth != 0) {
5721 // justification shift
5722 $xshift +
= (count(array_keys($uniarr, 32)) * $spw);
5724 $xshift +
= $this->GetArrStringWidth($uniarr); // + shift justification
5726 // character to print
5727 $topchr = $this->arrUTF8ToUTF16BE($uniarr, false);
5728 $topchr = $this->_escape($topchr);
5729 $s .= sprintf(' BT %.2F %.2F Td [(%s)] TJ ET', ($xdk +
($xshift * $k)), $ty, $topchr);
5733 if ($this->underline
) {
5734 $s .= ' '.$this->_dounderlinew($xdx, $basefonty, $width);
5736 if ($this->linethrough
) {
5737 $s .= ' '.$this->_dolinethroughw($xdx, $basefonty, $width);
5739 if ($this->overline
) {
5740 $s .= ' '.$this->_dooverlinew($xdx, $basefonty, $width);
5742 if ($this->ColorFlag
) {
5746 $this->Link($xdx, $yt, $width, ($this->FontAscent +
$this->FontDescent
), $link, $ns);
5753 if ($this->font_spacing
!= 0) {
5754 // reset font spacing mode
5755 $rs .= ' BT 0 Tc ET';
5757 if ($this->font_stretching
!= 100) {
5758 // reset font stretching mode
5759 $rs .= ' BT 100 Tz ET';
5762 // reset word spacing
5763 if (!$this->isUnicodeFont() AND ($align == 'J')) {
5764 $rs .= ' BT 0 Tw ET';
5766 // reset stretching and spacing
5767 $this->font_stretching
= $prev_font_stretching;
5768 $this->font_spacing
= $prev_font_spacing;
5771 //Go to the beginning of the next line
5772 $this->y
= $y +
$h +
$this->cell_margin
['B'];
5775 $this->x
= $this->w
- $this->rMargin
;
5777 $this->x
= $this->lMargin
;
5781 // go left or right by case
5783 $this->x
= $x - $w - $this->cell_margin
['L'];
5785 $this->x
= $x +
$w +
$this->cell_margin
['R'];
5788 $gstyles = ''.$this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
.' '.$this->FillColor
."\n";
5790 $this->cell_padding
= $prev_cell_padding;
5791 $this->cell_margin
= $prev_cell_margin;
5796 * Returns the code to draw the cell border
5797 * @param $x (float) X coordinate.
5798 * @param $y (float) Y coordinate.
5799 * @param $w (float) Cell width.
5800 * @param $h (float) Cell height.
5801 * @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)))
5802 * @return string containing cell border code
5804 * @see SetLineStyle()
5805 * @since 5.7.000 (2010-08-02)
5807 protected function getCellBorder($x, $y, $w, $h, $brd) {
5808 $s = ''; // string to be returned
5813 $brd = array('LRTB' => true);
5815 // calculate coordinates for border
5818 $xeL = ($x - $w) * $k;
5822 $xeR = ($x +
$w) * $k;
5824 $yeL = (($this->h
- ($y +
$h)) * $k);
5825 $yeT = (($this->h
- $y) * $k);
5830 if (is_string($brd)) {
5831 // convert string to array
5832 $slen = strlen($brd);
5834 for ($i = 0; $i < $slen; ++
$i) {
5835 $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
5839 if (isset($brd['mode'])) {
5840 $mode = $brd['mode'];
5841 unset($brd['mode']);
5845 foreach ($brd as $border => $style) {
5846 if (is_array($style) AND !empty($style)) {
5847 // apply border style
5848 $prev_style = $this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
.' ';
5849 $s .= $this->SetLineStyle($style, true)."\n";
5853 $off = (($this->LineWidth
/ 2) * $k);
5862 $w +
= $this->LineWidth
;
5863 $h +
= $this->LineWidth
;
5867 $off = ($this->LineWidth
/ 2) * $k;
5876 $w -= $this->LineWidth
;
5877 $h -= $this->LineWidth
;
5893 // draw borders by case
5894 if (strlen($border) == 4) {
5895 $s .= sprintf('%.2F %.2F %.2F %.2F re S ', $xT, $yT, ($w * $k), (-$h * $k));
5896 } elseif (strlen($border) == 3) {
5897 if (strpos($border,'B') === false) { // LTR
5898 $s .= sprintf('%.2F %.2F m ', $xL, $yL);
5899 $s .= sprintf('%.2F %.2F l ', $xT, $yT);
5900 $s .= sprintf('%.2F %.2F l ', $xR, $yR);
5901 $s .= sprintf('%.2F %.2F l ', $xB, $yB);
5903 } elseif (strpos($border,'L') === false) { // TRB
5904 $s .= sprintf('%.2F %.2F m ', $xT, $yT);
5905 $s .= sprintf('%.2F %.2F l ', $xR, $yR);
5906 $s .= sprintf('%.2F %.2F l ', $xB, $yB);
5907 $s .= sprintf('%.2F %.2F l ', $xL, $yL);
5909 } elseif (strpos($border,'T') === false) { // RBL
5910 $s .= sprintf('%.2F %.2F m ', $xR, $yR);
5911 $s .= sprintf('%.2F %.2F l ', $xB, $yB);
5912 $s .= sprintf('%.2F %.2F l ', $xL, $yL);
5913 $s .= sprintf('%.2F %.2F l ', $xT, $yT);
5915 } elseif (strpos($border,'R') === false) { // BLT
5916 $s .= sprintf('%.2F %.2F m ', $xB, $yB);
5917 $s .= sprintf('%.2F %.2F l ', $xL, $yL);
5918 $s .= sprintf('%.2F %.2F l ', $xT, $yT);
5919 $s .= sprintf('%.2F %.2F l ', $xR, $yR);
5922 } elseif (strlen($border) == 2) {
5923 if ((strpos($border,'L') !== false) AND (strpos($border,'T') !== false)) { // LT
5924 $s .= sprintf('%.2F %.2F m ', $xL, $yL);
5925 $s .= sprintf('%.2F %.2F l ', $xT, $yT);
5926 $s .= sprintf('%.2F %.2F l ', $xR, $yR);
5928 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'R') !== false)) { // TR
5929 $s .= sprintf('%.2F %.2F m ', $xT, $yT);
5930 $s .= sprintf('%.2F %.2F l ', $xR, $yR);
5931 $s .= sprintf('%.2F %.2F l ', $xB, $yB);
5933 } elseif ((strpos($border,'R') !== false) AND (strpos($border,'B') !== false)) { // RB
5934 $s .= sprintf('%.2F %.2F m ', $xR, $yR);
5935 $s .= sprintf('%.2F %.2F l ', $xB, $yB);
5936 $s .= sprintf('%.2F %.2F l ', $xL, $yL);
5938 } elseif ((strpos($border,'B') !== false) AND (strpos($border,'L') !== false)) { // BL
5939 $s .= sprintf('%.2F %.2F m ', $xB, $yB);
5940 $s .= sprintf('%.2F %.2F l ', $xL, $yL);
5941 $s .= sprintf('%.2F %.2F l ', $xT, $yT);
5943 } elseif ((strpos($border,'L') !== false) AND (strpos($border,'R') !== false)) { // LR
5944 $s .= sprintf('%.2F %.2F m ', $xL, $yL);
5945 $s .= sprintf('%.2F %.2F l ', $xT, $yT);
5947 $s .= sprintf('%.2F %.2F m ', $xR, $yR);
5948 $s .= sprintf('%.2F %.2F l ', $xB, $yB);
5950 } elseif ((strpos($border,'T') !== false) AND (strpos($border,'B') !== false)) { // TB
5951 $s .= sprintf('%.2F %.2F m ', $xT, $yT);
5952 $s .= sprintf('%.2F %.2F l ', $xR, $yR);
5954 $s .= sprintf('%.2F %.2F m ', $xB, $yB);
5955 $s .= sprintf('%.2F %.2F l ', $xL, $yL);
5958 } else { // strlen($border) == 1
5959 if (strpos($border,'L') !== false) { // L
5960 $s .= sprintf('%.2F %.2F m ', $xL, $yL);
5961 $s .= sprintf('%.2F %.2F l ', $xT, $yT);
5963 } elseif (strpos($border,'T') !== false) { // T
5964 $s .= sprintf('%.2F %.2F m ', $xT, $yT);
5965 $s .= sprintf('%.2F %.2F l ', $xR, $yR);
5967 } elseif (strpos($border,'R') !== false) { // R
5968 $s .= sprintf('%.2F %.2F m ', $xR, $yR);
5969 $s .= sprintf('%.2F %.2F l ', $xB, $yB);
5971 } elseif (strpos($border,'B') !== false) { // B
5972 $s .= sprintf('%.2F %.2F m ', $xB, $yB);
5973 $s .= sprintf('%.2F %.2F l ', $xL, $yL);
5977 if (is_array($style) AND !empty($style)) {
5978 // reset border style to previous value
5979 $s .= "\n".$this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
."\n";
5986 * This method allows printing text with line breaks.
5987 * 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 />
5988 * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
5989 * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
5990 * @param $h (float) Cell minimum height. The cell extends automatically if needed.
5991 * @param $txt (string) String to print
5992 * @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)))
5993 * @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>
5994 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
5995 * @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>
5996 * @param $x (float) x position in user units
5997 * @param $y (float) y position in user units
5998 * @param $reseth (boolean) if true reset the last cell height (default true).
5999 * @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.
6000 * @param $ishtml (boolean) set to true if $txt is HTML content (default = false).
6001 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
6002 * @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.
6003 * @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.
6004 * @param $fitcell (boolean) if true attempt to fit all the text within the cell by reducing the font size.
6005 * @return int Return the number of cells or 1 for html mode.
6008 * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
6010 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) {
6011 $prev_cell_margin = $this->cell_margin
;
6012 $prev_cell_padding = $this->cell_padding
;
6013 // adjust internal padding
6014 $this->adjustCellPadding($border);
6015 $mc_padding = $this->cell_padding
;
6016 $mc_margin = $this->cell_margin
;
6017 $this->cell_padding
['T'] = 0;
6018 $this->cell_padding
['B'] = 0;
6019 $this->setCellMargins(0, 0, 0, 0);
6020 if ($this->empty_string($this->lasth
) OR $reseth) {
6022 $this->resetLastH();
6024 if (!$this->empty_string($y)) {
6030 if ((!$this->InFooter
) AND (($y +
$h +
$mc_margin['T'] +
$mc_margin['B']) > $this->PageBreakTrigger
)) {
6031 // spit cell in more pages/columns
6032 $newh = $this->PageBreakTrigger
- $y;
6033 $resth = $h - $newh; // cell to be printed on the next page/column
6036 // get current page number
6037 $startpage = $this->page
;
6038 // get current column
6039 $startcolumn = $this->current_column
;
6040 if (!$this->empty_string($x)) {
6045 // check page for no-write regions and adapt page margins if necessary
6046 $this->checkPageRegions(0, $x, $y);
6048 $oy = $y +
$mc_margin['T'];
6050 $ox = $this->w
- $x - $mc_margin['R'];
6052 $ox = $x +
$mc_margin['L'];
6057 if ($this->empty_string($w) OR ($w <= 0)) {
6059 $w = $this->x
- $this->lMargin
- $mc_margin['L'];
6061 $w = $this->w
- $this->x
- $this->rMargin
- $mc_margin['R'];
6064 // store original margin values
6065 $lMargin = $this->lMargin
;
6066 $rMargin = $this->rMargin
;
6068 $this->rMargin
= $this->w
- $this->x
;
6069 $this->lMargin
= $this->x
- $w;
6071 $this->lMargin
= $this->x
;
6072 $this->rMargin
= $this->w
- $this->x
- $w;
6076 $this->y +
= $mc_padding['T'];
6078 if ($ishtml) { // ******* Write HTML text
6079 $this->writeHTML($txt, true, 0, $reseth, true, $align);
6081 } else { // ******* Write simple text
6082 // vertical alignment
6085 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
6087 $prev_FontSizePt = $this->FontSizePt
;
6088 // try to reduce font size to fit text on cell (use a quick search algorithm)
6090 $fmax = $this->FontSizePt
;
6091 $prev_text_height = $text_height;
6092 $maxit = 100; // max number of iterations
6093 while ($maxit > 0) {
6094 $fmid = (($fmax +
$fmin) / 2);
6095 $this->SetFontSize($fmid, false);
6096 $this->resetLastH();
6097 $text_height = $this->getStringHeight($w, $txt, $reseth, $autopadding, $mc_padding, $border);
6098 if (($text_height == $maxh) OR (($text_height < $maxh) AND ($fmin >= ($fmax - 0.01)))) {
6100 } elseif ($text_height < $maxh) {
6107 $this->SetFontSize($this->FontSizePt
);
6109 if ($text_height < $maxh) {
6110 if ($valign == 'M') {
6111 // text vertically centered
6112 $this->y +
= (($maxh - $text_height) / 2);
6113 } elseif ($valign == 'B') {
6114 // text vertically aligned on bottom
6115 $this->y +
= ($maxh - $text_height);
6119 $nl = $this->Write($this->lasth
, $txt, '', 0, $align, true, $stretch, false, true, $maxh, 0, $mc_margin);
6121 // restore font size
6122 $this->SetFontSize($prev_FontSizePt);
6126 // add bottom padding
6127 $this->y +
= $mc_padding['B'];
6129 // Get end-of-text Y position
6130 $currentY = $this->y
;
6131 // get latest page number
6132 $endpage = $this->page
;
6134 $skip = ($endpage - $startpage);
6136 while ($tmpresth > 0) {
6138 // add a page (or trig AcceptPageBreak() for multicolumn mode)
6139 $this->checkPageBreak($this->PageBreakTrigger +
1);
6141 if ($this->num_columns
> 1) {
6142 $tmpresth -= ($this->h
- $this->y
- $this->bMargin
);
6144 $tmpresth -= ($this->h
- $this->tMargin
- $this->bMargin
);
6148 $currentY = $this->y
;
6149 $endpage = $this->page
;
6151 // get latest column
6152 $endcolumn = $this->current_column
;
6153 if ($this->num_columns
== 0) {
6154 $this->num_columns
= 1;
6157 $border_start = $this->getBorderMode($border, $position='start');
6158 $border_end = $this->getBorderMode($border, $position='end');
6159 $border_middle = $this->getBorderMode($border, $position='middle');
6160 // design borders around HTML cells.
6161 for ($page = $startpage; $page <= $endpage; ++
$page) { // for each page
6163 $this->setPage($page);
6164 if ($this->num_columns
< 2) {
6165 // single-column mode
6167 $this->y
= $this->tMargin
;
6169 // account for margin changes
6170 if ($page > $startpage) {
6171 if (($this->rtl
) AND ($this->pagedim
[$page]['orm'] != $this->pagedim
[$startpage]['orm'])) {
6172 $this->x
-= ($this->pagedim
[$page]['orm'] - $this->pagedim
[$startpage]['orm']);
6173 } elseif ((!$this->rtl
) AND ($this->pagedim
[$page]['olm'] != $this->pagedim
[$startpage]['olm'])) {
6174 $this->x +
= ($this->pagedim
[$page]['olm'] - $this->pagedim
[$startpage]['olm']);
6177 if ($startpage == $endpage) {
6179 for ($column = $startcolumn; $column <= $endcolumn; ++
$column) { // for each column
6180 $this->selectColumn($column);
6182 $this->x
-= $mc_margin['R'];
6184 $this->x +
= $mc_margin['L'];
6186 if ($startcolumn == $endcolumn) { // single column
6188 $h = max($h, ($currentY - $oy));
6190 } elseif ($column == $startcolumn) { // first column
6191 $cborder = $border_start;
6193 $h = $this->h
- $this->y
- $this->bMargin
;
6194 } elseif ($column == $endcolumn) { // end column
6195 $cborder = $border_end;
6196 $h = $currentY - $this->y
;
6200 } else { // middle column
6201 $cborder = $border_middle;
6202 $h = $this->h
- $this->y
- $this->bMargin
;
6205 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6206 } // end for each column
6207 } elseif ($page == $startpage) { // first page
6208 for ($column = $startcolumn; $column < $this->num_columns
; ++
$column) { // for each column
6209 $this->selectColumn($column);
6211 $this->x
-= $mc_margin['R'];
6213 $this->x +
= $mc_margin['L'];
6215 if ($column == $startcolumn) { // first column
6216 $cborder = $border_start;
6218 $h = $this->h
- $this->y
- $this->bMargin
;
6219 } else { // middle column
6220 $cborder = $border_middle;
6221 $h = $this->h
- $this->y
- $this->bMargin
;
6224 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6225 } // end for each column
6226 } elseif ($page == $endpage) { // last page
6227 for ($column = 0; $column <= $endcolumn; ++
$column) { // for each column
6228 $this->selectColumn($column);
6230 $this->x
-= $mc_margin['R'];
6232 $this->x +
= $mc_margin['L'];
6234 if ($column == $endcolumn) {
6236 $cborder = $border_end;
6237 $h = $currentY - $this->y
;
6243 $cborder = $border_middle;
6244 $h = $this->h
- $this->y
- $this->bMargin
;
6247 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6248 } // end for each column
6249 } else { // middle page
6250 for ($column = 0; $column < $this->num_columns
; ++
$column) { // for each column
6251 $this->selectColumn($column);
6253 $this->x
-= $mc_margin['R'];
6255 $this->x +
= $mc_margin['L'];
6257 $cborder = $border_middle;
6258 $h = $this->h
- $this->y
- $this->bMargin
;
6260 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
6261 } // end for each column
6263 if ($cborder OR $fill) {
6264 // draw border and fill
6265 if ($this->inxobj
) {
6266 // we are inside an XObject template
6267 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
6268 $pagemarkkey = key($this->xobjects
[$this->xobjid
]['transfmrk']);
6269 $pagemark = &$this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey];
6271 $pagemark = &$this->xobjects
[$this->xobjid
]['intmrk'];
6273 $pagebuff = $this->xobjects
[$this->xobjid
]['outdata'];
6274 $pstart = substr($pagebuff, 0, $pagemark);
6275 $pend = substr($pagebuff, $pagemark);
6276 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$ccode.$pend;
6277 $pagemark +
= strlen($ccode);
6279 if (end($this->transfmrk
[$this->page
]) !== false) {
6280 $pagemarkkey = key($this->transfmrk
[$this->page
]);
6281 $pagemark = &$this->transfmrk
[$this->page
][$pagemarkkey];
6282 } elseif ($this->InFooter
) {
6283 $pagemark = &$this->footerpos
[$this->page
];
6285 $pagemark = &$this->intmrk
[$this->page
];
6287 $pagebuff = $this->getPageBuffer($this->page
);
6288 $pstart = substr($pagebuff, 0, $pagemark);
6289 $pend = substr($pagebuff, $pagemark);
6290 $this->setPageBuffer($this->page
, $pstart.$ccode.$pend);
6291 $pagemark +
= strlen($ccode);
6294 } // end for each page
6295 // Get end-of-cell Y position
6296 $currentY = $this->GetY();
6297 // restore original margin values
6298 $this->SetLeftMargin($lMargin);
6299 $this->SetRightMargin($rMargin);
6301 //Go to the beginning of the next line
6302 $this->SetY($currentY +
$mc_margin['B']);
6304 $this->SetX($x +
$w +
$mc_margin['L'] +
$mc_margin['R']);
6307 // go left or right by case
6308 $this->setPage($startpage);
6310 $this->SetX($x +
$w +
$mc_margin['L'] +
$mc_margin['R']);
6312 $this->setContentMark();
6313 $this->cell_padding
= $prev_cell_padding;
6314 $this->cell_margin
= $prev_cell_margin;
6319 * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
6320 * @param $brd (mixed) Indicates if borders must be drawn around the cell block. 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: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
6321 * @param $position (string) multicell position: 'start', 'middle', 'end'
6322 * @return border mode array
6324 * @since 4.4.002 (2008-12-09)
6326 protected function getBorderMode($brd, $position='start') {
6327 if ((!$this->opencell
) OR empty($brd)) {
6333 if (is_string($brd)) {
6334 // convert string to array
6335 $slen = strlen($brd);
6337 for ($i = 0; $i < $slen; ++
$i) {
6338 $newbrd[$brd{$i}] = array('cap' => 'square', 'join' => 'miter');
6342 foreach ($brd as $border => $style) {
6343 switch ($position) {
6345 if (strpos($border, 'B') !== false) {
6346 // remove bottom line
6347 $newkey = str_replace('B', '', $border);
6348 if (strlen($newkey) > 0) {
6349 $brd[$newkey] = $style;
6351 unset($brd[$border]);
6356 if (strpos($border, 'B') !== false) {
6357 // remove bottom line
6358 $newkey = str_replace('B', '', $border);
6359 if (strlen($newkey) > 0) {
6360 $brd[$newkey] = $style;
6362 unset($brd[$border]);
6365 if (strpos($border, 'T') !== false) {
6366 // remove bottom line
6367 $newkey = str_replace('T', '', $border);
6368 if (strlen($newkey) > 0) {
6369 $brd[$newkey] = $style;
6371 unset($brd[$border]);
6376 if (strpos($border, 'T') !== false) {
6377 // remove bottom line
6378 $newkey = str_replace('T', '', $border);
6379 if (strlen($newkey) > 0) {
6380 $brd[$newkey] = $style;
6382 unset($brd[$border]);
6392 * This method return the estimated number of lines for print a simple text string using Multicell() method.
6393 * @param $txt (string) String for calculating his height
6394 * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
6395 * @param $reseth (boolean) if true reset the last cell height (default false).
6396 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
6397 * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
6398 * @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)))
6399 * @return float Return the minimal height needed for multicell method for printing the $txt param.
6400 * @author Alexander Escalona Fernández, Nicola Asuni
6404 public function getNumLines($txt, $w=0, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
6409 // adjust internal padding
6410 $prev_cell_padding = $this->cell_padding
;
6411 $prev_lasth = $this->lasth
;
6412 if (is_array($cellpadding)) {
6413 $this->cell_padding
= $cellpadding;
6415 $this->adjustCellPadding($border);
6416 if ($this->empty_string($w) OR ($w <= 0)) {
6418 $w = $this->x
- $this->lMargin
;
6420 $w = $this->w
- $this->rMargin
- $this->x
;
6423 $wmax = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
6426 $this->resetLastH();
6430 $chars = $this->utf8Bidi($this->UTF8StringToArray($txt), $txt, $this->tmprtl
);
6431 $charsWidth = $this->GetArrStringWidth($chars, '', '', 0, true);
6432 $length = count($chars);
6433 $lastSeparator = -1;
6434 for ($i = 0; $i < $length; ++
$i) {
6435 $charWidth = $charsWidth[$i];
6436 if (preg_match($this->re_spaces
, $this->unichr($chars[$i]))) {
6437 $lastSeparator = $i;
6439 if ((($sum +
$charWidth) > $wmax) OR ($chars[$i] == 10)) {
6441 if ($lastSeparator != -1) {
6442 $i = $lastSeparator;
6443 $lastSeparator = -1;
6452 if ($chars[($length - 1)] == 10) {
6455 $this->cell_padding
= $prev_cell_padding;
6456 $this->lasth
= $prev_lasth;
6461 * This method return the estimated needed height for print a simple text string in Multicell() method.
6462 * Generally, if you want to know the exact height for a block of content you can use the following alternative technique:
6464 * // store current object
6465 * $pdf->startTransaction();
6466 * // store starting values
6467 * $start_y = $pdf->GetY();
6468 * $start_page = $pdf->getPage();
6469 * // call your printing functions with your parameters
6470 * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6471 * $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);
6472 * // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6474 * $end_y = $pdf->GetY();
6475 * $end_page = $pdf->getPage();
6476 * // calculate height
6478 * if ($end_page == $start_page) {
6479 * $height = $end_y - $start_y;
6481 * for ($page=$start_page; $page <= $end_page; ++$page) {
6482 * $this->setPage($page);
6483 * if ($page == $start_page) {
6485 * $height = $this->h - $start_y - $this->bMargin;
6486 * } elseif ($page == $end_page) {
6488 * $height = $end_y - $this->tMargin;
6490 * $height = $this->h - $this->tMargin - $this->bMargin;
6494 * // restore previous object
6495 * $pdf = $pdf->rollbackTransaction();
6497 * @param $w (float) Width of cells. If 0, they extend up to the right margin of the page.
6498 * @param $txt (string) String for calculating his height
6499 * @param $reseth (boolean) if true reset the last cell height (default false).
6500 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width (default true).
6501 * @param $cellpadding (float) Internal cell padding, if empty uses default cell padding.
6502 * @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)))
6503 * @return float Return the minimal height needed for multicell method for printing the $txt param.
6504 * @author Nicola Asuni, Alexander Escalona Fernández
6507 public function getStringHeight($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0) {
6508 // adjust internal padding
6509 $prev_cell_padding = $this->cell_padding
;
6510 $prev_lasth = $this->lasth
;
6511 if (is_array($cellpadding)) {
6512 $this->cell_padding
= $cellpadding;
6514 $this->adjustCellPadding($border);
6515 $lines = $this->getNumLines($txt, $w, $reseth, $autopadding, $cellpadding, $border);
6516 $height = $lines * ($this->FontSize
* $this->cell_height_ratio
);
6518 // add top and bottom padding
6519 $height +
= ($this->cell_padding
['T'] +
$this->cell_padding
['B']);
6521 $this->cell_padding
= $prev_cell_padding;
6522 $this->lasth
= $prev_lasth;
6527 * This method prints text from the current position.<br />
6528 * @param $h (float) Line height
6529 * @param $txt (string) String to print
6530 * @param $link (mixed) URL or identifier returned by AddLink()
6531 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
6532 * @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>
6533 * @param $ln (boolean) if true set cursor at the bottom of the line, otherwise set cursor at the top of the line.
6534 * @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.
6535 * @param $firstline (boolean) if true prints only the first line and return the remaining string.
6536 * @param $firstblock (boolean) if true the string is the starting of a line.
6537 * @param $maxh (float) maximum height. The remaining unprinted text will be returned. It should be >= $h and less then remaining space to the bottom of the page, or 0 for disable this feature.
6538 * @param $wadj (float) first line width will be reduced by this amount (used in HTML mode).
6539 * @param $margin (array) margin array of the parent container
6540 * @return mixed Return the number of cells or the remaining string if $firstline = true.
6544 public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $stretch=0, $firstline=false, $firstblock=false, $maxh=0, $wadj=0, $margin='') {
6545 // check page for no-write regions and adapt page margins if necessary
6546 $this->checkPageRegions($h, $this->x
, $this->y
);
6547 if (strlen($txt) == 0) {
6551 if ($margin === '') {
6552 // set default margins
6553 $margin = $this->cell_margin
;
6555 // remove carriage returns
6556 $s = str_replace("\r", '', $txt);
6557 // check if string contains arabic text
6558 if (preg_match($this->unicode
->uni_RE_PATTERN_ARABIC
, $s)) {
6563 // check if string contains RTL text
6564 if ($arabic OR ($this->tmprtl
== 'R') OR preg_match($this->unicode
->uni_RE_PATTERN_RTL
, $s)) {
6570 $chrwidth = $this->GetCharWidth('.');
6571 // get array of unicode values
6572 $chars = $this->UTF8StringToArray($s);
6573 // get array of chars
6574 $uchars = $this->UTF8ArrayToUniArray($chars);
6575 // get the number of characters
6576 $nb = count($chars);
6577 // replacement for SHY character (minus symbol)
6578 $shy_replacement = 45;
6579 $shy_replacement_char = $this->unichr($shy_replacement);
6580 // widht for SHY replacement
6581 $shy_replacement_width = $this->GetCharWidth($shy_replacement);
6583 $maxy = $this->y +
$maxh - $h - $this->cell_padding
['T'] - $this->cell_padding
['B'];
6584 // calculate remaining line width ($w)
6586 $w = $this->x
- $this->lMargin
;
6588 $w = $this->w
- $this->rMargin
- $this->x
;
6593 $wmax -= ($this->cell_padding
['L'] +
$this->cell_padding
['R']);
6595 if ((!$firstline) AND (($chrwidth > $wmax) OR ($this->GetCharWidth($chars[0]) > $wmax))) {
6596 // a single character do not fit on column
6599 // minimum row height
6600 $row_height = max($h, $this->FontSize
* $this->cell_height_ratio
);
6601 $start_page = $this->page
;
6602 $i = 0; // character position
6603 $j = 0; // current starting position
6604 $sep = -1; // position of the last blank space
6605 $shy = false; // true if the last blank is a soft hypen (SHY)
6606 $l = 0; // current string length
6607 $nl = 0; //number of lines
6609 $pc = 0; // previous character
6610 // for each character
6612 if (($maxh > 0) AND ($this->y
>= $maxy) ) {
6615 //Get the current character
6617 if ($c == 10) { // 10 = "\n" = new line
6618 //Explicit line break
6619 if ($align == 'J') {
6628 $tmpstr = $this->UniArrSubString($uchars, $j, $i);
6631 $tmparr = array_slice($chars, $j, ($i - $j));
6633 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl
);
6635 $linew = $this->GetArrStringWidth($tmparr);
6638 $this->endlinex
= $startx - $linew;
6640 $this->endlinex
= $startx +
$linew;
6643 $tmpcellpadding = $this->cell_padding
;
6645 $this->SetCellPadding(0);
6648 if ($firstblock AND $this->isRTLTextDir()) {
6649 $tmpstr = $this->stringRightTrim($tmpstr);
6651 // Skip newlines at the begining of a page or column
6652 if (!empty($tmpstr) OR ($this->y
< ($this->PageBreakTrigger
- $row_height))) {
6653 $this->Cell($w, $h, $tmpstr, 0, 1, $talign, $fill, $link, $stretch);
6657 $this->cell_padding
= $tmpcellpadding;
6658 return ($this->UniArrSubString($uchars, $i));
6665 // account for margin changes
6666 if ((($this->y +
$this->lasth
) > $this->PageBreakTrigger
) AND (!$this->InFooter
)) {
6667 $this->AcceptPageBreak();
6669 $this->x
-= $margin['R'];
6671 $this->x +
= $margin['L'];
6673 $this->lMargin +
= $margin['L'];
6674 $this->rMargin +
= $margin['R'];
6676 $w = $this->getRemainingWidth();
6677 $wmax = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
6679 // 160 is the non-breaking space.
6680 // 173 is SHY (Soft Hypen).
6681 // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
6682 // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
6683 // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
6684 if (($c != 160) AND (($c == 173) OR preg_match($this->re_spaces
, $this->unichr($c)))) {
6685 // update last blank space position
6687 // check if is a SHY
6691 $tmp_shy_replacement_width = 0;
6692 $tmp_shy_replacement_char = '';
6694 $tmp_shy_replacement_width = $shy_replacement_width;
6695 $tmp_shy_replacement_char = $shy_replacement_char;
6701 // update string length
6702 if ($this->isUnicodeFont() AND ($arabic)) {
6703 // with bidirectional algorithm some chars may be changed affecting the line length
6704 // *** very slow ***
6705 $l = $this->GetArrStringWidth($this->utf8Bidi(array_slice($chars, $j, ($i - $j)), '', $this->tmprtl
));
6707 $l +
= $this->GetCharWidth($c);
6709 if (($l > $wmax) OR (($c == 173) AND (($l +
$tmp_shy_replacement_width) > $wmax)) ) {
6710 // we have reached the end of column
6712 // check if the line was already started
6713 if (($this->rtl
AND ($this->x
<= ($this->w
- $this->rMargin
- $chrwidth)))
6714 OR ((!$this->rtl
) AND ($this->x
>= ($this->lMargin +
$chrwidth)))) {
6715 // print a void cell and go to next line
6716 $this->Cell($w, $h, '', 0, 1);
6719 return ($this->UniArrSubString($uchars, $j));
6722 // truncate the word because do not fit on column
6723 $tmpstr = $this->UniArrSubString($uchars, $j, $i);
6726 $tmparr = array_slice($chars, $j, ($i - $j));
6728 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl
);
6730 $linew = $this->GetArrStringWidth($tmparr);
6733 $this->endlinex
= $startx - $linew;
6735 $this->endlinex
= $startx +
$linew;
6738 $tmpcellpadding = $this->cell_padding
;
6740 $this->SetCellPadding(0);
6743 if ($firstblock AND $this->isRTLTextDir()) {
6744 $tmpstr = $this->stringRightTrim($tmpstr);
6746 $this->Cell($w, $h, $tmpstr, 0, 1, $align, $fill, $link, $stretch);
6749 $this->cell_padding
= $tmpcellpadding;
6750 return ($this->UniArrSubString($uchars, $i));
6757 if ($this->rtl
AND (!$firstblock) AND ($sep < $i)) {
6763 // add hypen (minus symbol) at the end of the line
6764 $shy_width = $tmp_shy_replacement_width;
6766 $shy_char_left = $tmp_shy_replacement_char;
6767 $shy_char_right = '';
6769 $shy_char_left = '';
6770 $shy_char_right = $tmp_shy_replacement_char;
6774 $shy_char_left = '';
6775 $shy_char_right = '';
6777 $tmpstr = $this->UniArrSubString($uchars, $j, ($sep +
$endspace));
6780 $tmparr = array_slice($chars, $j, (($sep +
$endspace) - $j));
6782 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl
);
6784 $linew = $this->GetArrStringWidth($tmparr);
6787 $this->endlinex
= $startx - $linew - $shy_width;
6789 $this->endlinex
= $startx +
$linew +
$shy_width;
6792 $tmpcellpadding = $this->cell_padding
;
6794 $this->SetCellPadding(0);
6798 if ($firstblock AND $this->isRTLTextDir()) {
6799 $tmpstr = $this->stringRightTrim($tmpstr);
6801 $this->Cell($w, $h, $shy_char_left.$tmpstr.$shy_char_right, 0, 1, $align, $fill, $link, $stretch);
6804 // return the remaining text
6805 $this->cell_padding
= $tmpcellpadding;
6806 return ($this->UniArrSubString($uchars, ($sep +
$endspace)));
6813 // account for margin changes
6814 if ((($this->y +
$this->lasth
) > $this->PageBreakTrigger
) AND (!$this->InFooter
)) {
6815 $this->AcceptPageBreak();
6817 $this->x
-= $margin['R'];
6819 $this->x +
= $margin['L'];
6821 $this->lMargin +
= $margin['L'];
6822 $this->rMargin +
= $margin['R'];
6824 $w = $this->getRemainingWidth();
6825 $wmax = $w - $this->cell_padding
['L'] - $this->cell_padding
['R'];
6834 // save last character
6837 } // end while i < nb
6838 // print last substring (if any)
6867 $tmpstr = $this->UniArrSubString($uchars, $j, $nb);
6870 $tmparr = array_slice($chars, $j, ($nb - $j));
6872 $tmparr = $this->utf8Bidi($tmparr, $tmpstr, $this->tmprtl
);
6874 $linew = $this->GetArrStringWidth($tmparr);
6877 $this->endlinex
= $startx - $linew;
6879 $this->endlinex
= $startx +
$linew;
6882 $tmpcellpadding = $this->cell_padding
;
6884 $this->SetCellPadding(0);
6887 if ($firstblock AND $this->isRTLTextDir()) {
6888 $tmpstr = $this->stringRightTrim($tmpstr);
6890 $this->Cell($w, $h, $tmpstr, 0, $ln, $align, $fill, $link, $stretch);
6893 $this->cell_padding
= $tmpcellpadding;
6894 return ($this->UniArrSubString($uchars, $nb));
6905 * Returns the remaining width between the current position and margins.
6906 * @return int Return the remaining width
6909 protected function getRemainingWidth() {
6910 $this->checkPageRegions(0, $this->x
, $this->y
);
6912 return ($this->x
- $this->lMargin
);
6914 return ($this->w
- $this->rMargin
- $this->x
);
6919 * Extract a slice of the $strarr array and return it as string.
6920 * @param $strarr (string) The input array of characters.
6921 * @param $start (int) the starting element of $strarr.
6922 * @param $end (int) first element that will not be returned.
6923 * @return Return part of a string
6926 public function UTF8ArrSubString($strarr, $start='', $end='') {
6927 if (strlen($start) == 0) {
6930 if (strlen($end) == 0) {
6931 $end = count($strarr);
6934 for ($i=$start; $i < $end; ++
$i) {
6935 $string .= $this->unichr($strarr[$i]);
6941 * Extract a slice of the $uniarr array and return it as string.
6942 * @param $uniarr (string) The input array of characters.
6943 * @param $start (int) the starting element of $strarr.
6944 * @param $end (int) first element that will not be returned.
6945 * @return Return part of a string
6947 * @since 4.5.037 (2009-04-07)
6949 public function UniArrSubString($uniarr, $start='', $end='') {
6950 if (strlen($start) == 0) {
6953 if (strlen($end) == 0) {
6954 $end = count($uniarr);
6957 for ($i=$start; $i < $end; ++
$i) {
6958 $string .= $uniarr[$i];
6964 * Convert an array of UTF8 values to array of unicode characters
6965 * @param $ta (string) The input array of UTF8 values.
6966 * @return Return array of unicode characters
6968 * @since 4.5.037 (2009-04-07)
6970 public function UTF8ArrayToUniArray($ta) {
6971 return array_map(array($this, 'unichr'), $ta);
6975 * Returns the unicode caracter specified by UTF-8 value
6976 * @param $c (int) UTF-8 value
6977 * @return Returns the specified character.
6978 * @author Miguel Perez, Nicola Asuni
6980 * @since 2.3.000 (2008-03-05)
6982 public function unichr($c) {
6983 if (!$this->isunicode
) {
6985 } elseif ($c <= 0x7F) {
6988 } elseif ($c <= 0x7FF) {
6990 return chr(0xC0 |
$c >> 6).chr(0x80 |
$c & 0x3F);
6991 } elseif ($c <= 0xFFFF) {
6993 return chr(0xE0 |
$c >> 12).chr(0x80 |
$c >> 6 & 0x3F).chr(0x80 |
$c & 0x3F);
6994 } elseif ($c <= 0x10FFFF) {
6996 return chr(0xF0 |
$c >> 18).chr(0x80 |
$c >> 12 & 0x3F).chr(0x80 |
$c >> 6 & 0x3F).chr(0x80 |
$c & 0x3F);
7003 * Return the image type given the file name or array returned by getimagesize() function.
7004 * @param $imgfile (string) image file name
7005 * @param $iminfo (array) array of image information returned by getimagesize() function.
7006 * @return string image type
7007 * @since 4.8.017 (2009-11-27)
7009 public function getImageFileType($imgfile, $iminfo=array()) {
7011 if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
7012 $mime = explode('/', $iminfo['mime']);
7013 if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
7014 $type = strtolower(trim($mime[1]));
7018 $fileinfo = pathinfo($imgfile);
7019 if (isset($fileinfo['extension']) AND (!$this->empty_string($fileinfo['extension']))) {
7020 $type = strtolower(trim($fileinfo['extension']));
7023 if ($type == 'jpg') {
7030 * Set the block dimensions accounting for page breaks and page/column fitting
7031 * @param $w (float) width
7032 * @param $h (float) height
7033 * @param $x (float) X coordinate
7034 * @param $y (float) Y coodiante
7035 * @param $fitonpage (boolean) if true the block is resized to not exceed page dimensions.
7037 * @since 5.5.009 (2010-07-05)
7039 protected function fitBlock(&$w, &$h, &$x, &$y, $fitonpage=false) {
7041 // set maximum width
7042 $w = ($this->w
- $this->lMargin
- $this->rMargin
);
7045 // set maximum height
7046 $h = ($this->PageBreakTrigger
- $this->tMargin
);
7048 // resize the block to be vertically contained on a single page or single column
7049 if ($fitonpage OR $this->AutoPageBreak
) {
7050 $ratio_wh = ($w / $h);
7051 if ($h > ($this->PageBreakTrigger
- $this->tMargin
)) {
7052 $h = $this->PageBreakTrigger
- $this->tMargin
;
7053 $w = ($h * $ratio_wh);
7055 // resize the block to be horizontally contained on a single page or single column
7057 $maxw = ($this->w
- $this->lMargin
- $this->rMargin
);
7060 $h = ($w / $ratio_wh);
7064 // Check whether we need a new page or new column first as this does not fit
7067 if ($this->checkPageBreak($h, $y) OR ($this->y
< $prev_y)) {
7070 $x +
= ($prev_x - $this->x
);
7072 $x +
= ($this->x
- $prev_x);
7075 // resize the block to be contained on the remaining available page or column space
7077 $ratio_wh = ($w / $h);
7078 if (($y +
$h) > $this->PageBreakTrigger
) {
7079 $h = $this->PageBreakTrigger
- $y;
7080 $w = ($h * $ratio_wh);
7082 if ((!$this->rtl
) AND (($x +
$w) > ($this->w
- $this->rMargin
))) {
7083 $w = $this->w
- $this->rMargin
- $x;
7084 $h = ($w / $ratio_wh);
7085 } elseif (($this->rtl
) AND (($x - $w) < ($this->lMargin
))) {
7086 $w = $x - $this->lMargin
;
7087 $h = ($w / $ratio_wh);
7093 * Puts an image in the page.
7094 * The upper-left corner must be given.
7095 * The dimensions can be specified in different ways:<ul>
7096 * <li>explicit width and height (expressed in user unit)</li>
7097 * <li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li>
7098 * <li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
7099 * 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;
7100 * The format can be specified explicitly or inferred from the file extension.<br />
7101 * It is possible to put a link on the image.<br />
7102 * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
7103 * @param $file (string) Name of the file containing the image or a '@' character followed by the image data string.
7104 * @param $x (float) Abscissa of the upper-left corner (LTR) or upper-right corner (RTL).
7105 * @param $y (float) Ordinate of the upper-left corner (LTR) or upper-right corner (RTL).
7106 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
7107 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
7108 * @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.
7109 * @param $link (mixed) URL or identifier returned by AddLink().
7110 * @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>
7111 * @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).
7112 * @param $dpi (int) dot-per-inch resolution used on resize
7113 * @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>
7114 * @param $ismask (boolean) true if this image is a mask, false otherwise
7115 * @param $imgmask (mixed) image object returned by this function or false
7116 * @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)))
7117 * @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).
7118 * @param $hidden (boolean) if true do not display the image.
7119 * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
7120 * @return image information
7124 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) {
7131 // check page for no-write regions and adapt page margins if necessary
7132 $this->checkPageRegions($h, $x, $y);
7133 $cached_file = false; // true when the file is cached
7134 // check if we are passing an image as file or string
7135 if ($file{0} === '@') { // image from string
7136 $imgdata = substr($file, 1);
7137 $file = tempnam(K_PATH_CACHE
, 'img_');
7138 $fp = fopen($file, 'w');
7139 fwrite($fp, $imgdata);
7142 $cached_file = true;
7143 $imsize = @getimagesize
($file);
7144 if ($imsize === FALSE) {
7146 $cached_file = false;
7148 } else { // image file
7149 // check if is local file
7150 if (!@file_exists
($file)) {
7151 // encode spaces on filename (file is probably an URL)
7152 $file = str_replace(' ', '%20', $file);
7154 // get image dimensions
7155 $imsize = @getimagesize
($file);
7156 if ($imsize === FALSE) {
7157 if (function_exists('curl_init')) {
7158 // try to get remote file data using cURL
7159 $cs = curl_init(); // curl session
7160 curl_setopt($cs, CURLOPT_URL
, $file);
7161 curl_setopt($cs, CURLOPT_BINARYTRANSFER
, true);
7162 curl_setopt($cs, CURLOPT_FAILONERROR
, true);
7163 curl_setopt($cs, CURLOPT_RETURNTRANSFER
, true);
7164 curl_setopt($cs, CURLOPT_CONNECTTIMEOUT
, 5);
7165 curl_setopt($cs, CURLOPT_TIMEOUT
, 30);
7166 $imgdata = curl_exec($cs);
7168 if($imgdata !== FALSE) {
7169 // copy image to cache
7170 $file = tempnam(K_PATH_CACHE
, 'img_');
7171 $fp = fopen($file, 'w');
7172 fwrite($fp, $imgdata);
7175 $cached_file = true;
7176 $imsize = @getimagesize
($file);
7177 if ($imsize === FALSE) {
7179 $cached_file = false;
7182 } elseif (($w > 0) AND ($h > 0)) {
7183 // get measures from specified data
7184 $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit
, true) * $this->imgscale
* $this->k
;
7185 $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit
, true) * $this->imgscale
* $this->k
;
7186 $imsize = array($pw, $ph);
7190 if ($imsize === FALSE) {
7191 $this->Error('[Image] Unable to get image: '.$file);
7193 // get original image width and height in pixels
7194 list($pixw, $pixh) = $imsize;
7195 // calculate image width and height on document
7196 if (($w <= 0) AND ($h <= 0)) {
7197 // convert image size to document unit
7198 $w = $this->pixelsToUnits($pixw);
7199 $h = $this->pixelsToUnits($pixh);
7200 } elseif ($w <= 0) {
7201 $w = $h * $pixw / $pixh;
7202 } elseif ($h <= 0) {
7203 $h = $w * $pixh / $pixw;
7204 } elseif (($fitbox !== false) AND ($w > 0) AND ($h > 0)) {
7205 if (strlen($fitbox) !== 2) {
7206 // set default alignment
7209 // scale image dimensions proportionally to fit within the ($w, $h) box
7210 if ((($w * $pixh) / ($h * $pixw)) < 1) {
7211 // store current height
7213 // calculate new height
7214 $h = $w * $pixh / $pixw;
7215 // height difference
7216 $hdiff = ($oldh - $h);
7217 // vertical alignment
7218 switch (strtoupper($fitbox{1})) {
7232 // store current width
7234 // calculate new width
7235 $w = $h * $pixw / $pixh;
7237 $wdiff = ($oldw - $w);
7238 // horizontal alignment
7239 switch (strtoupper($fitbox{0})) {
7263 // fit the image on available space
7264 $this->fitBlock($w, $h, $x, $y, $fitonpage);
7265 // calculate new minimum dimensions in pixels
7266 $neww = round($w * $this->k
* $dpi / $this->dpi
);
7267 $newh = round($h * $this->k
* $dpi / $this->dpi
);
7268 // check if resize is necessary (resize is used only to reduce the image)
7269 $newsize = ($neww * $newh);
7270 $pixsize = ($pixw * $pixh);
7271 if (intval($resize) == 2) {
7273 } elseif ($newsize >= $pixsize) {
7276 // check if image has been already added on document
7278 if (in_array($file, $this->imagekeys
)) {
7280 // get existing image data
7281 $info = $this->getImageBuffer($file);
7282 // check if the newer image is larger
7283 $oldsize = ($info['w'] * $info['h']);
7284 if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) {
7289 //First use of image, get info
7290 $type = strtolower($type);
7292 $type = $this->getImageFileType($file, $imsize);
7293 } elseif ($type == 'jpg') {
7296 $mqr = $this->get_mqr();
7297 $this->set_mqr(false);
7298 // Specific image handlers
7299 $mtd = '_parse'.$type;
7300 // GD image handler function
7301 $gdfunction = 'imagecreatefrom'.$type;
7303 if ((method_exists($this, $mtd)) AND (!($resize AND function_exists($gdfunction)))) {
7304 // TCPDF image functions
7305 $info = $this->$mtd($file);
7306 if ($info == 'pngalpha') {
7307 return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign);
7311 if (function_exists($gdfunction)) {
7313 $img = $gdfunction($file);
7315 $imgr = imagecreatetruecolor($neww, $newh);
7316 if (($type == 'gif') OR ($type == 'png')) {
7317 $imgr = $this->_setGDImageTransparency($imgr, $img);
7319 imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
7320 if (($type == 'gif') OR ($type == 'png')) {
7321 $info = $this->_toPNG($imgr);
7323 $info = $this->_toJPEG($imgr);
7326 if (($type == 'gif') OR ($type == 'png')) {
7327 $info = $this->_toPNG($img);
7329 $info = $this->_toJPEG($img);
7332 } elseif (extension_loaded('imagick')) {
7333 // ImageMagick library
7334 $img = new Imagick();
7335 if ($type == 'SVG') {
7336 // get SVG file content
7337 $svgimg = file_get_contents($file);
7338 // get width and height
7340 if (preg_match('/<svg([^\>]*)>/si', $svgimg, $regs)) {
7343 if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
7344 $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
7345 $owu = sprintf('%.3F', ($ow * $dpi / 72)).$this->pdfunit
;
7346 $svgtag = preg_replace('/[\s]+width[\s]*=[\s]*"[^"]*"/si', ' width="'.$owu.'"', $svgtag, 1);
7351 if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $svgtag, $tmp)) {
7352 $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
7353 $ohu = sprintf('%.3F', ($oh * $dpi / 72)).$this->pdfunit
;
7354 $svgtag = preg_replace('/[\s]+height[\s]*=[\s]*"[^"]*"/si', ' height="'.$ohu.'"', $svgtag, 1);
7359 if (!preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $svgtag, $tmp)) {
7360 $vbw = ($ow * $this->imgscale
* $this->k
);
7361 $vbh = ($oh * $this->imgscale
* $this->k
);
7362 $vbox = sprintf(' viewBox="0 0 %.3F %.3F" ', $vbw, $vbh);
7363 $svgtag = $vbox.$svgtag;
7365 $svgimg = preg_replace('/<svg([^\>]*)>/si', '<svg'.$svgtag.'>', $svgimg, 1);
7367 $img->readImageBlob($svgimg);
7369 $img->readImage($file);
7372 $img->resizeImage($neww, $newh, 10, 1, false);
7374 $img->setCompressionQuality($this->jpeg_quality
);
7375 $img->setImageFormat('jpeg');
7376 $tempname = tempnam(K_PATH_CACHE
, 'jpg_');
7377 $img->writeImage($tempname);
7378 $info = $this->_parsejpeg($tempname);
7385 if ($info === false) {
7386 //If false, we cannot process image
7389 $this->set_mqr($mqr);
7392 $info['cs'] = 'DeviceGray';
7394 $info['i'] = $this->numimages
;
7395 if (!in_array($file, $this->imagekeys
)) {
7398 if ($imgmask !== false) {
7399 $info['masked'] = $imgmask;
7401 // add image to document
7402 $this->setImageBuffer($file, $info);
7405 // remove cached file
7409 $this->img_rb_y
= $y +
$h;
7412 if ($palign == 'L') {
7413 $ximg = $this->lMargin
;
7414 } elseif ($palign == 'C') {
7415 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
7416 } elseif ($palign == 'R') {
7417 $ximg = $this->w
- $this->rMargin
- $w;
7421 $this->img_rb_x
= $ximg;
7423 if ($palign == 'L') {
7424 $ximg = $this->lMargin
;
7425 } elseif ($palign == 'C') {
7426 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
7427 } elseif ($palign == 'R') {
7428 $ximg = $this->w
- $this->rMargin
- $w;
7432 $this->img_rb_x
= $ximg +
$w;
7434 if ($ismask OR $hidden) {
7435 // image is not displayed
7438 $xkimg = $ximg * $this->k
;
7439 $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%u Do Q', ($w * $this->k
), ($h * $this->k
), $xkimg, (($this->h
- ($y +
$h)) * $this->k
), $info['i']));
7440 if (!empty($border)) {
7448 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
7453 $this->Link($ximg, $y, $w, $h, $link, 0);
7455 // set pointer to align the next text/objects
7459 $this->x
= $this->img_rb_x
;
7463 $this->y
= $y +
round($h/2);
7464 $this->x
= $this->img_rb_x
;
7468 $this->y
= $this->img_rb_y
;
7469 $this->x
= $this->img_rb_x
;
7473 $this->SetY($this->img_rb_y
);
7480 $this->endlinex
= $this->img_rb_x
;
7481 if ($this->inxobj
) {
7482 // we are inside an XObject template
7483 $this->xobjects
[$this->xobjid
]['images'][] = $info['i'];
7489 * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
7490 * @param $mqr (boolean) FALSE for off, TRUE for on.
7491 * @since 4.6.025 (2009-08-17)
7493 public function set_mqr($mqr) {
7494 if(!defined('PHP_VERSION_ID')) {
7495 $version = PHP_VERSION
;
7496 define('PHP_VERSION_ID', (($version{0} * 10000) +
($version{2} * 100) +
$version{4}));
7498 if (PHP_VERSION_ID
< 50300) {
7499 @set_magic_quotes_runtime
($mqr);
7504 * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
7505 * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
7506 * @since 4.6.025 (2009-08-17)
7508 public function get_mqr() {
7509 if(!defined('PHP_VERSION_ID')) {
7510 $version = PHP_VERSION
;
7511 define('PHP_VERSION_ID', (($version{0} * 10000) +
($version{2} * 100) +
$version{4}));
7513 if (PHP_VERSION_ID
< 50300) {
7514 return @get_magic_quotes_runtime
();
7520 * Convert the loaded image to a JPEG and then return a structure for the PDF creator.
7521 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
7522 * @param $image (image) Image object.
7523 * return image JPEG image object.
7526 protected function _toJPEG($image) {
7527 $tempname = tempnam(K_PATH_CACHE
, 'jpg_');
7528 imagejpeg($image, $tempname, $this->jpeg_quality
);
7529 imagedestroy($image);
7530 $retvars = $this->_parsejpeg($tempname);
7531 // tidy up by removing temporary image
7537 * Convert the loaded image to a PNG and then return a structure for the PDF creator.
7538 * This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.
7539 * @param $image (image) Image object.
7540 * return image PNG image object.
7542 * @since 4.9.016 (2010-04-20)
7544 protected function _toPNG($image) {
7545 // set temporary image file name
7546 $tempname = tempnam(K_PATH_CACHE
, 'jpg_');
7547 // turn off interlaced mode
7548 imageinterlace($image, 0);
7549 // create temporary PNG image
7550 imagepng($image, $tempname);
7551 // remove image from memory
7552 imagedestroy($image);
7553 // get PNG image data
7554 $retvars = $this->_parsepng($tempname);
7555 // tidy up by removing temporary image
7561 * Set the transparency for the given GD image.
7562 * @param $new_image (image) GD image object
7563 * @param $image (image) GD image object.
7564 * return GD image object.
7566 * @since 4.9.016 (2010-04-20)
7568 protected function _setGDImageTransparency($new_image, $image) {
7569 // transparency index
7570 $tid = imagecolortransparent($image);
7571 // default transparency color
7572 $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
7574 // get the colors for the transparency index
7575 $tcol = imagecolorsforindex($image, $tid);
7577 $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
7578 imagefill($new_image, 0, 0, $tid);
7579 imagecolortransparent($new_image, $tid);
7584 * Extract info from a JPEG file without using the GD library.
7585 * @param $file (string) image file to parse
7586 * @return array structure containing the image data
7589 protected function _parsejpeg($file) {
7590 $a = getimagesize($file);
7592 $this->Error('Missing or incorrect image file: '.$file);
7595 $this->Error('Not a JPEG file: '.$file);
7597 if ((!isset($a['channels'])) OR ($a['channels'] == 3)) {
7598 $colspace = 'DeviceRGB';
7599 } elseif ($a['channels'] == 4) {
7600 $colspace = 'DeviceCMYK';
7602 $colspace = 'DeviceGray';
7604 $bpc = isset($a['bits']) ?
$a['bits'] : 8;
7605 $data = file_get_contents($file);
7606 return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
7610 * Extract info from a PNG file without using the GD library.
7611 * @param $file (string) image file to parse
7612 * @return array structure containing the image data
7615 protected function _parsepng($file) {
7616 $f = fopen($file, 'rb');
7618 $this->Error('Can\'t open image file: '.$file);
7621 if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
7622 $this->Error('Not a PNG file: '.$file);
7626 if (fread($f, 4) != 'IHDR') {
7627 $this->Error('Incorrect PNG file: '.$file);
7629 $w = $this->_freadint($f);
7630 $h = $this->_freadint($f);
7631 $bpc = ord(fread($f, 1));
7633 //$this->Error('16-bit depth not supported: '.$file);
7637 $ct = ord(fread($f, 1));
7639 $colspace = 'DeviceGray';
7640 } elseif ($ct == 2) {
7641 $colspace = 'DeviceRGB';
7642 } elseif ($ct == 3) {
7643 $colspace = 'Indexed';
7649 if (ord(fread($f, 1)) != 0) {
7650 //$this->Error('Unknown compression method: '.$file);
7654 if (ord(fread($f, 1)) != 0) {
7655 //$this->Error('Unknown filter method: '.$file);
7659 if (ord(fread($f, 1)) != 0) {
7660 //$this->Error('Interlacing not supported: '.$file);
7665 $parms = '/DecodeParms << /Predictor 15 /Colors '.($ct == 2 ?
3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
7666 //Scan chunks looking for palette, transparency and image data
7671 $n = $this->_freadint($f);
7672 $type = fread($f, 4);
7673 if ($type == 'PLTE') {
7675 $pal = $this->rfread($f, $n);
7677 } elseif ($type == 'tRNS') {
7678 //Read transparency info
7679 $t = $this->rfread($f, $n);
7681 $trns = array(ord(substr($t, 1, 1)));
7682 } elseif ($ct == 2) {
7683 $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1)));
7685 $pos = strpos($t, chr(0));
7686 if ($pos !== false) {
7687 $trns = array($pos);
7691 } elseif ($type == 'IDAT') {
7692 //Read image data block
7693 $data .= $this->rfread($f, $n);
7695 } elseif ($type == 'IEND') {
7698 $this->rfread($f, $n +
4);
7701 if (($colspace == 'Indexed') AND (empty($pal))) {
7702 //$this->Error('Missing palette in '.$file);
7707 return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
7711 * Binary-safe and URL-safe file read.
7712 * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
7713 * @param $handle (resource)
7714 * @param $length (int)
7715 * @return Returns the read string or FALSE in case of error.
7716 * @author Nicola Asuni
7718 * @since 4.5.027 (2009-03-16)
7720 protected function rfread($handle, $length) {
7721 $data = fread($handle, $length);
7722 if ($data === false) {
7725 $rest = $length - strlen($data);
7727 $data .= $this->rfread($handle, $rest);
7733 * Extract info from a PNG image with alpha channel using the GD library.
7734 * @param $file (string) Name of the file containing the image.
7735 * @param $x (float) Abscissa of the upper-left corner.
7736 * @param $y (float) Ordinate of the upper-left corner.
7737 * @param $wpx (float) Original width of the image in pixels.
7738 * @param $hpx (float) original height of the image in pixels.
7739 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
7740 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
7741 * @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.
7742 * @param $link (mixed) URL or identifier returned by AddLink().
7743 * @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>
7744 * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library).
7745 * @param $dpi (int) dot-per-inch resolution used on resize
7746 * @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>
7747 * @author Nicola Asuni
7749 * @since 4.3.007 (2008-12-04)
7752 protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign) {
7753 // create temp image file (without alpha channel)
7754 $tempfile_plain = tempnam(K_PATH_CACHE
, 'mskp_');
7755 // create temp alpha file
7756 $tempfile_alpha = tempnam(K_PATH_CACHE
, 'mska_');
7757 if (extension_loaded('imagick')) { // ImageMagick
7758 // ImageMagick library
7759 $img = new Imagick();
7760 $img->readImage($file);
7761 // clone image object
7762 $imga = $img->clone();
7763 // extract alpha channel
7764 $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
7765 $img->negateImage(true);
7766 $img->setImageFormat('png');
7767 $img->writeImage($tempfile_alpha);
7768 // remove alpha channel
7769 $imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
7770 $imga->setImageFormat('png');
7771 $imga->writeImage($tempfile_plain);
7772 } else { // GD library
7774 $img = imagecreatefrompng($file);
7775 $imgalpha = imagecreate($wpx, $hpx);
7776 // generate gray scale palette (0 -> 255)
7777 for ($c = 0; $c < 256; ++
$c) {
7778 ImageColorAllocate($imgalpha, $c, $c, $c);
7780 // extract alpha channel
7781 for ($xpx = 0; $xpx < $wpx; ++
$xpx) {
7782 for ($ypx = 0; $ypx < $hpx; ++
$ypx) {
7783 $color = imagecolorat($img, $xpx, $ypx);
7784 $alpha = ($color >> 24); // shifts off the first 24 bits (where 8x3 are used for each color), and returns the remaining 7 allocated bits (commonly used for alpha)
7785 $alpha = (((127 - $alpha) / 127) * 255); // GD alpha is only 7 bit (0 -> 127)
7786 $alpha = $this->getGDgamma($alpha); // correct gamma
7787 imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
7790 imagepng($imgalpha, $tempfile_alpha);
7791 imagedestroy($imgalpha);
7792 // extract image without alpha channel
7793 $imgplain = imagecreatetruecolor($wpx, $hpx);
7794 imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
7795 imagepng($imgplain, $tempfile_plain);
7796 imagedestroy($imgplain);
7799 $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);
7800 // embed image, masked with previously embedded mask
7801 $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask);
7802 // remove temp files
7803 unlink($tempfile_alpha);
7804 unlink($tempfile_plain);
7808 * Correct the gamma value to be used with GD library
7809 * @param $v (float) the gamma value to be corrected
7811 * @since 4.3.007 (2008-12-04)
7813 protected function getGDgamma($v) {
7814 return (pow(($v / 255), 2.2) * 255);
7818 * Performs a line break.
7819 * The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
7820 * @param $h (float) The height of the break. By default, the value equals the height of the last printed cell.
7821 * @param $cell (boolean) if true add the current left (or right o for RTL) padding to the X coordinate
7826 public function Ln($h='', $cell=false) {
7827 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'])) {
7828 // revove vertical space from the top of the column
7833 $cellpadding = $this->cell_padding
['R'];
7835 $cellpadding = $this->cell_padding
['L'];
7841 $this->x
= $this->w
- $this->rMargin
- $cellpadding;
7843 $this->x
= $this->lMargin +
$cellpadding;
7845 if (is_string($h)) {
7846 $this->y +
= $this->lasth
;
7850 $this->newline
= true;
7854 * Returns the relative X value of current position.
7855 * The value is relative to the left border for LTR languages and to the right border for RTL languages.
7859 * @see SetX(), GetY(), SetY()
7861 public function GetX() {
7864 return ($this->w
- $this->x
);
7871 * Returns the absolute X value of current position.
7875 * @see SetX(), GetY(), SetY()
7877 public function GetAbsX() {
7882 * Returns the ordinate of the current position.
7886 * @see SetY(), GetX(), SetX()
7888 public function GetY() {
7893 * Defines the abscissa of the current position.
7894 * If the passed value is negative, it is relative to the right of the page (or left if language is RTL).
7895 * @param $x (float) The value of the abscissa.
7896 * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
7899 * @see GetX(), GetY(), SetY(), SetXY()
7901 public function SetX($x, $rtloff=false) {
7902 if (!$rtloff AND $this->rtl
) {
7904 $this->x
= $this->w
- $x;
7912 $this->x
= $this->w +
$x;
7918 if ($this->x
> $this->w
) {
7919 $this->x
= $this->w
;
7924 * Moves the current abscissa back to the left margin and sets the ordinate.
7925 * If the passed value is negative, it is relative to the bottom of the page.
7926 * @param $y (float) The value of the ordinate.
7927 * @param $resetx (bool) if true (default) reset the X position.
7928 * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
7931 * @see GetX(), GetY(), SetY(), SetXY()
7933 public function SetY($y, $resetx=true, $rtloff=false) {
7936 if (!$rtloff AND $this->rtl
) {
7937 $this->x
= $this->w
- $this->rMargin
;
7939 $this->x
= $this->lMargin
;
7945 $this->y
= $this->h +
$y;
7950 if ($this->y
> $this->h
) {
7951 $this->y
= $this->h
;
7956 * Defines the abscissa and ordinate of the current position.
7957 * If the passed values are negative, they are relative respectively to the right and bottom of the page.
7958 * @param $x (float) The value of the abscissa.
7959 * @param $y (float) The value of the ordinate.
7960 * @param $rtloff (boolean) if true always uses the page top-left corner as origin of axis.
7963 * @see SetX(), SetY()
7965 public function SetXY($x, $y, $rtloff=false) {
7966 $this->SetY($y, false, $rtloff);
7967 $this->SetX($x, $rtloff);
7971 * Send the document to a given destination: string, local file or browser.
7972 * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
7973 * The method first calls Close() if necessary to terminate the document.
7974 * @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.
7975 * @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>
7980 public function Output($name='doc.pdf', $dest='I') {
7981 //Output PDF to some destination
7982 //Finish document if necessary
7983 if ($this->state
< 3) {
7986 //Normalize parameters
7987 if (is_bool($dest)) {
7988 $dest = $dest ?
'D' : 'F';
7990 $dest = strtoupper($dest);
7991 if ($dest{0} != 'F') {
7992 $name = preg_replace('/[\s]+/', '_', $name);
7993 $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
7996 // *** apply digital signature to the document ***
7997 // get the document content
7998 $pdfdoc = $this->getBuffer();
7999 // remove last newline
8000 $pdfdoc = substr($pdfdoc, 0, -1);
8001 // Remove the original buffer
8002 if (isset($this->diskcache
) AND $this->diskcache
) {
8003 // remove buffer file from cache
8004 unlink($this->buffer
);
8006 unset($this->buffer
);
8007 // remove filler space
8008 $byterange_string_len = strlen($this->byterange_string
);
8009 // define the ByteRange
8010 $byte_range = array();
8012 $byte_range[1] = strpos($pdfdoc, $this->byterange_string
) +
$byterange_string_len +
10;
8013 $byte_range[2] = $byte_range[1] +
$this->signature_max_length +
2;
8014 $byte_range[3] = strlen($pdfdoc) - $byte_range[2];
8015 $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).substr($pdfdoc, $byte_range[2]);
8016 // replace the ByteRange
8017 $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]);
8018 $byterange .= str_repeat(' ', ($byterange_string_len - strlen($byterange)));
8019 $pdfdoc = str_replace($this->byterange_string
, $byterange, $pdfdoc);
8020 // write the document to a temporary folder
8021 $tempdoc = tempnam(K_PATH_CACHE
, 'tmppdf_');
8022 $f = fopen($tempdoc, 'wb');
8024 $this->Error('Unable to create temporary file: '.$tempdoc);
8026 $pdfdoc_length = strlen($pdfdoc);
8027 fwrite($f, $pdfdoc, $pdfdoc_length);
8029 // get digital signature via openssl library
8030 $tempsign = tempnam(K_PATH_CACHE
, 'tmpsig_');
8031 if (empty($this->signature_data
['extracerts'])) {
8032 openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data
['signcert'], array($this->signature_data
['privkey'], $this->signature_data
['password']), array(), PKCS7_BINARY | PKCS7_DETACHED
);
8034 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']);
8038 $signature = file_get_contents($tempsign);
8040 // extract signature
8041 $signature = substr($signature, $pdfdoc_length);
8042 $signature = substr($signature, (strpos($signature, "%%EOF\n\n------") +
13));
8043 $tmparr = explode("\n\n", $signature);
8044 $signature = $tmparr[1];
8047 $signature = base64_decode(trim($signature));
8048 // convert signature to hex
8049 $signature = current(unpack('H*', $signature));
8050 $signature = str_pad($signature, $this->signature_max_length
, '0');
8051 // Add signature to the document
8052 $pdfdoc = substr($pdfdoc, 0, $byte_range[1]).'<'.$signature.'>'.substr($pdfdoc, $byte_range[1]);
8053 $this->diskcache
= false;
8054 $this->buffer
= &$pdfdoc;
8055 $this->bufferlen
= strlen($pdfdoc);
8059 // Send PDF to the standard output
8060 if (ob_get_contents()) {
8061 $this->Error('Some data has already been output, can\'t send PDF file');
8063 if (php_sapi_name() != 'cli') {
8064 //We send to a browser
8065 header('Content-Type: application/pdf');
8066 if (headers_sent()) {
8067 $this->Error('Some data has already been output to browser, can\'t send PDF file');
8069 header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
8070 header('Pragma: public');
8071 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
8072 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
8073 header('Content-Length: '.$this->bufferlen
);
8074 header('Content-Disposition: inline; filename="'.basename($name).'";');
8076 echo $this->getBuffer();
8080 // Download PDF as file
8081 if (ob_get_contents()) {
8082 $this->Error('Some data has already been output, can\'t send PDF file');
8084 header('Content-Description: File Transfer');
8085 if (headers_sent()) {
8086 $this->Error('Some data has already been output to browser, can\'t send PDF file');
8088 header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
8089 header('Pragma: public');
8090 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
8091 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
8092 // force download dialog
8093 if (strpos(php_sapi_name(), 'cgi') === false) {
8094 header('Content-Type: application/force-download');
8095 header('Content-Type: application/octet-stream', false);
8096 header('Content-Type: application/download', false);
8097 header('Content-Type: application/pdf', false);
8099 header('Content-Type: application/pdf');
8101 // use the Content-Disposition header to supply a recommended filename
8102 header('Content-Disposition: attachment; filename="'.basename($name).'";');
8103 header('Content-Transfer-Encoding: binary');
8104 header('Content-Length: '.$this->bufferlen
);
8105 echo $this->getBuffer();
8111 // Save PDF to a local file
8112 if ($this->diskcache
) {
8113 copy($this->buffer
, $name);
8115 $f = fopen($name, 'wb');
8117 $this->Error('Unable to create output file: '.$name);
8119 fwrite($f, $this->getBuffer(), $this->bufferlen
);
8122 if ($dest == 'FI') {
8123 // send headers to browser
8124 header('Content-Type: application/pdf');
8125 header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
8126 header('Pragma: public');
8127 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
8128 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
8129 header('Content-Length: '.filesize($name));
8130 header('Content-Disposition: inline; filename="'.basename($name).'";');
8131 // send document to the browser
8132 echo file_get_contents($name);
8133 } elseif ($dest == 'FD') {
8134 // send headers to browser
8135 if (ob_get_contents()) {
8136 $this->Error('Some data has already been output, can\'t send PDF file');
8138 header('Content-Description: File Transfer');
8139 if (headers_sent()) {
8140 $this->Error('Some data has already been output to browser, can\'t send PDF file');
8142 header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
8143 header('Pragma: public');
8144 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
8145 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
8146 // force download dialog
8147 if (strpos(php_sapi_name(), 'cgi') === false) {
8148 header('Content-Type: application/force-download');
8149 header('Content-Type: application/octet-stream', false);
8150 header('Content-Type: application/download', false);
8151 header('Content-Type: application/pdf', false);
8153 header('Content-Type: application/pdf');
8155 // use the Content-Disposition header to supply a recommended filename
8156 header('Content-Disposition: attachment; filename="'.basename($name).'";');
8157 header('Content-Transfer-Encoding: binary');
8158 header('Content-Length: '.filesize($name));
8159 // send document to the browser
8160 echo file_get_contents($name);
8165 // Return PDF as base64 mime multi-part email attachment (RFC 2045)
8166 $retval = 'Content-Type: application/pdf;'."\r\n";
8167 $retval .= ' name="'.$name.'"'."\r\n";
8168 $retval .= 'Content-Transfer-Encoding: base64'."\r\n";
8169 $retval .= 'Content-Disposition: attachment;'."\r\n";
8170 $retval .= ' filename="'.$name.'"'."\r\n\r\n";
8171 $retval .= chunk_split(base64_encode($this->getBuffer()), 76, "\r\n");
8175 // Returns PDF as a string
8176 return $this->getBuffer();
8179 $this->Error('Incorrect output destination: '.$dest);
8186 * Unset all class variables except the following critical variables: internal_encoding, state, bufferlen, buffer and diskcache.
8187 * @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
8188 * @param $preserve_objcopy (boolean) if true preserves the objcopy variable
8190 * @since 4.5.016 (2009-02-24)
8192 public function _destroy($destroyall=false, $preserve_objcopy=false) {
8193 if ($destroyall AND isset($this->diskcache
) AND $this->diskcache
AND (!$preserve_objcopy) AND (!$this->empty_string($this->buffer
))) {
8194 // remove buffer file from cache
8195 unlink($this->buffer
);
8197 foreach (array_keys(get_object_vars($this)) as $val) {
8198 if ($destroyall OR (
8199 ($val != 'internal_encoding')
8200 AND ($val != 'state')
8201 AND ($val != 'bufferlen')
8202 AND ($val != 'buffer')
8203 AND ($val != 'diskcache')
8204 AND ($val != 'sign')
8205 AND ($val != 'signature_data')
8206 AND ($val != 'signature_max_length')
8207 AND ($val != 'byterange_string')
8209 if ((!$preserve_objcopy OR ($val != 'objcopy')) AND isset($this->$val)) {
8217 * Check for locale-related bug
8220 protected function _dochecks() {
8221 //Check for locale-related bug
8223 $this->Error('Don\'t alter the locale before including class file');
8225 //Check for decimal separator
8226 if (sprintf('%.1F', 1.0) != '1.0') {
8227 setlocale(LC_NUMERIC
, 'C');
8236 protected function _getfontpath() {
8237 if (!defined('K_PATH_FONTS') AND is_dir(dirname(__FILE__
).'/fonts')) {
8238 define('K_PATH_FONTS', dirname(__FILE__
).'/fonts/');
8240 return defined('K_PATH_FONTS') ? K_PATH_FONTS
: '';
8247 protected function _putpages() {
8248 $nb = $this->numpages
;
8249 if (!empty($this->AliasNbPages
)) {
8250 $nbs = $this->formatPageNumber($nb);
8251 $nbu = $this->UTF8ToUTF16BE($nbs, false); // replacement for unicode font
8252 $alias_a = $this->_escape($this->AliasNbPages
);
8253 $alias_au = $this->_escape('{'.$this->AliasNbPages
.'}');
8254 if ($this->isunicode
) {
8255 $alias_b = $this->_escape($this->UTF8ToLatin1($this->AliasNbPages
));
8256 $alias_bu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNbPages
.'}'));
8257 $alias_c = $this->_escape($this->utf8StrRev($this->AliasNbPages
, false, $this->tmprtl
));
8258 $alias_cu = $this->_escape($this->utf8StrRev('{'.$this->AliasNbPages
.'}', false, $this->tmprtl
));
8261 if (!empty($this->AliasNumPage
)) {
8262 $alias_pa = $this->_escape($this->AliasNumPage
);
8263 $alias_pau = $this->_escape('{'.$this->AliasNumPage
.'}');
8264 if ($this->isunicode
) {
8265 $alias_pb = $this->_escape($this->UTF8ToLatin1($this->AliasNumPage
));
8266 $alias_pbu = $this->_escape($this->UTF8ToLatin1('{'.$this->AliasNumPage
.'}'));
8267 $alias_pc = $this->_escape($this->utf8StrRev($this->AliasNumPage
, false, $this->tmprtl
));
8268 $alias_pcu = $this->_escape($this->utf8StrRev('{'.$this->AliasNumPage
.'}', false, $this->tmprtl
));
8272 $filter = ($this->compress
) ?
'/Filter /FlateDecode ' : '';
8273 for ($n=1; $n <= $nb; ++
$n) {
8274 $temppage = $this->getPageBuffer($n);
8275 if (!empty($this->pagegroups
)) {
8276 if(isset($this->newpagegroup
[$n])) {
8280 foreach ($this->pagegroups
as $k => $v) {
8281 // replace total pages group numbers
8282 $vs = $this->formatPageNumber($v);
8283 $vu = $this->UTF8ToUTF16BE($vs, false);
8284 $alias_ga = $this->_escape($k);
8285 $alias_gau = $this->_escape('{'.$k.'}');
8286 if ($this->isunicode
) {
8287 $alias_gb = $this->_escape($this->UTF8ToLatin1($k));
8288 $alias_gbu = $this->_escape($this->UTF8ToLatin1('{'.$k.'}'));
8289 $alias_gc = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl
));
8290 $alias_gcu = $this->_escape($this->utf8StrRev('{'.$k.'}', false, $this->tmprtl
));
8292 $temppage = str_replace($alias_gau, $vu, $temppage);
8293 if ($this->isunicode
) {
8294 $temppage = str_replace($alias_gbu, $vu, $temppage);
8295 $temppage = str_replace($alias_gcu, $vu, $temppage);
8296 $temppage = str_replace($alias_gb, $vs, $temppage);
8297 $temppage = str_replace($alias_gc, $vs, $temppage);
8299 $temppage = str_replace($alias_ga, $vs, $temppage);
8300 // replace page group numbers
8301 $pvs = $this->formatPageNumber($pagegroupnum);
8302 $pvu = $this->UTF8ToUTF16BE($pvs, false);
8303 $pk = str_replace('{nb', '{pnb', $k);
8304 $alias_pga = $this->_escape($pk);
8305 $alias_pgau = $this->_escape('{'.$pk.'}');
8306 if ($this->isunicode
) {
8307 $alias_pgb = $this->_escape($this->UTF8ToLatin1($pk));
8308 $alias_pgbu = $this->_escape($this->UTF8ToLatin1('{'.$pk.'}'));
8309 $alias_pgc = $this->_escape($this->utf8StrRev($pk, false, $this->tmprtl
));
8310 $alias_pgcu = $this->_escape($this->utf8StrRev('{'.$pk.'}', false, $this->tmprtl
));
8312 $temppage = str_replace($alias_pgau, $pvu, $temppage);
8313 if ($this->isunicode
) {
8314 $temppage = str_replace($alias_pgbu, $pvu, $temppage);
8315 $temppage = str_replace($alias_pgcu, $pvu, $temppage);
8316 $temppage = str_replace($alias_pgb, $pvs, $temppage);
8317 $temppage = str_replace($alias_pgc, $pvs, $temppage);
8319 $temppage = str_replace($alias_pga, $pvs, $temppage);
8322 if (!empty($this->AliasNbPages
)) {
8323 // replace total pages number
8324 $temppage = str_replace($alias_au, $nbu, $temppage);
8325 if ($this->isunicode
) {
8326 $temppage = str_replace($alias_bu, $nbu, $temppage);
8327 $temppage = str_replace($alias_cu, $nbu, $temppage);
8328 $temppage = str_replace($alias_b, $nbs, $temppage);
8329 $temppage = str_replace($alias_c, $nbs, $temppage);
8331 $temppage = str_replace($alias_a, $nbs, $temppage);
8333 if (!empty($this->AliasNumPage
)) {
8334 // replace page number
8335 $pnbs = $this->formatPageNumber($n);
8336 $pnbu = $this->UTF8ToUTF16BE($pnbs, false); // replacement for unicode font
8337 $temppage = str_replace($alias_pau, $pnbu, $temppage);
8338 if ($this->isunicode
) {
8339 $temppage = str_replace($alias_pbu, $pnbu, $temppage);
8340 $temppage = str_replace($alias_pcu, $pnbu, $temppage);
8341 $temppage = str_replace($alias_pb, $pnbs, $temppage);
8342 $temppage = str_replace($alias_pc, $pnbs, $temppage);
8344 $temppage = str_replace($alias_pa, $pnbs, $temppage);
8346 $temppage = str_replace($this->epsmarker
, '', $temppage);
8348 $this->page_obj_id
[$n] = $this->_newobj();
8350 $out .= ' /Type /Page';
8351 $out .= ' /Parent 1 0 R';
8352 $out .= ' /LastModified '.$this->_datestring();
8353 $out .= ' /Resources 2 0 R';
8354 $boxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
8355 foreach ($boxes as $box) {
8357 $out .= sprintf(' [%.2F %.2F %.2F %.2F]', $this->pagedim
[$n][$box]['llx'], $this->pagedim
[$n][$box]['lly'], $this->pagedim
[$n][$box]['urx'], $this->pagedim
[$n][$box]['ury']);
8359 if (isset($this->pagedim
[$n]['BoxColorInfo']) AND !empty($this->pagedim
[$n]['BoxColorInfo'])) {
8360 $out .= ' /BoxColorInfo <<';
8361 foreach ($boxes as $box) {
8362 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box])) {
8363 $out .= ' /'.$box.' <<';
8364 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['C'])) {
8365 $color = $this->pagedim
[$n]['BoxColorInfo'][$box]['C'];
8367 $out .= sprintf(' %.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255);
8370 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['W'])) {
8371 $out .= ' /W '.($this->pagedim
[$n]['BoxColorInfo'][$box]['W'] * $this->k
);
8373 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['S'])) {
8374 $out .= ' /S /'.$this->pagedim
[$n]['BoxColorInfo'][$box]['S'];
8376 if (isset($this->pagedim
[$n]['BoxColorInfo'][$box]['D'])) {
8377 $dashes = $this->pagedim
[$n]['BoxColorInfo'][$box]['D'];
8379 foreach ($dashes as $dash) {
8380 $out .= sprintf(' %.3F', ($dash * $this->k
));
8389 $out .= ' /Contents '.($this->n +
1).' 0 R';
8390 $out .= ' /Rotate '.$this->pagedim
[$n]['Rotate'];
8391 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
8392 if (isset($this->pagedim
[$n]['trans']) AND !empty($this->pagedim
[$n]['trans'])) {
8394 if (isset($this->pagedim
[$n]['trans']['Dur'])) {
8395 $out .= ' /Dur '.$this->pagedim
[$n]['trans']['Dur'];
8397 $out .= ' /Trans <<';
8398 $out .= ' /Type /Trans';
8399 if (isset($this->pagedim
[$n]['trans']['S'])) {
8400 $out .= ' /S /'.$this->pagedim
[$n]['trans']['S'];
8402 if (isset($this->pagedim
[$n]['trans']['D'])) {
8403 $out .= ' /D '.$this->pagedim
[$n]['trans']['D'];
8405 if (isset($this->pagedim
[$n]['trans']['Dm'])) {
8406 $out .= ' /Dm /'.$this->pagedim
[$n]['trans']['Dm'];
8408 if (isset($this->pagedim
[$n]['trans']['M'])) {
8409 $out .= ' /M /'.$this->pagedim
[$n]['trans']['M'];
8411 if (isset($this->pagedim
[$n]['trans']['Di'])) {
8412 $out .= ' /Di '.$this->pagedim
[$n]['trans']['Di'];
8414 if (isset($this->pagedim
[$n]['trans']['SS'])) {
8415 $out .= ' /SS '.$this->pagedim
[$n]['trans']['SS'];
8417 if (isset($this->pagedim
[$n]['trans']['B'])) {
8418 $out .= ' /B '.$this->pagedim
[$n]['trans']['B'];
8422 $out .= $this->_getannotsrefs($n);
8423 $out .= ' /PZ '.$this->pagedim
[$n]['PZ'];
8425 $out .= "\n".'endobj';
8428 $p = ($this->compress
) ?
gzcompress($temppage) : $temppage;
8430 $p = $this->_getrawstream($p);
8431 $this->_out('<<'.$filter.'/Length '.strlen($p).'>> stream'."\n".$p."\n".'endstream'."\n".'endobj');
8432 if ($this->diskcache
) {
8433 // remove temporary files
8434 unlink($this->pages
[$n]);
8438 $out = $this->_getobj(1)."\n";
8439 $out .= '<< /Type /Pages /Kids [';
8440 foreach($this->page_obj_id
as $page_obj) {
8441 $out .= ' '.$page_obj.' 0 R';
8443 $out .= ' ] /Count '.$nb.' >>';
8444 $out .= "\n".'endobj';
8449 * Output references to page annotations
8450 * @param $n (int) page number
8452 * @author Nicola Asuni
8453 * @since 4.7.000 (2008-08-29)
8456 protected function _putannotsrefs($n) {
8457 $this->_out($this->_getannotsrefs($n));
8461 * Get references to page annotations.
8462 * @param $n (int) page number
8465 * @author Nicola Asuni
8466 * @since 5.0.010 (2010-05-17)
8468 protected function _getannotsrefs($n) {
8469 if (!(isset($this->PageAnnots
[$n]) OR ($this->sign
AND isset($this->signature_data
['cert_type'])))) {
8472 $out = ' /Annots [';
8473 if (isset($this->PageAnnots
[$n])) {
8474 foreach ($this->PageAnnots
[$n] as $key => $val) {
8475 if (!in_array($val['n'], $this->radio_groups
)) {
8476 $out .= ' '.$val['n'].' 0 R';
8479 // add radiobutton groups
8480 if (isset($this->radiobutton_groups
[$n])) {
8481 foreach ($this->radiobutton_groups
[$n] as $key => $data) {
8482 if (isset($data['n'])) {
8483 $out .= ' '.$data['n'].' 0 R';
8488 if ($this->sign
AND ($n == $this->signature_appearance
['page']) AND isset($this->signature_data
['cert_type'])) {
8489 // set reference for signature object
8490 $out .= ' '.$this->sig_obj_id
.' 0 R';
8497 * Output annotations objects for all pages.
8498 * !!! THIS METHOD IS NOT YET COMPLETED !!!
8499 * See section 12.5 of PDF 32000_2008 reference.
8501 * @author Nicola Asuni
8502 * @since 4.0.018 (2008-08-06)
8504 protected function _putannotsobjs() {
8505 // reset object counter
8506 for ($n=1; $n <= $this->numpages
; ++
$n) {
8507 if (isset($this->PageAnnots
[$n])) {
8508 // set page annotations
8509 foreach ($this->PageAnnots
[$n] as $key => $pl) {
8510 $annot_obj_id = $this->PageAnnots
[$n][$key]['n'];
8511 // create annotation object for grouping radiobuttons
8512 if (isset($this->radiobutton_groups
[$n][$pl['txt']]) AND is_array($this->radiobutton_groups
[$n][$pl['txt']])) {
8513 $radio_button_obj_id = $this->radiobutton_groups
[$n][$pl['txt']]['n'];
8515 $annots .= ' /Type /Annot';
8516 $annots .= ' /Subtype /Widget';
8517 $annots .= ' /Rect [0 0 0 0]';
8518 $annots .= ' /T '.$this->_datastring($pl['txt'], $radio_button_obj_id);
8519 $annots .= ' /FT /Btn';
8520 $annots .= ' /Ff 49152';
8521 $annots .= ' /Kids [';
8522 foreach ($this->radiobutton_groups
[$n][$pl['txt']] as $key => $data) {
8524 $annots .= ' '.$data['kid'].' 0 R';
8525 if ($data['def'] !== 'Off') {
8526 $defval = $data['def'];
8531 if (isset($defval)) {
8532 $annots .= ' /V /'.$defval;
8535 $this->_out($this->_getobj($radio_button_obj_id)."\n".$annots."\n".'endobj');
8536 $this->form_obj_id
[] = $radio_button_obj_id;
8537 // store object id to be used on Parent entry of Kids
8538 $this->radiobutton_groups
[$n][$pl['txt']] = $radio_button_obj_id;
8541 $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER
);
8542 $a = $pl['x'] * $this->k
;
8543 $b = $this->pagedim
[$n]['h'] - (($pl['y'] +
$pl['h']) * $this->k
);
8544 $c = $pl['w'] * $this->k
;
8545 $d = $pl['h'] * $this->k
;
8546 $rect = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+
$c, $b+
$d);
8547 // create new annotation object
8548 $annots = '<</Type /Annot';
8549 $annots .= ' /Subtype /'.$pl['opt']['subtype'];
8550 $annots .= ' /Rect ['.$rect.']';
8551 $ft = array('Btn', 'Tx', 'Ch', 'Sig');
8552 if (isset($pl['opt']['ft']) AND in_array($pl['opt']['ft'], $ft)) {
8553 $annots .= ' /FT /'.$pl['opt']['ft'];
8556 $annots .= ' /Contents '.$this->_textstring($pl['txt'], $annot_obj_id);
8557 $annots .= ' /P '.$this->page_obj_id
[$n].' 0 R';
8558 $annots .= ' /NM '.$this->_datastring(sprintf('%04u-%04u', $n, $key), $annot_obj_id);
8559 $annots .= ' /M '.$this->_datestring($annot_obj_id);
8560 if (isset($pl['opt']['f'])) {
8562 if (is_array($pl['opt']['f'])) {
8563 foreach ($pl['opt']['f'] as $f) {
8564 switch (strtolower($f)) {
8597 case 'togglenoview': {
8601 case 'lockedcontents': {
8611 $val = intval($pl['opt']['f']);
8613 $annots .= ' /F '.intval($val);
8615 if (isset($pl['opt']['as']) AND is_string($pl['opt']['as'])) {
8616 $annots .= ' /AS /'.$pl['opt']['as'];
8618 if (isset($pl['opt']['ap'])) {
8619 // appearance stream
8620 $annots .= ' /AP <<';
8621 if (is_array($pl['opt']['ap'])) {
8622 foreach ($pl['opt']['ap'] as $apmode => $apdef) {
8623 // $apmode can be: n = normal; r = rollover; d = down;
8624 $annots .= ' /'.strtoupper($apmode);
8625 if (is_array($apdef)) {
8627 foreach ($apdef as $apstate => $stream) {
8628 // reference to XObject that define the appearance for this mode-state
8629 $apsobjid = $this->_putAPXObject($c, $d, $stream);
8630 $annots .= ' /'.$apstate.' '.$apsobjid.' 0 R';
8634 // reference to XObject that define the appearance for this mode
8635 $apsobjid = $this->_putAPXObject($c, $d, $apdef);
8636 $annots .= ' '.$apsobjid.' 0 R';
8640 $annots .= $pl['opt']['ap'];
8644 if (isset($pl['opt']['bs']) AND (is_array($pl['opt']['bs']))) {
8645 $annots .= ' /BS <<';
8646 $annots .= ' /Type /Border';
8647 if (isset($pl['opt']['bs']['w'])) {
8648 $annots .= ' /W '.intval($pl['opt']['bs']['w']);
8650 $bstyles = array('S', 'D', 'B', 'I', 'U');
8651 if (isset($pl['opt']['bs']['s']) AND in_array($pl['opt']['bs']['s'], $bstyles)) {
8652 $annots .= ' /S /'.$pl['opt']['bs']['s'];
8654 if (isset($pl['opt']['bs']['d']) AND (is_array($pl['opt']['bs']['d']))) {
8656 foreach ($pl['opt']['bs']['d'] as $cord) {
8657 $annots .= ' '.intval($cord);
8663 $annots .= ' /Border [';
8664 if (isset($pl['opt']['border']) AND (count($pl['opt']['border']) >= 3)) {
8665 $annots .= intval($pl['opt']['border'][0]).' ';
8666 $annots .= intval($pl['opt']['border'][1]).' ';
8667 $annots .= intval($pl['opt']['border'][2]);
8668 if (isset($pl['opt']['border'][3]) AND is_array($pl['opt']['border'][3])) {
8670 foreach ($pl['opt']['border'][3] as $dash) {
8671 $annots .= intval($dash).' ';
8680 if (isset($pl['opt']['be']) AND (is_array($pl['opt']['be']))) {
8681 $annots .= ' /BE <<';
8682 $bstyles = array('S', 'C');
8683 if (isset($pl['opt']['be']['s']) AND in_array($pl['opt']['be']['s'], $markups)) {
8684 $annots .= ' /S /'.$pl['opt']['bs']['s'];
8686 $annots .= ' /S /S';
8688 if (isset($pl['opt']['be']['i']) AND ($pl['opt']['be']['i'] >= 0) AND ($pl['opt']['be']['i'] <= 2)) {
8689 $annots .= ' /I '.sprintf(' %.4F', $pl['opt']['be']['i']);
8693 if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c'])) AND !empty($pl['opt']['c'])) {
8695 foreach ($pl['opt']['c'] as $col) {
8696 $col = intval($col);
8697 $color = $col <= 0 ?
0 : ($col >= 255 ?
1 : $col / 255);
8698 $annots .= sprintf(' %.4F', $color);
8702 //$annots .= ' /StructParent ';
8703 //$annots .= ' /OC ';
8704 $markups = array('text', 'freetext', 'line', 'square', 'circle', 'polygon', 'polyline', 'highlight', 'underline', 'squiggly', 'strikeout', 'stamp', 'caret', 'ink', 'fileattachment', 'sound');
8705 if (in_array(strtolower($pl['opt']['subtype']), $markups)) {
8706 // this is a markup type
8707 if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
8708 $annots .= ' /T '.$this->_textstring($pl['opt']['t'], $annot_obj_id);
8710 //$annots .= ' /Popup ';
8711 if (isset($pl['opt']['ca'])) {
8712 $annots .= ' /CA '.sprintf('%.4F', floatval($pl['opt']['ca']));
8714 if (isset($pl['opt']['rc'])) {
8715 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
8717 $annots .= ' /CreationDate '.$this->_datestring($annot_obj_id);
8718 //$annots .= ' /IRT ';
8719 if (isset($pl['opt']['subj'])) {
8720 $annots .= ' /Subj '.$this->_textstring($pl['opt']['subj'], $annot_obj_id);
8722 //$annots .= ' /RT ';
8723 //$annots .= ' /IT ';
8724 //$annots .= ' /ExData ';
8726 $lineendings = array('Square', 'Circle', 'Diamond', 'OpenArrow', 'ClosedArrow', 'None', 'Butt', 'ROpenArrow', 'RClosedArrow', 'Slash');
8728 switch (strtolower($pl['opt']['subtype'])) {
8730 if (isset($pl['opt']['open'])) {
8731 $annots .= ' /Open '. (strtolower($pl['opt']['open']) == 'true' ?
'true' : 'false');
8733 $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph');
8734 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8735 $annots .= ' /Name /'.$pl['opt']['name'];
8737 $annots .= ' /Name /Note';
8739 $statemodels = array('Marked', 'Review');
8740 if (isset($pl['opt']['statemodel']) AND in_array($pl['opt']['statemodel'], $statemodels)) {
8741 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
8743 $pl['opt']['statemodel'] = 'Marked';
8744 $annots .= ' /StateModel /'.$pl['opt']['statemodel'];
8746 if ($pl['opt']['statemodel'] == 'Marked') {
8747 $states = array('Accepted', 'Unmarked');
8749 $states = array('Accepted', 'Rejected', 'Cancelled', 'Completed', 'None');
8751 if (isset($pl['opt']['state']) AND in_array($pl['opt']['state'], $states)) {
8752 $annots .= ' /State /'.$pl['opt']['state'];
8754 if ($pl['opt']['statemodel'] == 'Marked') {
8755 $annots .= ' /State /Unmarked';
8757 $annots .= ' /State /None';
8763 if(is_string($pl['txt'])) {
8764 // external URI link
8765 $annots .= ' /A <</S /URI /URI '.$this->_datastring($this->unhtmlentities($pl['txt']), $annot_obj_id).'>>';
8768 $l = $this->links
[$pl['txt']];
8769 $annots .= sprintf(' /Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id
[($l[0])], ($this->pagedim
[$l[0]]['h'] - ($l[1] * $this->k
)));
8771 $hmodes = array('N', 'I', 'O', 'P');
8772 if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmodes)) {
8773 $annots .= ' /H /'.$pl['opt']['h'];
8775 $annots .= ' /H /I';
8777 //$annots .= ' /PA ';
8778 //$annots .= ' /Quadpoints ';
8782 if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
8783 $annots .= ' /DA ('.$pl['opt']['da'].')';
8785 if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
8786 $annots .= ' /Q '.intval($pl['opt']['q']);
8788 if (isset($pl['opt']['rc'])) {
8789 $annots .= ' /RC '.$this->_textstring($pl['opt']['rc'], $annot_obj_id);
8791 if (isset($pl['opt']['ds'])) {
8792 $annots .= ' /DS '.$this->_textstring($pl['opt']['ds'], $annot_obj_id);
8794 if (isset($pl['opt']['cl']) AND is_array($pl['opt']['cl'])) {
8795 $annots .= ' /CL [';
8796 foreach ($pl['opt']['cl'] as $cl) {
8797 $annots .= sprintf('%.4F ', $cl * $this->k
);
8801 $tfit = array('FreeText', 'FreeTextCallout', 'FreeTextTypeWriter');
8802 if (isset($pl['opt']['it']) AND in_array($pl['opt']['it'], $tfit)) {
8803 $annots .= ' /IT /'.$pl['opt']['it'];
8805 if (isset($pl['opt']['rd']) AND is_array($pl['opt']['rd'])) {
8806 $l = $pl['opt']['rd'][0] * $this->k
;
8807 $r = $pl['opt']['rd'][1] * $this->k
;
8808 $t = $pl['opt']['rd'][2] * $this->k
;
8809 $b = $pl['opt']['rd'][3] * $this->k
;
8810 $annots .= ' /RD ['.sprintf('%.2F %.2F %.2F %.2F', $l, $r, $t, $b).']';
8812 if (isset($pl['opt']['le']) AND in_array($pl['opt']['le'], $lineendings)) {
8813 $annots .= ' /LE /'.$pl['opt']['le'];
8856 case 'fileattachment': {
8857 if (!isset($pl['opt']['fs'])) {
8860 $filename = basename($pl['opt']['fs']);
8861 if (isset($this->embeddedfiles
[$filename]['n'])) {
8862 $annots .= ' /FS <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles
[$filename]['n'].' 0 R>> >>';
8863 $iconsapp = array('Graph', 'Paperclip', 'PushPin', 'Tag');
8864 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8865 $annots .= ' /Name /'.$pl['opt']['name'];
8867 $annots .= ' /Name /PushPin';
8873 if (!isset($pl['opt']['fs'])) {
8876 $filename = basename($pl['opt']['fs']);
8877 if (isset($this->embeddedfiles
[$filename]['n'])) {
8878 // ... TO BE COMPLETED ...
8879 // /R /C /B /E /CO /CP
8880 $annots .= ' /Sound <</Type /Filespec /F '.$this->_datastring($filename, $annot_obj_id).' /EF <</F '.$this->embeddedfiles
[$filename]['n'].' 0 R>> >>';
8881 $iconsapp = array('Speaker', 'Mic');
8882 if (isset($pl['opt']['name']) AND in_array($pl['opt']['name'], $iconsapp)) {
8883 $annots .= ' /Name /'.$pl['opt']['name'];
8885 $annots .= ' /Name /Speaker';
8894 $hmode = array('N', 'I', 'O', 'P', 'T');
8895 if (isset($pl['opt']['h']) AND in_array($pl['opt']['h'], $hmode)) {
8896 $annots .= ' /H /'.$pl['opt']['h'];
8898 if (isset($pl['opt']['mk']) AND (is_array($pl['opt']['mk'])) AND !empty($pl['opt']['mk'])) {
8899 $annots .= ' /MK <<';
8900 if (isset($pl['opt']['mk']['r'])) {
8901 $annots .= ' /R '.$pl['opt']['mk']['r'];
8903 if (isset($pl['opt']['mk']['bc']) AND (is_array($pl['opt']['mk']['bc']))) {
8904 $annots .= ' /BC [';
8905 foreach($pl['opt']['mk']['bc'] AS $col) {
8906 $col = intval($col);
8907 $color = $col <= 0 ?
0 : ($col >= 255 ?
1 : $col / 255);
8908 $annots .= sprintf(' %.2F', $color);
8912 if (isset($pl['opt']['mk']['bg']) AND (is_array($pl['opt']['mk']['bg']))) {
8913 $annots .= ' /BG [';
8914 foreach($pl['opt']['mk']['bg'] AS $col) {
8915 $col = intval($col);
8916 $color = $col <= 0 ?
0 : ($col >= 255 ?
1 : $col / 255);
8917 $annots .= sprintf(' %.2F', $color);
8921 if (isset($pl['opt']['mk']['ca'])) {
8922 $annots .= ' /CA '.$pl['opt']['mk']['ca'];
8924 if (isset($pl['opt']['mk']['rc'])) {
8925 $annots .= ' /RC '.$pl['opt']['mk']['rc'];
8927 if (isset($pl['opt']['mk']['ac'])) {
8928 $annots .= ' /AC '.$pl['opt']['mk']['ac'];
8930 if (isset($pl['opt']['mk']['i'])) {
8931 $info = $this->getImageBuffer($pl['opt']['mk']['i']);
8932 if ($info !== false) {
8933 $annots .= ' /I '.$info['n'].' 0 R';
8936 if (isset($pl['opt']['mk']['ri'])) {
8937 $info = $this->getImageBuffer($pl['opt']['mk']['ri']);
8938 if ($info !== false) {
8939 $annots .= ' /RI '.$info['n'].' 0 R';
8942 if (isset($pl['opt']['mk']['ix'])) {
8943 $info = $this->getImageBuffer($pl['opt']['mk']['ix']);
8944 if ($info !== false) {
8945 $annots .= ' /IX '.$info['n'].' 0 R';
8948 if (isset($pl['opt']['mk']['if']) AND (is_array($pl['opt']['mk']['if'])) AND !empty($pl['opt']['mk']['if'])) {
8949 $annots .= ' /IF <<';
8950 $if_sw = array('A', 'B', 'S', 'N');
8951 if (isset($pl['opt']['mk']['if']['sw']) AND in_array($pl['opt']['mk']['if']['sw'], $if_sw)) {
8952 $annots .= ' /SW /'.$pl['opt']['mk']['if']['sw'];
8954 $if_s = array('A', 'P');
8955 if (isset($pl['opt']['mk']['if']['s']) AND in_array($pl['opt']['mk']['if']['s'], $if_s)) {
8956 $annots .= ' /S /'.$pl['opt']['mk']['if']['s'];
8958 if (isset($pl['opt']['mk']['if']['a']) AND (is_array($pl['opt']['mk']['if']['a'])) AND !empty($pl['opt']['mk']['if']['a'])) {
8959 $annots .= sprintf(' /A [%.2F %.2F]', $pl['opt']['mk']['if']['a'][0], $pl['opt']['mk']['if']['a'][1]);
8961 if (isset($pl['opt']['mk']['if']['fb']) AND ($pl['opt']['mk']['if']['fb'])) {
8962 $annots .= ' /FB true';
8966 if (isset($pl['opt']['mk']['tp']) AND ($pl['opt']['mk']['tp'] >= 0) AND ($pl['opt']['mk']['tp'] <= 6)) {
8967 $annots .= ' /TP '.intval($pl['opt']['mk']['tp']);
8969 $annots .= ' /TP 0';
8973 // --- Entries for field dictionaries ---
8974 if (isset($this->radiobutton_groups
[$n][$pl['txt']])) {
8976 $annots .= ' /Parent '.$this->radiobutton_groups
[$n][$pl['txt']].' 0 R';
8978 if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) {
8979 $annots .= ' /T '.$this->_datastring($pl['opt']['t'], $annot_obj_id);
8981 if (isset($pl['opt']['tu']) AND is_string($pl['opt']['tu'])) {
8982 $annots .= ' /TU '.$this->_datastring($pl['opt']['tu'], $annot_obj_id);
8984 if (isset($pl['opt']['tm']) AND is_string($pl['opt']['tm'])) {
8985 $annots .= ' /TM '.$this->_datastring($pl['opt']['tm'], $annot_obj_id);
8987 if (isset($pl['opt']['ff'])) {
8988 if (is_array($pl['opt']['ff'])) {
8989 // array of bit settings
8991 foreach($pl['opt']['ff'] as $val) {
8992 $flag +
= 1 << ($val - 1);
8995 $flag = intval($pl['opt']['ff']);
8997 $annots .= ' /Ff '.$flag;
8999 if (isset($pl['opt']['maxlen'])) {
9000 $annots .= ' /MaxLen '.intval($pl['opt']['maxlen']);
9002 if (isset($pl['opt']['v'])) {
9004 if (is_array($pl['opt']['v'])) {
9005 foreach ($pl['opt']['v'] AS $optval) {
9006 if (is_float($optval)) {
9007 $optval = sprintf('%.2F', $optval);
9009 $annots .= ' '.$optval;
9012 $annots .= ' '.$this->_textstring($pl['opt']['v'], $annot_obj_id);
9015 if (isset($pl['opt']['dv'])) {
9017 if (is_array($pl['opt']['dv'])) {
9018 foreach ($pl['opt']['dv'] AS $optval) {
9019 if (is_float($optval)) {
9020 $optval = sprintf('%.2F', $optval);
9022 $annots .= ' '.$optval;
9025 $annots .= ' '.$this->_textstring($pl['opt']['dv'], $annot_obj_id);
9028 if (isset($pl['opt']['rv'])) {
9030 if (is_array($pl['opt']['rv'])) {
9031 foreach ($pl['opt']['rv'] AS $optval) {
9032 if (is_float($optval)) {
9033 $optval = sprintf('%.2F', $optval);
9035 $annots .= ' '.$optval;
9038 $annots .= ' '.$this->_textstring($pl['opt']['rv'], $annot_obj_id);
9041 if (isset($pl['opt']['a']) AND !empty($pl['opt']['a'])) {
9042 $annots .= ' /A << '.$pl['opt']['a'].' >>';
9044 if (isset($pl['opt']['aa']) AND !empty($pl['opt']['aa'])) {
9045 $annots .= ' /AA << '.$pl['opt']['aa'].' >>';
9047 if (isset($pl['opt']['da']) AND !empty($pl['opt']['da'])) {
9048 $annots .= ' /DA ('.$pl['opt']['da'].')';
9050 if (isset($pl['opt']['q']) AND ($pl['opt']['q'] >= 0) AND ($pl['opt']['q'] <= 2)) {
9051 $annots .= ' /Q '.intval($pl['opt']['q']);
9053 if (isset($pl['opt']['opt']) AND (is_array($pl['opt']['opt'])) AND !empty($pl['opt']['opt'])) {
9054 $annots .= ' /Opt [';
9055 foreach($pl['opt']['opt'] AS $copt) {
9056 if (is_array($copt)) {
9057 $annots .= ' ['.$this->_textstring($copt[0], $annot_obj_id).' '.$this->_textstring($copt[1], $annot_obj_id).']';
9059 $annots .= ' '.$this->_textstring($copt, $annot_obj_id);
9064 if (isset($pl['opt']['ti'])) {
9065 $annots .= ' /TI '.intval($pl['opt']['ti']);
9067 if (isset($pl['opt']['i']) AND (is_array($pl['opt']['i'])) AND !empty($pl['opt']['i'])) {
9069 foreach($pl['opt']['i'] AS $copt) {
9070 $annots .= intval($copt).' ';
9079 case 'printermark': {
9096 // create new annotation object
9097 $this->_out($this->_getobj($annot_obj_id)."\n".$annots."\n".'endobj');
9098 if ($formfield AND !isset($this->radiobutton_groups
[$n][$pl['txt']])) {
9099 // store reference of form object
9100 $this->form_obj_id
[] = $annot_obj_id;
9104 } // end for each page
9108 * Put appearance streams XObject used to define annotation's appearance states
9109 * @param $w (int) annotation width
9110 * @param $h (int) annotation height
9111 * @param $stream (string) appearance stream
9112 * @return int object ID
9114 * @since 4.8.001 (2009-09-09)
9116 protected function _putAPXObject($w=0, $h=0, $stream='') {
9117 $stream = trim($stream);
9118 $out = $this->_getobj()."\n";
9119 $this->xobjects
['AX'.$this->n
] = array('n' => $this->n
);
9121 $out .= ' /Type /XObject';
9122 $out .= ' /Subtype /Form';
9123 $out .= ' /FormType 1';
9124 if ($this->compress
) {
9125 $stream = gzcompress($stream);
9126 $out .= ' /Filter /FlateDecode';
9128 $rect = sprintf('%.2F %.2F', $w, $h);
9129 $out .= ' /BBox [0 0 '.$rect.']';
9130 $out .= ' /Matrix [1 0 0 1 0 0]';
9131 $out .= ' /Resources <<';
9132 $out .= ' /ProcSet [/PDF /Text]';
9133 $out .= ' /Font <<';
9134 foreach ($this->annotation_fonts
as $fontkey => $fontid) {
9135 $out .= ' /F'.$fontid.' '.$this->font_obj_ids
[$fontkey].' 0 R';
9139 $stream = $this->_getrawstream($stream);
9140 $out .= ' /Length '.strlen($stream);
9142 $out .= ' stream'."\n".$stream."\n".'endstream';
9143 $out .= "\n".'endobj';
9149 * Get ULONG from string (Big Endian 32-bit unsigned integer).
9150 * @param $str (string) string from where to extract value
9151 * @param $offset (int) point from where to read the data
9152 * @return int 32 bit value
9153 * @author Nicola Asuni
9155 * @since 5.2.000 (2010-06-02)
9157 protected function _getULONG(&$str, &$offset) {
9158 $v = unpack('Ni', substr($str, $offset, 4));
9164 * Get USHORT from string (Big Endian 16-bit unsigned integer).
9165 * @param $str (string) string from where to extract value
9166 * @param $offset (int) point from where to read the data
9167 * @return int 16 bit value
9168 * @author Nicola Asuni
9170 * @since 5.2.000 (2010-06-02)
9172 protected function _getUSHORT(&$str, &$offset) {
9173 $v = unpack('ni', substr($str, $offset, 2));
9179 * Get SHORT from string (Big Endian 16-bit signed integer).
9180 * @param $str (string) string from where to extract value
9181 * @param $offset (int) point from where to read the data
9182 * @return int 16 bit value
9183 * @author Nicola Asuni
9185 * @since 5.2.000 (2010-06-02)
9187 protected function _getSHORT(&$str, &$offset) {
9188 $v = unpack('si', substr($str, $offset, 2));
9194 * Get BYTE from string (8-bit unsigned integer).
9195 * @param $str (string) string from where to extract value
9196 * @param $offset (int) point from where to read the data
9197 * @return int 8 bit value
9198 * @author Nicola Asuni
9200 * @since 5.2.000 (2010-06-02)
9202 protected function _getBYTE(&$str, &$offset) {
9203 $v = unpack('Ci', substr($str, $offset, 1));
9209 * Returns a subset of the TrueType font data without the unused glyphs.
9210 * @param $font (string) TrueType font data
9211 * @param $subsetchars (array) array of used characters (the glyphs to keep)
9212 * @return string a subset of TrueType font data without the unused glyphs
9213 * @author Nicola Asuni
9215 * @since 5.2.000 (2010-06-02)
9217 protected function _getTrueTypeFontSubset($font, $subsetchars) {
9218 ksort($subsetchars);
9219 $offset = 0; // offset position of the font data
9220 if ($this->_getULONG($font, $offset) != 0x10000) {
9221 // sfnt version must be 0x00010000 for TrueType version 1.0.
9224 // get number of tables
9225 $numTables = $this->_getUSHORT($font, $offset);
9226 // skip searchRange, entrySelector and rangeShift
9231 for ($i = 0; $i < $numTables; ++
$i) {
9233 $tag = substr($font, $offset, 4);
9235 $table[$tag] = array();
9236 $table[$tag]['checkSum'] = $this->_getULONG($font, $offset);
9237 $table[$tag]['offset'] = $this->_getULONG($font, $offset);
9238 $table[$tag]['length'] = $this->_getULONG($font, $offset);
9240 // check magicNumber
9241 $offset = $table['head']['offset'] +
12;
9242 if ($this->_getULONG($font, $offset) != 0x5F0F3CF5) {
9243 // magicNumber must be 0x5F0F3CF5
9246 // get offset mode (indexToLocFormat : 0 = short, 1 = long)
9247 $offset = $table['head']['offset'] +
50;
9248 $short_offset = ($this->_getSHORT($font, $offset) == 0);
9249 // get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
9250 $indexToLoc = array();
9251 $offset = $table['loca']['offset'];
9252 if ($short_offset) {
9254 $n = $table['loca']['length'] / 2; // numGlyphs + 1
9255 for ($i = 0; $i < $n; ++
$i) {
9256 $indexToLoc[$i] = $this->_getUSHORT($font, $offset) * 2;
9260 $n = $table['loca']['length'] / 4; // numGlyphs + 1
9261 for ($i = 0; $i < $n; ++
$i) {
9262 $indexToLoc[$i] = $this->_getULONG($font, $offset);
9265 // get glyphs indexes of chars from cmap table
9266 $subsetglyphs = array(); // glyph IDs on key
9267 $subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
9268 $offset = $table['cmap']['offset'] +
2;
9269 $numEncodingTables = $this->_getUSHORT($font, $offset);
9270 $encodingTables = array();
9271 for ($i = 0; $i < $numEncodingTables; ++
$i) {
9272 $encodingTables[$i]['platformID'] = $this->_getUSHORT($font, $offset);
9273 $encodingTables[$i]['encodingID'] = $this->_getUSHORT($font, $offset);
9274 $encodingTables[$i]['offset'] = $this->_getULONG($font, $offset);
9276 foreach ($encodingTables as $enctable) {
9277 if (($enctable['platformID'] == 3) AND ($enctable['encodingID'] == 0)) {
9280 $modesymbol = false;
9282 $offset = $table['cmap']['offset'] +
$enctable['offset'];
9283 $format = $this->_getUSHORT($font, $offset);
9285 case 0: { // Format 0: Byte encoding table
9286 $offset +
= 4; // skip length and version/language
9287 for ($k = 0; $k < 256; ++
$k) {
9288 if (isset($subsetchars[$k])) {
9289 $g = $this->_getBYTE($font, $offset);
9290 $subsetglyphs[$g] = $k;
9297 case 2: { // Format 2: High-byte mapping through table
9298 $offset +
= 4; // skip length and version
9299 // to be implemented ...
9302 case 4: { // Format 4: Segment mapping to delta values
9303 $length = $this->_getUSHORT($font, $offset);
9304 $offset +
= 2; // skip version/language
9305 $segCount = ($this->_getUSHORT($font, $offset) / 2);
9306 $offset +
= 6; // skip searchRange, entrySelector, rangeShift
9307 $endCount = array(); // array of end character codes for each segment
9308 for ($k = 0; $k < $segCount; ++
$k) {
9309 $endCount[$k] = $this->_getUSHORT($font, $offset);
9311 $offset +
= 2; // skip reservedPad
9312 $startCount = array(); // array of start character codes for each segment
9313 for ($k = 0; $k < $segCount; ++
$k) {
9314 $startCount[$k] = $this->_getUSHORT($font, $offset);
9316 $idDelta = array(); // delta for all character codes in segment
9317 for ($k = 0; $k < $segCount; ++
$k) {
9318 $idDelta[$k] = $this->_getUSHORT($font, $offset);
9320 $idRangeOffset = array(); // Offsets into glyphIdArray or 0
9321 for ($k = 0; $k < $segCount; ++
$k) {
9322 $idRangeOffset[$k] = $this->_getUSHORT($font, $offset);
9324 $gidlen = ($length / 2) - 8 - (4 * $segCount);
9325 $glyphIdArray = array(); // glyph index array
9326 for ($k = 0; $k < $gidlen; ++
$k) {
9327 $glyphIdArray[$k] = $this->_getUSHORT($font, $offset);
9329 for ($k = 0; $k < $segCount; ++
$k) {
9330 for ($c = $startCount[$k]; $c <= $endCount[$k]; ++
$c) {
9331 if (isset($subsetchars[$c])) {
9332 if ($idRangeOffset[$k] == 0) {
9335 $gid = (($idRangeOffset[$k] / 2) +
($c - $startCount[$k]) - ($segCount - $k));
9336 $g = $glyphIdArray[$gid];
9338 $g +
= ($idDelta[$k] - 65536);
9342 $subsetglyphs[$g] = $c;
9348 case 6: { // Format 6: Trimmed table mapping
9349 $offset +
= 4; // skip length and version/language
9350 $firstCode = $this->_getUSHORT($font, $offset);
9351 $entryCount = $this->_getUSHORT($font, $offset);
9352 for ($k = 0; $k < $entryCount; ++
$k) {
9353 $c = ($k +
$firstCode);
9354 if (isset($subsetchars[$c])) {
9355 $g = $this->_getUSHORT($font, $offset);
9356 $subsetglyphs[$g] = $c;
9363 case 8: { // Format 8: Mixed 16-bit and 32-bit coverage
9364 $offset +
= 10; // skip length and version
9365 // to be implemented ...
9368 case 10: { // Format 10: Trimmed array
9369 $offset +
= 10; // skip length and version/language
9370 $startCharCode = $this->_getULONG($font, $offset);
9371 $numChars = $this->_getULONG($font, $offset);
9372 for ($k = 0; $k < $numChars; ++
$k) {
9373 $c = ($k +
$startCharCode);
9374 if (isset($subsetchars[$c])) {
9375 $g = $this->_getUSHORT($font, $offset);
9376 $subsetglyphs[$g] = $c;
9383 case 12: { // Format 12: Segmented coverage
9384 $offset +
= 10; // skip length and version/language
9385 $nGroups = $this->_getULONG($font, $offset);
9386 for ($k = 0; $k < $nGroups; ++
$k) {
9387 $startCharCode = $this->_getULONG($font, $offset);
9388 $endCharCode = $this->_getULONG($font, $offset);
9389 $startGlyphCode = $this->_getULONG($font, $offset);
9390 for ($c = $startCharCode; $c <= $endCharCode; ++
$c) {
9391 if (isset($subsetchars[$c])) {
9392 $subsetglyphs[$startGlyphCode] = $c;
9401 // sort glyphs by key
9402 ksort($subsetglyphs);
9403 // add composite glyps to $subsetglyphs and remove missing glyphs
9404 foreach ($subsetglyphs as $key => $val) {
9405 if (isset($indexToLoc[$key])) {
9406 $offset = $table['glyf']['offset'] +
$indexToLoc[$key];
9407 $numberOfContours = $this->_getSHORT($font, $offset);
9408 if ($numberOfContours < 0) { // composite glyph
9409 $offset +
= 8; // skip xMin, yMin, xMax, yMax
9411 $flags = $this->_getUSHORT($font, $offset);
9412 $glyphIndex = $this->_getUSHORT($font, $offset);
9413 if (!isset($subsetglyphs[$glyphIndex]) AND isset($indexToLoc[$glyphIndex])) {
9414 // add missing glyphs
9415 $subsetglyphs[$glyphIndex] = true;
9417 // skip some bytes by case
9425 } elseif ($flags & 64) {
9427 } elseif ($flags & 128) {
9430 } while ($flags & 32);
9433 unset($subsetglyphs[$key]);
9436 // build new glyf table with only used glyphs
9439 // create new empty indexToLoc table
9440 $newIndexToLoc = array_fill(0, count($indexToLoc), 0);
9442 foreach ($subsetglyphs as $glyphID => $char) {
9443 if (isset($indexToLoc[$glyphID]) AND isset($indexToLoc[($glyphID +
1)])) {
9444 $start = $indexToLoc[$glyphID];
9445 $length = ($indexToLoc[($glyphID +
1)] - $start);
9446 $glyf .= substr($font, ($table['glyf']['offset'] +
$start), $length);
9447 $newIndexToLoc[$glyphID] = $goffset;
9448 $goffset +
= $length;
9451 // build new loca table
9453 if ($short_offset) {
9454 foreach ($newIndexToLoc as $glyphID => $offset) {
9455 $loca .= pack('n', ($offset / 2));
9458 foreach ($newIndexToLoc as $glyphID => $offset) {
9459 $loca .= pack('N', $offset);
9462 // array of table names to preserve (loca and glyf tables will be added later)
9463 //$table_names = array ('cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'OS/2', 'post', 'cvt ', 'fpgm', 'prep');
9464 // the cmap table is not needed and shall not be present, since the mapping from character codes to glyph descriptions is provided separately
9465 $table_names = array ('head', 'hhea', 'hmtx', 'maxp', 'cvt ', 'fpgm', 'prep'); // minimum required table names
9466 // get the tables to preserve
9468 foreach ($table as $tag => $val) {
9469 if (in_array($tag, $table_names)) {
9470 $table[$tag]['data'] = substr($font, $table[$tag]['offset'], $table[$tag]['length']);
9471 if ($tag == 'head') {
9472 // set the checkSumAdjustment to 0
9473 $table[$tag]['data'] = substr($table[$tag]['data'], 0, 8)."\x0\x0\x0\x0".substr($table[$tag]['data'], 12);
9475 $pad = 4 - ($table[$tag]['length'] %
4);
9477 // the length of a table must be a multiple of four bytes
9478 $table[$tag]['length'] +
= $pad;
9479 $table[$tag]['data'] .= str_repeat("\x0", $pad);
9481 $table[$tag]['offset'] = $offset;
9482 $offset +
= $table[$tag]['length'];
9483 // check sum is not changed (so keep the following line commented)
9484 //$table[$tag]['checkSum'] = $this->_getTTFtableChecksum($table[$tag]['data'], $table[$tag]['length']);
9486 unset($table[$tag]);
9490 $table['loca']['data'] = $loca;
9491 $table['loca']['length'] = strlen($loca);
9492 $pad = 4 - ($table['loca']['length'] %
4);
9494 // the length of a table must be a multiple of four bytes
9495 $table['loca']['length'] +
= $pad;
9496 $table['loca']['data'] .= str_repeat("\x0", $pad);
9498 $table['loca']['offset'] = $offset;
9499 $table['loca']['checkSum'] = $this->_getTTFtableChecksum($table['loca']['data'], $table['loca']['length']);
9500 $offset +
= $table['loca']['length'];
9502 $table['glyf']['data'] = $glyf;
9503 $table['glyf']['length'] = strlen($glyf);
9504 $pad = 4 - ($table['glyf']['length'] %
4);
9506 // the length of a table must be a multiple of four bytes
9507 $table['glyf']['length'] +
= $pad;
9508 $table['glyf']['data'] .= str_repeat("\x0", $pad);
9510 $table['glyf']['offset'] = $offset;
9511 $table['glyf']['checkSum'] = $this->_getTTFtableChecksum($table['glyf']['data'], $table['glyf']['length']);
9514 $font .= pack('N', 0x10000); // sfnt version
9515 $numTables = count($table);
9516 $font .= pack('n', $numTables); // numTables
9517 $entrySelector = floor(log($numTables, 2));
9518 $searchRange = pow(2, $entrySelector) * 16;
9519 $rangeShift = ($numTables * 16) - $searchRange;
9520 $font .= pack('n', $searchRange); // searchRange
9521 $font .= pack('n', $entrySelector); // entrySelector
9522 $font .= pack('n', $rangeShift); // rangeShift
9523 $offset = ($numTables * 16);
9524 foreach ($table as $tag => $data) {
9525 $font .= $tag; // tag
9526 $font .= pack('N', $data['checkSum']); // checkSum
9527 $font .= pack('N', ($data['offset'] +
$offset)); // offset
9528 $font .= pack('N', $data['length']); // length
9530 foreach ($table as $data) {
9531 $font .= $data['data'];
9533 // set checkSumAdjustment on head table
9534 $checkSumAdjustment = 0xB1B0AFBA - $this->_getTTFtableChecksum($font, strlen($font));
9535 $font = substr($font, 0, $table['head']['offset'] +
8).pack('N', $checkSumAdjustment).substr($font, $table['head']['offset'] +
12);
9540 * Returs the checksum of a TTF table.
9541 * @param $table (string) table to check
9542 * @param $length (int) lenght of table in bytes
9543 * @return int checksum
9544 * @author Nicola Asuni
9546 * @since 5.2.000 (2010-06-02)
9548 protected function _getTTFtableChecksum($table, $length) {
9550 $tlen = ($length / 4);
9552 for ($i = 0; $i < $tlen; ++
$i) {
9553 $v = unpack('Ni', substr($table, $offset, 4));
9557 $sum = unpack('Ni', pack('N', $sum));
9562 * Outputs font widths
9563 * @param $font (array) font data
9564 * @param $cidoffset (int) offset for CID values
9565 * @return PDF command string for font widths
9566 * @author Nicola Asuni
9568 * @since 4.4.000 (2008-12-07)
9570 protected function _putfontwidths($font, $cidoffset=0) {
9577 // for each character
9578 foreach ($font['cw'] as $cid => $width) {
9580 if ($font['subset'] AND ($cid > 255) AND (!isset($font['subsetchars'][$cid]))) {
9581 // ignore the unused characters (font subsetting)
9584 if ($width != $font['dw']) {
9585 if ($cid == ($prevcid +
1)) {
9587 if ($width == $prevwidth) {
9588 if ($width == $range[$rangeid][0]) {
9589 $range[$rangeid][] = $width;
9591 array_pop($range[$rangeid]);
9593 $rangeid = $prevcid;
9594 $range[$rangeid] = array();
9595 $range[$rangeid][] = $prevwidth;
9596 $range[$rangeid][] = $width;
9599 $range[$rangeid]['interval'] = true;
9604 $range[$rangeid] = array();
9605 $range[$rangeid][] = $width;
9607 $range[$rangeid][] = $width;
9614 $range[$rangeid] = array();
9615 $range[$rangeid][] = $width;
9619 $prevwidth = $width;
9626 foreach ($range as $k => $ws) {
9628 if (($k == $nextk) AND (!$prevint) AND ((!isset($ws['interval'])) OR ($cws < 4))) {
9629 if (isset($range[$k]['interval'])) {
9630 unset($range[$k]['interval']);
9632 $range[$prevk] = array_merge($range[$prevk], $range[$k]);
9638 if (isset($ws['interval'])) {
9644 unset($range[$k]['interval']);
9652 foreach ($range as $k => $ws) {
9653 if (count(array_count_values($ws)) == 1) {
9654 // interval mode is more compact
9655 $w .= ' '.$k.' '.($k +
count($ws) - 1).' '.$ws[0];
9658 $w .= ' '.$k.' [ '.implode(' ', $ws).' ]';
9661 return '/W ['.$w.' ]';
9666 * @author Nicola Asuni
9669 protected function _putfonts() {
9671 foreach ($this->diffs
as $diff) {
9674 $this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
9676 $mqr = $this->get_mqr();
9677 $this->set_mqr(false);
9678 foreach ($this->FontFiles
as $file => $info) {
9679 // search and get font file to embedd
9680 $fontdir = $info['fontdir'];
9681 $file = strtolower($file);
9683 // search files on various directories
9684 if (($fontdir !== false) AND file_exists($fontdir.$file)) {
9685 $fontfile = $fontdir.$file;
9686 } elseif (file_exists($this->_getfontpath().$file)) {
9687 $fontfile = $this->_getfontpath().$file;
9688 } elseif (file_exists($file)) {
9691 if (!$this->empty_string($fontfile)) {
9692 $font = file_get_contents($fontfile);
9693 $compressed = (substr($file, -2) == '.z');
9694 if ((!$compressed) AND (isset($info['length2']))) {
9695 $header = (ord($font{0}) == 128);
9697 //Strip first binary header
9698 $font = substr($font, 6);
9700 if ($header AND (ord($font{$info['length1']}) == 128)) {
9701 //Strip second binary header
9702 $font = substr($font, 0, $info['length1']).substr($font, ($info['length1'] +
6));
9704 } elseif ($info['subset'] AND ((!$compressed) OR ($compressed AND function_exists('gzcompress')))) {
9707 $font = gzuncompress($font);
9709 // merge subset characters
9710 $subsetchars = array(); // used chars
9711 foreach ($info['fontkeys'] as $fontkey) {
9712 $fontinfo = $this->getFontBuffer($fontkey);
9713 $subsetchars +
= $fontinfo['subsetchars'];
9715 $font = $this->_getTrueTypeFontSubset($font, $subsetchars);
9718 $font = gzcompress($font);
9722 $this->FontFiles
[$file]['n'] = $this->n
;
9723 $stream = $this->_getrawstream($font);
9724 $out = '<< /Length '.strlen($stream);
9726 $out .= ' /Filter /FlateDecode';
9728 $out .= ' /Length1 '.$info['length1'];
9729 if (isset($info['length2'])) {
9730 $out .= ' /Length2 '.$info['length2'].' /Length3 0';
9733 $out .= ' stream'."\n".$stream."\n".'endstream';
9734 $out .= "\n".'endobj';
9738 $this->set_mqr($mqr);
9739 foreach ($this->fontkeys
as $k) {
9741 $font = $this->getFontBuffer($k);
9742 $type = $font['type'];
9743 $name = $font['name'];
9744 if ($type == 'core') {
9745 // standard core font
9746 $out = $this->_getobj($this->font_obj_ids
[$k])."\n";
9747 $out .= '<</Type /Font';
9748 $out .= ' /Subtype /Type1';
9749 $out .= ' /BaseFont /'.$name;
9750 $out .= ' /Name /F'.$font['i'];
9751 if ((strtolower($name) != 'symbol') AND (strtolower($name) != 'zapfdingbats')) {
9752 $out .= ' /Encoding /WinAnsiEncoding';
9754 if ($k == 'helvetica') {
9755 // add default font for annotations
9756 $this->annotation_fonts
[$k] = $font['i'];
9759 $out .= "\n".'endobj';
9761 } elseif (($type == 'Type1') OR ($type == 'TrueType')) {
9762 // additional Type1 or TrueType font
9763 $out = $this->_getobj($this->font_obj_ids
[$k])."\n";
9764 $out .= '<</Type /Font';
9765 $out .= ' /Subtype /'.$type;
9766 $out .= ' /BaseFont /'.$name;
9767 $out .= ' /Name /F'.$font['i'];
9768 $out .= ' /FirstChar 32 /LastChar 255';
9769 $out .= ' /Widths '.($this->n +
1).' 0 R';
9770 $out .= ' /FontDescriptor '.($this->n +
2).' 0 R';
9772 if (isset($font['diff'])) {
9773 $out .= ' /Encoding '.($nf +
$font['diff']).' 0 R';
9775 $out .= ' /Encoding /WinAnsiEncoding';
9779 $out .= "\n".'endobj';
9785 for ($i = 32; $i < 256; ++
$i) {
9789 $s .= "\n".'endobj';
9793 $s = '<</Type /FontDescriptor /FontName /'.$name;
9794 foreach ($font['desc'] as $fdk => $fdv) {
9795 if(is_float($fdv)) {
9796 $fdv = sprintf('%.3F', $fdv);
9798 $s .= ' /'.$fdk.' '.$fdv.'';
9800 if (!$this->empty_string($font['file'])) {
9801 $s .= ' /FontFile'.($type == 'Type1' ?
'' : '2').' '.$this->FontFiles
[$font['file']]['n'].' 0 R';
9804 $s .= "\n".'endobj';
9808 $mtd = '_put'.strtolower($type);
9809 if (!method_exists($this, $mtd)) {
9810 $this->Error('Unsupported font type: '.$type);
9818 * Adds unicode fonts.<br>
9819 * Based on PDF Reference 1.3 (section 5)
9820 * @param $font (array) font data
9822 * @author Nicola Asuni
9823 * @since 1.52.0.TC005 (2005-01-05)
9825 protected function _puttruetypeunicode($font) {
9827 if ($font['subset']) {
9828 // change name for font subsetting
9829 $subtag = sprintf('%06u', $font['i']);
9830 $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ');
9831 $fontname .= $subtag.'+';
9833 $fontname .= $font['name'];
9835 // A composite font composed of other fonts, organized hierarchically
9836 $out = $this->_getobj($this->font_obj_ids
[$font['fontkey']])."\n";
9837 $out .= '<< /Type /Font';
9838 $out .= ' /Subtype /Type0';
9839 $out .= ' /BaseFont /'.$fontname;
9840 $out .= ' /Name /F'.$font['i'];
9841 $out .= ' /Encoding /'.$font['enc'];
9842 $out .= ' /ToUnicode '.($this->n +
1).' 0 R';
9843 $out .= ' /DescendantFonts ['.($this->n +
2).' 0 R]';
9845 $out .= "\n".'endobj';
9847 // ToUnicode map for Identity-H
9848 $stream = "/CIDInit /ProcSet findresource begin\n";
9849 $stream .= "12 dict begin\n";
9850 $stream .= "begincmap\n";
9851 $stream .= "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n";
9852 $stream .= "/CMapName /Adobe-Identity-UCS def\n";
9853 $stream .= "/CMapType 2 def\n";
9854 $stream .= "/WMode 0 def\n";
9855 $stream .= "1 begincodespacerange\n";
9856 $stream .= "<0000> <FFFF>\n";
9857 $stream .= "endcodespacerange\n";
9858 $stream .= "100 beginbfrange\n";
9859 $stream .= "<0000> <00ff> <0000>\n";
9860 $stream .= "<0100> <01ff> <0100>\n";
9861 $stream .= "<0200> <02ff> <0200>\n";
9862 $stream .= "<0300> <03ff> <0300>\n";
9863 $stream .= "<0400> <04ff> <0400>\n";
9864 $stream .= "<0500> <05ff> <0500>\n";
9865 $stream .= "<0600> <06ff> <0600>\n";
9866 $stream .= "<0700> <07ff> <0700>\n";
9867 $stream .= "<0800> <08ff> <0800>\n";
9868 $stream .= "<0900> <09ff> <0900>\n";
9869 $stream .= "<0a00> <0aff> <0a00>\n";
9870 $stream .= "<0b00> <0bff> <0b00>\n";
9871 $stream .= "<0c00> <0cff> <0c00>\n";
9872 $stream .= "<0d00> <0dff> <0d00>\n";
9873 $stream .= "<0e00> <0eff> <0e00>\n";
9874 $stream .= "<0f00> <0fff> <0f00>\n";
9875 $stream .= "<1000> <10ff> <1000>\n";
9876 $stream .= "<1100> <11ff> <1100>\n";
9877 $stream .= "<1200> <12ff> <1200>\n";
9878 $stream .= "<1300> <13ff> <1300>\n";
9879 $stream .= "<1400> <14ff> <1400>\n";
9880 $stream .= "<1500> <15ff> <1500>\n";
9881 $stream .= "<1600> <16ff> <1600>\n";
9882 $stream .= "<1700> <17ff> <1700>\n";
9883 $stream .= "<1800> <18ff> <1800>\n";
9884 $stream .= "<1900> <19ff> <1900>\n";
9885 $stream .= "<1a00> <1aff> <1a00>\n";
9886 $stream .= "<1b00> <1bff> <1b00>\n";
9887 $stream .= "<1c00> <1cff> <1c00>\n";
9888 $stream .= "<1d00> <1dff> <1d00>\n";
9889 $stream .= "<1e00> <1eff> <1e00>\n";
9890 $stream .= "<1f00> <1fff> <1f00>\n";
9891 $stream .= "<2000> <20ff> <2000>\n";
9892 $stream .= "<2100> <21ff> <2100>\n";
9893 $stream .= "<2200> <22ff> <2200>\n";
9894 $stream .= "<2300> <23ff> <2300>\n";
9895 $stream .= "<2400> <24ff> <2400>\n";
9896 $stream .= "<2500> <25ff> <2500>\n";
9897 $stream .= "<2600> <26ff> <2600>\n";
9898 $stream .= "<2700> <27ff> <2700>\n";
9899 $stream .= "<2800> <28ff> <2800>\n";
9900 $stream .= "<2900> <29ff> <2900>\n";
9901 $stream .= "<2a00> <2aff> <2a00>\n";
9902 $stream .= "<2b00> <2bff> <2b00>\n";
9903 $stream .= "<2c00> <2cff> <2c00>\n";
9904 $stream .= "<2d00> <2dff> <2d00>\n";
9905 $stream .= "<2e00> <2eff> <2e00>\n";
9906 $stream .= "<2f00> <2fff> <2f00>\n";
9907 $stream .= "<3000> <30ff> <3000>\n";
9908 $stream .= "<3100> <31ff> <3100>\n";
9909 $stream .= "<3200> <32ff> <3200>\n";
9910 $stream .= "<3300> <33ff> <3300>\n";
9911 $stream .= "<3400> <34ff> <3400>\n";
9912 $stream .= "<3500> <35ff> <3500>\n";
9913 $stream .= "<3600> <36ff> <3600>\n";
9914 $stream .= "<3700> <37ff> <3700>\n";
9915 $stream .= "<3800> <38ff> <3800>\n";
9916 $stream .= "<3900> <39ff> <3900>\n";
9917 $stream .= "<3a00> <3aff> <3a00>\n";
9918 $stream .= "<3b00> <3bff> <3b00>\n";
9919 $stream .= "<3c00> <3cff> <3c00>\n";
9920 $stream .= "<3d00> <3dff> <3d00>\n";
9921 $stream .= "<3e00> <3eff> <3e00>\n";
9922 $stream .= "<3f00> <3fff> <3f00>\n";
9923 $stream .= "<4000> <40ff> <4000>\n";
9924 $stream .= "<4100> <41ff> <4100>\n";
9925 $stream .= "<4200> <42ff> <4200>\n";
9926 $stream .= "<4300> <43ff> <4300>\n";
9927 $stream .= "<4400> <44ff> <4400>\n";
9928 $stream .= "<4500> <45ff> <4500>\n";
9929 $stream .= "<4600> <46ff> <4600>\n";
9930 $stream .= "<4700> <47ff> <4700>\n";
9931 $stream .= "<4800> <48ff> <4800>\n";
9932 $stream .= "<4900> <49ff> <4900>\n";
9933 $stream .= "<4a00> <4aff> <4a00>\n";
9934 $stream .= "<4b00> <4bff> <4b00>\n";
9935 $stream .= "<4c00> <4cff> <4c00>\n";
9936 $stream .= "<4d00> <4dff> <4d00>\n";
9937 $stream .= "<4e00> <4eff> <4e00>\n";
9938 $stream .= "<4f00> <4fff> <4f00>\n";
9939 $stream .= "<5000> <50ff> <5000>\n";
9940 $stream .= "<5100> <51ff> <5100>\n";
9941 $stream .= "<5200> <52ff> <5200>\n";
9942 $stream .= "<5300> <53ff> <5300>\n";
9943 $stream .= "<5400> <54ff> <5400>\n";
9944 $stream .= "<5500> <55ff> <5500>\n";
9945 $stream .= "<5600> <56ff> <5600>\n";
9946 $stream .= "<5700> <57ff> <5700>\n";
9947 $stream .= "<5800> <58ff> <5800>\n";
9948 $stream .= "<5900> <59ff> <5900>\n";
9949 $stream .= "<5a00> <5aff> <5a00>\n";
9950 $stream .= "<5b00> <5bff> <5b00>\n";
9951 $stream .= "<5c00> <5cff> <5c00>\n";
9952 $stream .= "<5d00> <5dff> <5d00>\n";
9953 $stream .= "<5e00> <5eff> <5e00>\n";
9954 $stream .= "<5f00> <5fff> <5f00>\n";
9955 $stream .= "<6000> <60ff> <6000>\n";
9956 $stream .= "<6100> <61ff> <6100>\n";
9957 $stream .= "<6200> <62ff> <6200>\n";
9958 $stream .= "<6300> <63ff> <6300>\n";
9959 $stream .= "endbfrange\n";
9960 $stream .= "100 beginbfrange\n";
9961 $stream .= "<6400> <64ff> <6400>\n";
9962 $stream .= "<6500> <65ff> <6500>\n";
9963 $stream .= "<6600> <66ff> <6600>\n";
9964 $stream .= "<6700> <67ff> <6700>\n";
9965 $stream .= "<6800> <68ff> <6800>\n";
9966 $stream .= "<6900> <69ff> <6900>\n";
9967 $stream .= "<6a00> <6aff> <6a00>\n";
9968 $stream .= "<6b00> <6bff> <6b00>\n";
9969 $stream .= "<6c00> <6cff> <6c00>\n";
9970 $stream .= "<6d00> <6dff> <6d00>\n";
9971 $stream .= "<6e00> <6eff> <6e00>\n";
9972 $stream .= "<6f00> <6fff> <6f00>\n";
9973 $stream .= "<7000> <70ff> <7000>\n";
9974 $stream .= "<7100> <71ff> <7100>\n";
9975 $stream .= "<7200> <72ff> <7200>\n";
9976 $stream .= "<7300> <73ff> <7300>\n";
9977 $stream .= "<7400> <74ff> <7400>\n";
9978 $stream .= "<7500> <75ff> <7500>\n";
9979 $stream .= "<7600> <76ff> <7600>\n";
9980 $stream .= "<7700> <77ff> <7700>\n";
9981 $stream .= "<7800> <78ff> <7800>\n";
9982 $stream .= "<7900> <79ff> <7900>\n";
9983 $stream .= "<7a00> <7aff> <7a00>\n";
9984 $stream .= "<7b00> <7bff> <7b00>\n";
9985 $stream .= "<7c00> <7cff> <7c00>\n";
9986 $stream .= "<7d00> <7dff> <7d00>\n";
9987 $stream .= "<7e00> <7eff> <7e00>\n";
9988 $stream .= "<7f00> <7fff> <7f00>\n";
9989 $stream .= "<8000> <80ff> <8000>\n";
9990 $stream .= "<8100> <81ff> <8100>\n";
9991 $stream .= "<8200> <82ff> <8200>\n";
9992 $stream .= "<8300> <83ff> <8300>\n";
9993 $stream .= "<8400> <84ff> <8400>\n";
9994 $stream .= "<8500> <85ff> <8500>\n";
9995 $stream .= "<8600> <86ff> <8600>\n";
9996 $stream .= "<8700> <87ff> <8700>\n";
9997 $stream .= "<8800> <88ff> <8800>\n";
9998 $stream .= "<8900> <89ff> <8900>\n";
9999 $stream .= "<8a00> <8aff> <8a00>\n";
10000 $stream .= "<8b00> <8bff> <8b00>\n";
10001 $stream .= "<8c00> <8cff> <8c00>\n";
10002 $stream .= "<8d00> <8dff> <8d00>\n";
10003 $stream .= "<8e00> <8eff> <8e00>\n";
10004 $stream .= "<8f00> <8fff> <8f00>\n";
10005 $stream .= "<9000> <90ff> <9000>\n";
10006 $stream .= "<9100> <91ff> <9100>\n";
10007 $stream .= "<9200> <92ff> <9200>\n";
10008 $stream .= "<9300> <93ff> <9300>\n";
10009 $stream .= "<9400> <94ff> <9400>\n";
10010 $stream .= "<9500> <95ff> <9500>\n";
10011 $stream .= "<9600> <96ff> <9600>\n";
10012 $stream .= "<9700> <97ff> <9700>\n";
10013 $stream .= "<9800> <98ff> <9800>\n";
10014 $stream .= "<9900> <99ff> <9900>\n";
10015 $stream .= "<9a00> <9aff> <9a00>\n";
10016 $stream .= "<9b00> <9bff> <9b00>\n";
10017 $stream .= "<9c00> <9cff> <9c00>\n";
10018 $stream .= "<9d00> <9dff> <9d00>\n";
10019 $stream .= "<9e00> <9eff> <9e00>\n";
10020 $stream .= "<9f00> <9fff> <9f00>\n";
10021 $stream .= "<a000> <a0ff> <a000>\n";
10022 $stream .= "<a100> <a1ff> <a100>\n";
10023 $stream .= "<a200> <a2ff> <a200>\n";
10024 $stream .= "<a300> <a3ff> <a300>\n";
10025 $stream .= "<a400> <a4ff> <a400>\n";
10026 $stream .= "<a500> <a5ff> <a500>\n";
10027 $stream .= "<a600> <a6ff> <a600>\n";
10028 $stream .= "<a700> <a7ff> <a700>\n";
10029 $stream .= "<a800> <a8ff> <a800>\n";
10030 $stream .= "<a900> <a9ff> <a900>\n";
10031 $stream .= "<aa00> <aaff> <aa00>\n";
10032 $stream .= "<ab00> <abff> <ab00>\n";
10033 $stream .= "<ac00> <acff> <ac00>\n";
10034 $stream .= "<ad00> <adff> <ad00>\n";
10035 $stream .= "<ae00> <aeff> <ae00>\n";
10036 $stream .= "<af00> <afff> <af00>\n";
10037 $stream .= "<b000> <b0ff> <b000>\n";
10038 $stream .= "<b100> <b1ff> <b100>\n";
10039 $stream .= "<b200> <b2ff> <b200>\n";
10040 $stream .= "<b300> <b3ff> <b300>\n";
10041 $stream .= "<b400> <b4ff> <b400>\n";
10042 $stream .= "<b500> <b5ff> <b500>\n";
10043 $stream .= "<b600> <b6ff> <b600>\n";
10044 $stream .= "<b700> <b7ff> <b700>\n";
10045 $stream .= "<b800> <b8ff> <b800>\n";
10046 $stream .= "<b900> <b9ff> <b900>\n";
10047 $stream .= "<ba00> <baff> <ba00>\n";
10048 $stream .= "<bb00> <bbff> <bb00>\n";
10049 $stream .= "<bc00> <bcff> <bc00>\n";
10050 $stream .= "<bd00> <bdff> <bd00>\n";
10051 $stream .= "<be00> <beff> <be00>\n";
10052 $stream .= "<bf00> <bfff> <bf00>\n";
10053 $stream .= "<c000> <c0ff> <c000>\n";
10054 $stream .= "<c100> <c1ff> <c100>\n";
10055 $stream .= "<c200> <c2ff> <c200>\n";
10056 $stream .= "<c300> <c3ff> <c300>\n";
10057 $stream .= "<c400> <c4ff> <c400>\n";
10058 $stream .= "<c500> <c5ff> <c500>\n";
10059 $stream .= "<c600> <c6ff> <c600>\n";
10060 $stream .= "<c700> <c7ff> <c700>\n";
10061 $stream .= "endbfrange\n";
10062 $stream .= "56 beginbfrange\n";
10063 $stream .= "<c800> <c8ff> <c800>\n";
10064 $stream .= "<c900> <c9ff> <c900>\n";
10065 $stream .= "<ca00> <caff> <ca00>\n";
10066 $stream .= "<cb00> <cbff> <cb00>\n";
10067 $stream .= "<cc00> <ccff> <cc00>\n";
10068 $stream .= "<cd00> <cdff> <cd00>\n";
10069 $stream .= "<ce00> <ceff> <ce00>\n";
10070 $stream .= "<cf00> <cfff> <cf00>\n";
10071 $stream .= "<d000> <d0ff> <d000>\n";
10072 $stream .= "<d100> <d1ff> <d100>\n";
10073 $stream .= "<d200> <d2ff> <d200>\n";
10074 $stream .= "<d300> <d3ff> <d300>\n";
10075 $stream .= "<d400> <d4ff> <d400>\n";
10076 $stream .= "<d500> <d5ff> <d500>\n";
10077 $stream .= "<d600> <d6ff> <d600>\n";
10078 $stream .= "<d700> <d7ff> <d700>\n";
10079 $stream .= "<d800> <d8ff> <d800>\n";
10080 $stream .= "<d900> <d9ff> <d900>\n";
10081 $stream .= "<da00> <daff> <da00>\n";
10082 $stream .= "<db00> <dbff> <db00>\n";
10083 $stream .= "<dc00> <dcff> <dc00>\n";
10084 $stream .= "<dd00> <ddff> <dd00>\n";
10085 $stream .= "<de00> <deff> <de00>\n";
10086 $stream .= "<df00> <dfff> <df00>\n";
10087 $stream .= "<e000> <e0ff> <e000>\n";
10088 $stream .= "<e100> <e1ff> <e100>\n";
10089 $stream .= "<e200> <e2ff> <e200>\n";
10090 $stream .= "<e300> <e3ff> <e300>\n";
10091 $stream .= "<e400> <e4ff> <e400>\n";
10092 $stream .= "<e500> <e5ff> <e500>\n";
10093 $stream .= "<e600> <e6ff> <e600>\n";
10094 $stream .= "<e700> <e7ff> <e700>\n";
10095 $stream .= "<e800> <e8ff> <e800>\n";
10096 $stream .= "<e900> <e9ff> <e900>\n";
10097 $stream .= "<ea00> <eaff> <ea00>\n";
10098 $stream .= "<eb00> <ebff> <eb00>\n";
10099 $stream .= "<ec00> <ecff> <ec00>\n";
10100 $stream .= "<ed00> <edff> <ed00>\n";
10101 $stream .= "<ee00> <eeff> <ee00>\n";
10102 $stream .= "<ef00> <efff> <ef00>\n";
10103 $stream .= "<f000> <f0ff> <f000>\n";
10104 $stream .= "<f100> <f1ff> <f100>\n";
10105 $stream .= "<f200> <f2ff> <f200>\n";
10106 $stream .= "<f300> <f3ff> <f300>\n";
10107 $stream .= "<f400> <f4ff> <f400>\n";
10108 $stream .= "<f500> <f5ff> <f500>\n";
10109 $stream .= "<f600> <f6ff> <f600>\n";
10110 $stream .= "<f700> <f7ff> <f700>\n";
10111 $stream .= "<f800> <f8ff> <f800>\n";
10112 $stream .= "<f900> <f9ff> <f900>\n";
10113 $stream .= "<fa00> <faff> <fa00>\n";
10114 $stream .= "<fb00> <fbff> <fb00>\n";
10115 $stream .= "<fc00> <fcff> <fc00>\n";
10116 $stream .= "<fd00> <fdff> <fd00>\n";
10117 $stream .= "<fe00> <feff> <fe00>\n";
10118 $stream .= "<ff00> <ffff> <ff00>\n";
10119 $stream .= "endbfrange\n";
10120 $stream .= "endcmap\n";
10121 $stream .= "CMapName currentdict /CMap defineresource pop\n";
10122 $stream .= "end\n";
10124 // ToUnicode Object
10126 $stream = ($this->compress
) ?
gzcompress($stream) : $stream;
10127 $filter = ($this->compress
) ?
'/Filter /FlateDecode ' : '';
10128 $stream = $this->_getrawstream($stream);
10129 $this->_out('<<'.$filter.'/Length '.strlen($stream).'>> stream'."\n".$stream."\n".'endstream'."\n".'endobj');
10131 // A CIDFont whose glyph descriptions are based on TrueType font technology
10132 $oid = $this->_newobj();
10133 $out = '<< /Type /Font';
10134 $out .= ' /Subtype /CIDFontType2';
10135 $out .= ' /BaseFont /'.$fontname;
10136 // A dictionary containing entries that define the character collection of the CIDFont.
10137 $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
10138 $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
10139 $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
10140 $out .= ' /CIDSystemInfo << '.$cidinfo.' >>';
10141 $out .= ' /FontDescriptor '.($this->n +
1).' 0 R';
10142 $out .= ' /DW '.$font['dw']; // default width
10143 $out .= "\n".$this->_putfontwidths($font, 0);
10144 if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
10145 $out .= "\n".'/CIDToGIDMap '.($this->n +
2).' 0 R';
10148 $out .= "\n".'endobj';
10151 // A font descriptor describing the CIDFont default metrics other than its glyph widths
10153 $out = '<< /Type /FontDescriptor';
10154 $out .= ' /FontName /'.$fontname;
10155 foreach ($font['desc'] as $key => $value) {
10156 if(is_float($value)) {
10157 $value = sprintf('%.3F', $value);
10159 $out .= ' /'.$key.' '.$value;
10162 if (!$this->empty_string($font['file'])) {
10163 // A stream containing a TrueType font
10164 $out .= ' /FontFile2 '.$this->FontFiles
[$font['file']]['n'].' 0 R';
10165 $fontdir = $this->FontFiles
[$font['file']]['fontdir'];
10168 $out .= "\n".'endobj';
10170 if (isset($font['ctg']) AND (!$this->empty_string($font['ctg']))) {
10172 // Embed CIDToGIDMap
10173 // A specification of the mapping from CIDs to glyph indices
10174 // search and get CTG font file to embedd
10175 $ctgfile = strtolower($font['ctg']);
10176 // search and get ctg font file to embedd
10178 // search files on various directories
10179 if (($fontdir !== false) AND file_exists($fontdir.$ctgfile)) {
10180 $fontfile = $fontdir.$ctgfile;
10181 } elseif (file_exists($this->_getfontpath().$ctgfile)) {
10182 $fontfile = $this->_getfontpath().$ctgfile;
10183 } elseif (file_exists($ctgfile)) {
10184 $fontfile = $ctgfile;
10186 if ($this->empty_string($fontfile)) {
10187 $this->Error('Font file not found: '.$ctgfile);
10189 $stream = $this->_getrawstream(file_get_contents($fontfile));
10190 $out = '<< /Length '.strlen($stream).'';
10191 if (substr($fontfile, -2) == '.z') { // check file extension
10192 // Decompresses data encoded using the public-domain
10193 // zlib/deflate compression method, reproducing the
10194 // original text or binary data
10195 $out .= ' /Filter /FlateDecode';
10198 $out .= ' stream'."\n".$stream."\n".'endstream';
10199 $out .= "\n".'endobj';
10205 * Output CID-0 fonts.
10206 * A Type 0 CIDFont contains glyph descriptions based on the Adobe Type 1 font format
10207 * @param $font (array) font data
10209 * @author Andrew Whitehead, Nicola Asuni, Yukihiro Nakadaira
10210 * @since 3.2.000 (2008-06-23)
10212 protected function _putcidfont0($font) {
10214 if (!isset($font['cw'][1])) {
10217 if (isset($font['cidinfo']['uni2cid'])) {
10218 // convert unicode to cid.
10219 $uni2cid = $font['cidinfo']['uni2cid'];
10221 foreach ($font['cw'] as $uni => $width) {
10222 if (isset($uni2cid[$uni])) {
10223 $cw[($uni2cid[$uni] +
$cidoffset)] = $width;
10224 } elseif ($uni < 256) {
10225 $cw[$uni] = $width;
10226 } // else unknown character
10228 $font = array_merge($font, array('cw' => $cw));
10230 $name = $font['name'];
10231 $enc = $font['enc'];
10233 $longname = $name.'-'.$enc;
10237 $out = $this->_getobj($this->font_obj_ids
[$font['fontkey']])."\n";
10238 $out .= '<</Type /Font';
10239 $out .= ' /Subtype /Type0';
10240 $out .= ' /BaseFont /'.$longname;
10241 $out .= ' /Name /F'.$font['i'];
10243 $out .= ' /Encoding /'.$enc;
10245 $out .= ' /DescendantFonts ['.($this->n +
1).' 0 R]';
10247 $out .= "\n".'endobj';
10249 $oid = $this->_newobj();
10250 $out = '<</Type /Font';
10251 $out .= ' /Subtype /CIDFontType0';
10252 $out .= ' /BaseFont /'.$name;
10253 $cidinfo = '/Registry '.$this->_datastring($font['cidinfo']['Registry'], $oid);
10254 $cidinfo .= ' /Ordering '.$this->_datastring($font['cidinfo']['Ordering'], $oid);
10255 $cidinfo .= ' /Supplement '.$font['cidinfo']['Supplement'];
10256 $out .= ' /CIDSystemInfo <<'.$cidinfo.'>>';
10257 $out .= ' /FontDescriptor '.($this->n +
1).' 0 R';
10258 $out .= ' /DW '.$font['dw'];
10259 $out .= "\n".$this->_putfontwidths($font, $cidoffset);
10261 $out .= "\n".'endobj';
10264 $s = '<</Type /FontDescriptor /FontName /'.$name;
10265 foreach ($font['desc'] as $k => $v) {
10266 if ($k != 'Style') {
10268 $v = sprintf('%.3F', $v);
10270 $s .= ' /'.$k.' '.$v.'';
10274 $s .= "\n".'endobj';
10282 protected function _putimages() {
10283 $filter = ($this->compress
) ?
'/Filter /FlateDecode ' : '';
10284 foreach ($this->imagekeys
as $file) {
10285 $info = $this->getImageBuffer($file);
10286 $oid = $this->_newobj();
10287 $this->xobjects
['I'.$info['i']] = array('n' => $oid);
10288 $this->setImageSubBuffer($file, 'n', $this->n
);
10289 $out = '<</Type /XObject';
10290 $out .= ' /Subtype /Image';
10291 $out .= ' /Width '.$info['w'];
10292 $out .= ' /Height '.$info['h'];
10293 if (array_key_exists('masked', $info)) {
10294 $out .= ' /SMask '.($this->n
- 1).' 0 R';
10296 if ($info['cs'] == 'Indexed') {
10297 $out .= ' /ColorSpace [/Indexed /DeviceRGB '.((strlen($info['pal']) / 3) - 1).' '.($this->n +
1).' 0 R]';
10299 $out .= ' /ColorSpace /'.$info['cs'];
10300 if ($info['cs'] == 'DeviceCMYK') {
10301 $out .= ' /Decode [1 0 1 0 1 0 1 0]';
10304 $out .= ' /BitsPerComponent '.$info['bpc'];
10305 if (isset($info['f'])) {
10306 $out .= ' /Filter /'.$info['f'];
10308 if (isset($info['parms'])) {
10309 $out .= ' '.$info['parms'];
10311 if (isset($info['trns']) AND is_array($info['trns'])) {
10313 $count_info = count($info['trns']);
10314 for ($i=0; $i < $count_info; ++
$i) {
10315 $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
10317 $out .= ' /Mask ['.$trns.']';
10319 $stream = $this->_getrawstream($info['data']);
10320 $out .= ' /Length '.strlen($stream).' >>';
10321 $out .= ' stream'."\n".$stream."\n".'endstream';
10322 $out .= "\n".'endobj';
10325 if ($info['cs'] == 'Indexed') {
10327 $pal = ($this->compress
) ?
gzcompress($info['pal']) : $info['pal'];
10328 $pal = $this->_getrawstream($pal);
10329 $this->_out('<<'.$filter.'/Length '.strlen($pal).'>> stream'."\n".$pal."\n".'endstream'."\n".'endobj');
10335 * Output Form XObjects Templates.
10336 * @author Nicola Asuni
10337 * @since 5.8.017 (2010-08-24)
10339 * @see startTemplate(), endTemplate(), printTemplate()
10341 protected function _putxobjects() {
10342 foreach ($this->xobjects
as $key => $data) {
10343 if (isset($data['outdata'])) {
10344 $stream = trim($data['outdata']);
10345 $out = $this->_getobj($data['n'])."\n";
10347 $out .= ' /Type /XObject';
10348 $out .= ' /Subtype /Form';
10349 $out .= ' /FormType 1';
10350 if ($this->compress
) {
10351 $stream = gzcompress($stream);
10352 $out .= ' /Filter /FlateDecode';
10354 $out .= sprintf(' /BBox [%.2F %.2F %.2F %.2F]', ($data['x'] * $this->k
), (-$data['y'] * $this->k
), (($data['w'] +
$data['x']) * $this->k
), (($data['h'] - $data['y']) * $this->k
));
10355 $out .= ' /Matrix [1 0 0 1 0 0]';
10356 $out .= ' /Resources <<';
10357 $out .= ' /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
10359 if (!empty($data['fonts'])) {
10360 $out .= ' /Font <<';
10361 foreach ($data['fonts'] as $fontkey => $fontid) {
10362 $out .= ' /F'.$fontid.' '.$this->font_obj_ids
[$fontkey].' 0 R';
10366 // images or nested xobjects
10367 if (!empty($data['images']) OR !empty($data['xobjects'])) {
10368 $out .= ' /XObject <<';
10369 foreach ($data['images'] as $imgid) {
10370 $out .= ' /I'.$imgid.' '.$this->xobjects
['I'.$imgid]['n'].' 0 R';
10372 foreach ($data['xobjects'] as $sub_id => $sub_objid) {
10373 $out .= ' /'.$sub_id.' '.$sub_objid['n'].' 0 R';
10378 $stream = $this->_getrawstream($stream);
10379 $out .= ' /Length '.strlen($stream);
10381 $out .= ' stream'."\n".$stream."\n".'endstream';
10382 $out .= "\n".'endobj';
10389 * Output Spot Colors Resources.
10391 * @since 4.0.024 (2008-09-12)
10393 protected function _putspotcolors() {
10394 foreach ($this->spot_colors
as $name => $color) {
10396 $this->spot_colors
[$name]['n'] = $this->n
;
10397 $out = '[/Separation /'.str_replace(' ', '#20', $name);
10398 $out .= ' /DeviceCMYK <<';
10399 $out .= ' /Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0]';
10400 $out .= ' '.sprintf('/C1 [%.4F %.4F %.4F %.4F] ', ($color['c'] / 100), ($color['m'] / 100), ($color['y'] / 100), ($color['k'] / 100));
10401 $out .= ' /FunctionType 2 /Domain [0 1] /N 1>>]';
10402 $out .= "\n".'endobj';
10408 * Return XObjects Dictionary.
10409 * @return string XObjects dictionary
10411 * @since 5.8.014 (2010-08-23)
10413 protected function _getxobjectdict() {
10415 foreach ($this->xobjects
as $id => $objid) {
10416 $out .= ' /'.$id.' '.$objid['n'].' 0 R';
10422 * Output Resources Dictionary.
10425 protected function _putresourcedict() {
10426 $out = $this->_getobj(2)."\n";
10427 $out .= '<< /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]';
10428 $out .= ' /Font <<';
10429 foreach ($this->fontkeys
as $fontkey) {
10430 $font = $this->getFontBuffer($fontkey);
10431 $out .= ' /F'.$font['i'].' '.$font['n'].' 0 R';
10434 $out .= ' /XObject <<';
10435 $out .= $this->_getxobjectdict();
10438 $out .= ' /Properties <</OC1 '.$this->n_ocg_print
.' 0 R /OC2 '.$this->n_ocg_view
.' 0 R>>';
10440 $out .= ' /ExtGState <<';
10441 foreach ($this->extgstates
as $k => $extgstate) {
10442 if (isset($extgstate['name'])) {
10443 $out .= ' /'.$extgstate['name'];
10447 $out .= ' '.$extgstate['n'].' 0 R';
10450 // gradient patterns
10451 if (isset($this->gradients
) AND (count($this->gradients
) > 0)) {
10452 $out .= ' /Pattern <<';
10453 foreach ($this->gradients
as $id => $grad) {
10454 $out .= ' /p'.$id.' '.$grad['pattern'].' 0 R';
10458 // gradient shadings
10459 if (isset($this->gradients
) AND (count($this->gradients
) > 0)) {
10460 $out .= ' /Shading <<';
10461 foreach ($this->gradients
as $id => $grad) {
10462 $out .= ' /Sh'.$id.' '.$grad['id'].' 0 R';
10467 if (isset($this->spot_colors
) AND (count($this->spot_colors
) > 0)) {
10468 $out .= ' /ColorSpace <<';
10469 foreach ($this->spot_colors
as $color) {
10470 $out .= ' /CS'.$color['i'].' '.$color['n'].' 0 R';
10475 $out .= "\n".'endobj';
10480 * Output Resources.
10483 protected function _putresources() {
10484 $this->_putextgstates();
10486 $this->_putfonts();
10487 $this->_putimages();
10488 $this->_putxobjects();
10489 $this->_putspotcolors();
10490 $this->_putshaders();
10491 $this->_putresourcedict();
10492 $this->_putbookmarks();
10493 $this->_putEmbeddedFiles();
10494 $this->_putannotsobjs();
10495 $this->_putjavascript();
10496 $this->_putencryption();
10500 * Adds some Metadata information (Document Information Dictionary)
10501 * (see Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf Reference)
10502 * @return int object id
10505 protected function _putinfo() {
10506 $oid = $this->_newobj();
10508 // store current isunicode value
10509 $prev_isunicode = $this->isunicode
;
10510 if ($this->docinfounicode
) {
10511 $this->isunicode
= true;
10513 if (!$this->empty_string($this->title
)) {
10514 // The document's title.
10515 $out .= ' /Title '.$this->_textstring($this->title
, $oid);
10517 if (!$this->empty_string($this->author
)) {
10518 // The name of the person who created the document.
10519 $out .= ' /Author '.$this->_textstring($this->author
, $oid);
10521 if (!$this->empty_string($this->subject
)) {
10522 // The subject of the document.
10523 $out .= ' /Subject '.$this->_textstring($this->subject
, $oid);
10525 if (!$this->empty_string($this->keywords
)) {
10526 // Keywords associated with the document.
10527 $out .= ' /Keywords '.$this->_textstring($this->keywords
.' TCPDF', $oid);
10529 if (!$this->empty_string($this->creator
)) {
10530 // 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.
10531 $out .= ' /Creator '.$this->_textstring($this->creator
, $oid);
10533 // restore previous isunicode value
10534 $this->isunicode
= $prev_isunicode;
10535 // default producer
10536 $out .= ' /Producer '.$this->_textstring("\x54\x43\x50\x44\x46\x20".$this->tcpdf_version
."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29", $oid);
10537 // The date and time the document was created, in human-readable form
10538 $out .= ' /CreationDate '.$this->_datestring();
10539 // The date and time the document was most recently modified, in human-readable form
10540 $out .= ' /ModDate '.$this->_datestring();
10541 // A name object indicating whether the document has been modified to include trapping information
10542 $out .= ' /Trapped /False';
10544 $out .= "\n".'endobj';
10551 * @return int object id
10554 protected function _putcatalog() {
10555 $oid = $this->_newobj();
10556 $out = '<< /Type /Catalog';
10557 $out .= ' /Pages 1 0 R';
10558 if ($this->ZoomMode
== 'fullpage') {
10559 $out .= ' /OpenAction ['.$this->page_obj_id
[1].' 0 R /Fit]';
10560 } elseif ($this->ZoomMode
== 'fullwidth') {
10561 $out .= ' /OpenAction ['.$this->page_obj_id
[1].' 0 R /FitH null]';
10562 } elseif ($this->ZoomMode
== 'real') {
10563 $out .= ' /OpenAction ['.$this->page_obj_id
[1].' 0 R /XYZ null null 1]';
10564 } elseif (!is_string($this->ZoomMode
)) {
10565 $out .= sprintf(' /OpenAction ['.$this->page_obj_id
[1].' 0 R /XYZ null null %.2F]',($this->ZoomMode
/ 100));
10567 if (isset($this->LayoutMode
) AND (!$this->empty_string($this->LayoutMode
))) {
10568 $out .= ' /PageLayout /'.$this->LayoutMode
;
10570 if (isset($this->PageMode
) AND (!$this->empty_string($this->PageMode
))) {
10571 $out .= ' /PageMode /'.$this->PageMode
;
10573 if (isset($this->l
['a_meta_language'])) {
10574 $out .= ' /Lang '.$this->_textstring($this->l
['a_meta_language'], $oid);
10576 $out .= ' /Names <<';
10577 if ((!empty($this->javascript
)) OR (!empty($this->js_objects
))) {
10578 $out .= ' /JavaScript '.($this->n_js
).' 0 R';
10581 if (count($this->outlines
) > 0) {
10582 $out .= ' /Outlines '.$this->OutlineRoot
.' 0 R';
10583 $out .= ' /PageMode /UseOutlines';
10585 $out .= ' '.$this->_putviewerpreferences();
10586 $p = $this->n_ocg_print
.' 0 R';
10587 $v = $this->n_ocg_view
.' 0 R';
10588 $as = '<< /Event /Print /OCGs ['.$p.' '.$v.'] /Category [/Print] >> << /Event /View /OCGs ['.$p.' '.$v.'] /Category [/View] >>';
10589 $out .= ' /OCProperties << /OCGs ['.$p.' '.$v.'] /D << /ON ['.$p.'] /OFF ['.$v.'] /AS ['.$as.'] >> >>';
10591 if (!empty($this->form_obj_id
) OR ($this->sign
AND isset($this->signature_data
['cert_type']))) {
10592 $out .= ' /AcroForm <<';
10594 if ($this->sign
AND isset($this->signature_data
['cert_type'])) {
10595 $objrefs .= $this->sig_obj_id
.' 0 R';
10597 if (!empty($this->form_obj_id
)) {
10598 foreach($this->form_obj_id
as $objid) {
10599 $objrefs .= ' '.$objid.' 0 R';
10602 $out .= ' /Fields ['.$objrefs.']';
10603 if (!empty($this->form_obj_id
) AND !$this->sign
) {
10604 // It's better to turn off this value and set the appearance stream for each annotation (/AP) to avoid conflicts with signature fields.
10605 $out .= ' /NeedAppearances true';
10607 if ($this->sign
AND isset($this->signature_data
['cert_type'])) {
10608 if ($this->signature_data
['cert_type'] > 0) {
10609 $out .= ' /SigFlags 3';
10611 $out .= ' /SigFlags 1';
10615 if (isset($this->annotation_fonts
) AND !empty($this->annotation_fonts
)) {
10617 $out .= ' /Font <<';
10618 foreach ($this->annotation_fonts
as $fontkey => $fontid) {
10619 $out .= ' /F'.$fontid.' '.$this->font_obj_ids
[$fontkey].' 0 R';
10623 $font = $this->getFontBuffer('helvetica');
10624 $out .= ' /DA (/F'.$font['i'].' 0 Tf 0 g)';
10625 $out .= ' /Q '.(($this->rtl
)?
'2':'0');
10626 //$out .= ' /XFA ';
10629 if ($this->sign
AND isset($this->signature_data
['cert_type'])) {
10630 if ($this->signature_data
['cert_type'] > 0) {
10631 $out .= ' /Perms << /DocMDP '.($this->sig_obj_id +
1).' 0 R >>';
10633 $out .= ' /Perms << /UR3 '.($this->sig_obj_id +
1).' 0 R >>';
10638 $out .= "\n".'endobj';
10644 * Output viewer preferences.
10645 * @return string for viewer preferences
10646 * @author Nicola asuni
10647 * @since 3.1.000 (2008-06-09)
10650 protected function _putviewerpreferences() {
10651 $out = '/ViewerPreferences <<';
10653 $out .= ' /Direction /R2L';
10655 $out .= ' /Direction /L2R';
10657 if (isset($this->viewer_preferences
['HideToolbar']) AND ($this->viewer_preferences
['HideToolbar'])) {
10658 $out .= ' /HideToolbar true';
10660 if (isset($this->viewer_preferences
['HideMenubar']) AND ($this->viewer_preferences
['HideMenubar'])) {
10661 $out .= ' /HideMenubar true';
10663 if (isset($this->viewer_preferences
['HideWindowUI']) AND ($this->viewer_preferences
['HideWindowUI'])) {
10664 $out .= ' /HideWindowUI true';
10666 if (isset($this->viewer_preferences
['FitWindow']) AND ($this->viewer_preferences
['FitWindow'])) {
10667 $out .= ' /FitWindow true';
10669 if (isset($this->viewer_preferences
['CenterWindow']) AND ($this->viewer_preferences
['CenterWindow'])) {
10670 $out .= ' /CenterWindow true';
10672 if (isset($this->viewer_preferences
['DisplayDocTitle']) AND ($this->viewer_preferences
['DisplayDocTitle'])) {
10673 $out .= ' /DisplayDocTitle true';
10675 if (isset($this->viewer_preferences
['NonFullScreenPageMode'])) {
10676 $out .= ' /NonFullScreenPageMode /'.$this->viewer_preferences
['NonFullScreenPageMode'];
10678 if (isset($this->viewer_preferences
['ViewArea'])) {
10679 $out .= ' /ViewArea /'.$this->viewer_preferences
['ViewArea'];
10681 if (isset($this->viewer_preferences
['ViewClip'])) {
10682 $out .= ' /ViewClip /'.$this->viewer_preferences
['ViewClip'];
10684 if (isset($this->viewer_preferences
['PrintArea'])) {
10685 $out .= ' /PrintArea /'.$this->viewer_preferences
['PrintArea'];
10687 if (isset($this->viewer_preferences
['PrintClip'])) {
10688 $out .= ' /PrintClip /'.$this->viewer_preferences
['PrintClip'];
10690 if (isset($this->viewer_preferences
['PrintScaling'])) {
10691 $out .= ' /PrintScaling /'.$this->viewer_preferences
['PrintScaling'];
10693 if (isset($this->viewer_preferences
['Duplex']) AND (!$this->empty_string($this->viewer_preferences
['Duplex']))) {
10694 $out .= ' /Duplex /'.$this->viewer_preferences
['Duplex'];
10696 if (isset($this->viewer_preferences
['PickTrayByPDFSize'])) {
10697 if ($this->viewer_preferences
['PickTrayByPDFSize']) {
10698 $out .= ' /PickTrayByPDFSize true';
10700 $out .= ' /PickTrayByPDFSize false';
10703 if (isset($this->viewer_preferences
['PrintPageRange'])) {
10704 $PrintPageRangeNum = '';
10705 foreach ($this->viewer_preferences
['PrintPageRange'] as $k => $v) {
10706 $PrintPageRangeNum .= ' '.($v - 1).'';
10708 $out .= ' /PrintPageRange ['.substr($PrintPageRangeNum,1).']';
10710 if (isset($this->viewer_preferences
['NumCopies'])) {
10711 $out .= ' /NumCopies '.intval($this->viewer_preferences
['NumCopies']);
10718 * Output PDF header.
10721 protected function _putheader() {
10722 $this->_out('%PDF-'.$this->PDFVersion
);
10726 * Output end of document (EOF).
10729 protected function _enddoc() {
10731 $this->_putheader();
10732 $this->_putpages();
10733 $this->_putresources();
10735 if ($this->sign
AND isset($this->signature_data
['cert_type'])) {
10736 // widget annotation for signature
10737 $out = $this->_getobj($this->sig_obj_id
)."\n";
10738 $out .= '<< /Type /Annot';
10739 $out .= ' /Subtype /Widget';
10740 $out .= ' /Rect ['.$this->signature_appearance
['rect'].']';
10741 $out .= ' /P '.$this->page_obj_id
[($this->signature_appearance
['page'])].' 0 R'; // link to signature appearance page
10743 $out .= ' /FT /Sig';
10744 $out .= ' /T '.$this->_textstring('Signature', $this->sig_obj_id
);
10746 $out .= ' /V '.($this->sig_obj_id +
1).' 0 R';
10748 $out .= "\n".'endobj';
10751 $this->_putsignature();
10754 $objid_info = $this->_putinfo();
10756 $objid_catalog = $this->_putcatalog();
10758 $o = $this->bufferlen
;
10760 $this->_out('xref');
10761 $this->_out('0 '.($this->n +
1));
10762 $this->_out('0000000000 65535 f ');
10763 for ($i=1; $i <= $this->n
; ++
$i) {
10764 $this->_out(sprintf('%010d 00000 n ', $this->offsets
[$i]));
10767 $out = 'trailer <<';
10768 $out .= ' /Size '.($this->n +
1);
10769 $out .= ' /Root '.$objid_catalog.' 0 R';
10770 $out .= ' /Info '.$objid_info.' 0 R';
10771 if ($this->encrypted
) {
10772 $out .= ' /Encrypt '.$this->encryptdata
['objid'].' 0 R';
10774 $out .= ' /ID [ <'.$this->file_id
.'> <'.$this->file_id
.'> ]';
10777 $this->_out('startxref');
10779 $this->_out('%%EOF');
10780 $this->state
= 3; // end-of-doc
10781 if ($this->diskcache
) {
10782 // remove temporary files used for images
10783 foreach ($this->imagekeys
as $key) {
10784 // remove temporary files
10785 unlink($this->images
[$key]);
10787 foreach ($this->fontkeys
as $key) {
10788 // remove temporary files
10789 unlink($this->fonts
[$key]);
10795 * Initialize a new page.
10796 * @param $orientation (string) page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
10797 * @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().
10799 * @see getPageSizeFromFormat(), setPageFormat()
10801 protected function _beginpage($orientation='', $format='') {
10803 $this->setPageBuffer($this->page
, '');
10804 // initialize array for graphics tranformation positions inside a page buffer
10805 $this->transfmrk
[$this->page
] = array();
10807 if ($this->empty_string($orientation)) {
10808 if (isset($this->CurOrientation
)) {
10809 $orientation = $this->CurOrientation
;
10810 } elseif ($this->fwPt
> $this->fhPt
) {
10812 $orientation = 'L';
10815 $orientation = 'P';
10818 if ($this->empty_string($format)) {
10819 $this->pagedim
[$this->page
] = $this->pagedim
[($this->page
- 1)];
10820 $this->setPageOrientation($orientation);
10822 $this->setPageFormat($format, $orientation);
10825 $this->x
= $this->w
- $this->rMargin
;
10827 $this->x
= $this->lMargin
;
10829 $this->y
= $this->tMargin
;
10830 if (isset($this->newpagegroup
[$this->page
])) {
10831 // start a new group
10832 $n = sizeof($this->pagegroups
) +
1;
10833 $alias = '{nb'.$n.'}';
10834 $this->pagegroups
[$alias] = 1;
10835 $this->currpagegroup
= $alias;
10836 } elseif ($this->currpagegroup
) {
10837 ++
$this->pagegroups
[$this->currpagegroup
];
10842 * Mark end of page.
10845 protected function _endpage() {
10846 $this->setVisibility('all');
10851 * Begin a new object and return the object number.
10852 * @return int object number
10855 protected function _newobj() {
10856 $this->_out($this->_getobj());
10861 * Return the starting object string for the selected object ID.
10862 * @param $objid (int) Object ID (leave empty to get a new ID).
10863 * @return string the starting object string
10865 * @since 5.8.009 (2010-08-20)
10867 protected function _getobj($objid='') {
10868 if ($objid === '') {
10872 $this->offsets
[$objid] = $this->bufferlen
;
10873 return $objid.' 0 obj';
10878 * @param $x (int) X coordinate
10879 * @param $y (int) Y coordinate
10880 * @param $txt (string) text to underline
10883 protected function _dounderline($x, $y, $txt) {
10884 $w = $this->GetStringWidth($txt);
10885 return $this->_dounderlinew($x, $y, $w);
10889 * Underline for rectangular text area.
10890 * @param $x (int) X coordinate
10891 * @param $y (int) Y coordinate
10892 * @param $w (int) width to underline
10894 * @since 4.8.008 (2009-09-29)
10896 protected function _dounderlinew($x, $y, $w) {
10897 $linew = - $this->CurrentFont
['ut'] / 1000 * $this->FontSizePt
;
10898 return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k
, ((($this->h
- $y) * $this->k
) +
$linew), $w * $this->k
, $linew);
10902 * Line through text.
10903 * @param $x (int) X coordinate
10904 * @param $y (int) Y coordinate
10905 * @param $txt (string) text to linethrough
10908 protected function _dolinethrough($x, $y, $txt) {
10909 $w = $this->GetStringWidth($txt);
10910 return $this->_dolinethroughw($x, $y, $w);
10914 * Line through for rectangular text area.
10915 * @param $x (int) X coordinate
10916 * @param $y (int) Y coordinate
10917 * @param $w (int) line lenght (width)
10919 * @since 4.9.008 (2009-09-29)
10921 protected function _dolinethroughw($x, $y, $w) {
10922 $linew = - $this->CurrentFont
['ut'] / 1000 * $this->FontSizePt
;
10923 return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k
, ((($this->h
- $y) * $this->k
) +
$linew +
($this->FontSizePt
/ 3)), $w * $this->k
, $linew);
10928 * @param $x (int) X coordinate
10929 * @param $y (int) Y coordinate
10930 * @param $txt (string) text to overline
10932 * @since 4.9.015 (2010-04-19)
10934 protected function _dooverline($x, $y, $txt) {
10935 $w = $this->GetStringWidth($txt);
10936 return $this->_dooverlinew($x, $y, $w);
10940 * Overline for rectangular text area.
10941 * @param $x (int) X coordinate
10942 * @param $y (int) Y coordinate
10943 * @param $w (int) width to overline
10945 * @since 4.9.015 (2010-04-19)
10947 protected function _dooverlinew($x, $y, $w) {
10948 $linew = - $this->CurrentFont
['ut'] / 1000 * $this->FontSizePt
;
10949 return sprintf('%.2F %.2F %.2F %.2F re f', $x * $this->k
, (($this->h
- $y +
$this->FontAscent
) * $this->k
) - $linew, $w * $this->k
, $linew);
10954 * Read a 4-byte (32 bit) integer from file.
10955 * @param $f (string) file name.
10956 * @return 4-byte integer
10959 protected function _freadint($f) {
10960 $a = unpack('Ni', fread($f, 4));
10965 * Add "\" before "\", "(" and ")"
10966 * @param $s (string) string to escape.
10967 * @return string escaped string.
10970 protected function _escape($s) {
10971 // the chr(13) substitution fixes the Bugs item #1421290.
10972 return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
10976 * Format a data string for meta information
10977 * @param $s (string) data string to escape.
10978 * @param $n (int) object ID
10979 * @return string escaped string.
10982 protected function _datastring($s, $n=0) {
10986 $s = $this->_encrypt_data($n, $s);
10987 return '('. $this->_escape($s).')';
10991 * Returns a formatted date for meta information
10992 * @param $n (int) object ID
10993 * @return string escaped date string.
10995 * @since 4.6.028 (2009-08-25)
10997 protected function _datestring($n=0) {
10998 $current_time = substr_replace(date('YmdHisO'), '\'', (0 - 2), 0).'\'';
10999 return $this->_datastring('D:'.$current_time, $n);
11003 * Format a text string for meta information
11004 * @param $s (string) string to escape.
11005 * @param $n (int) object ID
11006 * @return string escaped string.
11009 protected function _textstring($s, $n=0) {
11010 if ($this->isunicode
) {
11011 //Convert string to UTF-16BE
11012 $s = $this->UTF8ToUTF16BE($s, true);
11014 return $this->_datastring($s, $n);
11018 * THIS METHOD IS DEPRECATED
11019 * Format a text string
11020 * @param $s (string) string to escape.
11021 * @return string escaped string.
11025 protected function _escapetext($s) {
11026 if ($this->isunicode
) {
11027 if (($this->CurrentFont
['type'] == 'core') OR ($this->CurrentFont
['type'] == 'TrueType') OR ($this->CurrentFont
['type'] == 'Type1')) {
11028 $s = $this->UTF8ToLatin1($s);
11030 //Convert string to UTF-16BE and reverse RTL language
11031 $s = $this->utf8StrRev($s, false, $this->tmprtl
);
11034 return $this->_escape($s);
11038 * get raw output stream.
11039 * @param $s (string) string to output.
11040 * @param $n (int) object reference for encryption mode
11042 * @author Nicola Asuni
11043 * @since 5.5.000 (2010-06-22)
11045 protected function _getrawstream($s, $n=0) {
11047 // default to current object
11050 return $this->_encrypt_data($n, $s);
11054 * Format output stream (DEPRECATED).
11055 * @param $s (string) string to output.
11056 * @param $n (int) object reference for encryption mode
11060 protected function _getstream($s, $n=0) {
11061 return 'stream'."\n".$this->_getrawstream($s, $n)."\n".'endstream';
11065 * Output a stream (DEPRECATED).
11066 * @param $s (string) string to output.
11067 * @param $n (int) object reference for encryption mode
11071 protected function _putstream($s, $n=0) {
11072 $this->_out($this->_getstream($s, $n));
11076 * Output a string to the document.
11077 * @param $s (string) string to output.
11080 protected function _out($s) {
11081 if ($this->state
== 2) {
11082 if ($this->inxobj
) {
11083 // we are inside an XObject template
11084 $this->xobjects
[$this->xobjid
]['outdata'] .= $s."\n";
11085 } elseif ((!$this->InFooter
) AND isset($this->footerlen
[$this->page
]) AND ($this->footerlen
[$this->page
] > 0)) {
11086 // puts data before page footer
11087 $pagebuff = $this->getPageBuffer($this->page
);
11088 $page = substr($pagebuff, 0, -$this->footerlen
[$this->page
]);
11089 $footer = substr($pagebuff, -$this->footerlen
[$this->page
]);
11090 $this->setPageBuffer($this->page
, $page.$s."\n".$footer);
11091 // update footer position
11092 $this->footerpos
[$this->page
] +
= strlen($s."\n");
11094 $this->setPageBuffer($this->page
, $s."\n", true);
11097 $this->setBuffer($s."\n");
11102 * Converts UTF-8 strings to codepoints array.<br>
11103 * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
11104 * Based on: http://www.faqs.org/rfcs/rfc3629.html
11106 * Char. number range | UTF-8 octet sequence
11107 * (hexadecimal) | (binary)
11108 * --------------------+-----------------------------------------------
11109 * 0000 0000-0000 007F | 0xxxxxxx
11110 * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
11111 * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
11112 * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
11113 * ---------------------------------------------------------------------
11116 * ---------------------------------------------------------------------
11117 * UTF8-octets = *( UTF8-char )
11118 * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
11120 * UTF8-2 = %xC2-DF UTF8-tail
11122 * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
11123 * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
11124 * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
11125 * %xF4 %x80-8F 2( UTF8-tail )
11126 * UTF8-tail = %x80-BF
11127 * ---------------------------------------------------------------------
11129 * @param $str (string) string to process.
11130 * @return array containing codepoints (UTF-8 characters values)
11132 * @author Nicola Asuni
11133 * @since 1.53.0.TC005 (2005-01-05)
11135 protected function UTF8StringToArray($str) {
11136 // build a unique string key
11137 $strkey = md5($str);
11138 if (isset($this->cache_UTF8StringToArray
[$strkey])) {
11139 // return cached value
11140 $chrarray = $this->cache_UTF8StringToArray
[$strkey]['s'];
11141 if (!isset($this->cache_UTF8StringToArray
[$strkey]['f'][$this->CurrentFont
['fontkey']])) {
11142 if ($this->isunicode
) {
11143 foreach ($chrarray as $chr) {
11144 // store this char for font subsetting
11145 $this->CurrentFont
['subsetchars'][$chr] = true;
11147 // update font subsetchars
11148 $this->setFontSubBuffer($this->CurrentFont
['fontkey'], 'subsetchars', $this->CurrentFont
['subsetchars']);
11150 $this->cache_UTF8StringToArray
[$strkey]['f'][$this->CurrentFont
['fontkey']] = true;
11154 // check cache size
11155 if ($this->cache_size_UTF8StringToArray
>= $this->cache_maxsize_UTF8StringToArray
) {
11156 // remove first element
11157 array_shift($this->cache_UTF8StringToArray
);
11159 // new cache array for selected string
11160 $this->cache_UTF8StringToArray
[$strkey] = array('s' => array(), 'f' => array());
11161 ++
$this->cache_size_UTF8StringToArray
;
11162 if (!$this->isunicode
) {
11163 // split string into array of equivalent codes
11165 $strlen = strlen($str);
11166 for ($i=0; $i < $strlen; ++
$i) {
11167 $strarr[] = ord($str{$i});
11169 // insert new value on cache
11170 $this->cache_UTF8StringToArray
[$strkey]['s'] = $strarr;
11171 $this->cache_UTF8StringToArray
[$strkey]['f'][$this->CurrentFont
['fontkey']] = true;
11174 $unichar = -1; // last unicode char
11175 $unicode = array(); // array containing unicode values
11176 $bytes = array(); // array containing single character byte sequences
11177 $numbytes = 1; // number of octetc needed to represent the UTF-8 character
11178 $str .= ''; // force $str to be a string
11179 $length = strlen($str);
11180 for ($i = 0; $i < $length; ++
$i) {
11181 $char = ord($str{$i}); // get one string character at time
11182 if (count($bytes) == 0) { // get starting octect
11183 if ($char <= 0x7F) {
11184 $unichar = $char; // use the character "as is" because is ASCII
11186 } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
11187 $bytes[] = ($char - 0xC0) << 0x06;
11189 } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
11190 $bytes[] = ($char - 0xE0) << 0x0C;
11192 } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
11193 $bytes[] = ($char - 0xF0) << 0x12;
11196 // use replacement character for other invalid sequences
11201 } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
11202 $bytes[] = $char - 0x80;
11203 if (count($bytes) == $numbytes) {
11204 // compose UTF-8 bytes to a single unicode value
11206 for ($j = 1; $j < $numbytes; ++
$j) {
11207 $char +
= ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
11209 if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
11210 /* The definition of UTF-8 prohibits encoding character numbers between
11211 U+D800 and U+DFFF, which are reserved for use with the UTF-16
11212 encoding form (as surrogate pairs) and do not directly represent
11214 $unichar = 0xFFFD; // use replacement character
11216 $unichar = $char; // add char to array
11218 // reset data for next char
11223 // use replacement character for other invalid sequences
11228 if ($unichar >= 0) {
11229 // insert unicode value into array
11230 $unicode[] = $unichar;
11231 // store this char for font subsetting
11232 $this->CurrentFont
['subsetchars'][$unichar] = true;
11236 // update font subsetchars
11237 $this->setFontSubBuffer($this->CurrentFont
['fontkey'], 'subsetchars', $this->CurrentFont
['subsetchars']);
11238 // insert new value on cache
11239 $this->cache_UTF8StringToArray
[$strkey]['s'] = $unicode;
11240 $this->cache_UTF8StringToArray
[$strkey]['f'][$this->CurrentFont
['fontkey']] = true;
11245 * Converts UTF-8 strings to UTF16-BE.<br>
11246 * @param $str (string) string to process.
11247 * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
11249 * @author Nicola Asuni
11250 * @since 1.53.0.TC005 (2005-01-05)
11251 * @see UTF8StringToArray(), arrUTF8ToUTF16BE()
11254 protected function UTF8ToUTF16BE($str, $setbom=true) {
11255 if (!$this->isunicode
) {
11256 return $str; // string is not in unicode
11258 $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
11259 return $this->arrUTF8ToUTF16BE($unicode, $setbom);
11263 * Converts UTF-8 strings to Latin1 when using the standard 14 core fonts.<br>
11264 * @param $str (string) string to process.
11266 * @author Andrew Whitehead, Nicola Asuni
11268 * @since 3.2.000 (2008-06-23)
11270 protected function UTF8ToLatin1($str) {
11271 if (!$this->isunicode
) {
11272 return $str; // string is not in unicode
11274 $outstr = ''; // string to be returned
11275 $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
11276 foreach ($unicode as $char) {
11278 $outstr .= chr($char);
11279 } elseif (array_key_exists($char, $this->unicode
->uni_utf8tolatin
)) {
11281 $outstr .= chr($this->unicode
->uni_utf8tolatin
[$char]);
11282 } elseif ($char == 0xFFFD) {
11292 * Converts UTF-8 characters array to array of Latin1 characters<br>
11293 * @param $unicode (array) array containing UTF-8 unicode values
11295 * @author Nicola Asuni
11297 * @since 4.8.023 (2010-01-15)
11299 protected function UTF8ArrToLatin1($unicode) {
11300 if ((!$this->isunicode
) OR $this->isUnicodeFont()) {
11303 $outarr = array(); // array to be returned
11304 foreach ($unicode as $char) {
11307 } elseif (array_key_exists($char, $this->unicode
->uni_utf8tolatin
)) {
11309 $outarr[] = $this->unicode
->uni_utf8tolatin
[$char];
11310 } elseif ($char == 0xFFFD) {
11313 $outarr[] = 63; // '?' character
11320 * Converts array of UTF-8 characters to UTF16-BE string.<br>
11321 * Based on: http://www.faqs.org/rfcs/rfc2781.html
11325 * Encoding of a single character from an ISO 10646 character value to
11326 * UTF-16 proceeds as follows. Let U be the character number, no greater
11329 * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
11332 * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
11333 * U' must be less than or equal to 0xFFFFF. That is, U' can be
11334 * represented in 20 bits.
11336 * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
11337 * 0xDC00, respectively. These integers each have 10 bits free to
11338 * encode the character value, for a total of 20 bits.
11340 * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
11341 * bits of W1 and the 10 low-order bits of U' to the 10 low-order
11342 * bits of W2. Terminate.
11344 * Graphically, steps 2 through 4 look like:
11345 * U' = yyyyyyyyyyxxxxxxxxxx
11346 * W1 = 110110yyyyyyyyyy
11347 * W2 = 110111xxxxxxxxxx
11349 * @param $unicode (array) array containing UTF-8 unicode values
11350 * @param $setbom (boolean) if true set the Byte Order Mark (BOM = 0xFEFF)
11353 * @author Nicola Asuni
11354 * @since 2.1.000 (2008-01-08)
11355 * @see UTF8ToUTF16BE()
11357 protected function arrUTF8ToUTF16BE($unicode, $setbom=true) {
11358 $outstr = ''; // string to be returned
11360 $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
11362 foreach ($unicode as $char) {
11363 if ($char == 0x200b) {
11364 // skip Unicode Character 'ZERO WIDTH SPACE' (DEC:8203, U+200B)
11365 } elseif ($char == 0xFFFD) {
11366 $outstr .= "\xFF\xFD"; // replacement character
11367 } elseif ($char < 0x10000) {
11368 $outstr .= chr($char >> 0x08);
11369 $outstr .= chr($char & 0xFF);
11372 $w1 = 0xD800 |
($char >> 0x10);
11373 $w2 = 0xDC00 |
($char & 0x3FF);
11374 $outstr .= chr($w1 >> 0x08);
11375 $outstr .= chr($w1 & 0xFF);
11376 $outstr .= chr($w2 >> 0x08);
11377 $outstr .= chr($w2 & 0xFF);
11382 // ====================================================
11386 * @param $font (array) font
11390 public function setHeaderFont($font) {
11391 $this->header_font
= $font;
11398 * @since 4.0.012 (2008-07-24)
11400 public function getHeaderFont() {
11401 return $this->header_font
;
11406 * @param $font (array) font
11410 public function setFooterFont($font) {
11411 $this->footer_font
= $font;
11418 * @since 4.0.012 (2008-07-24)
11420 public function getFooterFont() {
11421 return $this->footer_font
;
11425 * Set language array.
11426 * @param $language (array)
11430 public function setLanguageArray($language) {
11431 $this->l
= $language;
11432 if (isset($this->l
['a_meta_dir'])) {
11433 $this->rtl
= $this->l
['a_meta_dir']=='rtl' ?
true : false;
11435 $this->rtl
= false;
11440 * Returns the PDF data.
11443 public function getPDFData() {
11444 if ($this->state
< 3) {
11447 return $this->buffer
;
11451 * Output anchor link.
11452 * @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>)
11453 * @param $name (string) link name
11454 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
11455 * @param $firstline (boolean) if true prints only the first line and return the remaining string.
11456 * @param $color (array) array of RGB text color
11457 * @param $style (string) font style (U, D, B, I)
11458 * @param $firstblock (boolean) if true the string is the starting of a line.
11459 * @return the number of cells used or the remaining text if $firstline = true;
11462 public function addHtmlLink($url, $name, $fill=false, $firstline=false, $color='', $style=-1, $firstblock=false) {
11463 if (!$this->empty_string($url) AND ($url{0} == '#')) {
11464 // convert url to internal link
11465 $lnkdata = explode(',', $url);
11466 if (isset($lnkdata[0])) {
11467 $page = intval(substr($lnkdata[0], 1));
11468 if (empty($page) OR ($page <= 0)) {
11469 $page = $this->page
;
11471 if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
11472 $lnky = floatval($lnkdata[1]);
11476 $url = $this->AddLink();
11477 $this->SetLink($url, $lnky, $page);
11480 // store current settings
11481 $prevcolor = $this->fgcolor
;
11482 $prevstyle = $this->FontStyle
;
11483 if (empty($color)) {
11484 $this->SetTextColorArray($this->htmlLinkColorArray
);
11486 $this->SetTextColorArray($color);
11488 if ($style == -1) {
11489 $this->SetFont('', $this->FontStyle
.$this->htmlLinkFontStyle
);
11491 $this->SetFont('', $this->FontStyle
.$style);
11493 $ret = $this->Write($this->lasth
, $name, $url, $fill, '', false, 0, $firstline, $firstblock, 0);
11494 // restore settings
11495 $this->SetFont('', $prevstyle);
11496 $this->SetTextColorArray($prevcolor);
11501 * Returns an array (RGB or CMYK) from an html color name or a six-digit (i.e. #3FE5AA) or three-digit (i.e. #7FF) hexadecimal color representation.
11502 * @param $hcolor (string) html color
11503 * @return array RGB or CMYK color, or false in case of error.
11506 public function convertHTMLColorToDec($hcolor='#FFFFFF') {
11507 $returncolor = false;
11508 $color = preg_replace('/[\s]*/', '', $hcolor); // remove extra spaces
11509 $color = strtolower($color);
11510 if (($dotpos = strpos($color, '.')) !== false) {
11511 // remove class parent (i.e.: color.red)
11512 $color = substr($color, ($dotpos +
1));
11514 if (strlen($color) == 0) {
11518 if (substr($color, 0, 3) == 'rgb') {
11519 $codes = substr($color, 4);
11520 $codes = str_replace(')', '', $codes);
11521 $returncolor = explode(',', $codes);
11522 foreach ($returncolor as $key => $val) {
11523 if (strpos($val, '%') > 0) {
11525 $returncolor[$key] = (255 * intval($val) / 100);
11527 $returncolor[$key] = intval($val);
11530 $returncolor[$key] = max(0, min(255, $returncolor[$key]));
11532 return $returncolor;
11535 if (substr($color, 0, 4) == 'cmyk') {
11536 $codes = substr($color, 5);
11537 $codes = str_replace(')', '', $codes);
11538 $returncolor = explode(',', $codes);
11539 foreach ($returncolor as $key => $val) {
11540 if (strpos($val, '%') !== false) {
11542 $returncolor[$key] = (100 * intval($val) / 100);
11544 $returncolor[$key] = intval($val);
11547 $returncolor[$key] = max(0, min(100, $returncolor[$key]));
11549 return $returncolor;
11552 if (substr($color, 0, 1) != '#') {
11553 // decode color name
11554 if (isset($this->webcolor
[$color])) {
11556 $color_code = $this->webcolor
[$color];
11557 } elseif (isset($this->spot_colors
[$hcolor])) {
11558 // custom defined spot color
11559 return array($this->spot_colors
[$hcolor]['c'], $this->spot_colors
[$hcolor]['m'], $this->spot_colors
[$hcolor]['y'], $this->spot_colors
[$hcolor]['k'], $hcolor);
11560 } elseif (isset($this->spotcolor
[$color])) {
11561 // spot color from configuration file
11562 return $this->spotcolor
[$color];
11567 $color_code = substr($color, 1);
11570 switch (strlen($color_code)) {
11572 // three-digit hexadecimal representation
11573 $r = substr($color_code, 0, 1);
11574 $g = substr($color_code, 1, 1);
11575 $b = substr($color_code, 2, 1);
11576 $returncolor = array();
11577 $returncolor['R'] = max(0, min(255, hexdec($r.$r)));
11578 $returncolor['G'] = max(0, min(255, hexdec($g.$g)));
11579 $returncolor['B'] = max(0, min(255, hexdec($b.$b)));
11583 // six-digit hexadecimal representation
11584 $returncolor = array();
11585 $returncolor['R'] = max(0, min(255, hexdec(substr($color_code, 0, 2))));
11586 $returncolor['G'] = max(0, min(255, hexdec(substr($color_code, 2, 2))));
11587 $returncolor['B'] = max(0, min(255, hexdec(substr($color_code, 4, 2))));
11591 return $returncolor;
11595 * Converts pixels to User's Units.
11596 * @param $px (int) pixels
11597 * @return float value in user's unit
11599 * @see setImageScale(), getImageScale()
11601 public function pixelsToUnits($px) {
11602 return ($px / ($this->imgscale
* $this->k
));
11606 * Reverse function for htmlentities.
11607 * Convert entities in UTF-8.
11608 * @param $text_to_convert (string) Text to convert.
11609 * @return string converted text string
11612 public function unhtmlentities($text_to_convert) {
11613 return html_entity_decode($text_to_convert, ENT_QUOTES
, $this->encoding
);
11616 // ENCRYPTION METHODS ----------------------------------
11619 * Returns a string containing random data to be used as a seed for encryption methods.
11620 * @param $seed (string) starting seed value
11621 * @return string containing random data
11622 * @author Nicola Asuni
11623 * @since 5.9.006 (2010-10-19)
11626 protected function getRandomSeed($seed='') {
11627 $seed .= microtime();
11628 if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS
, 0, 3)) !== 'WIN')) {
11629 // this is not used on windows systems because it is very slow for a know bug
11630 $seed .= openssl_random_pseudo_bytes(512);
11632 for ($i = 0; $i < 23; ++
$i) {
11633 $seed .= uniqid('', true);
11636 $seed .= uniqid('', true);
11638 $seed .= getmypid();
11640 $seed .= $this->bufferlen
;
11641 if (isset($_SERVER['REMOTE_ADDR'])) {
11642 $seed .= $_SERVER['REMOTE_ADDR'];
11644 if (isset($_SERVER['HTTP_USER_AGENT'])) {
11645 $seed .= $_SERVER['HTTP_USER_AGENT'];
11647 if (isset($_SERVER['HTTP_ACCEPT'])) {
11648 $seed .= $_SERVER['HTTP_ACCEPT'];
11650 if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
11651 $seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
11653 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
11654 $seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
11656 if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
11657 $seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
11660 $seed .= uniqid('', true);
11661 $seed .= microtime();
11666 * Compute encryption key depending on object number where the encrypted data is stored.
11667 * This is used for all strings and streams without crypt filter specifier.
11668 * @param $n (int) object number
11669 * @return int object key
11671 * @author Nicola Asuni
11672 * @since 2.0.000 (2008-01-02)
11674 protected function _objectkey($n) {
11675 $objkey = $this->encryptdata
['key'].pack('VXxx', $n);
11676 if ($this->encryptdata
['mode'] == 2) { // AES-128
11678 $objkey .= "\x73\x41\x6C\x54"; // sAlT
11680 $objkey = substr($this->_md5_16($objkey), 0, (($this->encryptdata
['Length'] / 8) +
5));
11681 $objkey = substr($objkey, 0, 16);
11686 * Encrypt the input string.
11687 * @param $n (int) object number
11688 * @param $s (string) data string to encrypt
11689 * @return encrypted string
11691 * @author Nicola Asuni
11692 * @since 5.0.005 (2010-05-11)
11694 protected function _encrypt_data($n, $s) {
11695 if (!$this->encrypted
) {
11698 switch ($this->encryptdata
['mode']) {
11700 case 1: { // RC4-128
11701 $s = $this->_RC4($this->_objectkey($n), $s);
11704 case 2: { // AES-128
11705 $s = $this->_AES($this->_objectkey($n), $s);
11708 case 3: { // AES-256
11709 $s = $this->_AES($this->encryptdata
['key'], $s);
11717 * Put encryption on PDF document.
11719 * @author Nicola Asuni
11720 * @since 2.0.000 (2008-01-02)
11722 protected function _putencryption() {
11723 if (!$this->encrypted
) {
11726 $this->encryptdata
['objid'] = $this->_newobj();
11728 if (!isset($this->encryptdata
['Filter']) OR empty($this->encryptdata
['Filter'])) {
11729 $this->encryptdata
['Filter'] = 'Standard';
11731 $out .= ' /Filter /'.$this->encryptdata
['Filter'];
11732 if (isset($this->encryptdata
['SubFilter']) AND !empty($this->encryptdata
['SubFilter'])) {
11733 $out .= ' /SubFilter /'.$this->encryptdata
['SubFilter'];
11735 if (!isset($this->encryptdata
['V']) OR empty($this->encryptdata
['V'])) {
11736 $this->encryptdata
['V'] = 1;
11738 // V is a code specifying the algorithm to be used in encrypting and decrypting the document
11739 $out .= ' /V '.$this->encryptdata
['V'];
11740 if (isset($this->encryptdata
['Length']) AND !empty($this->encryptdata
['Length'])) {
11741 // The length of the encryption key, in bits. The value shall be a multiple of 8, in the range 40 to 256
11742 $out .= ' /Length '.$this->encryptdata
['Length'];
11744 $out .= ' /Length 40';
11746 if ($this->encryptdata
['V'] >= 4) {
11747 if (!isset($this->encryptdata
['StmF']) OR empty($this->encryptdata
['StmF'])) {
11748 $this->encryptdata
['StmF'] = 'Identity';
11750 if (!isset($this->encryptdata
['StrF']) OR empty($this->encryptdata
['StrF'])) {
11751 // The name of the crypt filter that shall be used when decrypting all strings in the document.
11752 $this->encryptdata
['StrF'] = 'Identity';
11754 // A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.
11755 if (isset($this->encryptdata
['CF']) AND !empty($this->encryptdata
['CF'])) {
11757 $out .= ' /'.$this->encryptdata
['StmF'].' <<';
11758 $out .= ' /Type /CryptFilter';
11759 if (isset($this->encryptdata
['CF']['CFM']) AND !empty($this->encryptdata
['CF']['CFM'])) {
11761 $out .= ' /CFM /'.$this->encryptdata
['CF']['CFM'];
11762 if ($this->encryptdata
['pubkey']) {
11763 $out .= ' /Recipients [';
11764 foreach ($this->encryptdata
['Recipients'] as $rec) {
11765 $out .= ' <'.$rec.'>';
11768 if (isset($this->encryptdata
['CF']['EncryptMetadata']) AND (!$this->encryptdata
['CF']['EncryptMetadata'])) {
11769 $out .= ' /EncryptMetadata false';
11771 $out .= ' /EncryptMetadata true';
11775 $out .= ' /CFM /None';
11777 if (isset($this->encryptdata
['CF']['AuthEvent']) AND !empty($this->encryptdata
['CF']['AuthEvent'])) {
11778 // The event to be used to trigger the authorization that is required to access encryption keys used by this filter.
11779 $out .= ' /AuthEvent /'.$this->encryptdata
['CF']['AuthEvent'];
11781 $out .= ' /AuthEvent /DocOpen';
11783 if (isset($this->encryptdata
['CF']['Length']) AND !empty($this->encryptdata
['CF']['Length'])) {
11784 // The bit length of the encryption key.
11785 $out .= ' /Length '.$this->encryptdata
['CF']['Length'];
11789 // The name of the crypt filter that shall be used by default when decrypting streams.
11790 $out .= ' /StmF /'.$this->encryptdata
['StmF'];
11791 // The name of the crypt filter that shall be used when decrypting all strings in the document.
11792 $out .= ' /StrF /'.$this->encryptdata
['StrF'];
11793 if (isset($this->encryptdata
['EFF']) AND !empty($this->encryptdata
['EFF'])) {
11794 // The name of the crypt filter that shall be used when encrypting embedded file streams that do not have their own crypt filter specifier.
11795 $out .= ' /EFF /'.$this->encryptdata
[''];
11798 // Additional encryption dictionary entries for the standard security handler
11799 if ($this->encryptdata
['pubkey']) {
11800 if (($this->encryptdata
['V'] < 4) AND isset($this->encryptdata
['Recipients']) AND !empty($this->encryptdata
['Recipients'])) {
11801 $out .= ' /Recipients [';
11802 foreach ($this->encryptdata
['Recipients'] as $rec) {
11803 $out .= ' <'.$rec.'>';
11809 if ($this->encryptdata
['V'] == 5) { // AES-256
11811 $out .= ' /OE ('.$this->_escape($this->encryptdata
['OE']).')';
11812 $out .= ' /UE ('.$this->_escape($this->encryptdata
['UE']).')';
11813 $out .= ' /Perms ('.$this->_escape($this->encryptdata
['perms']).')';
11814 } elseif ($this->encryptdata
['V'] == 4) { // AES-128
11816 } elseif ($this->encryptdata
['V'] < 2) { // RC-40
11821 $out .= ' /O ('.$this->_escape($this->encryptdata
['O']).')';
11822 $out .= ' /U ('.$this->_escape($this->encryptdata
['U']).')';
11823 $out .= ' /P '.$this->encryptdata
['P'];
11824 if (isset($this->encryptdata
['EncryptMetadata']) AND (!$this->encryptdata
['EncryptMetadata'])) {
11825 $out .= ' /EncryptMetadata false';
11827 $out .= ' /EncryptMetadata true';
11831 $out .= "\n".'endobj';
11836 * Returns the input text encrypted using RC4 algorithm and the specified key.
11837 * RC4 is the standard encryption algorithm used in PDF format
11838 * @param $key (string) encryption key
11839 * @param $text (String) input text to be encrypted
11840 * @return String encrypted text
11842 * @since 2.0.000 (2008-01-02)
11843 * @author Klemen Vodopivec, Nicola Asuni
11845 protected function _RC4($key, $text) {
11846 if (function_exists('mcrypt_decrypt') AND ($out = @mcrypt_decrypt
(MCRYPT_ARCFOUR
, $key, $text, MCRYPT_MODE_STREAM
, ''))) {
11847 // try to use mcrypt function if exist
11850 if ($this->last_enc_key
!= $key) {
11851 $k = str_repeat($key, ((256 / strlen($key)) +
1));
11852 $rc4 = range(0, 255);
11854 for ($i = 0; $i < 256; ++
$i) {
11856 $j = ($j +
$t +
ord($k{$i})) %
256;
11857 $rc4[$i] = $rc4[$j];
11860 $this->last_enc_key
= $key;
11861 $this->last_enc_key_c
= $rc4;
11863 $rc4 = $this->last_enc_key_c
;
11865 $len = strlen($text);
11869 for ($i = 0; $i < $len; ++
$i) {
11870 $a = ($a +
1) %
256;
11872 $b = ($b +
$t) %
256;
11873 $rc4[$a] = $rc4[$b];
11875 $k = $rc4[($rc4[$a] +
$rc4[$b]) %
256];
11876 $out .= chr(ord($text{$i}) ^
$k);
11882 * Returns the input text exrypted using AES algorithm and the specified key.
11883 * This method requires mcrypt.
11884 * @param $key (string) encryption key
11885 * @param $text (String) input text to be encrypted
11886 * @return String encrypted text
11888 * @author Nicola Asuni
11889 * @since 5.0.005 (2010-05-11)
11891 protected function _AES($key, $text) {
11892 // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
11893 $padding = 16 - (strlen($text) %
16);
11894 $text .= str_repeat(chr($padding), $padding);
11895 $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128
, MCRYPT_MODE_CBC
), MCRYPT_RAND
);
11896 $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128
, $key, $text, MCRYPT_MODE_CBC
, $iv);
11902 * Encrypts a string using MD5 and returns it's value as a binary string.
11903 * @param $str (string) input string
11904 * @return String MD5 encrypted binary string
11906 * @since 2.0.000 (2008-01-02)
11907 * @author Klemen Vodopivec
11909 protected function _md5_16($str) {
11910 return pack('H*', md5($str));
11914 * Compute U value (used for encryption)
11915 * @return string U value
11917 * @since 2.0.000 (2008-01-02)
11918 * @author Nicola Asuni
11920 protected function _Uvalue() {
11921 if ($this->encryptdata
['mode'] == 0) { // RC4-40
11922 return $this->_RC4($this->encryptdata
['key'], $this->enc_padding
);
11923 } elseif ($this->encryptdata
['mode'] < 3) { // RC4-128, AES-128
11924 $tmp = $this->_md5_16($this->enc_padding
.$this->encryptdata
['fileid']);
11925 $enc = $this->_RC4($this->encryptdata
['key'], $tmp);
11926 $len = strlen($tmp);
11927 for ($i = 1; $i <= 19; ++
$i) {
11929 for ($j = 0; $j < $len; ++
$j) {
11930 $ek .= chr(ord($this->encryptdata
['key']{$j}) ^
$i);
11932 $enc = $this->_RC4($ek, $enc);
11934 $enc .= str_repeat("\x00", 16);
11935 return substr($enc, 0, 32);
11936 } elseif ($this->encryptdata
['mode'] == 3) { // AES-256
11937 $seed = $this->_md5_16($this->getRandomSeed());
11938 // User Validation Salt
11939 $this->encryptdata
['UVS'] = substr($seed, 0, 8);
11941 $this->encryptdata
['UKS'] = substr($seed, 8, 16);
11942 return hash('sha256', $this->encryptdata
['user_password'].$this->encryptdata
['UVS'], true).$this->encryptdata
['UVS'].$this->encryptdata
['UKS'];
11947 * Compute UE value (used for encryption)
11948 * @return string UE value
11950 * @since 5.9.006 (2010-10-19)
11951 * @author Nicola Asuni
11953 protected function _UEvalue() {
11954 $hashkey = hash('sha256', $this->encryptdata
['user_password'].$this->encryptdata
['UKS'], true);
11955 $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128
, MCRYPT_MODE_CBC
));
11956 return mcrypt_encrypt(MCRYPT_RIJNDAEL_128
, $hashkey, $this->encryptdata
['key'], MCRYPT_MODE_CBC
, $iv);
11960 * Compute O value (used for encryption)
11961 * @return string O value
11963 * @since 2.0.000 (2008-01-02)
11964 * @author Nicola Asuni
11966 protected function _Ovalue() {
11967 if ($this->encryptdata
['mode'] < 3) { // RC4-40, RC4-128, AES-128
11968 $tmp = $this->_md5_16($this->encryptdata
['owner_password']);
11969 if ($this->encryptdata
['mode'] > 0) {
11970 for ($i = 0; $i < 50; ++
$i) {
11971 $tmp = $this->_md5_16($tmp);
11974 $owner_key = substr($tmp, 0, ($this->encryptdata
['Length'] / 8));
11975 $enc = $this->_RC4($owner_key, $this->encryptdata
['user_password']);
11976 if ($this->encryptdata
['mode'] > 0) {
11977 $len = strlen($owner_key);
11978 for ($i = 1; $i <= 19; ++
$i) {
11980 for ($j = 0; $j < $len; ++
$j) {
11981 $ek .= chr(ord($owner_key{$j}) ^
$i);
11983 $enc = $this->_RC4($ek, $enc);
11987 } elseif ($this->encryptdata
['mode'] == 3) { // AES-256
11988 $seed = $this->_md5_16($this->getRandomSeed());
11989 // Owner Validation Salt
11990 $this->encryptdata
['OVS'] = substr($seed, 0, 8);
11992 $this->encryptdata
['OKS'] = substr($seed, 8, 16);
11993 return hash('sha256', $this->encryptdata
['owner_password'].$this->encryptdata
['OVS'].$this->encryptdata
['U'], true).$this->encryptdata
['OVS'].$this->encryptdata
['OKS'];
11998 * Compute OE value (used for encryption)
11999 * @return string OE value
12001 * @since 5.9.006 (2010-10-19)
12002 * @author Nicola Asuni
12004 protected function _OEvalue() {
12005 $hashkey = hash('sha256', $this->encryptdata
['owner_password'].$this->encryptdata
['OKS'].$this->encryptdata
['U'], true);
12006 $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128
, MCRYPT_MODE_CBC
));
12007 return mcrypt_encrypt(MCRYPT_RIJNDAEL_128
, $hashkey, $this->encryptdata
['key'], MCRYPT_MODE_CBC
, $iv);
12011 * Convert password for AES-256 encryption mode
12012 * @param $password (string) password
12013 * @return string password
12015 * @since 5.9.006 (2010-10-19)
12016 * @author Nicola Asuni
12018 protected function _fixAES256Password($password) {
12019 $psw = ''; // password to be returned
12020 $psw_array = $this->utf8Bidi($this->UTF8StringToArray($password), $password, $this->rtl
);
12021 foreach ($psw_array as $c) {
12022 $psw .= $this->unichr($c);
12024 return substr($psw, 0, 127);
12028 * Compute encryption key
12030 * @since 2.0.000 (2008-01-02)
12031 * @author Nicola Asuni
12033 protected function _generateencryptionkey() {
12034 $keybytelen = ($this->encryptdata
['Length'] / 8);
12035 if (!$this->encryptdata
['pubkey']) { // standard mode
12036 if ($this->encryptdata
['mode'] == 3) { // AES-256
12037 // generate 256 bit random key
12038 $this->encryptdata
['key'] = substr(hash('sha256', $this->getRandomSeed(), true), 0, $keybytelen);
12039 // truncate passwords
12040 $this->encryptdata
['user_password'] = $this->_fixAES256Password($this->encryptdata
['user_password']);
12041 $this->encryptdata
['owner_password'] = $this->_fixAES256Password($this->encryptdata
['owner_password']);
12043 $this->encryptdata
['U'] = $this->_Uvalue();
12044 // Compute UE value
12045 $this->encryptdata
['UE'] = $this->_UEvalue();
12047 $this->encryptdata
['O'] = $this->_Ovalue();
12048 // Compute OE value
12049 $this->encryptdata
['OE'] = $this->_OEvalue();
12051 $this->encryptdata
['P'] = $this->encryptdata
['protection'];
12052 // Computing the encryption dictionary's Perms (permissions) value
12053 $perms = $this->getEncPermissionsString($this->encryptdata
['protection']); // bytes 0-3
12054 $perms .= chr(255).chr(255).chr(255).chr(255); // bytes 4-7
12055 if (isset($this->encryptdata
['CF']['EncryptMetadata']) AND (!$this->encryptdata
['CF']['EncryptMetadata'])) { // byte 8
12060 $perms .= 'adb'; // bytes 9-11
12061 $perms .= 'nick'; // bytes 12-15
12062 $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128
, MCRYPT_MODE_ECB
));
12063 $this->encryptdata
['perms'] = mcrypt_encrypt(MCRYPT_RIJNDAEL_128
, $this->encryptdata
['key'], $perms, MCRYPT_MODE_ECB
, $iv);
12064 } else { // RC4-40, RC4-128, AES-128
12066 $this->encryptdata
['user_password'] = substr($this->encryptdata
['user_password'].$this->enc_padding
, 0, 32);
12067 $this->encryptdata
['owner_password'] = substr($this->encryptdata
['owner_password'].$this->enc_padding
, 0, 32);
12069 $this->encryptdata
['O'] = $this->_Ovalue();
12070 // get default permissions (reverse byte order)
12071 $permissions = $this->getEncPermissionsString($this->encryptdata
['protection']);
12072 // Compute encryption key
12073 $tmp = $this->_md5_16($this->encryptdata
['user_password'].$this->encryptdata
['O'].$permissions.$this->encryptdata
['fileid']);
12074 if ($this->encryptdata
['mode'] > 0) {
12075 for ($i = 0; $i < 50; ++
$i) {
12076 $tmp = $this->_md5_16(substr($tmp, 0, $keybytelen));
12079 $this->encryptdata
['key'] = substr($tmp, 0, $keybytelen);
12081 $this->encryptdata
['U'] = $this->_Uvalue();
12083 $this->encryptdata
['P'] = $this->encryptdata
['protection'];
12085 } else { // Public-Key mode
12086 // random 20-byte seed
12087 $seed = sha1($this->getRandomSeed(), true);
12088 $recipient_bytes = '';
12089 foreach ($this->encryptdata
['pubkeys'] as $pubkey) {
12090 // for each public certificate
12091 if (isset($pubkey['p'])) {
12092 $pkprotection = $this->getUserPermissionCode($pubkey['p'], $this->encryptdata
['mode']);
12094 $pkprotection = $this->encryptdata
['protection'];
12096 // get default permissions (reverse byte order)
12097 $pkpermissions = $this->getEncPermissionsString($pkprotection);
12099 $envelope = $seed.$pkpermissions;
12100 // write the envelope data to a temporary file
12101 $tempkeyfile = tempnam(K_PATH_CACHE
, 'tmpkey_');
12102 $f = fopen($tempkeyfile, 'wb');
12104 $this->Error('Unable to create temporary key file: '.$tempkeyfile);
12106 $envelope_lenght = strlen($envelope);
12107 fwrite($f, $envelope, $envelope_lenght);
12109 $tempencfile = tempnam(K_PATH_CACHE
, 'tmpenc_');
12110 if (!openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, $pubkey['c'], array(), PKCS7_DETACHED | PKCS7_BINARY
)) {
12111 $this->Error('Unable to encrypt the file: '.$tempkeyfile);
12113 unlink($tempkeyfile);
12114 // read encryption signature
12115 $signature = file_get_contents($tempencfile, false, null, $envelope_lenght);
12116 unlink($tempencfile);
12117 // extract signature
12118 $signature = substr($signature, strpos($signature, 'Content-Disposition'));
12119 $tmparr = explode("\n\n", $signature);
12120 $signature = trim($tmparr[1]);
12122 // decode signature
12123 $signature = base64_decode($signature);
12124 // convert signature to hex
12125 $hexsignature = current(unpack('H*', $signature));
12126 // store signature on recipients array
12127 $this->encryptdata
['Recipients'][] = $hexsignature;
12128 // The bytes of each item in the Recipients array of PKCS#7 objects in the order in which they appear in the array
12129 $recipient_bytes .= $signature;
12131 // calculate encryption key
12132 if ($this->encryptdata
['mode'] == 3) { // AES-256
12133 $this->encryptdata
['key'] = substr(hash('sha256', $seed.$recipient_bytes, true), 0, $keybytelen);
12134 } else { // RC4-40, RC4-128, AES-128
12135 $this->encryptdata
['key'] = substr(sha1($seed.$recipient_bytes, true), 0, $keybytelen);
12141 * Return the premission code used on encryption (P value).
12142 * @param $permissions (Array) the set of permissions (specify the ones you want to block).
12143 * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
12145 * @since 5.0.005 (2010-05-12)
12146 * @author Nicola Asuni
12148 protected function getUserPermissionCode($permissions, $mode=0) {
12150 'owner' => 2, // bit 2 -- inverted logic: cleared by default
12151 'print' => 4, // bit 3
12152 'modify' => 8, // bit 4
12153 'copy' => 16, // bit 5
12154 'annot-forms' => 32, // bit 6
12155 'fill-forms' => 256, // bit 9
12156 'extract' => 512, // bit 10
12157 'assemble' => 1024,// bit 11
12158 'print-high' => 2048 // bit 12
12160 $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
12161 foreach ($permissions as $permission) {
12162 if (!isset($options[$permission])) {
12163 $this->Error('Incorrect permission: '.$permission);
12165 if (($mode > 0) OR ($options[$permission] <= 32)) {
12166 // set only valid permissions
12167 if ($options[$permission] == 2) {
12168 // the logic for bit 2 is inverted (cleared by default)
12169 $protection +
= $options[$permission];
12171 $protection -= $options[$permission];
12175 return $protection;
12179 * Set document protection
12180 * Remark: the protection against modification is for people who have the full Acrobat product.
12181 * 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.
12182 * 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.
12183 * @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>
12184 * @param $user_pass (String) user password. Empty by default.
12185 * @param $owner_pass (String) owner password. If not specified, a random value is used.
12186 * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
12187 * @param $pubkeys (String) array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../tcpdf.crt', 'p' => array('print')))
12189 * @since 2.0.000 (2008-01-02)
12190 * @author Nicola Asuni
12192 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) {
12193 $this->encryptdata
['protection'] = $this->getUserPermissionCode($permissions, $mode);
12194 if (($pubkeys !== null) AND (is_array($pubkeys))) {
12196 $this->encryptdata
['pubkeys'] = $pubkeys;
12198 // public-Key Security requires at least 128 bit
12201 if (!function_exists('openssl_pkcs7_encrypt')) {
12202 $this->Error('Public-Key Security requires openssl library.');
12204 // Set Public-Key filter (availabe are: Entrust.PPKEF, Adobe.PPKLite, Adobe.PubSec)
12205 $this->encryptdata
['pubkey'] = true;
12206 $this->encryptdata
['Filter'] = 'Adobe.PubSec';
12207 $this->encryptdata
['StmF'] = 'DefaultCryptFilter';
12208 $this->encryptdata
['StrF'] = 'DefaultCryptFilter';
12210 // standard mode (password mode)
12211 $this->encryptdata
['pubkey'] = false;
12212 $this->encryptdata
['Filter'] = 'Standard';
12213 $this->encryptdata
['StmF'] = 'StdCF';
12214 $this->encryptdata
['StrF'] = 'StdCF';
12216 if ($mode > 1) { // AES
12217 if (!extension_loaded('mcrypt')) {
12218 $this->Error('AES encryption requires mcrypt library (http://www.php.net/manual/en/mcrypt.requirements.php).');
12220 if (mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128
) === false) {
12221 $this->Error('AES encryption requires MCRYPT_RIJNDAEL_128 cypher.');
12223 if (($mode == 3) AND !function_exists('hash')) {
12224 // the Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2.
12225 $this->Error('AES 256 encryption requires HASH Message Digest Framework (http://www.php.net/manual/en/book.hash.php).');
12228 if ($owner_pass === null) {
12229 $owner_pass = md5($this->getRandomSeed());
12231 $this->encryptdata
['user_password'] = $user_pass;
12232 $this->encryptdata
['owner_password'] = $owner_pass;
12233 $this->encryptdata
['mode'] = $mode;
12235 case 0: { // RC4 40 bit
12236 $this->encryptdata
['V'] = 1;
12237 $this->encryptdata
['Length'] = 40;
12238 $this->encryptdata
['CF']['CFM'] = 'V2';
12241 case 1: { // RC4 128 bit
12242 $this->encryptdata
['V'] = 2;
12243 $this->encryptdata
['Length'] = 128;
12244 $this->encryptdata
['CF']['CFM'] = 'V2';
12245 if ($this->encryptdata
['pubkey']) {
12246 $this->encryptdata
['SubFilter'] = 'adbe.pkcs7.s4';
12247 $this->encryptdata
['Recipients'] = array();
12251 case 2: { // AES 128 bit
12252 $this->encryptdata
['V'] = 4;
12253 $this->encryptdata
['Length'] = 128;
12254 $this->encryptdata
['CF']['CFM'] = 'AESV2';
12255 $this->encryptdata
['CF']['Length'] = 128;
12256 if ($this->encryptdata
['pubkey']) {
12257 $this->encryptdata
['SubFilter'] = 'adbe.pkcs7.s5';
12258 $this->encryptdata
['Recipients'] = array();
12262 case 3: { // AES 256 bit
12263 $this->encryptdata
['V'] = 5;
12264 $this->encryptdata
['Length'] = 256;
12265 $this->encryptdata
['CF']['CFM'] = 'AESV3';
12266 $this->encryptdata
['CF']['Length'] = 256;
12267 if ($this->encryptdata
['pubkey']) {
12268 $this->encryptdata
['SubFilter'] = 'adbe.pkcs7.s5';
12269 $this->encryptdata
['Recipients'] = array();
12274 $this->encrypted
= true;
12275 $this->encryptdata
['fileid'] = $this->convertHexStringToString($this->file_id
);
12276 $this->_generateencryptionkey();
12280 * Convert hexadecimal string to string
12281 * @param $bs (string) byte-string to convert
12284 * @since 5.0.005 (2010-05-12)
12285 * @author Nicola Asuni
12287 protected function convertHexStringToString($bs) {
12288 $string = ''; // string to be returned
12289 $bslenght = strlen($bs);
12290 if (($bslenght %
2) != 0) {
12295 for ($i = 0; $i < $bslenght; $i +
= 2) {
12296 $string .= chr(hexdec($bs{$i}.$bs{($i +
1)}));
12302 * Convert string to hexadecimal string (byte string)
12303 * @param $s (string) string to convert
12304 * @return byte string
12306 * @since 5.0.010 (2010-05-17)
12307 * @author Nicola Asuni
12309 protected function convertStringToHexString($s) {
12311 $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY
);
12312 foreach ($chars as $c) {
12313 $bs .= sprintf('%02s', dechex(ord($c)));
12319 * Convert encryption P value to a string of bytes, low-order byte first.
12320 * @param $protection (string) 32bit encryption permission value (P value)
12323 * @since 5.0.005 (2010-05-12)
12324 * @author Nicola Asuni
12326 protected function getEncPermissionsString($protection) {
12327 $binprot = sprintf('%032b', $protection);
12328 $str = chr(bindec(substr($binprot, 24, 8)));
12329 $str .= chr(bindec(substr($binprot, 16, 8)));
12330 $str .= chr(bindec(substr($binprot, 8, 8)));
12331 $str .= chr(bindec(substr($binprot, 0, 8)));
12335 // END OF ENCRYPTION FUNCTIONS -------------------------
12337 // START TRANSFORMATIONS SECTION -----------------------
12340 * Starts a 2D tranformation saving current graphic state.
12341 * This function must be called before scaling, mirroring, translation, rotation and skewing.
12342 * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
12344 * @since 2.1.000 (2008-01-07)
12345 * @see StartTransform(), StopTransform()
12347 public function StartTransform() {
12349 if ($this->inxobj
) {
12350 // we are inside an XObject template
12351 $this->xobjects
[$this->xobjid
]['transfmrk'][] = strlen($this->xobjects
[$this->xobjid
]['outdata']);
12353 $this->transfmrk
[$this->page
][] = $this->pagelen
[$this->page
];
12355 ++
$this->transfmatrix_key
;
12356 $this->transfmatrix
[$this->transfmatrix_key
] = array();
12360 * Stops a 2D tranformation restoring previous graphic state.
12361 * This function must be called after scaling, mirroring, translation, rotation and skewing.
12362 * Use StartTransform() before, and StopTransform() after the transformations to restore the normal behavior.
12364 * @since 2.1.000 (2008-01-07)
12365 * @see StartTransform(), StopTransform()
12367 public function StopTransform() {
12369 if (isset($this->transfmatrix
[$this->transfmatrix_key
])) {
12370 array_pop($this->transfmatrix
[$this->transfmatrix_key
]);
12371 --$this->transfmatrix_key
;
12373 if ($this->inxobj
) {
12374 // we are inside an XObject template
12375 array_pop($this->xobjects
[$this->xobjid
]['transfmrk']);
12377 array_pop($this->transfmrk
[$this->page
]);
12381 * Horizontal Scaling.
12382 * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
12383 * @param $x (int) abscissa of the scaling center. Default is current x position
12384 * @param $y (int) ordinate of the scaling center. Default is current y position
12386 * @since 2.1.000 (2008-01-07)
12387 * @see StartTransform(), StopTransform()
12389 public function ScaleX($s_x, $x='', $y='') {
12390 $this->Scale($s_x, 100, $x, $y);
12394 * Vertical Scaling.
12395 * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
12396 * @param $x (int) abscissa of the scaling center. Default is current x position
12397 * @param $y (int) ordinate of the scaling center. Default is current y position
12399 * @since 2.1.000 (2008-01-07)
12400 * @see StartTransform(), StopTransform()
12402 public function ScaleY($s_y, $x='', $y='') {
12403 $this->Scale(100, $s_y, $x, $y);
12407 * Vertical and horizontal proportional Scaling.
12408 * @param $s (float) scaling factor for width and height as percent. 0 is not allowed.
12409 * @param $x (int) abscissa of the scaling center. Default is current x position
12410 * @param $y (int) ordinate of the scaling center. Default is current y position
12412 * @since 2.1.000 (2008-01-07)
12413 * @see StartTransform(), StopTransform()
12415 public function ScaleXY($s, $x='', $y='') {
12416 $this->Scale($s, $s, $x, $y);
12420 * Vertical and horizontal non-proportional Scaling.
12421 * @param $s_x (float) scaling factor for width as percent. 0 is not allowed.
12422 * @param $s_y (float) scaling factor for height as percent. 0 is not allowed.
12423 * @param $x (int) abscissa of the scaling center. Default is current x position
12424 * @param $y (int) ordinate of the scaling center. Default is current y position
12426 * @since 2.1.000 (2008-01-07)
12427 * @see StartTransform(), StopTransform()
12429 public function Scale($s_x, $s_y, $x='', $y='') {
12436 if (($s_x == 0) OR ($s_y == 0)) {
12437 $this->Error('Please do not use values equal to zero for scaling');
12439 $y = ($this->h
- $y) * $this->k
;
12441 //calculate elements of transformation matrix
12449 $tm[4] = $x * (1 - $s_x);
12450 $tm[5] = $y * (1 - $s_y);
12451 //scale the coordinate system
12452 $this->Transform($tm);
12456 * Horizontal Mirroring.
12457 * @param $x (int) abscissa of the point. Default is current x position
12459 * @since 2.1.000 (2008-01-07)
12460 * @see StartTransform(), StopTransform()
12462 public function MirrorH($x='') {
12463 $this->Scale(-100, 100, $x);
12467 * Verical Mirroring.
12468 * @param $y (int) ordinate of the point. Default is current y position
12470 * @since 2.1.000 (2008-01-07)
12471 * @see StartTransform(), StopTransform()
12473 public function MirrorV($y='') {
12474 $this->Scale(100, -100, '', $y);
12478 * Point reflection mirroring.
12479 * @param $x (int) abscissa of the point. Default is current x position
12480 * @param $y (int) ordinate of the point. Default is current y position
12482 * @since 2.1.000 (2008-01-07)
12483 * @see StartTransform(), StopTransform()
12485 public function MirrorP($x='',$y='') {
12486 $this->Scale(-100, -100, $x, $y);
12490 * Reflection against a straight line through point (x, y) with the gradient angle (angle).
12491 * @param $angle (float) gradient angle of the straight line. Default is 0 (horizontal line).
12492 * @param $x (int) abscissa of the point. Default is current x position
12493 * @param $y (int) ordinate of the point. Default is current y position
12495 * @since 2.1.000 (2008-01-07)
12496 * @see StartTransform(), StopTransform()
12498 public function MirrorL($angle=0, $x='',$y='') {
12499 $this->Scale(-100, 100, $x, $y);
12500 $this->Rotate(-2*($angle-90), $x, $y);
12504 * Translate graphic object horizontally.
12505 * @param $t_x (int) movement to the right (or left for RTL)
12507 * @since 2.1.000 (2008-01-07)
12508 * @see StartTransform(), StopTransform()
12510 public function TranslateX($t_x) {
12511 $this->Translate($t_x, 0);
12515 * Translate graphic object vertically.
12516 * @param $t_y (int) movement to the bottom
12518 * @since 2.1.000 (2008-01-07)
12519 * @see StartTransform(), StopTransform()
12521 public function TranslateY($t_y) {
12522 $this->Translate(0, $t_y);
12526 * Translate graphic object horizontally and vertically.
12527 * @param $t_x (int) movement to the right
12528 * @param $t_y (int) movement to the bottom
12530 * @since 2.1.000 (2008-01-07)
12531 * @see StartTransform(), StopTransform()
12533 public function Translate($t_x, $t_y) {
12534 //calculate elements of transformation matrix
12540 $tm[4] = $t_x * $this->k
;
12541 $tm[5] = -$t_y * $this->k
;
12542 //translate the coordinate system
12543 $this->Transform($tm);
12548 * @param $angle (float) angle in degrees for counter-clockwise rotation
12549 * @param $x (int) abscissa of the rotation center. Default is current x position
12550 * @param $y (int) ordinate of the rotation center. Default is current y position
12552 * @since 2.1.000 (2008-01-07)
12553 * @see StartTransform(), StopTransform()
12555 public function Rotate($angle, $x='', $y='') {
12562 $y = ($this->h
- $y) * $this->k
;
12564 //calculate elements of transformation matrix
12566 $tm[0] = cos(deg2rad($angle));
12567 $tm[1] = sin(deg2rad($angle));
12570 $tm[4] = $x +
($tm[1] * $y) - ($tm[0] * $x);
12571 $tm[5] = $y - ($tm[0] * $y) - ($tm[1] * $x);
12572 //rotate the coordinate system around ($x,$y)
12573 $this->Transform($tm);
12577 * Skew horizontally.
12578 * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
12579 * @param $x (int) abscissa of the skewing center. default is current x position
12580 * @param $y (int) ordinate of the skewing center. default is current y position
12582 * @since 2.1.000 (2008-01-07)
12583 * @see StartTransform(), StopTransform()
12585 public function SkewX($angle_x, $x='', $y='') {
12586 $this->Skew($angle_x, 0, $x, $y);
12591 * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
12592 * @param $x (int) abscissa of the skewing center. default is current x position
12593 * @param $y (int) ordinate of the skewing center. default is current y position
12595 * @since 2.1.000 (2008-01-07)
12596 * @see StartTransform(), StopTransform()
12598 public function SkewY($angle_y, $x='', $y='') {
12599 $this->Skew(0, $angle_y, $x, $y);
12604 * @param $angle_x (float) angle in degrees between -90 (skew to the left) and 90 (skew to the right)
12605 * @param $angle_y (float) angle in degrees between -90 (skew to the bottom) and 90 (skew to the top)
12606 * @param $x (int) abscissa of the skewing center. default is current x position
12607 * @param $y (int) ordinate of the skewing center. default is current y position
12609 * @since 2.1.000 (2008-01-07)
12610 * @see StartTransform(), StopTransform()
12612 public function Skew($angle_x, $angle_y, $x='', $y='') {
12619 if (($angle_x <= -90) OR ($angle_x >= 90) OR ($angle_y <= -90) OR ($angle_y >= 90)) {
12620 $this->Error('Please use values between -90 and +90 degrees for Skewing.');
12623 $y = ($this->h
- $y) * $this->k
;
12624 //calculate elements of transformation matrix
12627 $tm[1] = tan(deg2rad($angle_y));
12628 $tm[2] = tan(deg2rad($angle_x));
12630 $tm[4] = -$tm[2] * $y;
12631 $tm[5] = -$tm[1] * $x;
12632 //skew the coordinate system
12633 $this->Transform($tm);
12637 * Apply graphic transformations.
12638 * @param $tm (array) transformation matrix
12640 * @since 2.1.000 (2008-01-07)
12641 * @see StartTransform(), StopTransform()
12643 protected function Transform($tm) {
12644 $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
12645 // add tranformation matrix
12646 $this->transfmatrix
[$this->transfmatrix_key
][] = array('a' => $tm[0], 'b' => $tm[1], 'c' => $tm[2], 'd' => $tm[3], 'e' => $tm[4], 'f' => $tm[5]);
12647 // update transformation mark
12648 if ($this->inxobj
) {
12649 // we are inside an XObject template
12650 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
12651 $key = key($this->xobjects
[$this->xobjid
]['transfmrk']);
12652 $this->xobjects
[$this->xobjid
]['transfmrk'][$key] = strlen($this->xobjects
[$this->xobjid
]['outdata']);
12654 } elseif (end($this->transfmrk
[$this->page
]) !== false) {
12655 $key = key($this->transfmrk
[$this->page
]);
12656 $this->transfmrk
[$this->page
][$key] = $this->pagelen
[$this->page
];
12660 // END TRANSFORMATIONS SECTION -------------------------
12662 // START GRAPHIC FUNCTIONS SECTION ---------------------
12663 // The following section is based on the code provided by David Hernandez Sanz
12666 * 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.
12667 * @param $width (float) The width.
12670 * @see Line(), Rect(), Cell(), MultiCell()
12672 public function SetLineWidth($width) {
12674 $this->LineWidth
= $width;
12675 $this->linestyleWidth
= sprintf('%.2F w', ($width * $this->k
));
12676 if ($this->page
> 0) {
12677 $this->_out($this->linestyleWidth
);
12682 * Returns the current the line width.
12683 * @return int Line width
12685 * @since 2.1.000 (2008-01-07)
12686 * @see Line(), SetLineWidth()
12688 public function GetLineWidth() {
12689 return $this->LineWidth
;
12694 * @param $style (array) Line style. Array with keys among the following:
12696 * <li>width (float): Width of the line in user units.</li>
12697 * <li>cap (string): Type of cap to put on the line. Possible values are:
12698 * butt, round, square. The difference between "square" and "butt" is that
12699 * "square" projects a flat end past the end of the line.</li>
12700 * <li>join (string): Type of join. Possible values are: miter, round,
12702 * <li>dash (mixed): Dash pattern. Is 0 (without dash) or string with
12703 * series of length values, which are the lengths of the on and off dashes.
12704 * For example: "2" represents 2 on, 2 off, 2 on, 2 off, ...; "2,1" is 2 on,
12705 * 1 off, 2 on, 1 off, ...</li>
12706 * <li>phase (integer): Modifier on the dash pattern which is used to shift
12707 * the point at which the pattern starts.</li>
12708 * <li>color (array): Draw color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K).</li>
12710 * @param $ret (boolean) if true do not send the command.
12711 * @return string the PDF command
12713 * @since 2.1.000 (2008-01-08)
12715 public function SetLineStyle($style, $ret=false) {
12716 $s = ''; // string to be returned
12717 if (!is_array($style)) {
12721 if (isset($width)) {
12722 $this->LineWidth
= $width;
12723 $this->linestyleWidth
= sprintf('%.2F w', ($width * $this->k
));
12724 $s .= $this->linestyleWidth
.' ';
12727 $ca = array('butt' => 0, 'round'=> 1, 'square' => 2);
12728 if (isset($ca[$cap])) {
12729 $this->linestyleCap
= $ca[$cap].' J';
12730 $s .= $this->linestyleCap
.' ';
12733 if (isset($join)) {
12734 $ja = array('miter' => 0, 'round' => 1, 'bevel' => 2);
12735 if (isset($ja[$join])) {
12736 $this->linestyleJoin
= $ja[$join].' j';
12737 $s .= $this->linestyleJoin
.' ';
12740 if (isset($dash)) {
12743 if (preg_match('/^.+,/', $dash) > 0) {
12744 $tab = explode(',', $dash);
12746 $tab = array($dash);
12749 foreach ($tab as $i => $v) {
12751 $dash_string .= ' ';
12753 $dash_string .= sprintf('%.2F', $v);
12756 if (!isset($phase) OR !$dash) {
12759 $this->linestyleDash
= sprintf('[%s] %.2F d', $dash_string, $phase);
12760 $s .= $this->linestyleDash
.' ';
12762 if (isset($color)) {
12763 $s .= $this->SetDrawColorArray($color, true).' ';
12772 * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment.
12773 * @param $x (float) Abscissa of point.
12774 * @param $y (float) Ordinate of point.
12776 * @since 2.1.000 (2008-01-08)
12778 protected function _outPoint($x, $y) {
12779 $this->_out(sprintf('%.2F %.2F m', $x * $this->k
, ($this->h
- $y) * $this->k
));
12783 * Append a straight line segment from the current point to the point (x, y).
12784 * The new current point shall be (x, y).
12785 * @param $x (float) Abscissa of end point.
12786 * @param $y (float) Ordinate of end point.
12788 * @since 2.1.000 (2008-01-08)
12790 protected function _outLine($x, $y) {
12791 $this->_out(sprintf('%.2F %.2F l', $x * $this->k
, ($this->h
- $y) * $this->k
));
12795 * Append a rectangle to the current path as a complete subpath, with lower-left corner (x, y) and dimensions widthand height in user space.
12796 * @param $x (float) Abscissa of upper-left corner.
12797 * @param $y (float) Ordinate of upper-left corner.
12798 * @param $w (float) Width.
12799 * @param $h (float) Height.
12800 * @param $op (string) options
12802 * @since 2.1.000 (2008-01-08)
12804 protected function _outRect($x, $y, $w, $h, $op) {
12805 $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s', $x * $this->k
, ($this->h
- $y) * $this->k
, $w * $this->k
, -$h * $this->k
, $op));
12809 * Append a cubic Bézier 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 Bézier control points.
12810 * The new current point shall be (x3, y3).
12811 * @param $x1 (float) Abscissa of control point 1.
12812 * @param $y1 (float) Ordinate of control point 1.
12813 * @param $x2 (float) Abscissa of control point 2.
12814 * @param $y2 (float) Ordinate of control point 2.
12815 * @param $x3 (float) Abscissa of end point.
12816 * @param $y3 (float) Ordinate of end point.
12818 * @since 2.1.000 (2008-01-08)
12820 protected function _outCurve($x1, $y1, $x2, $y2, $x3, $y3) {
12821 $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1 * $this->k
, ($this->h
- $y1) * $this->k
, $x2 * $this->k
, ($this->h
- $y2) * $this->k
, $x3 * $this->k
, ($this->h
- $y3) * $this->k
));
12825 * Append a cubic Bézier 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 Bézier control points.
12826 * The new current point shall be (x3, y3).
12827 * @param $x2 (float) Abscissa of control point 2.
12828 * @param $y2 (float) Ordinate of control point 2.
12829 * @param $x3 (float) Abscissa of end point.
12830 * @param $y3 (float) Ordinate of end point.
12832 * @since 4.9.019 (2010-04-26)
12834 protected function _outCurveV($x2, $y2, $x3, $y3) {
12835 $this->_out(sprintf('%.2F %.2F %.2F %.2F v', $x2 * $this->k
, ($this->h
- $y2) * $this->k
, $x3 * $this->k
, ($this->h
- $y3) * $this->k
));
12839 * Append a cubic Bézier 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 Bézier control points.
12840 * The new current point shall be (x3, y3).
12841 * @param $x1 (float) Abscissa of control point 1.
12842 * @param $y1 (float) Ordinate of control point 1.
12843 * @param $x3 (float) Abscissa of end point.
12844 * @param $y3 (float) Ordinate of end point.
12846 * @since 2.1.000 (2008-01-08)
12848 protected function _outCurveY($x1, $y1, $x3, $y3) {
12849 $this->_out(sprintf('%.2F %.2F %.2F %.2F y', $x1 * $this->k
, ($this->h
- $y1) * $this->k
, $x3 * $this->k
, ($this->h
- $y3) * $this->k
));
12853 * Draws a line between two points.
12854 * @param $x1 (float) Abscissa of first point.
12855 * @param $y1 (float) Ordinate of first point.
12856 * @param $x2 (float) Abscissa of second point.
12857 * @param $y2 (float) Ordinate of second point.
12858 * @param $style (array) Line style. Array like for SetLineStyle(). Default value: default line style (empty array).
12861 * @see SetLineWidth(), SetDrawColor(), SetLineStyle()
12863 public function Line($x1, $y1, $x2, $y2, $style=array()) {
12864 if (is_array($style)) {
12865 $this->SetLineStyle($style);
12867 $this->_outPoint($x1, $y1);
12868 $this->_outLine($x2, $y2);
12873 * Draws a rectangle.
12874 * @param $x (float) Abscissa of upper-left corner.
12875 * @param $y (float) Ordinate of upper-left corner.
12876 * @param $w (float) Width.
12877 * @param $h (float) Height.
12878 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
12879 * @param $border_style (array) Border style of rectangle. Array with keys among the following:
12881 * <li>all: Line style of all borders. Array like for SetLineStyle().</li>
12882 * <li>L, T, R, B or combinations: Line style of left, top, right or bottom border. Array like for SetLineStyle().</li>
12884 * If a key is not present or is null, not draws the border. Default value: default line style (empty array).
12885 * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
12886 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
12889 * @see SetLineStyle()
12891 public function Rect($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array()) {
12892 if (!(false === strpos($style, 'F')) AND !empty($fill_color)) {
12893 $this->SetFillColorArray($fill_color);
12895 $op = $this->getPathPaintOperator($style);
12896 if ((!$border_style) OR (isset($border_style['all']))) {
12897 if (isset($border_style['all']) AND $border_style['all']) {
12898 $this->SetLineStyle($border_style['all']);
12899 $border_style = array();
12902 $this->_outRect($x, $y, $w, $h, $op);
12903 if ($border_style) {
12904 $border_style2 = array();
12905 foreach ($border_style as $line => $value) {
12906 $length = strlen($line);
12907 for ($i = 0; $i < $length; ++
$i) {
12908 $border_style2[$line[$i]] = $value;
12911 $border_style = $border_style2;
12912 if (isset($border_style['L']) AND $border_style['L']) {
12913 $this->Line($x, $y, $x, $y +
$h, $border_style['L']);
12915 if (isset($border_style['T']) AND $border_style['T']) {
12916 $this->Line($x, $y, $x +
$w, $y, $border_style['T']);
12918 if (isset($border_style['R']) AND $border_style['R']) {
12919 $this->Line($x +
$w, $y, $x +
$w, $y +
$h, $border_style['R']);
12921 if (isset($border_style['B']) AND $border_style['B']) {
12922 $this->Line($x, $y +
$h, $x +
$w, $y +
$h, $border_style['B']);
12928 * Draws a Bezier curve.
12929 * The Bezier curve is a tangent to the line between the control points at
12930 * either end of the curve.
12931 * @param $x0 (float) Abscissa of start point.
12932 * @param $y0 (float) Ordinate of start point.
12933 * @param $x1 (float) Abscissa of control point 1.
12934 * @param $y1 (float) Ordinate of control point 1.
12935 * @param $x2 (float) Abscissa of control point 2.
12936 * @param $y2 (float) Ordinate of control point 2.
12937 * @param $x3 (float) Abscissa of end point.
12938 * @param $y3 (float) Ordinate of end point.
12939 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
12940 * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
12941 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
12943 * @see SetLineStyle()
12944 * @since 2.1.000 (2008-01-08)
12946 public function Curve($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3, $style='', $line_style=array(), $fill_color=array()) {
12947 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
12948 $this->SetFillColorArray($fill_color);
12950 $op = $this->getPathPaintOperator($style);
12952 $this->SetLineStyle($line_style);
12954 $this->_outPoint($x0, $y0);
12955 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
12960 * Draws a poly-Bezier curve.
12961 * Each Bezier curve segment is a tangent to the line between the control points at
12962 * either end of the curve.
12963 * @param $x0 (float) Abscissa of start point.
12964 * @param $y0 (float) Ordinate of start point.
12965 * @param $segments (float) An array of bezier descriptions. Format: array(x1, y1, x2, y2, x3, y3).
12966 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
12967 * @param $line_style (array) Line style of curve. Array like for SetLineStyle(). Default value: default line style (empty array).
12968 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
12970 * @see SetLineStyle()
12971 * @since 3.0008 (2008-05-12)
12973 public function Polycurve($x0, $y0, $segments, $style='', $line_style=array(), $fill_color=array()) {
12974 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
12975 $this->SetFillColorArray($fill_color);
12977 $op = $this->getPathPaintOperator($style);
12979 $line_style = array();
12982 $this->SetLineStyle($line_style);
12984 $this->_outPoint($x0, $y0);
12985 foreach ($segments as $segment) {
12986 list($x1, $y1, $x2, $y2, $x3, $y3) = $segment;
12987 $this->_outCurve($x1, $y1, $x2, $y2, $x3, $y3);
12993 * Draws an ellipse.
12994 * An ellipse is formed from n Bezier curves.
12995 * @param $x0 (float) Abscissa of center point.
12996 * @param $y0 (float) Ordinate of center point.
12997 * @param $rx (float) Horizontal radius.
12998 * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
12999 * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
13000 * @param $astart: (float) Angle start of draw line. Default value: 0.
13001 * @param $afinish: (float) Angle finish of draw line. Default value: 360.
13002 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13003 * @param $line_style (array) Line style of ellipse. Array like for SetLineStyle(). Default value: default line style (empty array).
13004 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
13005 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
13006 * @author Nicola Asuni
13008 * @since 2.1.000 (2008-01-08)
13010 public function Ellipse($x0, $y0, $rx, $ry='', $angle=0, $astart=0, $afinish=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
13011 if ($this->empty_string($ry) OR ($ry == 0)) {
13014 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
13015 $this->SetFillColorArray($fill_color);
13017 $op = $this->getPathPaintOperator($style);
13019 $line_style = array();
13022 $this->SetLineStyle($line_style);
13024 $this->_outellipticalarc($x0, $y0, $rx, $ry, $angle, $astart, $afinish, false, $nc);
13029 * Append an elliptical arc to the current path.
13030 * An ellipse is formed from n Bezier curves.
13031 * @param $xc (float) Abscissa of center point.
13032 * @param $yc (float) Ordinate of center point.
13033 * @param $rx (float) Horizontal radius.
13034 * @param $ry (float) Vertical radius (if ry = 0 then is a circle, see Circle()). Default value: 0.
13035 * @param $xang: (float) Angle between the X-axis and the major axis of the ellipse. Default value: 0.
13036 * @param $angs: (float) Angle start of draw line. Default value: 0.
13037 * @param $angf: (float) Angle finish of draw line. Default value: 360.
13038 * @param $pie (boolean) if true do not mark the border point (used to draw pie sectors).
13039 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of ellipse.
13040 * @param $startpoint (boolean) if true output a starting point
13041 * @param $ccw (boolean) if true draws in counter-clockwise
13042 * @return array bounding box coordinates (x min, y min, x max, y max)
13043 * @author Nicola Asuni
13045 * @since 4.9.019 (2010-04-26)
13047 protected function _outellipticalarc($xc, $yc, $rx, $ry, $xang=0, $angs=0, $angf=360, $pie=false, $nc=2, $startpoint=true, $ccw=true) {
13052 $xmin = 2147483647;
13053 $ymin = 2147483647;
13057 // center of the arc
13058 $this->_outPoint($xc, $yc);
13060 $xang = deg2rad((float) $xang);
13061 $angs = deg2rad((float) $angs);
13062 $angf = deg2rad((float) $angf);
13063 $as = atan2((sin($angs) / $ry), (cos($angs) / $rx));
13064 $af = atan2((sin($angf) / $ry), (cos($angf) / $rx));
13071 if ($ccw AND ($as > $af)) {
13072 // reverse rotation
13074 } elseif (!$ccw AND ($as < $af)) {
13075 // reverse rotation
13078 $total_angle = ($af - $as);
13082 // total arcs to draw
13083 $nc *= (2 * abs($total_angle) / M_PI
);
13084 $nc = round($nc) +
1;
13085 // angle of each arc
13086 $arcang = $total_angle / $nc;
13087 // center point in PDF coordiantes
13089 $y0 = ($this->h
- $yc);
13092 $alpha = sin($arcang) * ((sqrt(4 +
(3 * pow(tan(($arcang) / 2), 2))) - 1) / 3);
13093 $cos_xang = cos($xang);
13094 $sin_xang = sin($xang);
13095 $cos_ang = cos($ang);
13096 $sin_ang = sin($ang);
13098 $px1 = $x0 +
($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
13099 $py1 = $y0 +
($rx * $sin_xang * $cos_ang) +
($ry * $cos_xang * $sin_ang);
13100 // first Bezier control point
13101 $qx1 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
13102 $qy1 = ($alpha * ((-$rx * $sin_xang * $sin_ang) +
($ry * $cos_xang * $cos_ang)));
13104 // line from center to arc starting point
13105 $this->_outLine($px1, $this->h
- $py1);
13106 } elseif ($startpoint) {
13107 // arc starting point
13108 $this->_outPoint($px1, $this->h
- $py1);
13111 for ($i = 1; $i <= $nc; ++
$i) {
13113 $ang = $as +
($i * $arcang);
13114 $cos_xang = cos($xang);
13115 $sin_xang = sin($xang);
13116 $cos_ang = cos($ang);
13117 $sin_ang = sin($ang);
13118 // second arc point
13119 $px2 = $x0 +
($rx * $cos_xang * $cos_ang) - ($ry * $sin_xang * $sin_ang);
13120 $py2 = $y0 +
($rx * $sin_xang * $cos_ang) +
($ry * $cos_xang * $sin_ang);
13121 // second Bezier control point
13122 $qx2 = ($alpha * ((-$rx * $cos_xang * $sin_ang) - ($ry * $sin_xang * $cos_ang)));
13123 $qy2 = ($alpha * ((-$rx * $sin_xang * $sin_ang) +
($ry * $cos_xang * $cos_ang)));
13125 $cx1 = ($px1 +
$qx1);
13126 $cy1 = ($this->h
- ($py1 +
$qy1));
13127 $cx2 = ($px2 - $qx2);
13128 $cy2 = ($this->h
- ($py2 - $qy2));
13130 $cy3 = ($this->h
- $py2);
13131 $this->_outCurve($cx1, $cy1, $cx2, $cy2, $cx3, $cy3);
13132 // get bounding box coordinates
13133 $xmin = min($xmin, $cx1, $cx2, $cx3);
13134 $ymin = min($ymin, $cy1, $cy2, $cy3);
13135 $xmax = max($xmax, $cx1, $cx2, $cx3);
13136 $ymax = max($ymax, $cy1, $cy2, $cy3);
13137 // move to next point
13144 $this->_outLine($xc, $yc);
13145 // get bounding box coordinates
13146 $xmin = min($xmin, $xc);
13147 $ymin = min($ymin, $yc);
13148 $xmax = max($xmax, $xc);
13149 $ymax = max($ymax, $yc);
13151 return array($xmin, $ymin, $xmax, $ymax);
13156 * A circle is formed from n Bezier curves.
13157 * @param $x0 (float) Abscissa of center point.
13158 * @param $y0 (float) Ordinate of center point.
13159 * @param $r (float) Radius.
13160 * @param $angstr: (float) Angle start of draw line. Default value: 0.
13161 * @param $angend: (float) Angle finish of draw line. Default value: 360.
13162 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13163 * @param $line_style (array) Line style of circle. Array like for SetLineStyle(). Default value: default line style (empty array).
13164 * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
13165 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of circle.
13167 * @since 2.1.000 (2008-01-08)
13169 public function Circle($x0, $y0, $r, $angstr=0, $angend=360, $style='', $line_style=array(), $fill_color=array(), $nc=2) {
13170 $this->Ellipse($x0, $y0, $r, $r, 0, $angstr, $angend, $style, $line_style, $fill_color, $nc);
13174 * Draws a polygonal line
13175 * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
13176 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13177 * @param $line_style (array) Line style of polygon. Array with keys among the following:
13179 * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
13180 * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
13182 * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
13183 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
13184 * @since 4.8.003 (2009-09-15)
13187 public function PolyLine($p, $style='', $line_style=array(), $fill_color=array()) {
13188 $this->Polygon($p, $style, $line_style, $fill_color, false);
13193 * @param $p (array) Points 0 to ($np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
13194 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13195 * @param $line_style (array) Line style of polygon. Array with keys among the following:
13197 * <li>all: Line style of all lines. Array like for SetLineStyle().</li>
13198 * <li>0 to ($np - 1): Line style of each line. Array like for SetLineStyle().</li>
13200 * If a key is not present or is null, not draws the line. Default value is default line style (empty array).
13201 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
13202 * @param $closed (boolean) if true the polygon is closes, otherwise will remain open
13204 * @since 2.1.000 (2008-01-08)
13206 public function Polygon($p, $style='', $line_style=array(), $fill_color=array(), $closed=true) {
13207 $nc = count($p); // number of coordinates
13208 $np = $nc / 2; // number of points
13210 // close polygon by adding the first 2 points at the end (one line)
13211 for ($i = 0; $i < 4; ++
$i) {
13212 $p[$nc +
$i] = $p[$i];
13214 // copy style for the last added line
13215 if (isset($line_style[0])) {
13216 $line_style[$np] = $line_style[0];
13220 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
13221 $this->SetFillColorArray($fill_color);
13223 $op = $this->getPathPaintOperator($style);
13225 $line_style = array();
13229 if (isset($line_style['all'])) {
13230 $this->SetLineStyle($line_style['all']);
13236 $this->_outPoint($p[0], $p[1]);
13237 for ($i = 2; $i < $nc; $i = $i +
2) {
13238 $this->_outLine($p[$i], $p[$i +
1]);
13243 $this->_outPoint($p[0], $p[1]);
13244 for ($i = 2; $i < $nc; $i = $i +
2) {
13245 $line_num = ($i / 2) - 1;
13246 if (isset($line_style[$line_num])) {
13247 if ($line_style[$line_num] != 0) {
13248 if (is_array($line_style[$line_num])) {
13250 $this->SetLineStyle($line_style[$line_num]);
13251 $this->_outPoint($p[$i - 2], $p[$i - 1]);
13252 $this->_outLine($p[$i], $p[$i +
1]);
13254 $this->_outPoint($p[$i], $p[$i +
1]);
13256 $this->_outLine($p[$i], $p[$i +
1]);
13260 $this->_outLine($p[$i], $p[$i +
1]);
13267 $this->_outPoint($p[0], $p[1]);
13268 for ($i = 2; $i < $nc; $i = $i +
2) {
13269 $this->_outLine($p[$i], $p[$i +
1]);
13276 * Draws a regular polygon.
13277 * @param $x0 (float) Abscissa of center point.
13278 * @param $y0 (float) Ordinate of center point.
13279 * @param $r: (float) Radius of inscribed circle.
13280 * @param $ns (integer) Number of sides.
13281 * @param $angle (float) Angle oriented (anti-clockwise). Default value: 0.
13282 * @param $draw_circle (boolean) Draw inscribed circle or not. Default value: false.
13283 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13284 * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
13286 * <li>all: Line style of all sides. Array like for SetLineStyle().</li>
13287 * <li>0 to ($ns - 1): Line style of each side. Array like for SetLineStyle().</li>
13289 * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
13290 * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
13291 * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
13293 * <li>D or empty string: Draw (default).</li>
13294 * <li>F: Fill.</li>
13295 * <li>DF or FD: Draw and fill.</li>
13296 * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
13297 * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
13299 * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
13300 * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
13302 * @since 2.1.000 (2008-01-08)
13304 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()) {
13308 if ($draw_circle) {
13309 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
13312 for ($i = 0; $i < $ns; ++
$i) {
13313 $a = $angle +
($i * 360 / $ns);
13314 $a_rad = deg2rad((float) $a);
13315 $p[] = $x0 +
($r * sin($a_rad));
13316 $p[] = $y0 +
($r * cos($a_rad));
13318 $this->Polygon($p, $style, $line_style, $fill_color);
13322 * Draws a star polygon
13323 * @param $x0 (float) Abscissa of center point.
13324 * @param $y0 (float) Ordinate of center point.
13325 * @param $r (float) Radius of inscribed circle.
13326 * @param $nv (integer) Number of vertices.
13327 * @param $ng (integer) Number of gap (if ($ng % $nv = 1) then is a regular polygon).
13328 * @param $angle: (float) Angle oriented (anti-clockwise). Default value: 0.
13329 * @param $draw_circle: (boolean) Draw inscribed circle or not. Default value is false.
13330 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13331 * @param $line_style (array) Line style of polygon sides. Array with keys among the following:
13333 * <li>all: Line style of all sides. Array like for
13334 * SetLineStyle().</li>
13335 * <li>0 to (n - 1): Line style of each side. Array like for SetLineStyle().</li>
13337 * If a key is not present or is null, not draws the side. Default value is default line style (empty array).
13338 * @param $fill_color (array) Fill color. Format: array(red, green, blue). Default value: default color (empty array).
13339 * @param $circle_style (string) Style of rendering of inscribed circle (if draws). Possible values are:
13341 * <li>D or empty string: Draw (default).</li>
13342 * <li>F: Fill.</li>
13343 * <li>DF or FD: Draw and fill.</li>
13344 * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
13345 * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
13347 * @param $circle_outLine_style (array) Line style of inscribed circle (if draws). Array like for SetLineStyle(). Default value: default line style (empty array).
13348 * @param $circle_fill_color (array) Fill color of inscribed circle (if draws). Format: array(red, green, blue). Default value: default color (empty array).
13350 * @since 2.1.000 (2008-01-08)
13352 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()) {
13356 if ($draw_circle) {
13357 $this->Circle($x0, $y0, $r, 0, 360, $circle_style, $circle_outLine_style, $circle_fill_color);
13360 $visited = array();
13361 for ($i = 0; $i < $nv; ++
$i) {
13362 $a = $angle +
($i * 360 / $nv);
13363 $a_rad = deg2rad((float) $a);
13364 $p2[] = $x0 +
($r * sin($a_rad));
13365 $p2[] = $y0 +
($r * cos($a_rad));
13366 $visited[] = false;
13371 $p[] = $p2[$i * 2];
13372 $p[] = $p2[($i * 2) +
1];
13373 $visited[$i] = true;
13376 } while (!$visited[$i]);
13377 $this->Polygon($p, $style, $line_style, $fill_color);
13381 * Draws a rounded rectangle.
13382 * @param $x (float) Abscissa of upper-left corner.
13383 * @param $y (float) Ordinate of upper-left corner.
13384 * @param $w (float) Width.
13385 * @param $h (float) Height.
13386 * @param $r (float) the radius of the circle used to round off the corners of the rectangle.
13387 * @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 left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
13388 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13389 * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
13390 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
13392 * @since 2.1.000 (2008-01-08)
13394 public function RoundedRect($x, $y, $w, $h, $r, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
13395 $this->RoundedRectXY($x, $y, $w, $h, $r, $r, $round_corner, $style, $border_style, $fill_color);
13399 * Draws a rounded rectangle.
13400 * @param $x (float) Abscissa of upper-left corner.
13401 * @param $y (float) Ordinate of upper-left corner.
13402 * @param $w (float) Width.
13403 * @param $h (float) Height.
13404 * @param $rx (float) the x-axis radius of the ellipse used to round off the corners of the rectangle.
13405 * @param $ry (float) the y-axis radius of the ellipse used to round off the corners of the rectangle.
13406 * @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 left, top right, bottom right and bottom left. Default value: all rounded corner ("1111").
13407 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
13408 * @param $border_style (array) Border style of rectangle. Array like for SetLineStyle(). Default value: default line style (empty array).
13409 * @param $fill_color (array) Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
13411 * @since 4.9.019 (2010-04-22)
13413 public function RoundedRectXY($x, $y, $w, $h, $rx, $ry, $round_corner='1111', $style='', $border_style=array(), $fill_color=array()) {
13414 if (($round_corner == '0000') OR (($rx == $ry) AND ($rx == 0))) {
13416 $this->Rect($x, $y, $w, $h, $style, $border_style, $fill_color);
13420 if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
13421 $this->SetFillColorArray($fill_color);
13423 $op = $this->getPathPaintOperator($style);
13425 $border_style = array();
13427 if ($border_style) {
13428 $this->SetLineStyle($border_style);
13430 $MyArc = 4 / 3 * (sqrt(2) - 1);
13431 $this->_outPoint($x +
$rx, $y);
13432 $xc = $x +
$w - $rx;
13434 $this->_outLine($xc, $y);
13435 if ($round_corner[0]) {
13436 $this->_outCurve($xc +
($rx * $MyArc), $yc - $ry, $xc +
$rx, $yc - ($ry * $MyArc), $xc +
$rx, $yc);
13438 $this->_outLine($x +
$w, $y);
13440 $xc = $x +
$w - $rx;
13441 $yc = $y +
$h - $ry;
13442 $this->_outLine($x +
$w, $yc);
13443 if ($round_corner[1]) {
13444 $this->_outCurve($xc +
$rx, $yc +
($ry * $MyArc), $xc +
($rx * $MyArc), $yc +
$ry, $xc, $yc +
$ry);
13446 $this->_outLine($x +
$w, $y +
$h);
13449 $yc = $y +
$h - $ry;
13450 $this->_outLine($xc, $y +
$h);
13451 if ($round_corner[2]) {
13452 $this->_outCurve($xc - ($rx * $MyArc), $yc +
$ry, $xc - $rx, $yc +
($ry * $MyArc), $xc - $rx, $yc);
13454 $this->_outLine($x, $y +
$h);
13458 $this->_outLine($x, $yc);
13459 if ($round_corner[3]) {
13460 $this->_outCurve($xc - $rx, $yc - ($ry * $MyArc), $xc - ($rx * $MyArc), $yc - $ry, $xc, $yc - $ry);
13462 $this->_outLine($x, $y);
13463 $this->_outLine($x +
$rx, $y);
13469 * Draws a grahic arrow.
13470 * @param $x0 (float) Abscissa of first point.
13471 * @param $y0 (float) Ordinate of first point.
13472 * @param $x1 (float) Abscissa of second point.
13473 * @param $y1 (float) Ordinate of second point.
13474 * @param $head_style (int) (0 = draw only arrowhead arms, 1 = draw closed arrowhead, but no fill, 2 = closed and filled arrowhead, 3 = filled arrowhead)
13475 * @param $arm_size (float) length of arrowhead arms
13476 * @param $arm_angle (int) angle between an arm and the shaft
13477 * @author Piotr Galecki, Nicola Asuni, Andy Meier
13478 * @since 4.6.018 (2009-07-10)
13480 public function Arrow($x0, $y0, $x1, $y1, $head_style=0, $arm_size=5, $arm_angle=15) {
13481 // getting arrow direction angle
13482 // 0 deg angle is when both arms go along X axis. angle grows clockwise.
13483 $dir_angle = atan2(($y0 - $y1), ($x0 - $x1));
13484 if ($dir_angle < 0) {
13485 $dir_angle +
= (2 * M_PI
);
13487 $arm_angle = deg2rad($arm_angle);
13490 if ($head_style > 0) {
13491 // calculate the stopping point for the arrow shaft
13492 $sx1 = $x1 +
(($arm_size - $this->LineWidth
) * cos($dir_angle));
13493 $sy1 = $y1 +
(($arm_size - $this->LineWidth
) * sin($dir_angle));
13495 // main arrow line / shaft
13496 $this->Line($x0, $y0, $sx1, $sy1);
13497 // left arrowhead arm tip
13498 $x2L = $x1 +
($arm_size * cos($dir_angle +
$arm_angle));
13499 $y2L = $y1 +
($arm_size * sin($dir_angle +
$arm_angle));
13500 // right arrowhead arm tip
13501 $x2R = $x1 +
($arm_size * cos($dir_angle - $arm_angle));
13502 $y2R = $y1 +
($arm_size * sin($dir_angle - $arm_angle));
13505 switch ($head_style) {
13507 // draw only arrowhead arms
13509 $style = array(1, 1, 0);
13513 // draw closed arrowhead, but no fill
13518 // closed and filled arrowhead
13523 // filled arrowhead
13528 $this->Polygon(array($x2L, $y2L, $x1, $y1, $x2R, $y2R), $mode, $style, array());
13531 // END GRAPHIC FUNCTIONS SECTION -----------------------
13533 // BIDIRECTIONAL TEXT SECTION --------------------------
13536 * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
13537 * @param $str (string) string to manipulate.
13538 * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
13539 * @param $forcertl (bool) if true forces RTL text direction
13542 * @author Nicola Asuni
13543 * @since 2.1.000 (2008-01-08)
13545 protected function utf8StrRev($str, $setbom=false, $forcertl=false) {
13546 return $this->utf8StrArrRev($this->UTF8StringToArray($str), $str, $setbom, $forcertl);
13550 * Reverse the RLT substrings array using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
13551 * @param $arr (array) array of unicode values.
13552 * @param $str (string) string to manipulate (or empty value).
13553 * @param $setbom (bool) if true set the Byte Order Mark (BOM = 0xFEFF)
13554 * @param $forcertl (bool) if true forces RTL text direction
13557 * @author Nicola Asuni
13558 * @since 4.9.000 (2010-03-27)
13560 protected function utf8StrArrRev($arr, $str='', $setbom=false, $forcertl=false) {
13561 return $this->arrUTF8ToUTF16BE($this->utf8Bidi($arr, $str, $forcertl), $setbom);
13565 * Reverse the RLT substrings using the Bidirectional Algorithm (http://unicode.org/reports/tr9/).
13566 * @param $ta (array) array of characters composing the string.
13567 * @param $str (string) string to process
13568 * @param $forcertl (bool) if 'R' forces RTL, if 'L' forces LTR
13569 * @return array of unicode chars
13570 * @author Nicola Asuni
13572 * @since 2.4.000 (2008-03-06)
13574 protected function utf8Bidi($ta, $str='', $forcertl=false) {
13575 // paragraph embedding level
13579 if ($this->empty_string($str)) {
13580 // create string from array
13581 $str = $this->UTF8ArrSubString($ta);
13583 // check if string contains arabic text
13584 if (preg_match($this->unicode
->uni_RE_PATTERN_ARABIC
, $str)) {
13589 // check if string contains RTL text
13590 if (!($forcertl OR $arabic OR preg_match($this->unicode
->uni_RE_PATTERN_RTL
, $str))) {
13594 // get number of chars
13595 $numchars = count($ta);
13597 if ($forcertl == 'R') {
13599 } elseif ($forcertl == 'L') {
13602 // P2. In each paragraph, find the first character of type L, AL, or R.
13603 // P3. If a character is found in P2 and it is of type AL or R, then set the paragraph embedding level to one; otherwise, set it to zero.
13604 for ($i=0; $i < $numchars; ++
$i) {
13605 $type = $this->unicode
->uni_type
[$ta[$i]];
13606 if ($type == 'L') {
13609 } elseif (($type == 'AL') OR ($type == 'R')) {
13616 // Current Embedding Level
13618 // directional override status
13620 $remember = array();
13621 // start-of-level-run
13622 $sor = $pel %
2 ?
'R' : 'L';
13625 // Array of characters data
13626 $chardata = Array();
13628 // X1. Begin by setting the current embedding level to the paragraph embedding level. Set the directional override status to neutral. Process each character iteratively, applying rules X2 through X9. Only embedding levels from 0 to 61 are valid in this phase.
13629 // In the resolution of levels in rules I1 and I2, the maximum embedding level of 62 can be reached.
13630 for ($i=0; $i < $numchars; ++
$i) {
13631 if ($ta[$i] == $this->unicode
->uni_RLE
) {
13632 // X2. With each RLE, compute the least greater odd embedding level.
13633 // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
13634 // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
13635 $next_level = $cel +
($cel %
2) +
1;
13636 if ($next_level < 62) {
13637 $remember[] = array('num' => $this->unicode
->uni_RLE
, 'cel' => $cel, 'dos' => $dos);
13638 $cel = $next_level;
13641 $eor = $cel %
2 ?
'R' : 'L';
13643 } elseif ($ta[$i] == $this->unicode
->uni_LRE
) {
13644 // X3. With each LRE, compute the least greater even embedding level.
13645 // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to neutral.
13646 // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
13647 $next_level = $cel +
2 - ($cel %
2);
13648 if ( $next_level < 62 ) {
13649 $remember[] = array('num' => $this->unicode
->uni_LRE
, 'cel' => $cel, 'dos' => $dos);
13650 $cel = $next_level;
13653 $eor = $cel %
2 ?
'R' : 'L';
13655 } elseif ($ta[$i] == $this->unicode
->uni_RLO
) {
13656 // X4. With each RLO, compute the least greater odd embedding level.
13657 // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to right-to-left.
13658 // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
13659 $next_level = $cel +
($cel %
2) +
1;
13660 if ($next_level < 62) {
13661 $remember[] = array('num' => $this->unicode
->uni_RLO
, 'cel' => $cel, 'dos' => $dos);
13662 $cel = $next_level;
13665 $eor = $cel %
2 ?
'R' : 'L';
13667 } elseif ($ta[$i] == $this->unicode
->uni_LRO
) {
13668 // X5. With each LRO, compute the least greater even embedding level.
13669 // a. If this new level would be valid, then this embedding code is valid. Remember (push) the current embedding level and override status. Reset the current level to this new level, and reset the override status to left-to-right.
13670 // b. If the new level would not be valid, then this code is invalid. Do not change the current level or override status.
13671 $next_level = $cel +
2 - ($cel %
2);
13672 if ( $next_level < 62 ) {
13673 $remember[] = array('num' => $this->unicode
->uni_LRO
, 'cel' => $cel, 'dos' => $dos);
13674 $cel = $next_level;
13677 $eor = $cel %
2 ?
'R' : 'L';
13679 } elseif ($ta[$i] == $this->unicode
->uni_PDF
) {
13680 // X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
13681 if (count($remember)) {
13682 $last = count($remember ) - 1;
13683 if (($remember[$last]['num'] == $this->unicode
->uni_RLE
) OR
13684 ($remember[$last]['num'] == $this->unicode
->uni_LRE
) OR
13685 ($remember[$last]['num'] == $this->unicode
->uni_RLO
) OR
13686 ($remember[$last]['num'] == $this->unicode
->uni_LRO
)) {
13687 $match = array_pop($remember);
13688 $cel = $match['cel'];
13689 $dos = $match['dos'];
13691 $eor = ($cel > $match['cel'] ?
$cel : $match['cel']) %
2 ?
'R' : 'L';
13694 } elseif (($ta[$i] != $this->unicode
->uni_RLE
) AND
13695 ($ta[$i] != $this->unicode
->uni_LRE
) AND
13696 ($ta[$i] != $this->unicode
->uni_RLO
) AND
13697 ($ta[$i] != $this->unicode
->uni_LRO
) AND
13698 ($ta[$i] != $this->unicode
->uni_PDF
)) {
13699 // X6. For all types besides RLE, LRE, RLO, LRO, and PDF:
13700 // a. Set the level of the current character to the current embedding level.
13701 // b. Whenever the directional override status is not neutral, reset the current character type to the directional override status.
13705 if (isset($this->unicode
->uni_type
[$ta[$i]])) {
13706 $chardir = $this->unicode
->uni_type
[$ta[$i]];
13711 // stores string characters and other information
13712 $chardata[] = array('char' => $ta[$i], 'level' => $cel, 'type' => $chardir, 'sor' => $sor, 'eor' => $eor);
13714 } // end for each char
13716 // X8. All explicit directional embeddings and overrides are completely terminated at the end of each paragraph. Paragraph separators are not included in the embedding.
13717 // X9. Remove all RLE, LRE, RLO, LRO, PDF, and BN codes.
13718 // X10. The remaining rules are applied to each run of characters at the same level. For each run, determine the start-of-level-run (sor) and end-of-level-run (eor) type, either L or R. This depends on the higher of the two levels on either side of the boundary (at the start or end of the paragraph, the level of the 'other' run is the base embedding level). If the higher level is odd, the type is R; otherwise, it is L.
13720 // 3.3.3 Resolving Weak Types
13721 // Weak types are now resolved one level run at a time. At level run boundaries where the type of the character on the other side of the boundary is required, the type assigned to sor or eor is used.
13722 // Nonspacing marks are now resolved based on the previous characters.
13723 $numchars = count($chardata);
13725 // W1. Examine each nonspacing mark (NSM) in the level run, and change the type of the NSM to the type of the previous character. If the NSM is at the start of the level run, it will get the type of sor.
13726 $prevlevel = -1; // track level changes
13727 $levcount = 0; // counts consecutive chars at the same level
13728 for ($i=0; $i < $numchars; ++
$i) {
13729 if ($chardata[$i]['type'] == 'NSM') {
13731 $chardata[$i]['type'] = $chardata[$i]['sor'];
13732 } elseif ($i > 0) {
13733 $chardata[$i]['type'] = $chardata[($i-1)]['type'];
13736 if ($chardata[$i]['level'] != $prevlevel) {
13741 $prevlevel = $chardata[$i]['level'];
13744 // W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sor) is found. If an AL is found, change the type of the European number to Arabic number.
13747 for ($i=0; $i < $numchars; ++
$i) {
13748 if ($chardata[$i]['char'] == 'EN') {
13749 for ($j=$levcount; $j >= 0; $j--) {
13750 if ($chardata[$j]['type'] == 'AL') {
13751 $chardata[$i]['type'] = 'AN';
13752 } elseif (($chardata[$j]['type'] == 'L') OR ($chardata[$j]['type'] == 'R')) {
13757 if ($chardata[$i]['level'] != $prevlevel) {
13762 $prevlevel = $chardata[$i]['level'];
13765 // W3. Change all ALs to R.
13766 for ($i=0; $i < $numchars; ++
$i) {
13767 if ($chardata[$i]['type'] == 'AL') {
13768 $chardata[$i]['type'] = 'R';
13772 // W4. A single European separator between two European numbers changes to a European number. A single common separator between two numbers of the same type changes to that type.
13775 for ($i=0; $i < $numchars; ++
$i) {
13776 if (($levcount > 0) AND (($i+
1) < $numchars) AND ($chardata[($i+
1)]['level'] == $prevlevel)) {
13777 if (($chardata[$i]['type'] == 'ES') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+
1)]['type'] == 'EN')) {
13778 $chardata[$i]['type'] = 'EN';
13779 } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'EN') AND ($chardata[($i+
1)]['type'] == 'EN')) {
13780 $chardata[$i]['type'] = 'EN';
13781 } elseif (($chardata[$i]['type'] == 'CS') AND ($chardata[($i-1)]['type'] == 'AN') AND ($chardata[($i+
1)]['type'] == 'AN')) {
13782 $chardata[$i]['type'] = 'AN';
13785 if ($chardata[$i]['level'] != $prevlevel) {
13790 $prevlevel = $chardata[$i]['level'];
13793 // W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
13796 for ($i=0; $i < $numchars; ++
$i) {
13797 if ($chardata[$i]['type'] == 'ET') {
13798 if (($levcount > 0) AND ($chardata[($i-1)]['type'] == 'EN')) {
13799 $chardata[$i]['type'] = 'EN';
13802 while (($j < $numchars) AND ($chardata[$j]['level'] == $prevlevel)) {
13803 if ($chardata[$j]['type'] == 'EN') {
13804 $chardata[$i]['type'] = 'EN';
13806 } elseif ($chardata[$j]['type'] != 'ET') {
13813 if ($chardata[$i]['level'] != $prevlevel) {
13818 $prevlevel = $chardata[$i]['level'];
13821 // W6. Otherwise, separators and terminators change to Other Neutral.
13824 for ($i=0; $i < $numchars; ++
$i) {
13825 if (($chardata[$i]['type'] == 'ET') OR ($chardata[$i]['type'] == 'ES') OR ($chardata[$i]['type'] == 'CS')) {
13826 $chardata[$i]['type'] = 'ON';
13828 if ($chardata[$i]['level'] != $prevlevel) {
13833 $prevlevel = $chardata[$i]['level'];
13836 //W7. Search backward from each instance of a European number until the first strong type (R, L, or sor) is found. If an L is found, then change the type of the European number to L.
13839 for ($i=0; $i < $numchars; ++
$i) {
13840 if ($chardata[$i]['char'] == 'EN') {
13841 for ($j=$levcount; $j >= 0; $j--) {
13842 if ($chardata[$j]['type'] == 'L') {
13843 $chardata[$i]['type'] = 'L';
13844 } elseif ($chardata[$j]['type'] == 'R') {
13849 if ($chardata[$i]['level'] != $prevlevel) {
13854 $prevlevel = $chardata[$i]['level'];
13857 // N1. A sequence of neutrals takes the direction of the surrounding strong text if the text on both sides has the same direction. European and Arabic numbers act as if they were R in terms of their influence on neutrals. Start-of-level-run (sor) and end-of-level-run (eor) are used at level run boundaries.
13860 for ($i=0; $i < $numchars; ++
$i) {
13861 if (($levcount > 0) AND (($i+
1) < $numchars) AND ($chardata[($i+
1)]['level'] == $prevlevel)) {
13862 if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[($i+
1)]['type'] == 'L')) {
13863 $chardata[$i]['type'] = 'L';
13864 } elseif (($chardata[$i]['type'] == 'N') AND
13865 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
13866 (($chardata[($i+
1)]['type'] == 'R') OR ($chardata[($i+
1)]['type'] == 'EN') OR ($chardata[($i+
1)]['type'] == 'AN'))) {
13867 $chardata[$i]['type'] = 'R';
13868 } elseif ($chardata[$i]['type'] == 'N') {
13869 // N2. Any remaining neutrals take the embedding direction
13870 $chardata[$i]['type'] = $chardata[$i]['sor'];
13872 } elseif (($levcount == 0) AND (($i+
1) < $numchars) AND ($chardata[($i+
1)]['level'] == $prevlevel)) {
13874 if (($chardata[$i]['type'] == 'N') AND ($chardata[$i]['sor'] == 'L') AND ($chardata[($i+
1)]['type'] == 'L')) {
13875 $chardata[$i]['type'] = 'L';
13876 } elseif (($chardata[$i]['type'] == 'N') AND
13877 (($chardata[$i]['sor'] == 'R') OR ($chardata[$i]['sor'] == 'EN') OR ($chardata[$i]['sor'] == 'AN')) AND
13878 (($chardata[($i+
1)]['type'] == 'R') OR ($chardata[($i+
1)]['type'] == 'EN') OR ($chardata[($i+
1)]['type'] == 'AN'))) {
13879 $chardata[$i]['type'] = 'R';
13880 } elseif ($chardata[$i]['type'] == 'N') {
13881 // N2. Any remaining neutrals take the embedding direction
13882 $chardata[$i]['type'] = $chardata[$i]['sor'];
13884 } elseif (($levcount > 0) AND ((($i+
1) == $numchars) OR (($i+
1) < $numchars) AND ($chardata[($i+
1)]['level'] != $prevlevel))) {
13886 if (($chardata[$i]['type'] == 'N') AND ($chardata[($i-1)]['type'] == 'L') AND ($chardata[$i]['eor'] == 'L')) {
13887 $chardata[$i]['type'] = 'L';
13888 } elseif (($chardata[$i]['type'] == 'N') AND
13889 (($chardata[($i-1)]['type'] == 'R') OR ($chardata[($i-1)]['type'] == 'EN') OR ($chardata[($i-1)]['type'] == 'AN')) AND
13890 (($chardata[$i]['eor'] == 'R') OR ($chardata[$i]['eor'] == 'EN') OR ($chardata[$i]['eor'] == 'AN'))) {
13891 $chardata[$i]['type'] = 'R';
13892 } elseif ($chardata[$i]['type'] == 'N') {
13893 // N2. Any remaining neutrals take the embedding direction
13894 $chardata[$i]['type'] = $chardata[$i]['sor'];
13896 } elseif ($chardata[$i]['type'] == 'N') {
13897 // N2. Any remaining neutrals take the embedding direction
13898 $chardata[$i]['type'] = $chardata[$i]['sor'];
13900 if ($chardata[$i]['level'] != $prevlevel) {
13905 $prevlevel = $chardata[$i]['level'];
13908 // I1. For all characters with an even (left-to-right) embedding direction, those of type R go up one level and those of type AN or EN go up two levels.
13909 // I2. For all characters with an odd (right-to-left) embedding direction, those of type L, EN or AN go up one level.
13910 for ($i=0; $i < $numchars; ++
$i) {
13911 $odd = $chardata[$i]['level'] %
2;
13913 if (($chardata[$i]['type'] == 'L') OR ($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
13914 $chardata[$i]['level'] +
= 1;
13917 if ($chardata[$i]['type'] == 'R') {
13918 $chardata[$i]['level'] +
= 1;
13919 } elseif (($chardata[$i]['type'] == 'AN') OR ($chardata[$i]['type'] == 'EN')) {
13920 $chardata[$i]['level'] +
= 2;
13923 $maxlevel = max($chardata[$i]['level'],$maxlevel);
13926 // L1. On each line, reset the embedding level of the following characters to the paragraph embedding level:
13927 // 1. Segment separators,
13928 // 2. Paragraph separators,
13929 // 3. Any sequence of whitespace characters preceding a segment separator or paragraph separator, and
13930 // 4. Any sequence of white space characters at the end of the line.
13931 for ($i=0; $i < $numchars; ++
$i) {
13932 if (($chardata[$i]['type'] == 'B') OR ($chardata[$i]['type'] == 'S')) {
13933 $chardata[$i]['level'] = $pel;
13934 } elseif ($chardata[$i]['type'] == 'WS') {
13936 while ($j < $numchars) {
13937 if ((($chardata[$j]['type'] == 'B') OR ($chardata[$j]['type'] == 'S')) OR
13938 (($j == ($numchars-1)) AND ($chardata[$j]['type'] == 'WS'))) {
13939 $chardata[$i]['level'] = $pel;
13941 } elseif ($chardata[$j]['type'] != 'WS') {
13950 // Cursively connected scripts, such as Arabic or Syriac, require the selection of positional character shapes that depend on adjacent characters. Shaping is logically applied after the Bidirectional Algorithm is used and is limited to characters within the same directional run.
13952 $endedletter = array(1569,1570,1571,1572,1573,1575,1577,1583,1584,1585,1586,1608,1688);
13953 $alfletter = array(1570,1571,1573,1575);
13954 $chardata2 = $chardata;
13955 $laaletter = false;
13958 for ($i=0; $i < $numchars; ++
$i) {
13959 if (($this->unicode
->uni_type
[$chardata[$i]['char']] == 'AL') OR ($chardata[$i]['char'] == 32) OR ($chardata[$i]['char'] == 8204)) {
13960 $charAL[$x] = $chardata[$i];
13961 $charAL[$x]['i'] = $i;
13962 $chardata[$i]['x'] = $x;
13967 for ($i=0; $i < $numchars; ++
$i) {
13968 $thischar = $chardata[$i];
13970 $prevchar = $chardata[($i-1)];
13974 if (($i+
1) < $numchars) {
13975 $nextchar = $chardata[($i+
1)];
13979 if ($this->unicode
->uni_type
[$thischar['char']] == 'AL') {
13980 $x = $thischar['x'];
13982 $prevchar = $charAL[($x-1)];
13986 if (($x+
1) < $numAL) {
13987 $nextchar = $charAL[($x+
1)];
13992 if (($prevchar !== false) AND ($prevchar['char'] == 1604) AND (in_array($thischar['char'], $alfletter))) {
13993 $arabicarr = $this->unicode
->uni_laa_array
;
13996 $prevchar = $charAL[($x-2)];
14001 $arabicarr = $this->unicode
->uni_arabicsubst
;
14002 $laaletter = false;
14004 if (($prevchar !== false) AND ($nextchar !== false) AND
14005 (($this->unicode
->uni_type
[$prevchar['char']] == 'AL') OR ($this->unicode
->uni_type
[$prevchar['char']] == 'NSM')) AND
14006 (($this->unicode
->uni_type
[$nextchar['char']] == 'AL') OR ($this->unicode
->uni_type
[$nextchar['char']] == 'NSM')) AND
14007 ($prevchar['type'] == $thischar['type']) AND
14008 ($nextchar['type'] == $thischar['type']) AND
14009 ($nextchar['char'] != 1567)) {
14010 if (in_array($prevchar['char'], $endedletter)) {
14011 if (isset($arabicarr[$thischar['char']][2])) {
14013 $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
14016 if (isset($arabicarr[$thischar['char']][3])) {
14018 $chardata2[$i]['char'] = $arabicarr[$thischar['char']][3];
14021 } elseif (($nextchar !== false) AND
14022 (($this->unicode
->uni_type
[$nextchar['char']] == 'AL') OR ($this->unicode
->uni_type
[$nextchar['char']] == 'NSM')) AND
14023 ($nextchar['type'] == $thischar['type']) AND
14024 ($nextchar['char'] != 1567)) {
14025 if (isset($arabicarr[$chardata[$i]['char']][2])) {
14027 $chardata2[$i]['char'] = $arabicarr[$thischar['char']][2];
14029 } elseif ((($prevchar !== false) AND
14030 (($this->unicode
->uni_type
[$prevchar['char']] == 'AL') OR ($this->unicode
->uni_type
[$prevchar['char']] == 'NSM')) AND
14031 ($prevchar['type'] == $thischar['type'])) OR
14032 (($nextchar !== false) AND ($nextchar['char'] == 1567))) {
14034 if (($i > 1) AND ($thischar['char'] == 1607) AND
14035 ($chardata[$i-1]['char'] == 1604) AND
14036 ($chardata[$i-2]['char'] == 1604)) {
14038 // mark characters to delete with false
14039 $chardata2[$i-2]['char'] = false;
14040 $chardata2[$i-1]['char'] = false;
14041 $chardata2[$i]['char'] = 65010;
14043 if (($prevchar !== false) AND in_array($prevchar['char'], $endedletter)) {
14044 if (isset($arabicarr[$thischar['char']][0])) {
14046 $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
14049 if (isset($arabicarr[$thischar['char']][1])) {
14051 $chardata2[$i]['char'] = $arabicarr[$thischar['char']][1];
14055 } elseif (isset($arabicarr[$thischar['char']][0])) {
14057 $chardata2[$i]['char'] = $arabicarr[$thischar['char']][0];
14061 // mark characters to delete with false
14062 $chardata2[($charAL[($x-1)]['i'])]['char'] = false;
14064 } // end if AL (Arabic Letter)
14065 } // end for each char
14067 * Combining characters that can occur with Arabic Shadda (0651 HEX, 1617 DEC) are replaced.
14068 * Putting the combining mark and shadda in the same glyph allows us to avoid the two marks overlapping each other in an illegible manner.
14070 $cw = &$this->CurrentFont
['cw'];
14071 for ($i = 0; $i < ($numchars-1); ++
$i) {
14072 if (($chardata2[$i]['char'] == 1617) AND (isset($this->unicode
->uni_diacritics
[($chardata2[$i+
1]['char'])]))) {
14073 // check if the subtitution font is defined on current font
14074 if (isset($cw[($this->unicode
->uni_diacritics
[($chardata2[$i+
1]['char'])])])) {
14075 $chardata2[$i]['char'] = false;
14076 $chardata2[$i+
1]['char'] = $this->unicode
->uni_diacritics
[($chardata2[$i+
1]['char'])];
14080 // remove marked characters
14081 foreach ($chardata2 as $key => $value) {
14082 if ($value['char'] === false) {
14083 unset($chardata2[$key]);
14086 $chardata = array_values($chardata2);
14087 $numchars = count($chardata);
14094 // L2. From the highest level found in the text to the lowest odd level on each line, including intermediate levels not actually present in the text, reverse any contiguous sequence of characters that are at that level or higher.
14095 for ($j=$maxlevel; $j > 0; $j--) {
14096 $ordarray = Array();
14099 for ($i=0; $i < $numchars; ++
$i) {
14100 if ($chardata[$i]['level'] >= $j) {
14102 if (isset($this->unicode
->uni_mirror
[$chardata[$i]['char']])) {
14103 // L4. A character is depicted by a mirrored glyph if and only if (a) the resolved directionality of that character is R, and (b) the Bidi_Mirrored property value of that character is true.
14104 $chardata[$i]['char'] = $this->unicode
->uni_mirror
[$chardata[$i]['char']];
14106 $revarr[] = $chardata[$i];
14109 $revarr = array_reverse($revarr);
14110 $ordarray = array_merge($ordarray, $revarr);
14114 $ordarray[] = $chardata[$i];
14118 $revarr = array_reverse($revarr);
14119 $ordarray = array_merge($ordarray, $revarr);
14121 $chardata = $ordarray;
14124 $ordarray = array();
14125 for ($i=0; $i < $numchars; ++
$i) {
14126 $ordarray[] = $chardata[$i]['char'];
14127 // store char values for subsetting
14128 $this->CurrentFont
['subsetchars'][$chardata[$i]['char']] = true;
14130 // update font subsetchars
14131 $this->setFontSubBuffer($this->CurrentFont
['fontkey'], 'subsetchars', $this->CurrentFont
['subsetchars']);
14135 // END OF BIDIRECTIONAL TEXT SECTION -------------------
14139 * @param $txt (string) bookmark description.
14140 * @param $level (int) bookmark level (minimum value is 0).
14141 * @param $y (float) Y position in user units of the bookmark on the selected page (default = -1 = current position; 0 = page start;).
14142 * @param $page (int) target page number (leave empty for current page).
14144 * @author Olivier Plathey, Nicola Asuni
14145 * @since 2.1.002 (2008-02-12)
14147 public function Bookmark($txt, $level=0, $y=-1, $page='') {
14151 if (isset($this->outlines
[0])) {
14152 $lastoutline = end($this->outlines
);
14153 $maxlevel = $lastoutline['l'] +
1;
14157 if ($level > $maxlevel) {
14158 $level = $maxlevel;
14161 $y = $this->GetY();
14163 if (empty($page)) {
14164 $page = $this->PageNo();
14165 if (empty($page)) {
14169 $this->outlines
[] = array('t' => $txt, 'l' => $level, 'y' => $y, 'p' => $page);
14173 * Create a bookmark PDF string.
14175 * @author Olivier Plathey, Nicola Asuni
14176 * @since 2.1.002 (2008-02-12)
14178 protected function _putbookmarks() {
14179 $nb = count($this->outlines
);
14183 // get sorting columns
14184 $outline_p = array();
14185 $outline_y = array();
14186 foreach ($this->outlines
as $key => $row) {
14187 $outline_p[$key] = $row['p'];
14188 $outline_k[$key] = $key;
14190 // sort outlines by page and original position
14191 array_multisort($outline_p, SORT_NUMERIC
, SORT_ASC
, $outline_k, SORT_NUMERIC
, SORT_ASC
, $this->outlines
);
14194 foreach ($this->outlines
as $i => $o) {
14196 $parent = $lru[($o['l'] - 1)];
14197 //Set parent and last pointers
14198 $this->outlines
[$i]['parent'] = $parent;
14199 $this->outlines
[$parent]['last'] = $i;
14200 if ($o['l'] > $level) {
14201 //Level increasing: set first pointer
14202 $this->outlines
[$parent]['first'] = $i;
14205 $this->outlines
[$i]['parent'] = $nb;
14207 if (($o['l'] <= $level) AND ($i > 0)) {
14208 //Set prev and next pointers
14209 $prev = $lru[$o['l']];
14210 $this->outlines
[$prev]['next'] = $i;
14211 $this->outlines
[$i]['prev'] = $prev;
14213 $lru[$o['l']] = $i;
14218 $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';
14219 foreach ($this->outlines
as $i => $o) {
14220 if (isset($this->page_obj_id
[($o['p'])])) {
14221 $oid = $this->_newobj();
14222 // covert HTML title to string
14223 $title = preg_replace($nltags, "\n", $o['t']);
14224 $title = preg_replace("/[\r]+/si", '', $title);
14225 $title = preg_replace("/[\n]+/si", "\n", $title);
14226 $title = strip_tags($title);
14227 $title = $this->stringTrim($title);
14228 $out = '<</Title '.$this->_textstring($title, $oid);
14229 $out .= ' /Parent '.($n +
$o['parent']).' 0 R';
14230 if (isset($o['prev'])) {
14231 $out .= ' /Prev '.($n +
$o['prev']).' 0 R';
14233 if (isset($o['next'])) {
14234 $out .= ' /Next '.($n +
$o['next']).' 0 R';
14236 if (isset($o['first'])) {
14237 $out .= ' /First '.($n +
$o['first']).' 0 R';
14239 if (isset($o['last'])) {
14240 $out .= ' /Last '.($n +
$o['last']).' 0 R';
14242 $out .= ' '.sprintf('/Dest [%u 0 R /XYZ 0 %.2F null]', $this->page_obj_id
[($o['p'])], ($this->pagedim
[$o['p']]['h'] - ($o['y'] * $this->k
)));
14243 $out .= ' /Count 0 >>';
14244 $out .= "\n".'endobj';
14249 $this->OutlineRoot
= $this->_newobj();
14250 $this->_out('<< /Type /Outlines /First '.$n.' 0 R /Last '.($n +
$lru[0]).' 0 R >>'."\n".'endobj');
14253 // --- JAVASCRIPT ------------------------------------------------------
14256 * Adds a javascript
14257 * @param $script (string) Javascript code
14259 * @author Johannes Güntert, Nicola Asuni
14260 * @since 2.1.002 (2008-02-12)
14262 public function IncludeJS($script) {
14263 $this->javascript
.= $script;
14267 * Adds a javascript object and return object ID
14268 * @param $script (string) Javascript code
14269 * @param $onload (boolean) if true executes this object when opening the document
14270 * @return int internal object ID
14272 * @author Nicola Asuni
14273 * @since 4.8.000 (2009-09-07)
14275 public function addJavascriptObject($script, $onload=false) {
14277 $this->js_objects
[$this->n
] = array('n' => $this->n
, 'js' => $script, 'onload' => $onload);
14282 * Create a javascript PDF string.
14284 * @author Johannes Güntert, Nicola Asuni
14285 * @since 2.1.002 (2008-02-12)
14287 protected function _putjavascript() {
14288 if (empty($this->javascript
) AND empty($this->js_objects
)) {
14291 if (strpos($this->javascript
, 'this.addField') > 0) {
14292 if (!$this->ur
['enabled']) {
14293 //$this->setUserRights();
14295 // the following two lines are used to avoid form fields duplication after saving
14296 // The addField method only works when releasing user rights (UR3)
14297 $jsa = sprintf("ftcpdfdocsaved=this.addField('%s','%s',%d,[%.2F,%.2F,%.2F,%.2F]);", 'tcpdfdocsaved', 'text', 0, 0, 1, 0, 1);
14298 $jsb = "getField('tcpdfdocsaved').value='saved';";
14299 $this->javascript
= $jsa."\n".$this->javascript
."\n".$jsb;
14301 $this->n_js
= $this->_newobj();
14302 $out = ' << /Names [';
14303 if (!empty($this->javascript
)) {
14304 $out .= ' (EmbeddedJS) '.($this->n +
1).' 0 R';
14306 if (!empty($this->js_objects
)) {
14307 foreach ($this->js_objects
as $key => $val) {
14308 if ($val['onload']) {
14309 $out .= ' (JS'.$key.') '.$key.' 0 R';
14314 $out .= "\n".'endobj';
14316 // default Javascript object
14317 if (!empty($this->javascript
)) {
14318 $obj_id = $this->_newobj();
14319 $out = '<< /S /JavaScript';
14320 $out .= ' /JS '.$this->_textstring($this->javascript
, $obj_id);
14322 $out .= "\n".'endobj';
14325 // additional Javascript objects
14326 if (!empty($this->js_objects
)) {
14327 foreach ($this->js_objects
as $key => $val) {
14328 $out = $this->_getobj($key)."\n".' << /S /JavaScript /JS '.$this->_textstring($val['js'], $key).' >>'."\n".'endobj';
14335 * Convert color to javascript color.
14336 * @param $color (string) color name or "#RRGGBB"
14338 * @author Denis Van Nuffelen, Nicola Asuni
14339 * @since 2.1.002 (2008-02-12)
14341 protected function _JScolor($color) {
14342 static $aColors = array('transparent', 'black', 'white', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'dkGray', 'gray', 'ltGray');
14343 if (substr($color,0,1) == '#') {
14344 return sprintf("['RGB',%.3F,%.3F,%.3F]", hexdec(substr($color,1,2))/255, hexdec(substr($color,3,2))/255, hexdec(substr($color,5,2))/255);
14346 if (!in_array($color,$aColors)) {
14347 $this->Error('Invalid color: '.$color);
14349 return 'color.'.$color;
14353 * Adds a javascript form field.
14354 * @param $type (string) field type
14355 * @param $name (string) field name
14356 * @param $x (int) horizontal position
14357 * @param $y (int) vertical position
14358 * @param $w (int) width
14359 * @param $h (int) height
14360 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
14362 * @author Denis Van Nuffelen, Nicola Asuni
14363 * @since 2.1.002 (2008-02-12)
14365 protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
14369 // the followind avoid fields duplication after saving the document
14370 $this->javascript
.= "if(getField('tcpdfdocsaved').value != 'saved') {";
14372 $this->javascript
.= sprintf("f".$name."=this.addField('%s','%s',%u,[%.2F,%.2F,%.2F,%.2F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h
-$y)*$k+
1, ($x+
$w)*$k, ($this->h
-$y-$h)*$k+
1)."\n";
14373 $this->javascript
.= 'f'.$name.'.textSize='.$this->FontSizePt
.";\n";
14374 while (list($key, $val) = each($prop)) {
14375 if (strcmp(substr($key, -5), 'Color') == 0) {
14376 $val = $this->_JScolor($val);
14378 $val = "'".$val."'";
14380 $this->javascript
.= 'f'.$name.'.'.$key.'='.$val.";\n";
14387 $this->javascript
.= '}';
14390 // --- FORM FIELDS -----------------------------------------------------
14393 * Convert JavaScript form fields properties array to Annotation Properties array.
14394 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
14395 * @return array of annotation properties
14397 * @author Nicola Asuni
14398 * @since 4.8.000 (2009-09-06)
14400 protected function getAnnotOptFromJSProp($prop) {
14401 if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
14402 // the annotation options area lready defined
14403 return $prop['aopt'];
14405 $opt = array(); // value to be returned
14406 // alignment: Controls how the text is laid out within the text field.
14407 if (isset($prop['alignment'])) {
14408 switch ($prop['alignment']) {
14422 $opt['q'] = ($this->rtl
)?
2:0;
14427 // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
14428 if (isset($prop['lineWidth'])) {
14429 $linewidth = intval($prop['lineWidth']);
14433 // borderStyle: The border style for a field.
14434 if (isset($prop['borderStyle'])) {
14435 switch ($prop['borderStyle']) {
14438 $opt['border'] = array(0, 0, $linewidth, array(3, 2));
14439 $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
14444 $opt['border'] = array(0, 0, $linewidth);
14445 $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
14450 $opt['border'] = array(0, 0, $linewidth);
14451 $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
14455 case 'underline': {
14456 $opt['border'] = array(0, 0, $linewidth);
14457 $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
14463 $opt['border'] = array(0, 0, $linewidth);
14464 $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
14469 if (isset($prop['border']) AND is_array($prop['border'])) {
14470 $opt['border'] = $prop['border'];
14472 if (!isset($opt['mk'])) {
14473 $opt['mk'] = array();
14475 if (!isset($opt['mk']['if'])) {
14476 $opt['mk']['if'] = array();
14478 $opt['mk']['if']['a'] = array(0.5, 0.5);
14479 // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
14480 if (isset($prop['buttonAlignX'])) {
14481 $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
14483 // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
14484 if (isset($prop['buttonAlignY'])) {
14485 $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
14487 // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
14488 if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
14489 $opt['mk']['if']['fb'] = true;
14491 // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
14492 if (isset($prop['buttonScaleHow'])) {
14493 switch ($prop['buttonScaleHow']) {
14494 case 'scaleHow.proportional': {
14495 $opt['mk']['if']['s'] = 'P';
14498 case 'scaleHow.anamorphic': {
14499 $opt['mk']['if']['s'] = 'A';
14504 // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
14505 if (isset($prop['buttonScaleWhen'])) {
14506 switch ($prop['buttonScaleWhen']) {
14507 case 'scaleWhen.always': {
14508 $opt['mk']['if']['sw'] = 'A';
14511 case 'scaleWhen.never': {
14512 $opt['mk']['if']['sw'] = 'N';
14515 case 'scaleWhen.tooBig': {
14516 $opt['mk']['if']['sw'] = 'B';
14519 case 'scaleWhen.tooSmall': {
14520 $opt['mk']['if']['sw'] = 'S';
14525 // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
14526 if (isset($prop['buttonPosition'])) {
14527 switch ($prop['buttonPosition']) {
14529 case 'position.textOnly': {
14530 $opt['mk']['tp'] = 0;
14534 case 'position.iconOnly': {
14535 $opt['mk']['tp'] = 1;
14539 case 'position.iconTextV': {
14540 $opt['mk']['tp'] = 2;
14544 case 'position.textIconV': {
14545 $opt['mk']['tp'] = 3;
14549 case 'position.iconTextH': {
14550 $opt['mk']['tp'] = 4;
14554 case 'position.textIconH': {
14555 $opt['mk']['tp'] = 5;
14559 case 'position.overlay': {
14560 $opt['mk']['tp'] = 6;
14565 // fillColor: Specifies the background color for a field.
14566 if (isset($prop['fillColor'])) {
14567 if (is_array($prop['fillColor'])) {
14568 $opt['mk']['bg'] = $prop['fillColor'];
14570 $opt['mk']['bg'] = $this->convertHTMLColorToDec($prop['fillColor']);
14573 // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width.
14574 if (isset($prop['strokeColor'])) {
14575 if (is_array($prop['strokeColor'])) {
14576 $opt['mk']['bc'] = $prop['strokeColor'];
14578 $opt['mk']['bc'] = $this->convertHTMLColorToDec($prop['strokeColor']);
14581 // rotation: The rotation of a widget in counterclockwise increments.
14582 if (isset($prop['rotation'])) {
14583 $opt['mk']['r'] = $prop['rotation'];
14585 // charLimit: Limits the number of characters that a user can type into a text field.
14586 if (isset($prop['charLimit'])) {
14587 $opt['maxlen'] = intval($prop['charLimit']);
14592 // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
14593 if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
14596 // required: Specifies whether a field requires a value.
14597 if (isset($prop['required']) AND ($prop['required'] == 'true')) {
14600 // multiline: Controls how text is wrapped within the field.
14601 if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
14604 // password: Specifies whether the field should display asterisks when data is entered in the field.
14605 if (isset($prop['password']) AND ($prop['password'] == 'true')) {
14608 // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
14609 if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
14612 // Radio: If set, the field is a set of radio buttons.
14613 if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
14616 // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
14617 if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
14620 // Combo: If set, the field is a combo box; if clear, the field is a list box.
14621 if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
14624 // editable: Controls whether a combo box is editable.
14625 if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
14628 // Sort: If set, the field's option items shall be sorted alphabetically.
14629 if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
14632 // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
14633 if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
14636 // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
14637 if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
14640 // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
14641 if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
14644 // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
14645 if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
14648 // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set.
14649 if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
14652 // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons.
14653 if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
14656 // richText: If true, the field allows rich text formatting.
14657 if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
14660 // commitOnSelChange: Controls whether a field value is committed after a selection change.
14661 if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
14665 // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
14666 if (isset($prop['defaultValue'])) {
14667 $opt['dv'] = $prop['defaultValue'];
14669 $f = 4; // default value for annotation flags
14670 // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
14671 if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
14674 // display: Controls whether the field is hidden or visible on screen and in print.
14675 if (isset($prop['display'])) {
14676 if ($prop['display'] == 'display.visible') {
14678 } elseif ($prop['display'] == 'display.hidden') {
14680 } elseif ($prop['display'] == 'display.noPrint') {
14682 } elseif ($prop['display'] == 'display.noView') {
14687 // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
14688 if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
14689 $opt['i'] = $prop['currentValueIndices'];
14691 // value: The value of the field data that the user has entered.
14692 if (isset($prop['value'])) {
14693 if (is_array($prop['value'])) {
14694 $opt['opt'] = array();
14695 foreach ($prop['value'] AS $key => $optval) {
14696 // exportValues: An array of strings representing the export values for the field.
14697 if (isset($prop['exportValues'][$key])) {
14698 $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
14700 $opt['opt'][$key] = $prop['value'][$key];
14704 $opt['v'] = $prop['value'];
14707 // richValue: This property specifies the text contents and formatting of a rich text field.
14708 if (isset($prop['richValue'])) {
14709 $opt['rv'] = $prop['richValue'];
14711 // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
14712 if (isset($prop['submitName'])) {
14713 $opt['tm'] = $prop['submitName'];
14715 // name: Fully qualified field name.
14716 if (isset($prop['name'])) {
14717 $opt['t'] = $prop['name'];
14719 // userName: The user name (short description string) of the field.
14720 if (isset($prop['userName'])) {
14721 $opt['tu'] = $prop['userName'];
14723 // highlight: Defines how a button reacts when a user clicks it.
14724 if (isset($prop['highlight'])) {
14725 switch ($prop['highlight']) {
14727 case 'highlight.n': {
14732 case 'highlight.i': {
14737 case 'highlight.p': {
14742 case 'highlight.o': {
14748 // Unsupported options:
14749 // - calcOrderIndex: Changes the calculation order of fields in the document.
14750 // - delay: Delays the redrawing of a field's appearance.
14751 // - defaultStyle: This property defines the default style attributes for the form field.
14752 // - style: Allows the user to set the glyph style of a check box or radio button.
14753 // - textColor, textFont, textSize
14758 * Set default properties for form fields.
14759 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
14761 * @author Nicola Asuni
14762 * @since 4.8.000 (2009-09-06)
14764 public function setFormDefaultProp($prop=array()) {
14765 $this->default_form_prop
= $prop;
14769 * Return the default properties for form fields.
14770 * @return array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
14772 * @author Nicola Asuni
14773 * @since 4.8.000 (2009-09-06)
14775 public function getFormDefaultProp() {
14776 return $this->default_form_prop
;
14780 * Creates a text field
14781 * @param $name (string) field name
14782 * @param $w (float) Width of the rectangle
14783 * @param $h (float) Height of the rectangle
14784 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
14785 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
14786 * @param $x (float) Abscissa of the upper-left corner of the rectangle
14787 * @param $y (float) Ordinate of the upper-left corner of the rectangle
14788 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
14790 * @author Nicola Asuni
14791 * @since 4.8.000 (2009-09-07)
14793 public function TextField($name, $w, $h, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
14800 // check page for no-write regions and adapt page margins if necessary
14801 $this->checkPageRegions($h, $x, $y);
14803 $this->_addfield('text', $name, $x, $y, $w, $h, $prop);
14806 // get default style
14807 $prop = array_merge($this->getFormDefaultProp(), $prop);
14808 // get annotation data
14809 $popt = $this->getAnnotOptFromJSProp($prop);
14810 // set default appearance stream
14811 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
14812 $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
14813 $popt['da'] = $fontstyle;
14814 $popt['ap'] = array();
14815 $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
14817 $opt = array_merge($popt, $opt);
14818 // remove some conflicting options
14820 // set remaining annotation data
14821 $opt['Subtype'] = 'Widget';
14825 Additional annotation's parameters (check _putannotsobj() method):
14845 //$opt['mk']['if']['sw']
14846 //$opt['mk']['if']['s']
14847 //$opt['mk']['if']['a']
14848 //$opt['mk']['if']['fb']
14859 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
14868 * Creates a RadioButton field
14869 * @param $name (string) field name
14870 * @param $w (int) width
14871 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
14872 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
14873 * @param $onvalue (string) value to be returned if selected.
14874 * @param $checked (boolean) define the initial state.
14875 * @param $x (float) Abscissa of the upper-left corner of the rectangle
14876 * @param $y (float) Ordinate of the upper-left corner of the rectangle
14877 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
14879 * @author Nicola Asuni
14880 * @since 4.8.000 (2009-09-07)
14882 public function RadioButton($name, $w, $prop=array(), $opt=array(), $onvalue='On', $checked=false, $x='', $y='', $js=false) {
14889 // check page for no-write regions and adapt page margins if necessary
14890 $this->checkPageRegions($w, $x, $y);
14892 $this->_addfield('radiobutton', $name, $x, $y, $w, $w, $prop);
14895 if ($this->empty_string($onvalue)) {
14899 $defval = $onvalue;
14903 // set data for parent group
14904 if (!isset($this->radiobutton_groups
[$this->page
])) {
14905 $this->radiobutton_groups
[$this->page
] = array();
14907 if (!isset($this->radiobutton_groups
[$this->page
][$name])) {
14908 $this->radiobutton_groups
[$this->page
][$name] = array();
14910 $this->radiobutton_groups
[$this->page
][$name]['n'] = $this->n
;
14911 $this->radio_groups
[] = $this->n
;
14912 $kid = ($this->n +
2);
14914 $kid = ($this->n +
1);
14916 // save object ID to be added on Kids entry on parent object
14917 $this->radiobutton_groups
[$this->page
][$name][] = array('kid' => $kid, 'def' => $defval);
14918 // get default style
14919 $prop = array_merge($this->getFormDefaultProp(), $prop);
14920 $prop['NoToggleToOff'] = 'true';
14921 $prop['Radio'] = 'true';
14922 $prop['borderStyle'] = 'inset';
14923 // get annotation data
14924 $popt = $this->getAnnotOptFromJSProp($prop);
14925 // set additional default values
14926 $font = 'zapfdingbats';
14927 $this->AddFont($font);
14928 $tmpfont = $this->getFontBuffer($font);
14929 $this->annotation_fonts
[$tmpfont['fontkey']] = $tmpfont['i'];
14930 $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt
, $this->TextColor
);
14931 $popt['da'] = $fontstyle;
14932 $popt['ap'] = array();
14933 $popt['ap']['n'] = array();
14934 $popt['ap']['n'][$onvalue] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
14935 $popt['ap']['n']['Off'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
14936 if (!isset($popt['mk'])) {
14937 $popt['mk'] = array();
14939 $popt['mk']['ca'] = '(l)';
14941 $opt = array_merge($popt, $opt);
14942 // set remaining annotation data
14943 $opt['Subtype'] = 'Widget';
14944 $opt['ft'] = 'Btn';
14946 $opt['v'] = array('/'.$onvalue);
14947 $opt['as'] = $onvalue;
14949 $opt['as'] = 'Off';
14951 $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
14960 * Creates a List-box field
14961 * @param $name (string) field name
14962 * @param $w (int) width
14963 * @param $h (int) height
14964 * @param $values (array) array containing the list of values.
14965 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
14966 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
14967 * @param $x (float) Abscissa of the upper-left corner of the rectangle
14968 * @param $y (float) Ordinate of the upper-left corner of the rectangle
14969 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
14971 * @author Nicola Asuni
14972 * @since 4.8.000 (2009-09-07)
14974 public function ListBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
14981 // check page for no-write regions and adapt page margins if necessary
14982 $this->checkPageRegions($h, $x, $y);
14984 $this->_addfield('listbox', $name, $x, $y, $w, $h, $prop);
14986 foreach ($values as $value) {
14987 $s .= "'".addslashes($value)."',";
14989 $this->javascript
.= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
14992 // get default style
14993 $prop = array_merge($this->getFormDefaultProp(), $prop);
14994 // get annotation data
14995 $popt = $this->getAnnotOptFromJSProp($prop);
14996 // set additional default values
14997 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
14998 $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
14999 $popt['da'] = $fontstyle;
15000 $popt['ap'] = array();
15001 $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
15003 $opt = array_merge($popt, $opt);
15004 // set remaining annotation data
15005 $opt['Subtype'] = 'Widget';
15008 $opt['opt'] = $values;
15009 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
15018 * Creates a Combo-box field
15019 * @param $name (string) field name
15020 * @param $w (int) width
15021 * @param $h (int) height
15022 * @param $values (array) array containing the list of values.
15023 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
15024 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
15025 * @param $x (float) Abscissa of the upper-left corner of the rectangle
15026 * @param $y (float) Ordinate of the upper-left corner of the rectangle
15027 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
15029 * @author Nicola Asuni
15030 * @since 4.8.000 (2009-09-07)
15032 public function ComboBox($name, $w, $h, $values, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
15039 // check page for no-write regions and adapt page margins if necessary
15040 $this->checkPageRegions($h, $x, $y);
15042 $this->_addfield('combobox', $name, $x, $y, $w, $h, $prop);
15044 foreach ($values as $value) {
15045 $s .= "'".addslashes($value)."',";
15047 $this->javascript
.= 'f'.$name.'.setItems(['.substr($s, 0, -1)."]);\n";
15050 // get default style
15051 $prop = array_merge($this->getFormDefaultProp(), $prop);
15052 $prop['Combo'] = true;
15053 // get annotation data
15054 $popt = $this->getAnnotOptFromJSProp($prop);
15055 // set additional default options
15056 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
15057 $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
15058 $popt['da'] = $fontstyle;
15059 $popt['ap'] = array();
15060 $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
15062 $opt = array_merge($popt, $opt);
15063 // set remaining annotation data
15064 $opt['Subtype'] = 'Widget';
15067 $opt['opt'] = $values;
15068 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
15077 * Creates a CheckBox field
15078 * @param $name (string) field name
15079 * @param $w (int) width
15080 * @param $checked (boolean) define the initial state.
15081 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
15082 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
15083 * @param $onvalue (string) value to be returned if selected.
15084 * @param $x (float) Abscissa of the upper-left corner of the rectangle
15085 * @param $y (float) Ordinate of the upper-left corner of the rectangle
15086 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
15088 * @author Nicola Asuni
15089 * @since 4.8.000 (2009-09-07)
15091 public function CheckBox($name, $w, $checked=false, $prop=array(), $opt=array(), $onvalue='Yes', $x='', $y='', $js=false) {
15098 // check page for no-write regions and adapt page margins if necessary
15099 $this->checkPageRegions($w, $x, $y);
15101 $this->_addfield('checkbox', $name, $x, $y, $w, $w, $prop);
15104 if (!isset($prop['value'])) {
15105 $prop['value'] = array('Yes');
15107 // get default style
15108 $prop = array_merge($this->getFormDefaultProp(), $prop);
15109 $prop['borderStyle'] = 'inset';
15110 // get annotation data
15111 $popt = $this->getAnnotOptFromJSProp($prop);
15112 // set additional default options
15113 $font = 'zapfdingbats';
15114 $this->AddFont($font);
15115 $tmpfont = $this->getFontBuffer($font);
15116 $this->annotation_fonts
[$tmpfont['fontkey']] = $tmpfont['i'];
15117 $fontstyle = sprintf('/F%d %.2F Tf %s', $tmpfont['i'], $this->FontSizePt
, $this->TextColor
);
15118 $popt['da'] = $fontstyle;
15119 $popt['ap'] = array();
15120 $popt['ap']['n'] = array();
15121 $popt['ap']['n']['Yes'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
15122 $popt['ap']['n']['Off'] = 'q BT '.$fontstyle.' 0 0 Td (8) Tj ET Q';
15124 $opt = array_merge($popt, $opt);
15125 // set remaining annotation data
15126 $opt['Subtype'] = 'Widget';
15127 $opt['ft'] = 'Btn';
15129 $opt['opt'] = array($onvalue);
15131 $opt['v'] = array('/0');
15132 $opt['as'] = 'Yes';
15134 $opt['v'] = array('/Off');
15135 $opt['as'] = 'Off';
15137 $this->Annotation($x, $y, $w, $w, $name, $opt, 0);
15146 * Creates a button field
15147 * @param $name (string) field name
15148 * @param $w (int) width
15149 * @param $h (int) height
15150 * @param $caption (string) caption.
15151 * @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.
15152 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
15153 * @param $opt (array) annotation parameters. Possible values are described on official PDF32000_2008 reference.
15154 * @param $x (float) Abscissa of the upper-left corner of the rectangle
15155 * @param $y (float) Ordinate of the upper-left corner of the rectangle
15156 * @param $js (boolean) if true put the field using JavaScript (requires Acrobat Writer to be rendered).
15158 * @author Nicola Asuni
15159 * @since 4.8.000 (2009-09-07)
15161 public function Button($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false) {
15168 // check page for no-write regions and adapt page margins if necessary
15169 $this->checkPageRegions($h, $x, $y);
15171 $this->_addfield('button', $name, $this->x
, $this->y
, $w, $h, $prop);
15172 $this->javascript
.= 'f'.$name.".buttonSetCaption('".addslashes($caption)."');\n";
15173 $this->javascript
.= 'f'.$name.".setAction('MouseUp','".addslashes($action)."');\n";
15174 $this->javascript
.= 'f'.$name.".highlight='push';\n";
15175 $this->javascript
.= 'f'.$name.".print=false;\n";
15178 // get default style
15179 $prop = array_merge($this->getFormDefaultProp(), $prop);
15180 $prop['Pushbutton'] = 'true';
15181 $prop['highlight'] = 'push';
15182 $prop['display'] = 'display.noPrint';
15183 // get annotation data
15184 $popt = $this->getAnnotOptFromJSProp($prop);
15185 $this->annotation_fonts
[$this->CurrentFont
['fontkey']] = $this->CurrentFont
['i'];
15186 $fontstyle = sprintf('/F%d %.2F Tf %s', $this->CurrentFont
['i'], $this->FontSizePt
, $this->TextColor
);
15187 $popt['da'] = $fontstyle;
15188 $popt['ap'] = array();
15189 $popt['ap']['n'] = 'q BT '.$fontstyle.' ET Q';
15190 // set additional default options
15191 if (!isset($popt['mk'])) {
15192 $popt['mk'] = array();
15194 $ann_obj_id = ($this->n +
1);
15195 if (!empty($action) AND !is_array($action)) {
15196 $ann_obj_id = ($this->n +
2);
15198 $popt['mk']['ca'] = $this->_textstring($caption, $ann_obj_id);
15199 $popt['mk']['rc'] = $this->_textstring($caption, $ann_obj_id);
15200 $popt['mk']['ac'] = $this->_textstring($caption, $ann_obj_id);
15202 $opt = array_merge($popt, $opt);
15203 // set remaining annotation data
15204 $opt['Subtype'] = 'Widget';
15205 $opt['ft'] = 'Btn';
15206 $opt['t'] = $caption;
15208 if (!empty($action)) {
15209 if (is_array($action)) {
15210 // form action options as on section 12.7.5 of PDF32000_2008.
15211 $opt['aa'] = '/D <<';
15212 $bmode = array('SubmitForm', 'ResetForm', 'ImportData');
15213 foreach ($action AS $key => $val) {
15214 if (($key == 'S') AND in_array($val, $bmode)) {
15215 $opt['aa'] .= ' /S /'.$val;
15216 } elseif (($key == 'F') AND (!empty($val))) {
15217 $opt['aa'] .= ' /F '.$this->_datastring($val, $ann_obj_id);
15218 } elseif (($key == 'Fields') AND is_array($val) AND !empty($val)) {
15219 $opt['aa'] .= ' /Fields [';
15220 foreach ($val AS $field) {
15221 $opt['aa'] .= ' '.$this->_textstring($field, $ann_obj_id);
15224 } elseif (($key == 'Flags')) {
15226 if (is_array($val)) {
15227 foreach ($val AS $flag) {
15229 case 'Include/Exclude': {
15233 case 'IncludeNoValueFields': {
15237 case 'ExportFormat': {
15241 case 'GetMethod': {
15245 case 'SubmitCoordinates': {
15253 case 'IncludeAppendSaves': {
15257 case 'IncludeAnnotations': {
15261 case 'SubmitPDF': {
15265 case 'CanonicalFormat': {
15269 case 'ExclNonUserAnnots': {
15277 case 'EmbedForm': {
15284 $ff = intval($val);
15286 $opt['aa'] .= ' /Flags '.$ff;
15289 $opt['aa'] .= ' >>';
15291 // Javascript action or raw action command
15292 $js_obj_id = $this->addJavascriptObject($action);
15293 $opt['aa'] = '/D '.$js_obj_id.' 0 R';
15296 $this->Annotation($x, $y, $w, $h, $name, $opt, 0);
15304 // --- END FORMS FIELDS ------------------------------------------------
15307 * Add certification signature (DocMDP or UR3)
15308 * You can set only one signature type
15310 * @author Nicola Asuni
15311 * @since 4.6.008 (2009-05-07)
15313 protected function _putsignature() {
15314 if ((!$this->sign
) OR (!isset($this->signature_data
['cert_type']))) {
15317 $out = $this->_getobj($this->sig_obj_id +
1)."\n";
15318 $out .= '<< /Type /Sig';
15319 $out .= ' /Filter /Adobe.PPKLite';
15320 $out .= ' /SubFilter /adbe.pkcs7.detached';
15321 $out .= ' '.$this->byterange_string
;
15322 $out .= ' /Contents<'.str_repeat('0', $this->signature_max_length
).'>';
15323 $out .= ' /Reference ['; // array of signature reference dictionaries
15324 $out .= ' << /Type /SigRef';
15325 if ($this->signature_data
['cert_type'] > 0) {
15326 $out .= ' /TransformMethod /DocMDP';
15327 $out .= ' /TransformParams <<';
15328 $out .= ' /Type /TransformParams';
15329 $out .= ' /V /1.2';
15330 $out .= ' /P '.$this->signature_data
['cert_type'];
15332 $out .= ' /TransformMethod /UR3';
15333 $out .= ' /TransformParams <<';
15334 $out .= ' /Type /TransformParams';
15335 $out .= ' /V /2.2';
15336 if (!$this->empty_string($this->ur
['document'])) {
15337 $out .= ' /Document['.$this->ur
['document'].']';
15339 if (!$this->empty_string($this->ur
['form'])) {
15340 $out .= ' /Form['.$this->ur
['form'].']';
15342 if (!$this->empty_string($this->ur
['signature'])) {
15343 $out .= ' /Signature['.$this->ur
['signature'].']';
15345 if (!$this->empty_string($this->ur
['annots'])) {
15346 $out .= ' /Annots['.$this->ur
['annots'].']';
15348 if (!$this->empty_string($this->ur
['ef'])) {
15349 $out .= ' /EF['.$this->ur
['ef'].']';
15351 if (!$this->empty_string($this->ur
['formex'])) {
15352 $out .= ' /FormEX['.$this->ur
['formex'].']';
15355 $out .= ' >>'; // close TransformParams
15356 // optional digest data (values must be calculated and replaced later)
15357 //$out .= ' /Data ********** 0 R';
15358 //$out .= ' /DigestMethod/MD5';
15359 //$out .= ' /DigestLocation[********** 34]';
15360 //$out .= ' /DigestValue<********************************>';
15362 $out .= ' ]'; // end of reference
15363 if (isset($this->signature_data
['info']['Name']) AND !$this->empty_string($this->signature_data
['info']['Name'])) {
15364 $out .= ' /Name '.$this->_textstring($this->signature_data
['info']['Name']);
15366 if (isset($this->signature_data
['info']['Location']) AND !$this->empty_string($this->signature_data
['info']['Location'])) {
15367 $out .= ' /Location '.$this->_textstring($this->signature_data
['info']['Location']);
15369 if (isset($this->signature_data
['info']['Reason']) AND !$this->empty_string($this->signature_data
['info']['Reason'])) {
15370 $out .= ' /Reason '.$this->_textstring($this->signature_data
['info']['Reason']);
15372 if (isset($this->signature_data
['info']['ContactInfo']) AND !$this->empty_string($this->signature_data
['info']['ContactInfo'])) {
15373 $out .= ' /ContactInfo '.$this->_textstring($this->signature_data
['info']['ContactInfo']);
15375 $out .= ' /M '.$this->_datestring();
15377 $out .= "\n".'endobj';
15382 * Set User's Rights for PDF Reader
15383 * WARNING: This is experimental and currently do not work.
15384 * Check the PDF Reference 8.7.1 Transform Methods,
15385 * Table 8.105 Entries in the UR transform parameters dictionary
15386 * @param $enable (boolean) if true enable user's rights on PDF reader
15387 * @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.
15388 * @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.
15389 * @param $form (string) Names specifying additional form-field-related usage rights for the document. Valid names are: /Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate
15390 * @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.
15391 * @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
15392 Names specifying additional embedded-files-related usage rights for the document.
15393 * @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.
15395 * @author Nicola Asuni
15396 * @since 2.9.000 (2008-03-26)
15398 public function setUserRights(
15400 $document='/FullSave',
15401 $annots='/Create/Delete/Modify/Copy/Import/Export',
15402 $form='/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate',
15403 $signature='/Modify',
15404 $ef='/Create/Delete/Modify/Import',
15406 $this->ur
['enabled'] = $enable;
15407 $this->ur
['document'] = $document;
15408 $this->ur
['annots'] = $annots;
15409 $this->ur
['form'] = $form;
15410 $this->ur
['signature'] = $signature;
15411 $this->ur
['ef'] = $ef;
15412 $this->ur
['formex'] = $formex;
15413 if (!$this->sign
) {
15414 $this->setSignature('', '', '', '', 0, array());
15419 * Enable document signature (requires the OpenSSL Library).
15420 * The digital signature improve document authenticity and integrity and allows o enable extra features on Acrobat Reader.
15421 * To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
15422 * To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
15423 * To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
15424 * @param $signing_cert (mixed) signing certificate (string or filename prefixed with 'file://')
15425 * @param $private_key (mixed) private key (string or filename prefixed with 'file://')
15426 * @param $private_key_password (string) password
15427 * @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.
15428 * @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.
15429 * @param $info (array) array of option information: Name, Location, Reason, ContactInfo.
15431 * @author Nicola Asuni
15432 * @since 4.6.005 (2009-04-24)
15434 public function setSignature($signing_cert='', $private_key='', $private_key_password='', $extracerts='', $cert_type=2, $info=array()) {
15435 // to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
15436 // to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
15437 // to convert pfx certificate to pem: openssl
15438 // OpenSSL> pkcs12 -in <cert.pfx> -out <cert.crt> -nodes
15439 $this->sign
= true;
15441 $this->sig_obj_id
= $this->n
; // signature widget
15442 ++
$this->n
; // signature object ($this->sig_obj_id + 1)
15443 $this->signature_data
= array();
15444 if (strlen($signing_cert) == 0) {
15445 $signing_cert = 'file://'.dirname(__FILE__
).'/tcpdf.crt';
15446 $private_key_password = 'tcpdfdemo';
15448 if (strlen($private_key) == 0) {
15449 $private_key = $signing_cert;
15451 $this->signature_data
['signcert'] = $signing_cert;
15452 $this->signature_data
['privkey'] = $private_key;
15453 $this->signature_data
['password'] = $private_key_password;
15454 $this->signature_data
['extracerts'] = $extracerts;
15455 $this->signature_data
['cert_type'] = $cert_type;
15456 $this->signature_data
['info'] = $info;
15460 * Set the digital signature appearance (a cliccable rectangle area to get signature properties)
15461 * @param $x (float) Abscissa of the upper-left corner.
15462 * @param $y (float) Ordinate of the upper-left corner.
15463 * @param $w (float) Width of the signature area.
15464 * @param $h (float) Height of the signature area.
15465 * @param $page (int) option page number (if < 0 the current page is used).
15467 * @author Nicola Asuni
15468 * @since 5.3.011 (2010-06-17)
15470 public function setSignatureAppearance($x=0, $y=0, $w=0, $h=0, $page=-1) {
15471 if (($page < 1) OR ($page > $this->numpages
)) {
15472 $this->signature_appearance
['page'] = $this->page
;
15474 $this->signature_appearance
['page'] = intval($page);
15476 $a = $x * $this->k
;
15477 $b = $this->pagedim
[($this->signature_appearance
['page'])]['h'] - (($y +
$h) * $this->k
);
15478 $c = $w * $this->k
;
15479 $d = $h * $this->k
;
15480 $this->signature_appearance
['rect'] = sprintf('%.2F %.2F %.2F %.2F', $a, $b, $a+
$c, $b+
$d);
15484 * Create a new page group.
15485 * NOTE: call this function before calling AddPage()
15486 * @param $page (int) starting group page (leave empty for next page).
15488 * @since 3.0.000 (2008-03-27)
15490 public function startPageGroup($page='') {
15491 if (empty($page)) {
15492 $page = $this->page +
1;
15494 $this->newpagegroup
[$page] = true;
15498 * Defines a string alias for the total number of pages. It will be substituted as the document is closed.
15499 * @param $numalias (string) The alias.
15501 * @see getAliasNbPages(), PageNo(), Footer()
15504 public function AliasNbPages($numalias="{nb}") {
15505 $this->AliasNbPages
= $numalias;
15509 * Returns the string alias used for the total number of pages.
15510 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
15512 * @since 4.0.018 (2008-08-08)
15513 * @see AliasNbPages(), PageNo(), Footer()
15516 public function getAliasNbPages() {
15517 if ($this->isUnicodeFont()) {
15518 return '{'.$this->AliasNbPages
.'}';
15520 return $this->AliasNbPages
;
15524 * Defines a string alias for the page number. It will be substituted as the document is closed.
15525 * @param $numalias (string) The alias.
15526 * @since 4.5.000 (2009-01-02)
15527 * @see getAliasNbPages(), PageNo(), Footer()
15530 public function AliasNumPage($numalias="{pnb}") {
15531 $this->AliasNumPage
= $numalias;
15535 * Returns the string alias used for the page number.
15536 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
15538 * @since 4.5.000 (2009-01-02)
15539 * @see AliasNbPages(), PageNo(), Footer()
15542 public function getAliasNumPage() {
15543 if ($this->isUnicodeFont()) {
15544 return '{'.$this->AliasNumPage
.'}';
15546 return $this->AliasNumPage
;
15550 * Return the current page in the group.
15551 * @return current page in the group
15553 * @since 3.0.000 (2008-03-27)
15555 public function getGroupPageNo() {
15556 return $this->pagegroups
[$this->currpagegroup
];
15560 * Returns the current group page number formatted as a string.
15562 * @since 4.3.003 (2008-11-18)
15563 * @see PaneNo(), formatPageNumber()
15565 public function getGroupPageNoFormatted() {
15566 return $this->formatPageNumber($this->getGroupPageNo());
15570 * Return the alias of the current page group
15571 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
15572 * (will be replaced by the total number of pages in this group).
15573 * @return alias of the current page group
15575 * @since 3.0.000 (2008-03-27)
15577 public function getPageGroupAlias() {
15578 if ($this->isUnicodeFont()) {
15579 return '{'.$this->currpagegroup
.'}';
15581 return $this->currpagegroup
;
15585 * Return the alias for the page number on the current page group
15586 * If the current font is unicode type, the returned string is surrounded by additional curly braces.
15587 * (will be replaced by the total number of pages in this group).
15588 * @return alias of the current page group
15590 * @since 4.5.000 (2009-01-02)
15592 public function getPageNumGroupAlias() {
15593 if ($this->isUnicodeFont()) {
15594 return '{'.str_replace('{nb', '{pnb', $this->currpagegroup
).'}';
15596 return str_replace('{nb', '{pnb', $this->currpagegroup
);
15600 * Format the page numbers.
15601 * This method can be overriden for custom formats.
15602 * @param $num (int) page number
15604 * @since 4.2.005 (2008-11-06)
15606 protected function formatPageNumber($num) {
15607 return number_format((float)$num, 0, '', '.');
15611 * Format the page numbers on the Table Of Content.
15612 * This method can be overriden for custom formats.
15613 * @param $num (int) page number
15615 * @since 4.5.001 (2009-01-04)
15616 * @see addTOC(), addHTMLTOC()
15618 protected function formatTOCPageNumber($num) {
15619 return number_format((float)$num, 0, '', '.');
15623 * Returns the current page number formatted as a string.
15625 * @since 4.2.005 (2008-11-06)
15626 * @see PaneNo(), formatPageNumber()
15628 public function PageNoFormatted() {
15629 return $this->formatPageNumber($this->PageNo());
15633 * Put visibility settings.
15635 * @since 3.0.000 (2008-03-27)
15637 protected function _putocg() {
15638 $this->n_ocg_print
= $this->_newobj();
15639 $this->_out('<< /Type /OCG /Name '.$this->_textstring('print', $this->n_ocg_print
).' /Usage << /Print <</PrintState /ON>> /View <</ViewState /OFF>> >> >>'."\n".'endobj');
15640 $this->n_ocg_view
= $this->_newobj();
15641 $this->_out('<< /Type /OCG /Name '.$this->_textstring('view', $this->n_ocg_view
).' /Usage << /Print <</PrintState /OFF>> /View <</ViewState /ON>> >> >>'."\n".'endobj');
15645 * Set the visibility of the successive elements.
15646 * This can be useful, for instance, to put a background
15647 * image or color that will show on screen but won't print.
15648 * @param $v (string) visibility mode. Legal values are: all, print, screen.
15650 * @since 3.0.000 (2008-03-27)
15652 public function setVisibility($v) {
15653 if ($this->openMarkedContent
) {
15654 // close existing open marked-content
15655 $this->_out('EMC');
15656 $this->openMarkedContent
= false;
15660 $this->_out('/OC /OC1 BDC');
15661 $this->openMarkedContent
= true;
15665 $this->_out('/OC /OC2 BDC');
15666 $this->openMarkedContent
= true;
15674 $this->Error('Incorrect visibility: '.$v);
15678 $this->visibility
= $v;
15682 * Add transparency parameters to the current extgstate
15683 * @param $parms (array) parameters
15684 * @return the number of extgstates
15686 * @since 3.0.000 (2008-03-27)
15688 protected function addExtGState($parms) {
15689 $n = count($this->extgstates
) +
1;
15690 // check if this ExtGState already exist
15691 for ($i = 1; $i < $n; ++
$i) {
15692 if ($this->extgstates
[$i]['parms'] == $parms) {
15693 // return reference to existing ExtGState
15697 $this->extgstates
[$n]['parms'] = $parms;
15703 * @param $gs (array) extgstate
15705 * @since 3.0.000 (2008-03-27)
15707 protected function setExtGState($gs) {
15708 $this->_out(sprintf('/GS%d gs', $gs));
15712 * Put extgstates for object transparency
15714 * @since 3.0.000 (2008-03-27)
15716 protected function _putextgstates() {
15717 $ne = count($this->extgstates
);
15718 for ($i = 1; $i <= $ne; ++
$i) {
15719 $this->extgstates
[$i]['n'] = $this->_newobj();
15720 $out = '<< /Type /ExtGState';
15721 foreach ($this->extgstates
[$i]['parms'] as $k => $v) {
15722 if (is_float($v)) {
15723 $v = sprintf('%.2F', $v);
15725 $out .= ' /'.$k.' '.$v;
15728 $out .= "\n".'endobj';
15734 * Set alpha for stroking (CA) and non-stroking (ca) operations.
15735 * @param $alpha (float) real value from 0 (transparent) to 1 (opaque)
15736 * @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
15738 * @since 3.0.000 (2008-03-27)
15740 public function setAlpha($alpha, $bm='Normal') {
15741 $gs = $this->addExtGState(array('ca' => $alpha, 'CA' => $alpha, 'BM' => '/'.$bm, 'AIS' => 'false'));
15742 $this->setExtGState($gs);
15746 * Set the default JPEG compression quality (1-100)
15747 * @param $quality (int) JPEG quality, integer between 1 and 100
15749 * @since 3.0.000 (2008-03-27)
15751 public function setJPEGQuality($quality) {
15752 if (($quality < 1) OR ($quality > 100)) {
15755 $this->jpeg_quality
= intval($quality);
15759 * Set the default number of columns in a row for HTML tables.
15760 * @param $cols (int) number of columns
15762 * @since 3.0.014 (2008-06-04)
15764 public function setDefaultTableColumns($cols=4) {
15765 $this->default_table_columns
= intval($cols);
15769 * Set the height of the cell (line height) respect the font height.
15770 * @param $h (int) cell proportion respect font height (typical value = 1.25).
15772 * @since 3.0.014 (2008-06-04)
15774 public function setCellHeightRatio($h) {
15775 $this->cell_height_ratio
= $h;
15779 * return the height of cell repect font height.
15781 * @since 4.0.012 (2008-07-24)
15783 public function getCellHeightRatio() {
15784 return $this->cell_height_ratio
;
15788 * Set the PDF version (check PDF reference for valid values).
15789 * @param $version (string) PDF document version.
15791 * @since 3.1.000 (2008-06-09)
15793 public function setPDFVersion($version='1.7') {
15794 $this->PDFVersion
= $version;
15798 * Set the viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
15799 * (see Section 8.1 of PDF reference, "Viewer Preferences").
15800 * <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>
15801 * @param $preferences (array) array of options.
15802 * @author Nicola Asuni
15804 * @since 3.1.000 (2008-06-09)
15806 public function setViewerPreferences($preferences) {
15807 $this->viewer_preferences
= $preferences;
15811 * Paints color transition registration bars
15812 * @param $x (float) abscissa of the top left corner of the rectangle.
15813 * @param $y (float) ordinate of the top left corner of the rectangle.
15814 * @param $w (float) width of the rectangle.
15815 * @param $h (float) height of the rectangle.
15816 * @param $transition (boolean) if true prints tcolor transitions to white.
15817 * @param $vertical (boolean) if true prints bar vertically.
15818 * @param $colors (string) colors to print, one letter per color separated by comma (for example 'A,W,R,G,B,C,M,Y,K'): A=black, W=white, R=red, G=green, B=blue, C=cyan, M=magenta, Y=yellow, K=black.
15819 * @author Nicola Asuni
15820 * @since 4.9.000 (2010-03-26)
15823 public function colorRegistrationBar($x, $y, $w, $h, $transition=true, $vertical=false, $colors='A,R,G,B,C,M,Y,K') {
15824 $bars = explode(',', $colors);
15825 $numbars = count($bars); // number of bars to print
15826 // set bar measures
15828 $coords = array(0, 0, 0, 1);
15829 $wb = $w / $numbars; // bar width
15830 $hb = $h; // bar height
15831 $xd = $wb; // delta x
15832 $yd = 0; // delta y
15834 $coords = array(1, 0, 0, 0);
15835 $wb = $w; // bar width
15836 $hb = $h / $numbars; // bar height
15837 $xd = 0; // delta x
15838 $yd = $hb; // delta y
15842 foreach ($bars as $col) {
15844 // set transition colors
15845 case 'A': { // BLACK
15846 $col_a = array(255);
15850 case 'W': { // WHITE
15852 $col_b = array(255);
15856 $col_a = array(255,255,255);
15857 $col_b = array(255,0,0);
15861 $col_a = array(255,255,255);
15862 $col_b = array(0,255,0);
15866 $col_a = array(255,255,255);
15867 $col_b = array(0,0,255);
15871 $col_a = array(0,0,0,0);
15872 $col_b = array(100,0,0,0);
15876 $col_a = array(0,0,0,0);
15877 $col_b = array(0,100,0,0);
15881 $col_a = array(0,0,0,0);
15882 $col_b = array(0,0,100,0);
15886 $col_a = array(0,0,0,0);
15887 $col_b = array(0,0,0,100);
15891 $col_a = array(255);
15898 $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
15901 $this->SetFillColorArray($col_b);
15902 $this->Rect($xb, $yb, $wb, $hb, 'F', array());
15911 * @param $x (float) abscissa of the crop mark center.
15912 * @param $y (float) ordinate of the crop mark center.
15913 * @param $w (float) width of the crop mark.
15914 * @param $h (float) height of the crop mark.
15915 * @param $type (string) type of crop mark, one sybol per type separated by comma: A = top left, B = top right, C = bottom left, D = bottom right.
15916 * @param $color (array) crop mark color (default black).
15917 * @author Nicola Asuni
15918 * @since 4.9.000 (2010-03-26)
15921 public function cropMark($x, $y, $w, $h, $type='A,B,C,D', $color=array(0,0,0)) {
15922 $this->SetLineStyle(array('width' => (0.5 / $this->k
), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $color));
15923 $crops = explode(',', $type);
15924 $numcrops = count($crops); // number of crop marks to print
15925 $dw = $w / 4; // horizontal space to leave before the intersection point
15926 $dh = $h / 4; // vertical space to leave before the intersection point
15927 foreach ($crops as $crop) {
15974 $this->Line($x1, $y1, $x2, $y2);
15975 $this->Line($x3, $y3, $x4, $y4);
15980 * Paints a registration mark
15981 * @param $x (float) abscissa of the registration mark center.
15982 * @param $y (float) ordinate of the registration mark center.
15983 * @param $r (float) radius of the crop mark.
15984 * @param $double (boolean) if true print two concentric crop marks.
15985 * @param $cola (array) crop mark color (default black).
15986 * @param $colb (array) second crop mark color.
15987 * @author Nicola Asuni
15988 * @since 4.9.000 (2010-03-26)
15991 public function registrationMark($x, $y, $r, $double=false, $cola=array(0,0,0), $colb=array(255,255,255)) {
15992 $line_style = array('width' => (0.5 / $this->k
), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $cola);
15993 $this->SetFillColorArray($cola);
15994 $this->PieSector($x, $y, $r, 90, 180, 'F');
15995 $this->PieSector($x, $y, $r, 270, 360, 'F');
15996 $this->Circle($x, $y, $r, 0, 360, 'C', $line_style, array(), 8);
15999 $this->SetFillColorArray($colb);
16000 $this->PieSector($x, $y, $r2, 90, 180, 'F');
16001 $this->PieSector($x, $y, $r2, 270, 360, 'F');
16002 $this->SetFillColorArray($cola);
16003 $this->PieSector($x, $y, $r2, 0, 90, 'F');
16004 $this->PieSector($x, $y, $r2, 180, 270, 'F');
16005 $this->Circle($x, $y, $r2, 0, 360, 'C', $line_style, array(), 8);
16010 * Paints a linear colour gradient.
16011 * @param $x (float) abscissa of the top left corner of the rectangle.
16012 * @param $y (float) ordinate of the top left corner of the rectangle.
16013 * @param $w (float) width of the rectangle.
16014 * @param $h (float) height of the rectangle.
16015 * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
16016 * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
16017 * @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).
16018 * @author Andreas Würmser, Nicola Asuni
16019 * @since 3.1.000 (2008-06-09)
16022 public function LinearGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0,0,1,0)) {
16023 $this->Clip($x, $y, $w, $h);
16024 $this->Gradient(2, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
16028 * Paints a radial colour gradient.
16029 * @param $x (float) abscissa of the top left corner of the rectangle.
16030 * @param $y (float) ordinate of the top left corner of the rectangle.
16031 * @param $w (float) width of the rectangle.
16032 * @param $h (float) height of the rectangle.
16033 * @param $col1 (array) first color (Grayscale, RGB or CMYK components).
16034 * @param $col2 (array) second color (Grayscale, RGB or CMYK components).
16035 * @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.
16036 * @author Andreas Würmser, Nicola Asuni
16037 * @since 3.1.000 (2008-06-09)
16040 public function RadialGradient($x, $y, $w, $h, $col1=array(), $col2=array(), $coords=array(0.5,0.5,0.5,0.5,1)) {
16041 $this->Clip($x, $y, $w, $h);
16042 $this->Gradient(3, $coords, array(array('color' => $col1, 'offset' => 0, 'exponent' => 1), array('color' => $col2, 'offset' => 1, 'exponent' => 1)), array(), false);
16046 * Paints a coons patch mesh.
16047 * @param $x (float) abscissa of the top left corner of the rectangle.
16048 * @param $y (float) ordinate of the top left corner of the rectangle.
16049 * @param $w (float) width of the rectangle.
16050 * @param $h (float) height of the rectangle.
16051 * @param $col1 (array) first color (lower left corner) (RGB components).
16052 * @param $col2 (array) second color (lower right corner) (RGB components).
16053 * @param $col3 (array) third color (upper right corner) (RGB components).
16054 * @param $col4 (array) fourth color (upper left corner) (RGB components).
16055 * @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>
16056 * @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
16057 * @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
16058 * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
16059 * @author Andreas Würmser, Nicola Asuni
16060 * @since 3.1.000 (2008-06-09)
16063 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) {
16064 $this->Clip($x, $y, $w, $h);
16065 $n = count($this->gradients
) +
1;
16066 $this->gradients
[$n] = array();
16067 $this->gradients
[$n]['type'] = 6; //coons patch mesh
16068 $this->gradients
[$n]['coords'] = array();
16069 $this->gradients
[$n]['antialias'] = $antialias;
16070 $this->gradients
[$n]['colors'] = array();
16071 $this->gradients
[$n]['transparency'] = false;
16072 //check the coords array if it is the simple array or the multi patch array
16073 if (!isset($coords[0]['f'])) {
16074 //simple array -> convert to multi patch array
16075 if (!isset($col1[1])) {
16076 $col1[1] = $col1[2] = $col1[0];
16078 if (!isset($col2[1])) {
16079 $col2[1] = $col2[2] = $col2[0];
16081 if (!isset($col3[1])) {
16082 $col3[1] = $col3[2] = $col3[0];
16084 if (!isset($col4[1])) {
16085 $col4[1] = $col4[2] = $col4[0];
16087 $patch_array[0]['f'] = 0;
16088 $patch_array[0]['points'] = $coords;
16089 $patch_array[0]['colors'][0]['r'] = $col1[0];
16090 $patch_array[0]['colors'][0]['g'] = $col1[1];
16091 $patch_array[0]['colors'][0]['b'] = $col1[2];
16092 $patch_array[0]['colors'][1]['r'] = $col2[0];
16093 $patch_array[0]['colors'][1]['g'] = $col2[1];
16094 $patch_array[0]['colors'][1]['b'] = $col2[2];
16095 $patch_array[0]['colors'][2]['r'] = $col3[0];
16096 $patch_array[0]['colors'][2]['g'] = $col3[1];
16097 $patch_array[0]['colors'][2]['b'] = $col3[2];
16098 $patch_array[0]['colors'][3]['r'] = $col4[0];
16099 $patch_array[0]['colors'][3]['g'] = $col4[1];
16100 $patch_array[0]['colors'][3]['b'] = $col4[2];
16102 //multi patch array
16103 $patch_array = $coords;
16105 $bpcd = 65535; //16 bits per coordinate
16106 //build the data stream
16107 $this->gradients
[$n]['stream'] = '';
16108 $count_patch = count($patch_array);
16109 for ($i=0; $i < $count_patch; ++
$i) {
16110 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
16111 $count_points = count($patch_array[$i]['points']);
16112 for ($j=0; $j < $count_points; ++
$j) {
16113 //each point as 16 bit
16114 $patch_array[$i]['points'][$j] = (($patch_array[$i]['points'][$j] - $coords_min) / ($coords_max - $coords_min)) * $bpcd;
16115 if ($patch_array[$i]['points'][$j] < 0) {
16116 $patch_array[$i]['points'][$j] = 0;
16118 if ($patch_array[$i]['points'][$j] > $bpcd) {
16119 $patch_array[$i]['points'][$j] = $bpcd;
16121 $this->gradients
[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] / 256));
16122 $this->gradients
[$n]['stream'] .= chr(floor($patch_array[$i]['points'][$j] %
256));
16124 $count_cols = count($patch_array[$i]['colors']);
16125 for ($j=0; $j < $count_cols; ++
$j) {
16126 //each color component as 8 bit
16127 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['r']);
16128 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['g']);
16129 $this->gradients
[$n]['stream'] .= chr($patch_array[$i]['colors'][$j]['b']);
16132 //paint the gradient
16133 $this->_out('/Sh'.$n.' sh');
16134 //restore previous Graphic State
16139 * Set a rectangular clipping area.
16140 * @param $x (float) abscissa of the top left corner of the rectangle (or top right corner for RTL mode).
16141 * @param $y (float) ordinate of the top left corner of the rectangle.
16142 * @param $w (float) width of the rectangle.
16143 * @param $h (float) height of the rectangle.
16144 * @author Andreas Würmser, Nicola Asuni
16145 * @since 3.1.000 (2008-06-09)
16148 protected function Clip($x, $y, $w, $h) {
16150 $x = $this->w
- $x - $w;
16152 //save current Graphic State
16154 //set clipping area
16155 $s .= sprintf(' %.2F %.2F %.2F %.2F re W n', $x*$this->k
, ($this->h
-$y)*$this->k
, $w*$this->k
, -$h*$this->k
);
16156 //set up transformation matrix for gradient
16157 $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k
, $h*$this->k
, $x*$this->k
, ($this->h
-($y+
$h))*$this->k
);
16163 * @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)
16164 * @param $coords (array) array of coordinates.
16165 * @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).
16166 * @param $background (array) An array of colour components appropriate to the colour space, specifying a single background colour value.
16167 * @param $antialias (boolean) A flag indicating whether to filter the shading function to prevent aliasing artifacts.
16168 * @author Nicola Asuni
16169 * @since 3.1.000 (2008-06-09)
16172 public function Gradient($type, $coords, $stops, $background=array(), $antialias=false) {
16173 $n = count($this->gradients
) +
1;
16174 $this->gradients
[$n] = array();
16175 $this->gradients
[$n]['type'] = $type;
16176 $this->gradients
[$n]['coords'] = $coords;
16177 $this->gradients
[$n]['antialias'] = $antialias;
16178 $this->gradients
[$n]['colors'] = array();
16179 $this->gradients
[$n]['transparency'] = false;
16181 $numcolspace = count($stops[0]['color']);
16182 $bcolor = array_values($background);
16183 switch($numcolspace) {
16185 $this->gradients
[$n]['colspace'] = 'DeviceCMYK';
16186 if (!empty($background)) {
16187 $this->gradients
[$n]['background'] = sprintf('%.3F %.3F %.3F %.3F', $bcolor[0]/100, $bcolor[1]/100, $bcolor[2]/100, $bcolor[3]/100);
16192 $this->gradients
[$n]['colspace'] = 'DeviceRGB';
16193 if (!empty($background)) {
16194 $this->gradients
[$n]['background'] = sprintf('%.3F %.3F %.3F', $bcolor[0]/255, $bcolor[1]/255, $bcolor[2]/255);
16198 case 1: { // Gray scale
16199 $this->gradients
[$n]['colspace'] = 'DeviceGray';
16200 if (!empty($background)) {
16201 $this->gradients
[$n]['background'] = sprintf('%.3F', $bcolor[0]/255);
16206 $num_stops = count($stops);
16207 $last_stop_id = $num_stops - 1;
16208 foreach ($stops as $key => $stop) {
16209 $this->gradients
[$n]['colors'][$key] = array();
16210 // offset represents a location along the gradient vector
16211 if (isset($stop['offset'])) {
16212 $this->gradients
[$n]['colors'][$key]['offset'] = $stop['offset'];
16215 $this->gradients
[$n]['colors'][$key]['offset'] = 0;
16216 } elseif ($key == $last_stop_id) {
16217 $this->gradients
[$n]['colors'][$key]['offset'] = 1;
16219 $offsetstep = (1 - $this->gradients
[$n]['colors'][($key - 1)]['offset']) / ($num_stops - $key);
16220 $this->gradients
[$n]['colors'][$key]['offset'] = $this->gradients
[$n]['colors'][($key - 1)]['offset'] +
$offsetstep;
16223 if (isset($stop['opacity'])) {
16224 $this->gradients
[$n]['colors'][$key]['opacity'] = $stop['opacity'];
16225 if ($stop['opacity'] < 1) {
16226 $this->gradients
[$n]['transparency'] = true;
16229 $this->gradients
[$n]['colors'][$key]['opacity'] = 1;
16231 // exponent for the exponential interpolation function
16232 if (isset($stop['exponent'])) {
16233 $this->gradients
[$n]['colors'][$key]['exponent'] = $stop['exponent'];
16235 $this->gradients
[$n]['colors'][$key]['exponent'] = 1;
16238 $color = array_values($stop['color']);
16239 switch($numcolspace) {
16241 $this->gradients
[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F %.3F', $color[0]/100, $color[1]/100, $color[2]/100, $color[3]/100);
16245 $this->gradients
[$n]['colors'][$key]['color'] = sprintf('%.3F %.3F %.3F', $color[0]/255, $color[1]/255, $color[2]/255);
16248 case 1: { // Gray scale
16249 $this->gradients
[$n]['colors'][$key]['color'] = sprintf('%.3F', $color[0]/255);
16254 if ($this->gradients
[$n]['transparency']) {
16255 // paint luminosity gradient
16256 $this->_out('/TGS'.$n.' gs');
16258 //paint the gradient
16259 $this->_out('/Sh'.$n.' sh');
16260 //restore previous Graphic State
16265 * Output gradient shaders.
16266 * @author Nicola Asuni
16267 * @since 3.1.000 (2008-06-09)
16270 function _putshaders() {
16271 $idt = count($this->gradients
); //index for transparency gradients
16272 foreach ($this->gradients
as $id => $grad) {
16273 if (($grad['type'] == 2) OR ($grad['type'] == 3)) {
16274 $fc = $this->_newobj();
16276 $out .= ' /FunctionType 3';
16277 $out .= ' /Domain [0 1]';
16282 $num_cols = count($grad['colors']);
16283 $lastcols = $num_cols - 1;
16284 for ($i = 1; $i < $num_cols; ++
$i) {
16285 $functions .= ($fc +
$i).' 0 R ';
16286 if ($i < $lastcols) {
16287 $bounds .= sprintf('%.3F ', $grad['colors'][$i]['offset']);
16291 $out .= ' /Functions ['.trim($functions).']';
16292 $out .= ' /Bounds ['.trim($bounds).']';
16293 $out .= ' /Encode ['.trim($encode).']';
16295 $out .= "\n".'endobj';
16297 for ($i = 1; $i < $num_cols; ++
$i) {
16300 $out .= ' /FunctionType 2';
16301 $out .= ' /Domain [0 1]';
16302 $out .= ' /C0 ['.$grad['colors'][($i - 1)]['color'].']';
16303 $out .= ' /C1 ['.$grad['colors'][$i]['color'].']';
16304 $out .= ' /N '.$grad['colors'][$i]['exponent'];
16306 $out .= "\n".'endobj';
16309 // set transparency fuctions
16310 if ($grad['transparency']) {
16311 $ft = $this->_newobj();
16313 $out .= ' /FunctionType 3';
16314 $out .= ' /Domain [0 1]';
16317 $num_cols = count($grad['colors']);
16318 for ($i = 1; $i < $num_cols; ++
$i) {
16319 $functions .= ($ft +
$i).' 0 R ';
16321 $out .= ' /Functions ['.trim($functions).']';
16322 $out .= ' /Bounds ['.trim($bounds).']';
16323 $out .= ' /Encode ['.trim($encode).']';
16325 $out .= "\n".'endobj';
16327 for ($i = 1; $i < $num_cols; ++
$i) {
16330 $out .= ' /FunctionType 2';
16331 $out .= ' /Domain [0 1]';
16332 $out .= ' /C0 ['.$grad['colors'][($i - 1)]['opacity'].']';
16333 $out .= ' /C1 ['.$grad['colors'][$i]['opacity'].']';
16334 $out .= ' /N '.$grad['colors'][$i]['exponent'];
16336 $out .= "\n".'endobj';
16341 // set shading object
16343 $out = '<< /ShadingType '.$grad['type'];
16344 if (isset($grad['colspace'])) {
16345 $out .= ' /ColorSpace /'.$grad['colspace'];
16347 $out .= ' /ColorSpace /DeviceRGB';
16349 if (isset($grad['background']) AND !empty($grad['background'])) {
16350 $out .= ' /Background ['.$grad['background'].']';
16352 if (isset($grad['antialias']) AND ($grad['antialias'] === true)) {
16353 $out .= ' /AntiAlias true';
16355 if ($grad['type'] == 2) {
16356 $out .= ' '.sprintf('/Coords [%.3F %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3]);
16357 $out .= ' /Domain [0 1]';
16358 $out .= ' /Function '.$fc.' 0 R';
16359 $out .= ' /Extend [true true]';
16361 } elseif ($grad['type'] == 3) {
16362 //x0, y0, r0, x1, y1, r1
16363 //at this this time radius of inner circle is 0
16364 $out .= ' '.sprintf('/Coords [%.3F %.3F 0 %.3F %.3F %.3F]', $grad['coords'][0], $grad['coords'][1], $grad['coords'][2], $grad['coords'][3], $grad['coords'][4]);
16365 $out .= ' /Domain [0 1]';
16366 $out .= ' /Function '.$fc.' 0 R';
16367 $out .= ' /Extend [true true]';
16369 } elseif ($grad['type'] == 6) {
16370 $out .= ' /BitsPerCoordinate 16';
16371 $out .= ' /BitsPerComponent 8';
16372 $out .= ' /Decode[0 1 0 1 0 1 0 1 0 1]';
16373 $out .= ' /BitsPerFlag 8';
16374 $stream = $this->_getrawstream($grad['stream']);
16375 $out .= ' /Length '.strlen($stream);
16377 $out .= ' stream'."\n".$stream."\n".'endstream';
16379 $out .= "\n".'endobj';
16381 if ($grad['transparency']) {
16382 $shading_transparency = preg_replace('/\/ColorSpace \/[^\s]+/si', '/ColorSpace /DeviceGray', $out);
16383 $shading_transparency = preg_replace('/\/Function [0-9]+ /si', '/Function '.$ft.' ', $shading_transparency);
16385 $this->gradients
[$id]['id'] = $this->n
;
16386 // set pattern object
16388 $out = '<< /Type /Pattern /PatternType 2';
16389 $out .= ' /Shading '.$this->gradients
[$id]['id'].' 0 R';
16391 $out .= "\n".'endobj';
16393 $this->gradients
[$id]['pattern'] = $this->n
;
16394 // set shading and pattern for transparency mask
16395 if ($grad['transparency']) {
16396 // luminosity pattern
16397 $idgs = $id +
$idt;
16399 $this->_out($shading_transparency);
16400 $this->gradients
[$idgs]['id'] = $this->n
;
16402 $out = '<< /Type /Pattern /PatternType 2';
16403 $out .= ' /Shading '.$this->gradients
[$idgs]['id'].' 0 R';
16405 $out .= "\n".'endobj';
16407 $this->gradients
[$idgs]['pattern'] = $this->n
;
16408 // luminosity XObject
16409 $oid = $this->_newobj();
16410 $this->xobjects
['LX'.$oid] = array('n' => $oid);
16412 $stream = 'q /a0 gs /Pattern cs /p'.$idgs.' scn 0 0 '.$this->wPt
.' '.$this->hPt
.' re f Q';
16413 if ($this->compress
) {
16414 $filter = ' /Filter /FlateDecode';
16415 $stream = gzcompress($stream);
16417 $stream = $this->_getrawstream($stream);
16418 $out = '<< /Type /XObject /Subtype /Form /FormType 1'.$filter;
16419 $out .= ' /Length '.strlen($stream);
16420 $rect = sprintf('%.2F %.2F', $this->wPt
, $this->hPt
);
16421 $out .= ' /BBox [0 0 '.$rect.']';
16422 $out .= ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>';
16423 $out .= ' /Resources <<';
16424 $out .= ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>';
16425 $out .= ' /Pattern << /p'.$idgs.' '.$this->gradients
[$idgs]['pattern'].' 0 R >>';
16428 $out .= ' stream'."\n".$stream."\n".'endstream';
16429 $out .= "\n".'endobj';
16433 $out = '<< /Type /Mask /S /Luminosity /G '.($this->n
- 1).' 0 R >>'."\n".'endobj';
16437 $out = '<< /Type /ExtGState /SMask '.($this->n
- 1).' 0 R /AIS false >>'."\n".'endobj';
16439 $this->extgstates
[] = array('n' => $this->n
, 'name' => 'TGS'.$id);
16445 * Draw the sector of a circle.
16446 * It can be used for instance to render pie charts.
16447 * @param $xc (float) abscissa of the center.
16448 * @param $yc (float) ordinate of the center.
16449 * @param $r (float) radius.
16450 * @param $a (float) start angle (in degrees).
16451 * @param $b (float) end angle (in degrees).
16452 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
16453 * @param $cw: (float) indicates whether to go clockwise (default: true).
16454 * @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.
16455 * @author Maxime Delorme, Nicola Asuni
16456 * @since 3.1.000 (2008-06-09)
16459 public function PieSector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90) {
16460 $this->PieSectorXY($xc, $yc, $r, $r, $a, $b, $style, $cw, $o);
16464 * Draw the sector of an ellipse.
16465 * It can be used for instance to render pie charts.
16466 * @param $xc (float) abscissa of the center.
16467 * @param $yc (float) ordinate of the center.
16468 * @param $rx (float) the x-axis radius.
16469 * @param $ry (float) the y-axis radius.
16470 * @param $a (float) start angle (in degrees).
16471 * @param $b (float) end angle (in degrees).
16472 * @param $style (string) Style of rendering. See the getPathPaintOperator() function for more information.
16473 * @param $cw: (float) indicates whether to go clockwise.
16474 * @param $o: (float) origin of angles (0 for 3 o'clock, 90 for noon, 180 for 9 o'clock, 270 for 6 o'clock).
16475 * @param $nc (integer) Number of curves used to draw a 90 degrees portion of arc.
16476 * @author Maxime Delorme, Nicola Asuni
16477 * @since 3.1.000 (2008-06-09)
16480 public function PieSectorXY($xc, $yc, $rx, $ry, $a, $b, $style='FD', $cw=false, $o=0, $nc=2) {
16482 $xc = $this->w
- $xc;
16484 $op = $this->getPathPaintOperator($style);
16486 $line_style = array();
16490 $b = 360 - $a +
$o;
16491 $a = 360 - $d +
$o;
16496 $this->_outellipticalarc($xc, $yc, $rx, $ry, 0, $a, $b, true, $nc);
16501 * Embed vector-based Adobe Illustrator (AI) or AI-compatible EPS files.
16502 * NOTE: EPS is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
16503 * Only vector drawing is supported, not text or bitmap.
16504 * 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).
16505 * @param $file (string) Name of the file containing the image or a '@' character followed by the EPS/AI data string.
16506 * @param $x (float) Abscissa of the upper-left corner.
16507 * @param $y (float) Ordinate of the upper-left corner.
16508 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
16509 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
16510 * @param $link (mixed) URL or identifier returned by AddLink().
16511 * @param $useBoundingBox (boolean) specifies whether to position the bounding box (true) or the complete canvas (false) at location (x,y). Default value is true.
16512 * @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>
16513 * @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>
16514 * @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)))
16515 * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
16516 * @param $fixoutvals (boolean) if true remove values outside the bounding box.
16517 * @author Valentin Schmidt, Nicola Asuni
16518 * @since 3.1.000 (2008-06-09)
16521 public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) {
16522 if ($this->rasterize_vector_images
AND ($w > 0) AND ($h > 0)) {
16523 // convert EPS to raster image using GD or ImageMagick libraries
16524 return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
16532 // check page for no-write regions and adapt page margins if necessary
16533 $this->checkPageRegions($h, $x, $y);
16535 if ($file{0} === '@') { // image from string
16536 $data = substr($file, 1);
16537 } else { // EPS/AI file
16538 $data = file_get_contents($file);
16540 if ($data === false) {
16541 $this->Error('EPS file not found: '.$file);
16544 // EPS/AI compatibility check (only checks files created by Adobe Illustrator!)
16545 preg_match("/%%Creator:([^\r\n]+)/", $data, $regs); # find Creator
16546 if (count($regs) > 1) {
16547 $version_str = trim($regs[1]); # e.g. "Adobe Illustrator(R) 8.0"
16548 if (strpos($version_str, 'Adobe Illustrator') !== false) {
16549 $versexp = explode(' ', $version_str);
16550 $version = (float)array_pop($versexp);
16551 if ($version >= 9) {
16552 $this->Error('This version of Adobe Illustrator file is not supported: '.$file);
16556 // strip binary bytes in front of PS-header
16557 $start = strpos($data, '%!PS-Adobe');
16559 $data = substr($data, $start);
16561 // find BoundingBox params
16562 preg_match("/%%BoundingBox:([^\r\n]+)/", $data, $regs);
16563 if (count($regs) > 1) {
16564 list($x1, $y1, $x2, $y2) = explode(' ', trim($regs[1]));
16566 $this->Error('No BoundingBox found in EPS/AI file: '.$file);
16568 $start = strpos($data, '%%EndSetup');
16569 if ($start === false) {
16570 $start = strpos($data, '%%EndProlog');
16572 if ($start === false) {
16573 $start = strpos($data, '%%BoundingBox');
16575 $data = substr($data, $start);
16576 $end = strpos($data, '%%PageTrailer');
16577 if ($end===false) {
16578 $end = strpos($data, 'showpage');
16581 $data = substr($data, 0, $end);
16583 // calculate image width and height on document
16584 if (($w <= 0) AND ($h <= 0)) {
16585 $w = ($x2 - $x1) / $k;
16586 $h = ($y2 - $y1) / $k;
16587 } elseif ($w <= 0) {
16588 $w = ($x2-$x1) / $k * ($h / (($y2 - $y1) / $k));
16589 } elseif ($h <= 0) {
16590 $h = ($y2 - $y1) / $k * ($w / (($x2 - $x1) / $k));
16592 // fit the image on available space
16593 $this->fitBlock($w, $h, $x, $y, $fitonpage);
16594 if ($this->rasterize_vector_images
) {
16595 // convert EPS to raster image using GD or ImageMagick libraries
16596 return $this->Image($file, $x, $y, $w, $h, 'EPS', $link, $align, true, 300, $palign, false, false, $border, false, false, $fitonpage);
16598 // set scaling factors
16599 $scale_x = $w / (($x2 - $x1) / $k);
16600 $scale_y = $h / (($y2 - $y1) / $k);
16602 $this->img_rb_y
= $y +
$h;
16605 if ($palign == 'L') {
16606 $ximg = $this->lMargin
;
16607 } elseif ($palign == 'C') {
16608 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
16609 } elseif ($palign == 'R') {
16610 $ximg = $this->w
- $this->rMargin
- $w;
16614 $this->img_rb_x
= $ximg;
16616 if ($palign == 'L') {
16617 $ximg = $this->lMargin
;
16618 } elseif ($palign == 'C') {
16619 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
16620 } elseif ($palign == 'R') {
16621 $ximg = $this->w
- $this->rMargin
- $w;
16625 $this->img_rb_x
= $ximg +
$w;
16627 if ($useBoundingBox) {
16628 $dx = $ximg * $k - $x1;
16629 $dy = $y * $k - $y1;
16634 // save the current graphic state
16635 $this->_out('q'.$this->epsmarker
);
16637 $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', 1, 0, 0, 1, $dx, $dy +
($this->hPt
- (2 * $y * $k) - ($y2 - $y1))));
16639 if (isset($scale_x)) {
16640 $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
16642 // handle pc/unix/mac line endings
16643 $lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY
);
16645 $cnt = count($lines);
16646 for ($i=0; $i < $cnt; ++
$i) {
16647 $line = $lines[$i];
16648 if (($line == '') OR ($line{0} == '%')) {
16651 $len = strlen($line);
16652 // check for spot color names
16654 if (strcasecmp('x', substr(trim($line), -1)) == 0) {
16655 if (preg_match('/\([^\)]*\)/', $line, $matches) > 0) {
16656 // extract spot color name
16657 $color_name = $matches[0];
16658 // remove color name from string
16659 $line = str_replace(' '.$color_name, '', $line);
16660 // remove pharentesis from color name
16661 $color_name = substr($color_name, 1, -1);
16664 $chunks = explode(' ', $line);
16665 $cmd = trim(array_pop($chunks));
16667 if (($cmd == 'Xa') OR ($cmd == 'XA')) {
16668 $b = array_pop($chunks);
16669 $g = array_pop($chunks);
16670 $r = array_pop($chunks);
16671 $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!
16676 // check for values outside the bounding box
16681 // skip values outside bounding box
16682 foreach ($chunks as $key => $val) {
16683 if ((($key %
2) == 0) AND (($val < $x1) OR ($val > $x2))) {
16685 } elseif ((($key %
2) != 0) AND (($val < $y1) OR ($val > $y2))) {
16713 $this->_out($line);
16716 case 'x': {// custom fill color
16717 if (empty($color_name)) {
16719 list($col_c, $col_m, $col_y, $col_k) = $chunks;
16720 $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' k');
16722 // Spot Color (CMYK + tint)
16723 list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
16724 $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
16725 $color_cmd = sprintf('/CS%d cs %.3F scn', $this->spot_colors
[$color_name]['i'], (1 - $col_t));
16726 $this->_out($color_cmd);
16730 case 'X': { // custom stroke color
16731 if (empty($color_name)) {
16733 list($col_c, $col_m, $col_y, $col_k) = $chunks;
16734 $this->_out(''.$col_c.' '.$col_m.' '.$col_y.' '.$col_k.' K');
16736 // Spot Color (CMYK + tint)
16737 list($col_c, $col_m, $col_y, $col_k, $col_t) = $chunks;
16738 $this->AddSpotColor($color_name, ($col_c * 100), ($col_m * 100), ($col_y * 100), ($col_k * 100));
16739 $color_cmd = sprintf('/CS%d CS %.3F SCN', $this->spot_colors
[$color_name]['i'], (1 - $col_t));
16740 $this->_out($color_cmd);
16752 $line{$len-1} = strtolower($cmd);
16753 $this->_out($line);
16758 $this->_out($cmd . '*');
16765 $max = min(($i +
5), $cnt);
16766 for ($j = ($i +
1); $j < $max; ++
$j) {
16767 $isU = ($isU OR (($lines[$j] == 'U') OR ($lines[$j] == '*U')));
16787 // restore previous graphic state
16788 $this->_out($this->epsmarker
.'Q');
16789 if (!empty($border)) {
16797 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
16802 $this->Link($ximg, $y, $w, $h, $link, 0);
16804 // set pointer to align the next text/objects
16808 $this->x
= $this->img_rb_x
;
16812 $this->y
= $y +
round($h/2);
16813 $this->x
= $this->img_rb_x
;
16817 $this->y
= $this->img_rb_y
;
16818 $this->x
= $this->img_rb_x
;
16822 $this->SetY($this->img_rb_y
);
16829 $this->endlinex
= $this->img_rb_x
;
16833 * Set document barcode.
16834 * @param $bc (string) barcode
16837 public function setBarcode($bc='') {
16838 $this->barcode
= $bc;
16842 * Get current barcode.
16845 * @since 4.0.012 (2008-07-24)
16847 public function getBarcode() {
16848 return $this->barcode
;
16852 * Print a Linear Barcode.
16853 * @param $code (string) code to print
16854 * @param $type (string) type of barcode (see barcodes.php for supported formats).
16855 * @param $x (int) x position in user units (empty string = current x position)
16856 * @param $y (int) y position in user units (empty string = current y position)
16857 * @param $w (int) width in user units (empty string = remaining page width)
16858 * @param $h (int) height in user units (empty string = remaining page height)
16859 * @param $xres (float) width of the smallest bar in user units (empty string = default value = 0.4mm)
16860 * @param $style (array) array of options:<ul>
16861 * <li>boolean $style['border'] if true prints a border</li>
16862 * <li>int $style['padding'] padding to leave around the barcode in user units (set to 'auto' for automatic padding)</li>
16863 * <li>int $style['hpadding'] horizontal padding in user units (set to 'auto' for automatic padding)</li>
16864 * <li>int $style['vpadding'] vertical padding in user units (set to 'auto' for automatic padding)</li>
16865 * <li>array $style['fgcolor'] color array for bars and text</li>
16866 * <li>mixed $style['bgcolor'] color array for background (set to false for transparent)</li>
16867 * <li>boolean $style['text'] if true prints text below the barcode</li>
16868 * <li>string $style['label'] override default label</li>
16869 * <li>string $style['font'] font name for text</li><li>int $style['fontsize'] font size for text</li>
16870 * <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>
16871 * <li>string $style['position'] horizontal position of the containing barcode cell on the page: L = left margin; C = center; R = right margin.</li>
16872 * <li>string $style['align'] horizontal position of the barcode on the containing rectangle: L = left; C = center; R = right.</li>
16873 * <li>string $style['stretch'] if true stretch the barcode to best fit the available width, otherwise uses $xres resolution for a single bar.</li>
16874 * <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>
16875 * <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>
16876 * @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>
16877 * @author Nicola Asuni
16878 * @since 3.1.000 (2008-06-09)
16881 public function write1DBarcode($code, $type, $x='', $y='', $w='', $h='', $xres='', $style='', $align='') {
16882 if ($this->empty_string(trim($code))) {
16885 require_once(dirname(__FILE__
).'/barcodes.php');
16886 // save current graphic settings
16887 $gvars = $this->getGraphicVars();
16888 // create new barcode object
16889 $barcodeobj = new TCPDFBarcode($code, $type);
16890 $arrcode = $barcodeobj->getBarcodeArray();
16891 if ($arrcode === false) {
16892 $this->Error('Error in 1D barcode string');
16894 // set default values
16895 if (!isset($style['position'])) {
16896 $style['position'] = '';
16897 } elseif ($style['position'] == 'S') {
16898 // keep this for backward compatibility
16899 $style['position'] = '';
16900 $style['stretch'] = true;
16902 if (!isset($style['fitwidth'])) {
16903 if (!isset($style['stretch'])) {
16904 $style['fitwidth'] = true;
16906 $style['fitwidth'] = false;
16909 if ($style['fitwidth']) {
16911 $style['stretch'] = false;
16913 if (!isset($style['stretch'])) {
16914 if (($w === '') OR ($w <= 0)) {
16915 $style['stretch'] = false;
16917 $style['stretch'] = true;
16920 if (!isset($style['fgcolor'])) {
16921 $style['fgcolor'] = array(0,0,0); // default black
16923 if (!isset($style['bgcolor'])) {
16924 $style['bgcolor'] = false; // default transparent
16926 if (!isset($style['border'])) {
16927 $style['border'] = false;
16930 if (!isset($style['text'])) {
16931 $style['text'] = false;
16933 if ($style['text'] AND isset($style['font'])) {
16934 if (isset($style['fontsize'])) {
16935 $fontsize = $style['fontsize'];
16937 $this->SetFont($style['font'], '', $fontsize);
16939 if (!isset($style['stretchtext'])) {
16940 $style['stretchtext'] = 4;
16948 // check page for no-write regions and adapt page margins if necessary
16949 $this->checkPageRegions($h, $x, $y);
16950 if (($w === '') OR ($w <= 0)) {
16952 $w = $x - $this->lMargin
;
16954 $w = $this->w
- $this->rMargin
- $x;
16958 if (!isset($style['padding'])) {
16960 } elseif ($style['padding'] === 'auto') {
16961 $padding = 10 * ($w / ($arrcode['maxw'] +
20));
16963 $padding = floatval($style['padding']);
16965 // horizontal padding
16966 if (!isset($style['hpadding'])) {
16967 $hpadding = $padding;
16968 } elseif ($style['hpadding'] === 'auto') {
16969 $hpadding = 10 * ($w / ($arrcode['maxw'] +
20));
16971 $hpadding = floatval($style['hpadding']);
16973 // vertical padding
16974 if (!isset($style['vpadding'])) {
16975 $vpadding = $padding;
16976 } elseif ($style['vpadding'] === 'auto') {
16977 $vpadding = ($hpadding / 2);
16979 $vpadding = floatval($style['vpadding']);
16981 // calculate xres (single bar width)
16982 $max_xres = ($w - (2 * $hpadding)) / $arrcode['maxw'];
16983 if ($style['stretch']) {
16986 if ($this->empty_string($xres)) {
16987 $xres = (0.141 * $this->k
); // default bar width = 0.4 mm
16989 if ($xres > $max_xres) {
16990 // correct xres to fit on $w
16993 if ((isset($style['padding']) AND ($style['padding'] === 'auto'))
16994 OR (isset($style['hpadding']) AND ($style['hpadding'] === 'auto'))) {
16995 $hpadding = 10 * $xres;
16996 if (isset($style['vpadding']) AND ($style['vpadding'] === 'auto')) {
16997 $vpadding = ($hpadding / 2);
17001 if ($style['fitwidth']) {
17003 $w = (($arrcode['maxw'] * $xres) +
(2 * $hpadding));
17004 if (isset($style['cellfitalign'])) {
17005 switch ($style['cellfitalign']) {
17008 $x -= ($wold - $w);
17014 $x +
= ($wold - $w);
17020 $x -= (($wold - $w) / 2);
17022 $x +
= (($wold - $w) / 2);
17032 $text_height = ($this->cell_height_ratio
* $fontsize / $this->k
);
17034 if (($h === '') OR ($h <= 0)) {
17035 // set default height
17036 $h = (($arrcode['maxw'] * $xres) / 3) +
(2 * $vpadding) +
$text_height;
17038 $barh = $h - $text_height - (2 * $vpadding);
17040 // try to reduce font or padding to fit barcode on available height
17041 if ($text_height > $h) {
17042 $fontsize = (($h * $this->k
) / (4 * $this->cell_height_ratio
));
17043 $text_height = ($this->cell_height_ratio
* $fontsize / $this->k
);
17044 $this->SetFont($style['font'], '', $fontsize);
17046 if ($vpadding > 0) {
17047 $vpadding = (($h - $text_height) / 4);
17049 $barh = $h - $text_height - (2 * $vpadding);
17051 // fit the barcode on available space
17052 $this->fitBlock($w, $h, $x, $y, false);
17054 $this->img_rb_y
= $y +
$h;
17057 if ($style['position'] == 'L') {
17058 $xpos = $this->lMargin
;
17059 } elseif ($style['position'] == 'C') {
17060 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
17061 } elseif ($style['position'] == 'R') {
17062 $xpos = $this->w
- $this->rMargin
- $w;
17066 $this->img_rb_x
= $xpos;
17068 if ($style['position'] == 'L') {
17069 $xpos = $this->lMargin
;
17070 } elseif ($style['position'] == 'C') {
17071 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
17072 } elseif ($style['position'] == 'R') {
17073 $xpos = $this->w
- $this->rMargin
- $w;
17077 $this->img_rb_x
= $xpos +
$w;
17079 $xpos_rect = $xpos;
17080 if (!isset($style['align'])) {
17081 $style['align'] = 'C';
17083 switch ($style['align']) {
17085 $xpos = $xpos_rect +
$hpadding;
17089 $xpos = $xpos_rect +
($w - ($arrcode['maxw'] * $xres)) - $hpadding;
17094 $xpos = $xpos_rect +
(($w - ($arrcode['maxw'] * $xres)) / 2);
17098 $xpos_text = $xpos;
17099 // barcode is always printed in LTR direction
17100 $tempRTL = $this->rtl
;
17101 $this->rtl
= false;
17102 // print background color
17103 if ($style['bgcolor']) {
17104 $this->Rect($xpos_rect, $y, $w, $h, $style['border'] ?
'DF' : 'F', '', $style['bgcolor']);
17105 } elseif ($style['border']) {
17106 $this->Rect($xpos_rect, $y, $w, $h, 'D');
17108 // set foreground color
17109 $this->SetDrawColorArray($style['fgcolor']);
17110 $this->SetTextColorArray($style['fgcolor']);
17112 foreach ($arrcode['bcode'] as $k => $v) {
17113 $bw = ($v['w'] * $xres);
17115 // draw a vertical bar
17116 $ypos = $y +
$vpadding +
($v['p'] * $barh / $arrcode['maxh']);
17117 $this->Rect($xpos, $ypos, $bw, ($v['h'] * $barh / $arrcode['maxh']), 'F', array(), $style['fgcolor']);
17122 if ($style['text']) {
17123 if (isset($style['label']) AND !$this->empty_string($style['label'])) {
17124 $label = $style['label'];
17128 $txtwidth = ($arrcode['maxw'] * $xres);
17129 if ($this->GetStringWidth($label) > $txtwidth) {
17130 $style['stretchtext'] = 2;
17133 $this->x
= $xpos_text;
17134 $this->y
= $y +
$vpadding +
$barh;
17135 $cellpadding = $this->cell_padding
;
17136 $this->SetCellPadding(0);
17137 $this->Cell($txtwidth, '', $label, 0, 0, 'C', 0, '', $style['stretchtext'], false, 'T', 'T');
17138 $this->cell_padding
= $cellpadding;
17140 // restore original direction
17141 $this->rtl
= $tempRTL;
17142 // restore previous settings
17143 $this->setGraphicVars($gvars);
17144 // set pointer to align the next text/objects
17148 $this->x
= $this->img_rb_x
;
17152 $this->y
= $y +
round($h / 2);
17153 $this->x
= $this->img_rb_x
;
17157 $this->y
= $this->img_rb_y
;
17158 $this->x
= $this->img_rb_x
;
17162 $this->SetY($this->img_rb_y
);
17169 $this->endlinex
= $this->img_rb_x
;
17173 * This function is DEPRECATED, please use the new write1DBarcode() function.
17174 * @param $x (int) x position in user units
17175 * @param $y (int) y position in user units
17176 * @param $w (int) width in user units
17177 * @param $h (int) height position in user units
17178 * @param $type (string) type of barcode
17179 * @param $style (string) barcode style
17180 * @param $font (string) font for text
17181 * @param $xres (int) x resolution
17182 * @param $code (string) code to print
17183 * @deprecated deprecated since version 3.1.000 (2008-06-10)
17185 * @see write1DBarcode()
17187 public function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) {
17188 // convert old settings for the new write1DBarcode() function.
17193 'stretch' => false,
17194 'fitwidth' => false,
17195 'cellfitalign' => '',
17198 'fgcolor' => array(0,0,0),
17199 'bgcolor' => false,
17206 $newstyle['border'] = true;
17209 $newstyle['bgcolor'] = false;
17212 $newstyle['position'] = 'C';
17213 } elseif ($style & 8) {
17214 $newstyle['position'] = 'L';
17215 } elseif ($style & 16) {
17216 $newstyle['position'] = 'R';
17218 if ($style & 128) {
17219 $newstyle['text'] = true;
17221 if ($style & 256) {
17222 $newstyle['stretchtext'] = 4;
17224 $this->write1DBarcode($code, $type, $x, $y, $w, $h, $xres, $newstyle, '');
17228 * Print 2D Barcode.
17229 * @param $code (string) code to print
17230 * @param $type (string) type of barcode (see 2dbarcodes.php for supported formats).
17231 * @param $x (int) x position in user units
17232 * @param $y (int) y position in user units
17233 * @param $w (int) width in user units
17234 * @param $h (int) height in user units
17235 * @param $style (array) array of options:<ul>
17236 * <li>boolean $style['border'] if true prints a border around the barcode</li>
17237 * <li>int $style['padding'] padding to leave around the barcode in barcode units (set to 'auto' for automatic padding)</li>
17238 * <li>int $style['hpadding'] horizontal padding in barcode units (set to 'auto' for automatic padding)</li>
17239 * <li>int $style['vpadding'] vertical padding in barcode units (set to 'auto' for automatic padding)</li>
17240 * <li>int $style['module_width'] width of a single module in points</li>
17241 * <li>int $style['module_height'] height of a single module in points</li>
17242 * <li>array $style['fgcolor'] color array for bars and text</li>
17243 * <li>mixed $style['bgcolor'] color array for background or false for transparent</li>
17244 * <li>string $style['position'] barcode position on the page: L = left margin; C = center; R = right margin; S = stretch</li><li>$style['module_width'] width of a single module in points</li>
17245 * <li>$style['module_height'] height of a single module in points</li></ul>
17246 * @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>
17247 * @param $distort (boolean) if true distort the barcode to fit width and height, otherwise preserve aspect ratio
17248 * @author Nicola Asuni
17249 * @since 4.5.037 (2009-04-07)
17252 public function write2DBarcode($code, $type, $x='', $y='', $w='', $h='', $style='', $align='', $distort=false) {
17253 if ($this->empty_string(trim($code))) {
17256 require_once(dirname(__FILE__
).'/2dbarcodes.php');
17257 // save current graphic settings
17258 $gvars = $this->getGraphicVars();
17259 // create new barcode object
17260 $barcodeobj = new TCPDF2DBarcode($code, $type);
17261 $arrcode = $barcodeobj->getBarcodeArray();
17262 if (($arrcode === false) OR empty($arrcode)) {
17263 $this->Error('Error in 2D barcode string');
17265 // set default values
17266 if (!isset($style['position'])) {
17267 $style['position'] = '';
17269 if (!isset($style['fgcolor'])) {
17270 $style['fgcolor'] = array(0,0,0); // default black
17272 if (!isset($style['bgcolor'])) {
17273 $style['bgcolor'] = false; // default transparent
17275 if (!isset($style['border'])) {
17276 $style['border'] = false;
17279 if (!isset($style['padding'])) {
17280 $style['padding'] = 0;
17281 } elseif ($style['padding'] === 'auto') {
17282 $style['padding'] = 4;
17284 if (!isset($style['hpadding'])) {
17285 $style['hpadding'] = $style['padding'];
17286 } elseif ($style['hpadding'] === 'auto') {
17287 $style['hpadding'] = 4;
17289 if (!isset($style['vpadding'])) {
17290 $style['vpadding'] = $style['padding'];
17291 } elseif ($style['vpadding'] === 'auto') {
17292 $style['vpadding'] = 4;
17294 // cell (module) dimension
17295 if (!isset($style['module_width'])) {
17296 $style['module_width'] = 1; // width of a single module in points
17298 if (!isset($style['module_height'])) {
17299 $style['module_height'] = 1; // height of a single module in points
17307 // check page for no-write regions and adapt page margins if necessary
17308 $this->checkPageRegions($h, $x, $y);
17309 // number of barcode columns and rows
17310 $rows = $arrcode['num_rows'];
17311 $cols = $arrcode['num_cols'];
17312 // module width and height
17313 $mw = $style['module_width'];
17314 $mh = $style['module_height'];
17315 // get max dimensions
17317 $maxw = $x - $this->lMargin
;
17319 $maxw = $this->w
- $this->rMargin
- $x;
17321 $maxh = ($this->h
- $this->tMargin
- $this->bMargin
);
17322 $ratioHW = ($rows * $mh) / ($cols * $mw);
17323 $ratioWH = ($cols * $mw) / ($rows * $mh);
17325 if (($maxw * $ratioHW) > $maxh) {
17326 $maxw = $maxh * $ratioWH;
17328 if (($maxh * $ratioWH) > $maxw) {
17329 $maxh = $maxw * $ratioHW;
17332 // set maximum dimesions
17339 $hpad = (2 * $style['hpadding']);
17340 $vpad = (2 * $style['vpadding']);
17342 if ((($w === '') OR ($w <= 0)) AND (($h === '') OR ($h <= 0))) {
17343 $w = ($cols +
$hpad) * ($mw / $this->k
);
17344 $h = ($rows +
$vpad) * ($mh / $this->k
);
17345 } elseif (($w === '') OR ($w <= 0)) {
17346 $w = $h * $ratioWH;
17347 } elseif (($h === '') OR ($h <= 0)) {
17348 $h = $w * $ratioHW;
17350 // barcode size (excluding padding)
17351 $bw = ($w * $cols) / ($cols +
$hpad);
17352 $bh = ($h * $rows) / ($rows +
$vpad);
17353 // dimension of single barcode cell unit
17357 if (($cw / $ch) > ($mw / $mh)) {
17358 // correct horizontal distortion
17359 $cw = $ch * $mw / $mh;
17361 $style['hpadding'] = ($w - $bw) / (2 * $cw);
17363 // correct vertical distortion
17364 $ch = $cw * $mh / $mw;
17366 $style['vpadding'] = ($h - $bh) / (2 * $ch);
17369 // fit the barcode on available space
17370 $this->fitBlock($w, $h, $x, $y, false);
17372 $this->img_rb_y
= $y +
$h;
17375 if ($style['position'] == 'L') {
17376 $xpos = $this->lMargin
;
17377 } elseif ($style['position'] == 'C') {
17378 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
17379 } elseif ($style['position'] == 'R') {
17380 $xpos = $this->w
- $this->rMargin
- $w;
17384 $this->img_rb_x
= $xpos;
17386 if ($style['position'] == 'L') {
17387 $xpos = $this->lMargin
;
17388 } elseif ($style['position'] == 'C') {
17389 $xpos = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
17390 } elseif ($style['position'] == 'R') {
17391 $xpos = $this->w
- $this->rMargin
- $w;
17395 $this->img_rb_x
= $xpos +
$w;
17397 $xstart = $xpos +
($style['hpadding'] * $cw);
17398 $ystart = $y +
($style['vpadding'] * $ch);
17399 // barcode is always printed in LTR direction
17400 $tempRTL = $this->rtl
;
17401 $this->rtl
= false;
17402 // print background color
17403 if ($style['bgcolor']) {
17404 $this->Rect($xpos, $y, $w, $h, $style['border'] ?
'DF' : 'F', '', $style['bgcolor']);
17405 } elseif ($style['border']) {
17406 $this->Rect($xpos, $y, $w, $h, 'D');
17408 // set foreground color
17409 $this->SetDrawColorArray($style['fgcolor']);
17410 // print barcode cells
17412 for ($r = 0; $r < $rows; ++
$r) {
17415 for ($c = 0; $c < $cols; ++
$c) {
17416 if ($arrcode['bcode'][$r][$c] == 1) {
17417 // draw a single barcode cell
17418 $this->Rect($xr, $ystart, $cw, $ch, 'F', array(), $style['fgcolor']);
17424 // restore original direction
17425 $this->rtl
= $tempRTL;
17426 // restore previous settings
17427 $this->setGraphicVars($gvars);
17428 // set pointer to align the next text/objects
17432 $this->x
= $this->img_rb_x
;
17436 $this->y
= $y +
round($h/2);
17437 $this->x
= $this->img_rb_x
;
17441 $this->y
= $this->img_rb_y
;
17442 $this->x
= $this->img_rb_x
;
17446 $this->SetY($this->img_rb_y
);
17453 $this->endlinex
= $this->img_rb_x
;
17457 * Returns an array containing current margins:
17459 <li>$ret['left'] = left margin</li>
17460 <li>$ret['right'] = right margin</li>
17461 <li>$ret['top'] = top margin</li>
17462 <li>$ret['bottom'] = bottom margin</li>
17463 <li>$ret['header'] = header margin</li>
17464 <li>$ret['footer'] = footer margin</li>
17465 <li>$ret['cell'] = cell padding array</li>
17466 <li>$ret['padding_left'] = cell left padding</li>
17467 <li>$ret['padding_top'] = cell top padding</li>
17468 <li>$ret['padding_right'] = cell right padding</li>
17469 <li>$ret['padding_bottom'] = cell bottom padding</li>
17471 * @return array containing all margins measures
17473 * @since 3.2.000 (2008-06-23)
17475 public function getMargins() {
17477 'left' => $this->lMargin
,
17478 'right' => $this->rMargin
,
17479 'top' => $this->tMargin
,
17480 'bottom' => $this->bMargin
,
17481 'header' => $this->header_margin
,
17482 'footer' => $this->footer_margin
,
17483 'cell' => $this->cell_padding
,
17484 'padding_left' => $this->cell_padding
['L'],
17485 'padding_top' => $this->cell_padding
['T'],
17486 'padding_right' => $this->cell_padding
['R'],
17487 'padding_bottom' => $this->cell_padding
['B']
17493 * Returns an array containing original margins:
17495 <li>$ret['left'] = left margin</li>
17496 <li>$ret['right'] = right margin</li>
17498 * @return array containing all margins measures
17500 * @since 4.0.012 (2008-07-24)
17502 public function getOriginalMargins() {
17504 'left' => $this->original_lMargin
,
17505 'right' => $this->original_rMargin
17511 * Returns the current font size.
17512 * @return current font size
17514 * @since 3.2.000 (2008-06-23)
17516 public function getFontSize() {
17517 return $this->FontSize
;
17521 * Returns the current font size in points unit.
17522 * @return current font size in points unit
17524 * @since 3.2.000 (2008-06-23)
17526 public function getFontSizePt() {
17527 return $this->FontSizePt
;
17531 * Returns the current font family name.
17532 * @return string current font family name
17534 * @since 4.3.008 (2008-12-05)
17536 public function getFontFamily() {
17537 return $this->FontFamily
;
17541 * Returns the current font style.
17542 * @return string current font style
17544 * @since 4.3.008 (2008-12-05)
17546 public function getFontStyle() {
17547 return $this->FontStyle
;
17551 * Cleanup HTML code (requires HTML Tidy library).
17552 * @param $html (string) htmlcode to fix
17553 * @param $default_css (string) CSS commands to add
17554 * @param $tagvs (array) parameters for setHtmlVSpace method
17555 * @param $tidy_options (array) options for tidy_parse_string function
17556 * @return string XHTML code cleaned up
17557 * @author Nicola Asuni
17559 * @since 5.9.017 (2010-11-16)
17560 * @see setHtmlVSpace()
17562 public function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='') {
17563 // configure parameters for HTML Tidy
17564 if ($tidy_options === '') {
17565 $tidy_options = array (
17567 'drop-empty-paras' => 0,
17568 'drop-proprietary-attributes' => 1,
17569 'fix-backslash' => 1,
17570 'hide-comments' => 1,
17571 'join-styles' => 1,
17572 'lower-literals' => 1,
17574 'merge-spans' => 1,
17575 'output-xhtml' => 1,
17579 //'char-encoding' => 'utf8',
17580 //'input-encoding' => 'utf8',
17581 //'output-encoding' => 'utf8'
17584 // clean up the HTML code
17585 $tidy = tidy_parse_string($html, $tidy_options);
17587 $tidy->cleanRepair();
17588 // get the CSS part
17589 $tidy_head = tidy_get_head($tidy);
17590 $css = $tidy_head->value
;
17591 $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
17592 $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
17593 $css = str_replace('/*<![CDATA[*/', '', $css);
17594 $css = str_replace('/*]]>*/', '', $css);
17595 preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
17596 $css = strtolower($matches[1]);
17597 // include default css
17598 $css = '<style>'.$default_css.$css.'</style>';
17599 // get the body part
17600 $tidy_body = tidy_get_body($tidy);
17601 $html = $tidy_body->value
;
17602 // fix some self-closing tags
17603 $html = str_replace('<br>', '<br />', $html);
17604 // remove some empty tag blocks
17605 $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
17606 $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
17607 if ($tagvs !== '') {
17608 // set vertical space for some XHTML tags
17609 $this->setHtmlVSpace($tagvs);
17611 // return the cleaned XHTML code + CSS
17616 * Extracts the CSS properties from a CSS string.
17617 * @param $cssdata (string) string containing CSS definitions.
17618 * @return An array where the keys are the CSS selectors and the values are the CSS properties.
17619 * @author Nicola Asuni
17620 * @since 5.1.000 (2010-05-25)
17623 protected function extractCSSproperties($cssdata) {
17624 if (empty($cssdata)) {
17628 $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
17629 // remove newlines and multiple spaces
17630 $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
17631 // remove some spaces
17632 $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
17633 // remove empty blocks
17634 $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
17635 // replace media type parenthesis
17636 $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
17637 $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
17639 $cssdata = trim($cssdata);
17640 // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
17641 $cssblocks = array();
17642 $matches = array();
17643 if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
17644 foreach ($matches[1] as $key => $type) {
17645 $cssblocks[$type] = $matches[2][$key];
17647 // remove media blocks
17648 $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
17650 // keep 'all' and 'print' media, other media types are discarded
17651 if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
17652 $cssdata .= $cssblocks['all'];
17654 if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
17655 $cssdata .= $cssblocks['print'];
17657 // reset css blocks array
17658 $cssblocks = array();
17659 $matches = array();
17660 // explode css data string into array
17661 if (substr($cssdata, -1) == '}') {
17662 // remove last parethesis
17663 $cssdata = substr($cssdata, 0, -1);
17665 $matches = explode('}', $cssdata);
17666 foreach ($matches as $key => $block) {
17667 // index 0 contains the CSS selector, index 1 contains CSS properties
17668 $cssblocks[$key] = explode('{', $block);
17669 if (!isset($cssblocks[$key][1])) {
17670 // remove empty definitions
17671 unset($cssblocks[$key]);
17674 // split groups of selectors (comma-separated list of selectors)
17675 foreach ($cssblocks as $key => $block) {
17676 if (strpos($block[0], ',') > 0) {
17677 $selectors = explode(',', $block[0]);
17678 foreach ($selectors as $sel) {
17679 $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
17681 unset($cssblocks[$key]);
17684 // covert array to selector => properties
17685 $cssdata = array();
17686 foreach ($cssblocks as $block) {
17687 $selector = $block[0];
17688 // calculate selector's specificity
17689 $matches = array();
17690 $a = 0; // the declaration is not from is a 'style' attribute
17691 $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
17692 $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
17693 $c +
= intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches)); // number of pseudo-classes
17694 $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9\*]+/', ' '.$selector, $matches)); // number of element names
17695 $d +
= intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
17696 $specificity = $a.$b.$c.$d;
17697 // add specificity to the beginning of the selector
17698 $cssdata[$specificity.' '.$selector] = $block[1];
17700 // sort selectors alphabetically to account for specificity
17701 ksort($cssdata, SORT_STRING
);
17707 * Returns true if the CSS selector is valid for the selected HTML tag
17708 * @param $dom (array) array of HTML tags and properties
17709 * @param $key (int) key of the current HTML tag
17710 * @param $selector (string) CSS selector string
17711 * @return true if the selector is valid, false otherwise
17713 * @since 5.1.000 (2010-05-25)
17715 protected function isValidCSSSelectorForTag($dom, $key, $selector) {
17716 $valid = false; // value to be returned
17717 $tag = $dom[$key]['value'];
17719 if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
17720 $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
17723 if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
17724 $id = strtolower($dom[$key]['attribute']['id']);
17726 $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
17727 $matches = array();
17728 if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE
) > 0) {
17729 $parentop = array_pop($matches[1]);
17730 $operator = $parentop[0];
17731 $offset = $parentop[1];
17732 $lasttag = array_pop($matches[2]);
17733 $lasttag = strtolower(trim($lasttag[0]));
17734 if (($lasttag == '*') OR ($lasttag == $tag)) {
17735 // the last element on selector is our tag or 'any tag'
17736 $attrib = array_pop($matches[3]);
17737 $attrib = strtolower(trim($attrib[0]));
17738 if (!empty($attrib)) {
17739 // check if matches class, id, attribute, pseudo-class or pseudo-element
17740 switch ($attrib{0}) {
17741 case '.': { // class
17742 if (in_array(substr($attrib, 1), $class)) {
17748 if (substr($attrib, 1) == $id) {
17753 case '[': { // attribute
17754 $attrmatch = array();
17755 if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
17756 $att = strtolower($attrmatch[1]);
17757 $val = $attrmatch[3];
17758 if (isset($dom[$key]['attribute'][$att])) {
17759 switch ($attrmatch[2]) {
17761 if ($dom[$key]['attribute'][$att] == $val) {
17767 if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
17773 if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
17779 if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
17785 if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
17791 if ($dom[$key]['attribute'][$att] == $val) {
17793 } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
17806 case ':': { // pseudo-class or pseudo-element
17807 if ($attrib{1} == ':') { // pseudo-element
17808 // pseudo-elements are not supported!
17809 // (::first-line, ::first-letter, ::before, ::after)
17810 } else { // pseudo-class
17811 // pseudo-classes are not supported!
17812 // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked)
17820 if ($valid AND ($offset > 0)) {
17822 // check remaining selector part
17823 $selector = substr($selector, 0, $offset);
17824 switch ($operator) {
17825 case ' ': { // descendant of an element
17826 while ($dom[$key]['parent'] > 0) {
17827 if ($this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
17831 $key = $dom[$key]['parent'];
17836 case '>': { // child of an element
17837 $valid = $this->isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
17840 case '+': { // immediately preceded by an element
17841 for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
17842 if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
17843 $valid = $this->isValidCSSSelectorForTag($dom, $i, $selector);
17849 case '~': { // preceded by an element
17850 for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
17851 if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
17852 if ($this->isValidCSSSelectorForTag($dom, $i, $selector)) {
17867 * Returns the styles that apply for the selected HTML tag.
17868 * @param $dom (array) array of HTML tags and properties
17869 * @param $key (int) key of the current HTML tag
17870 * @param $css (array) array of CSS properties
17871 * @return string containing CSS properties
17873 * @since 5.1.000 (2010-05-25)
17875 protected function getTagStyleFromCSS($dom, $key, $css) {
17876 $tagstyle = ''; // style to be returned
17877 // get all styles that apply
17878 foreach($css as $selector => $style) {
17879 // remove specificity
17880 $selector = substr($selector, strpos($selector, ' '));
17881 // check if this selector apply to current tag
17882 if ($this->isValidCSSSelectorForTag($dom, $key, $selector)) {
17884 $tagstyle .= ';'.$style;
17887 if (isset($dom[$key]['attribute']['style'])) {
17888 // attach inline style (latest properties have high priority)
17889 $tagstyle .= ';'.$dom[$key]['attribute']['style'];
17891 // remove multiple semicolons
17892 $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
17897 * Returns the border width from CSS property
17898 * @param $width (string) border width
17899 * @return int with in user units
17901 * @since 5.7.000 (2010-08-02)
17903 protected function getCSSBorderWidth($width) {
17904 if ($width == 'thin') {
17905 $width = (2 / $this->k
);
17906 } elseif ($width == 'medium') {
17907 $width = (4 / $this->k
);
17908 } elseif ($width == 'thick') {
17909 $width = (6 / $this->k
);
17911 $width = $this->getHTMLUnitToUnits($width, 1, 'px', false);
17917 * Returns the border dash style from CSS property
17918 * @param $style (string) border style to convert
17919 * @return int sash style (return -1 in case of none or hidden border)
17921 * @since 5.7.000 (2010-08-02)
17923 protected function getCSSBorderDashStyle($style) {
17924 switch (strtolower($style)) {
17953 * Returns the border style array from CSS border properties
17954 * @param $cssborder (string) border properties
17955 * @return array containing border properties
17957 * @since 5.7.000 (2010-08-02)
17959 protected function getCSSBorderStyle($cssborder) {
17960 $bprop = preg_split('/[\s]+/', trim($cssborder));
17961 $border = array(); // value to be returned
17962 switch (count($bprop)) {
17964 $width = $bprop[0];
17965 $style = $bprop[1];
17966 $color = $bprop[2];
17971 $style = $bprop[0];
17972 $color = $bprop[1];
17977 $style = $bprop[0];
17988 if ($style == 'none') {
17991 $border['cap'] = 'square';
17992 $border['join'] = 'miter';
17993 $border['dash'] = $this->getCSSBorderDashStyle($style);
17994 if ($border['dash'] < 0) {
17997 $border['width'] = $this->getCSSBorderWidth($width);
17998 $border['color'] = $this->convertHTMLColorToDec($color);
18003 * Get the internal Cell padding from CSS attribute.
18004 * @param $csspadding (string) padding properties
18005 * @param $width (float) width of the containing element
18006 * @return array of cell paddings
18008 * @since 5.9.000 (2010-10-04)
18010 public function getCSSPadding($csspadding, $width=0) {
18011 $padding = preg_split('/[\s]+/', trim($csspadding));
18012 $cell_padding = array(); // value to be returned
18013 switch (count($padding)) {
18015 $cell_padding['T'] = $padding[0];
18016 $cell_padding['R'] = $padding[1];
18017 $cell_padding['B'] = $padding[2];
18018 $cell_padding['L'] = $padding[3];
18022 $cell_padding['T'] = $padding[0];
18023 $cell_padding['R'] = $padding[1];
18024 $cell_padding['B'] = $padding[2];
18025 $cell_padding['L'] = $padding[1];
18029 $cell_padding['T'] = $padding[0];
18030 $cell_padding['R'] = $padding[1];
18031 $cell_padding['B'] = $padding[0];
18032 $cell_padding['L'] = $padding[1];
18036 $cell_padding['T'] = $padding[0];
18037 $cell_padding['R'] = $padding[0];
18038 $cell_padding['B'] = $padding[0];
18039 $cell_padding['L'] = $padding[0];
18043 return $this->cell_padding
;
18047 $width = $this->w
- $this->lMargin
- $this->rMargin
;
18049 $cell_padding['T'] = $this->getHTMLUnitToUnits($cell_padding['T'], $width, 'px', false);
18050 $cell_padding['R'] = $this->getHTMLUnitToUnits($cell_padding['R'], $width, 'px', false);
18051 $cell_padding['B'] = $this->getHTMLUnitToUnits($cell_padding['B'], $width, 'px', false);
18052 $cell_padding['L'] = $this->getHTMLUnitToUnits($cell_padding['L'], $width, 'px', false);
18053 return $cell_padding;
18057 * Get the internal Cell margin from CSS attribute.
18058 * @param $cssmargin (string) margin properties
18059 * @param $width (float) width of the containing element
18060 * @return array of cell margins
18062 * @since 5.9.000 (2010-10-04)
18064 public function getCSSMargin($cssmargin, $width=0) {
18065 $margin = preg_split('/[\s]+/', trim($cssmargin));
18066 $cell_margin = array(); // value to be returned
18067 switch (count($margin)) {
18069 $cell_margin['T'] = $margin[0];
18070 $cell_margin['R'] = $margin[1];
18071 $cell_margin['B'] = $margin[2];
18072 $cell_margin['L'] = $margin[3];
18076 $cell_margin['T'] = $margin[0];
18077 $cell_margin['R'] = $margin[1];
18078 $cell_margin['B'] = $margin[2];
18079 $cell_margin['L'] = $margin[1];
18083 $cell_margin['T'] = $margin[0];
18084 $cell_margin['R'] = $margin[1];
18085 $cell_margin['B'] = $margin[0];
18086 $cell_margin['L'] = $margin[1];
18090 $cell_margin['T'] = $margin[0];
18091 $cell_margin['R'] = $margin[0];
18092 $cell_margin['B'] = $margin[0];
18093 $cell_margin['L'] = $margin[0];
18097 return $this->cell_margin
;
18101 $width = $this->w
- $this->lMargin
- $this->rMargin
;
18103 $cell_margin['T'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['T']), $width, 'px', false);
18104 $cell_margin['R'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['R']), $width, 'px', false);
18105 $cell_margin['B'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['B']), $width, 'px', false);
18106 $cell_margin['L'] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $cell_margin['L']), $width, 'px', false);
18107 return $cell_margin;
18111 * Get the border-spacing from CSS attribute.
18112 * @param $cssbspace (string) border-spacing CSS properties
18113 * @param $width (float) width of the containing element
18114 * @return array of border spacings
18116 * @since 5.9.010 (2010-10-27)
18118 public function getCSSBorderMargin($cssbspace, $width=0) {
18119 $space = preg_split('/[\s]+/', trim($cssbspace));
18120 $border_spacing = array(); // value to be returned
18121 switch (count($space)) {
18123 $border_spacing['H'] = $space[0];
18124 $border_spacing['V'] = $space[1];
18128 $border_spacing['H'] = $space[0];
18129 $border_spacing['V'] = $space[0];
18133 return array('H' => 0, 'V' => 0);
18137 $width = $this->w
- $this->lMargin
- $this->rMargin
;
18139 $border_spacing['H'] = $this->getHTMLUnitToUnits($border_spacing['H'], $width, 'px', false);
18140 $border_spacing['V'] = $this->getHTMLUnitToUnits($border_spacing['V'], $width, 'px', false);
18141 return $border_spacing;
18145 * Returns the letter-spacing value from CSS value
18146 * @param $spacing (string) letter-spacing value
18147 * @param $parent (float) font spacing (tracking/kerning) value of the parent element
18148 * @return float quantity to increases or decreases the space between characters in a text.
18150 * @since 5.9.000 (2010-10-02)
18152 protected function getCSSFontSpacing($spacing, $parent=0) {
18153 $val = 0; // value to be returned
18154 $spacing = trim($spacing);
18155 switch ($spacing) {
18161 if ($parent == 'normal') {
18169 $val = $this->getHTMLUnitToUnits($spacing, 0, 'px', false);
18176 * Returns the percentage of font stretching from CSS value
18177 * @param $stretch (string) stretch mode
18178 * @param $parent (float) stretch value of the parent element
18179 * @return float font stretching percentage
18181 * @since 5.9.000 (2010-10-02)
18183 protected function getCSSFontStretching($stretch, $parent=100) {
18184 $val = 100; // value to be returned
18185 $stretch = trim($stretch);
18186 switch ($stretch) {
18187 case 'ultra-condensed': {
18191 case 'extra-condensed': {
18195 case 'condensed': {
18199 case 'semi-condensed': {
18207 case 'semi-expanded': {
18215 case 'extra-expanded': {
18219 case 'ultra-expanded': {
18224 $val = $parent +
10;
18228 $val = $parent - 10;
18232 if ($parent == 'normal') {
18240 $val = $this->getHTMLUnitToUnits($stretch, 100, '%', false);
18247 * Returns the HTML DOM array.
18248 * @param $html (string) html code
18251 * @since 3.2.000 (2008-06-20)
18253 protected function getHtmlDomArray($html) {
18254 // array of CSS styles ( selector => properties).
18256 // get CSS array defined at previous call
18257 $matches = array();
18258 if (preg_match_all('/<cssarray>([^\<]*)<\/cssarray>/isU', $html, $matches) > 0) {
18259 if (isset($matches[1][0])) {
18260 $css = array_merge($css, unserialize($this->unhtmlentities($matches[1][0])));
18262 $html = preg_replace('/<cssarray>(.*?)<\/cssarray>/isU', '', $html);
18264 // extract external CSS files
18265 $matches = array();
18266 if (preg_match_all('/<link([^\>]*)>/isU', $html, $matches) > 0) {
18267 foreach ($matches[1] as $key => $link) {
18269 if (preg_match('/type[\s]*=[\s]*"text\/css"/', $link, $type)) {
18271 preg_match('/media[\s]*=[\s]*"([^"]*)"/', $link, $type);
18272 // get 'all' and 'print' media, other media types are discarded
18273 // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
18274 if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
18276 if (preg_match('/href[\s]*=[\s]*"([^"]*)"/', $link, $type) > 0) {
18277 // read CSS data file
18278 $cssdata = file_get_contents(trim($type[1]));
18279 $css = array_merge($css, $this->extractCSSproperties($cssdata));
18285 // extract style tags
18286 $matches = array();
18287 if (preg_match_all('/<style([^\>]*)>([^\<]*)<\/style>/isU', $html, $matches) > 0) {
18288 foreach ($matches[1] as $key => $media) {
18290 preg_match('/media[\s]*=[\s]*"([^"]*)"/', $media, $type);
18291 // get 'all' and 'print' media, other media types are discarded
18292 // (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
18293 if (empty($type) OR (isset($type[1]) AND (($type[1] == 'all') OR ($type[1] == 'print')))) {
18294 $cssdata = $matches[2][$key];
18295 $css = array_merge($css, $this->extractCSSproperties($cssdata));
18299 // create a special tag to contain the CSS array (used for table content)
18300 $csstagarray = '<cssarray>'.htmlentities(serialize($css)).'</cssarray>';
18301 // remove head and style blocks
18302 $html = preg_replace('/<head([^\>]*)>(.*?)<\/head>/siU', '', $html);
18303 $html = preg_replace('/<style([^\>]*)>([^\<]*)<\/style>/isU', '', $html);
18304 // define block tags
18305 $blocktags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table','tr','td');
18306 // define self-closing tags
18307 $selfclosingtags = array('area','base','basefont','br','hr','input','img','link','meta');
18308 // remove all unsupported tags (the line below lists all supported tags)
18309 $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>');
18310 //replace some blank characters
18311 $html = preg_replace('/<pre/', '<xre', $html); // preserve pre tag
18312 $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);
18313 $html = preg_replace('@(\r\n|\r)@', "\n", $html);
18314 $repTable = array("\t" => ' ', "\0" => ' ', "\x0B" => ' ', "\\" => "\\\\");
18315 $html = strtr($html, $repTable);
18317 while (($offset < strlen($html)) AND ($pos = strpos($html, '</pre>', $offset)) !== false) {
18318 $html_a = substr($html, 0, $offset);
18319 $html_b = substr($html, $offset, ($pos - $offset +
6));
18320 while (preg_match("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", $html_b)) {
18321 // preserve newlines on <pre> tag
18322 $html_b = preg_replace("'<xre([^\>]*)>(.*?)\n(.*?)</pre>'si", "<xre\\1>\\2<br />\\3</pre>", $html_b);
18324 while (preg_match("'<xre([^\>]*)>(.*?)".$this->re_space
['p']."(.*?)</pre>'".$this->re_space
['m'], $html_b)) {
18325 // preserve spaces on <pre> tag
18326 $html_b = preg_replace("'<xre([^\>]*)>(.*?)".$this->re_space
['p']."(.*?)</pre>'".$this->re_space
['m'], "<xre\\1>\\2 \\3</pre>", $html_b);
18328 $html = $html_a.$html_b.substr($html, $pos +
6);
18329 $offset = strlen($html_a.$html_b);
18332 while (($offset < strlen($html)) AND ($pos = strpos($html, '</textarea>', $offset)) !== false) {
18333 $html_a = substr($html, 0, $offset);
18334 $html_b = substr($html, $offset, ($pos - $offset +
11));
18335 while (preg_match("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", $html_b)) {
18336 // preserve newlines on <textarea> tag
18337 $html_b = preg_replace("'<textarea([^\>]*)>(.*?)\n(.*?)</textarea>'si", "<textarea\\1>\\2<TBR>\\3</textarea>", $html_b);
18338 $html_b = preg_replace("'<textarea([^\>]*)>(.*?)[\"](.*?)</textarea>'si", "<textarea\\1>\\2''\\3</textarea>", $html_b);
18340 $html = $html_a.$html_b.substr($html, $pos +
11);
18341 $offset = strlen($html_a.$html_b);
18343 $html = preg_replace('/([\s]*)<option/si', '<option', $html);
18344 $html = preg_replace('/<\/option>([\s]*)/si', '</option>', $html);
18346 while (($offset < strlen($html)) AND ($pos = strpos($html, '</option>', $offset)) !== false) {
18347 $html_a = substr($html, 0, $offset);
18348 $html_b = substr($html, $offset, ($pos - $offset +
9));
18349 while (preg_match("'<option([^\>]*)>(.*?)</option>'si", $html_b)) {
18350 $html_b = preg_replace("'<option([\s]+)value=\"([^\"]*)\"([^\>]*)>(.*?)</option>'si", "\\2#!TaB!#\\4#!NwL!#", $html_b);
18351 $html_b = preg_replace("'<option([^\>]*)>(.*?)</option>'si", "\\2#!NwL!#", $html_b);
18353 $html = $html_a.$html_b.substr($html, $pos +
9);
18354 $offset = strlen($html_a.$html_b);
18356 if (preg_match("'</select'si", $html)) {
18357 $html = preg_replace("'<select([^\>]*)>'si", "<select\\1 opt=\"", $html);
18358 $html = preg_replace("'#!NwL!#</select>'si", "\" />", $html);
18360 $html = str_replace("\n", ' ', $html);
18361 // restore textarea newlines
18362 $html = str_replace('<TBR>', "\n", $html);
18363 // remove extra spaces from code
18364 $html = preg_replace('/[\s]+<\/(table|tr|ul|ol|dl)>/', '</\\1>', $html);
18365 $html = preg_replace('/'.$this->re_space
['p'].'+<\/(td|th|li|dt|dd)>/'.$this->re_space
['m'], '</\\1>', $html);
18366 $html = preg_replace('/[\s]+<(tr|td|th|li|dt|dd)/', '<\\1', $html);
18367 $html = preg_replace('/'.$this->re_space
['p'].'+<(ul|ol|dl|br)/'.$this->re_space
['m'], '<\\1', $html);
18368 $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);
18369 $html = preg_replace('/<\/(td|th)>/', '<marker style="font-size:0"/></\\1>', $html);
18370 $html = preg_replace('/<\/table>([\s]*)<marker style="font-size:0"\/>/', '</table>', $html);
18371 $html = preg_replace('/'.$this->re_space
['p'].'+<img/'.$this->re_space
['m'], chr(32).'<img', $html);
18372 $html = preg_replace('/<img([^\>]*)>/xi', '<img\\1><span><marker style="font-size:0"/></span>', $html);
18373 $html = preg_replace('/<xre/', '<pre', $html); // restore pre tag
18374 $html = preg_replace('/<textarea([^\>]*)>([^\<]*)<\/textarea>/xi', '<textarea\\1 value="\\2" />', $html);
18375 $html = preg_replace('/<li([^\>]*)><\/li>/', '<li\\1> </li>', $html);
18376 $html = preg_replace('/<li([^\>]*)>'.$this->re_space
['p'].'*<img/'.$this->re_space
['m'], '<li\\1><font size="1"> </font><img', $html);
18377 $html = preg_replace('/<([^\>\/]*)>[\s]/', '<\\1> ', $html); // preserve some spaces
18378 $html = preg_replace('/[\s]<\/([^\>]*)>/', ' </\\1>', $html); // preserve some spaces
18379 $html = preg_replace('/'.$this->re_space
['p'].'+/'.$this->re_space
['m'], chr(32), $html); // replace multiple spaces with a single space
18381 $html = $this->stringTrim($html);
18382 // pattern for generic tag
18383 $tagpattern = '/(<[^>]+>)/';
18384 // explodes the string
18385 $a = preg_split($tagpattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
18387 $maxel = count($a);
18390 // create an array of elements
18392 $dom[$key] = array();
18393 // set inheritable properties fot the first void element
18394 // 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
18395 $dom[$key]['tag'] = false;
18396 $dom[$key]['block'] = false;
18397 $dom[$key]['value'] = '';
18398 $dom[$key]['parent'] = 0;
18399 $dom[$key]['fontname'] = $this->FontFamily
;
18400 $dom[$key]['fontstyle'] = $this->FontStyle
;
18401 $dom[$key]['fontsize'] = $this->FontSizePt
;
18402 $dom[$key]['font-stretch'] = $this->font_stretching
;
18403 $dom[$key]['letter-spacing'] = $this->font_spacing
;
18404 $dom[$key]['stroke'] = $this->textstrokewidth
;
18405 $dom[$key]['fill'] = (($this->textrendermode %
2) == 0);
18406 $dom[$key]['clip'] = ($this->textrendermode
> 3);
18407 $dom[$key]['line-height'] = $this->cell_height_ratio
;
18408 $dom[$key]['bgcolor'] = false;
18409 $dom[$key]['fgcolor'] = $this->fgcolor
; // color
18410 $dom[$key]['strokecolor'] = $this->strokecolor
;
18411 $dom[$key]['align'] = '';
18412 $dom[$key]['listtype'] = '';
18413 $dom[$key]['text-indent'] = 0;
18414 $dom[$key]['border'] = array();
18415 $dom[$key]['dir'] = $this->rtl?
'rtl':'ltr';
18416 $thead = false; // true when we are inside the THEAD tag
18419 array_push($level, 0); // root
18420 while ($elkey < $maxel) {
18421 $dom[$key] = array();
18422 $element = $a[$elkey];
18423 $dom[$key]['elkey'] = $elkey;
18424 if (preg_match($tagpattern, $element)) {
18426 $element = substr($element, 1, -1);
18428 preg_match('/[\/]?([a-zA-Z0-9]*)/', $element, $tag);
18429 $tagname = strtolower($tag[1]);
18430 // check if we are inside a table header
18431 if ($tagname == 'thead') {
18432 if ($element{0} == '/') {
18440 $dom[$key]['tag'] = true;
18441 $dom[$key]['value'] = $tagname;
18442 if (in_array($dom[$key]['value'], $blocktags)) {
18443 $dom[$key]['block'] = true;
18445 $dom[$key]['block'] = false;
18447 if ($element{0} == '/') {
18448 // *** closing html tag
18449 $dom[$key]['opening'] = false;
18450 $dom[$key]['parent'] = end($level);
18452 $dom[$key]['fontname'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontname'];
18453 $dom[$key]['fontstyle'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontstyle'];
18454 $dom[$key]['fontsize'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fontsize'];
18455 $dom[$key]['font-stretch'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['font-stretch'];
18456 $dom[$key]['letter-spacing'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['letter-spacing'];
18457 $dom[$key]['stroke'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['stroke'];
18458 $dom[$key]['fill'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fill'];
18459 $dom[$key]['clip'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['clip'];
18460 $dom[$key]['line-height'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['line-height'];
18461 $dom[$key]['bgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['bgcolor'];
18462 $dom[$key]['fgcolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['fgcolor'];
18463 $dom[$key]['strokecolor'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['strokecolor'];
18464 $dom[$key]['align'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['align'];
18465 $dom[$key]['dir'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['dir'];
18466 if (isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'])) {
18467 $dom[$key]['listtype'] = $dom[($dom[($dom[$key]['parent'])]['parent'])]['listtype'];
18469 // set the number of columns in table tag
18470 if (($dom[$key]['value'] == 'tr') AND (!isset($dom[($dom[($dom[$key]['parent'])]['parent'])]['cols']))) {
18471 $dom[($dom[($dom[$key]['parent'])]['parent'])]['cols'] = $dom[($dom[$key]['parent'])]['cols'];
18473 if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
18474 $dom[($dom[$key]['parent'])]['content'] = $csstagarray;
18475 for ($i = ($dom[$key]['parent'] +
1); $i < $key; ++
$i) {
18476 $dom[($dom[$key]['parent'])]['content'] .= $a[$dom[$i]['elkey']];
18479 // mark nested tables
18480 $dom[($dom[$key]['parent'])]['content'] = str_replace('<table', '<table nested="true"', $dom[($dom[$key]['parent'])]['content']);
18481 // remove thead sections from nested tables
18482 $dom[($dom[$key]['parent'])]['content'] = str_replace('<thead>', '', $dom[($dom[$key]['parent'])]['content']);
18483 $dom[($dom[$key]['parent'])]['content'] = str_replace('</thead>', '', $dom[($dom[$key]['parent'])]['content']);
18485 // store header rows on a new table
18486 if (($dom[$key]['value'] == 'tr') AND ($dom[($dom[$key]['parent'])]['thead'] === true)) {
18487 if ($this->empty_string($dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'])) {
18488 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] = $a[$dom[($dom[($dom[$key]['parent'])]['parent'])]['elkey']];
18490 for ($i = $dom[$key]['parent']; $i <= $key; ++
$i) {
18491 $dom[($dom[($dom[$key]['parent'])]['parent'])]['thead'] .= $a[$dom[$i]['elkey']];
18493 if (!isset($dom[($dom[$key]['parent'])]['attribute'])) {
18494 $dom[($dom[$key]['parent'])]['attribute'] = array();
18496 // header elements must be always contained in a single page
18497 $dom[($dom[$key]['parent'])]['attribute']['nobr'] = 'true';
18499 if (($dom[$key]['value'] == 'table') AND (!$this->empty_string($dom[($dom[$key]['parent'])]['thead']))) {
18500 // remove the nobr attributes from the table header
18501 $dom[($dom[$key]['parent'])]['thead'] = str_replace(' nobr="true"', '', $dom[($dom[$key]['parent'])]['thead']);
18502 $dom[($dom[$key]['parent'])]['thead'] .= '</tablehead>';
18505 // *** opening or self-closing html tag
18506 $dom[$key]['opening'] = true;
18507 $dom[$key]['parent'] = end($level);
18508 if ((substr($element, -1, 1) == '/') OR (in_array($dom[$key]['value'], $selfclosingtags))) {
18509 // self-closing tag
18510 $dom[$key]['self'] = true;
18513 array_push($level, $key);
18514 $dom[$key]['self'] = false;
18516 // copy some values from parent
18519 $parentkey = $dom[$key]['parent'];
18520 $dom[$key]['fontname'] = $dom[$parentkey]['fontname'];
18521 $dom[$key]['fontstyle'] = $dom[$parentkey]['fontstyle'];
18522 $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'];
18523 $dom[$key]['font-stretch'] = $dom[$parentkey]['font-stretch'];
18524 $dom[$key]['letter-spacing'] = $dom[$parentkey]['letter-spacing'];
18525 $dom[$key]['stroke'] = $dom[$parentkey]['stroke'];
18526 $dom[$key]['fill'] = $dom[$parentkey]['fill'];
18527 $dom[$key]['clip'] = $dom[$parentkey]['clip'];
18528 $dom[$key]['line-height'] = $dom[$parentkey]['line-height'];
18529 $dom[$key]['bgcolor'] = $dom[$parentkey]['bgcolor'];
18530 $dom[$key]['fgcolor'] = $dom[$parentkey]['fgcolor'];
18531 $dom[$key]['strokecolor'] = $dom[$parentkey]['strokecolor'];
18532 $dom[$key]['align'] = $dom[$parentkey]['align'];
18533 $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
18534 $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
18535 $dom[$key]['border'] = array();
18536 $dom[$key]['dir'] = $dom[$parentkey]['dir'];
18539 preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER
);
18540 $dom[$key]['attribute'] = array(); // reset attribute array
18541 while (list($id, $name) = each($attr_array[1])) {
18542 $dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
18544 if (!empty($css)) {
18545 // merge eternal CSS style to current style
18546 $dom[$key]['attribute']['style'] = $this->getTagStyleFromCSS($dom, $key, $css);
18548 // split style attributes
18549 if (isset($dom[$key]['attribute']['style']) AND !empty($dom[$key]['attribute']['style'])) {
18550 // get style attributes
18551 preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER
);
18552 $dom[$key]['style'] = array(); // reset style attribute array
18553 while (list($id, $name) = each($style_array[1])) {
18554 // in case of duplicate attribute the last replace the previous
18555 $dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
18557 // --- get some style attributes ---
18559 if (isset($dom[$key]['style']['direction'])) {
18560 $dom[$key]['dir'] = $dom[$key]['style']['direction'];
18563 if (isset($dom[$key]['style']['font-family'])) {
18564 $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['style']['font-family']);
18567 if (isset($dom[$key]['style']['list-style-type'])) {
18568 $dom[$key]['listtype'] = trim(strtolower($dom[$key]['style']['list-style-type']));
18569 if ($dom[$key]['listtype'] == 'inherit') {
18570 $dom[$key]['listtype'] = $dom[$parentkey]['listtype'];
18574 if (isset($dom[$key]['style']['text-indent'])) {
18575 $dom[$key]['text-indent'] = $this->getHTMLUnitToUnits($dom[$key]['style']['text-indent']);
18576 if ($dom[$key]['text-indent'] == 'inherit') {
18577 $dom[$key]['text-indent'] = $dom[$parentkey]['text-indent'];
18581 if (isset($dom[$key]['style']['font-size'])) {
18582 $fsize = trim($dom[$key]['style']['font-size']);
18586 $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 4;
18590 $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 3;
18594 $dom[$key]['fontsize'] = $dom[0]['fontsize'] - 2;
18598 $dom[$key]['fontsize'] = $dom[0]['fontsize'];
18602 $dom[$key]['fontsize'] = $dom[0]['fontsize'] +
2;
18606 $dom[$key]['fontsize'] = $dom[0]['fontsize'] +
4;
18610 $dom[$key]['fontsize'] = $dom[0]['fontsize'] +
6;
18615 $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] - 3;
18619 $dom[$key]['fontsize'] = $dom[$parentkey]['fontsize'] +
3;
18623 $dom[$key]['fontsize'] = $this->getHTMLUnitToUnits($fsize, $dom[$parentkey]['fontsize'], 'pt', true);
18628 if (isset($dom[$key]['style']['font-stretch'])) {
18629 $dom[$key]['font-stretch'] = $this->getCSSFontStretching($dom[$key]['style']['font-stretch'], $dom[$parentkey]['font-stretch']);
18632 if (isset($dom[$key]['style']['letter-spacing'])) {
18633 $dom[$key]['letter-spacing'] = $this->getCSSFontSpacing($dom[$key]['style']['letter-spacing'], $dom[$parentkey]['letter-spacing']);
18636 if (isset($dom[$key]['style']['line-height'])) {
18637 $lineheight = trim($dom[$key]['style']['line-height']);
18638 switch ($lineheight) {
18639 // A normal line height. This is default
18641 $dom[$key]['line-height'] = $dom[0]['line-height'];
18645 if (is_numeric($lineheight)) {
18646 $lineheight = $lineheight * 100;
18648 $dom[$key]['line-height'] = $this->getHTMLUnitToUnits($lineheight, 1, '%', true);
18653 if (isset($dom[$key]['style']['font-weight']) AND (strtolower($dom[$key]['style']['font-weight']{0}) == 'b')) {
18654 $dom[$key]['fontstyle'] .= 'B';
18656 if (isset($dom[$key]['style']['font-style']) AND (strtolower($dom[$key]['style']['font-style']{0}) == 'i')) {
18657 $dom[$key]['fontstyle'] .= 'I';
18660 if (isset($dom[$key]['style']['color']) AND (!$this->empty_string($dom[$key]['style']['color']))) {
18661 $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['color']);
18662 } elseif ($dom[$key]['value'] == 'a') {
18663 $dom[$key]['fgcolor'] = $this->htmlLinkColorArray
;
18665 // background color
18666 if (isset($dom[$key]['style']['background-color']) AND (!$this->empty_string($dom[$key]['style']['background-color']))) {
18667 $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['style']['background-color']);
18670 if (isset($dom[$key]['style']['text-decoration'])) {
18671 $decors = explode(' ', strtolower($dom[$key]['style']['text-decoration']));
18672 foreach ($decors as $dec) {
18674 if (!$this->empty_string($dec)) {
18675 if ($dec{0} == 'u') {
18677 $dom[$key]['fontstyle'] .= 'U';
18678 } elseif ($dec{0} == 'l') {
18680 $dom[$key]['fontstyle'] .= 'D';
18681 } elseif ($dec{0} == 'o') {
18683 $dom[$key]['fontstyle'] .= 'O';
18687 } elseif ($dom[$key]['value'] == 'a') {
18688 $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle
;
18690 // check for width attribute
18691 if (isset($dom[$key]['style']['width'])) {
18692 $dom[$key]['width'] = $dom[$key]['style']['width'];
18694 // check for height attribute
18695 if (isset($dom[$key]['style']['height'])) {
18696 $dom[$key]['height'] = $dom[$key]['style']['height'];
18698 // check for text alignment
18699 if (isset($dom[$key]['style']['text-align'])) {
18700 $dom[$key]['align'] = strtoupper($dom[$key]['style']['text-align']{0});
18702 // check for CSS border properties
18703 if (isset($dom[$key]['style']['border'])) {
18704 $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border']);
18705 if (!empty($borderstyle)) {
18706 $dom[$key]['border']['LTRB'] = $borderstyle;
18709 if (isset($dom[$key]['style']['border-color'])) {
18710 $brd_colors = preg_split('/[\s]+/', trim($dom[$key]['style']['border-color']));
18711 if (isset($brd_colors[3])) {
18712 $dom[$key]['border']['L']['color'] = $this->convertHTMLColorToDec($brd_colors[3]);
18714 if (isset($brd_colors[1])) {
18715 $dom[$key]['border']['R']['color'] = $this->convertHTMLColorToDec($brd_colors[1]);
18717 if (isset($brd_colors[0])) {
18718 $dom[$key]['border']['T']['color'] = $this->convertHTMLColorToDec($brd_colors[0]);
18720 if (isset($brd_colors[2])) {
18721 $dom[$key]['border']['B']['color'] = $this->convertHTMLColorToDec($brd_colors[2]);
18724 if (isset($dom[$key]['style']['border-width'])) {
18725 $brd_widths = preg_split('/[\s]+/', trim($dom[$key]['style']['border-width']));
18726 if (isset($brd_widths[3])) {
18727 $dom[$key]['border']['L']['width'] = $this->getCSSBorderWidth($brd_widths[3]);
18729 if (isset($brd_widths[1])) {
18730 $dom[$key]['border']['R']['width'] = $this->getCSSBorderWidth($brd_widths[1]);
18732 if (isset($brd_widths[0])) {
18733 $dom[$key]['border']['T']['width'] = $this->getCSSBorderWidth($brd_widths[0]);
18735 if (isset($brd_widths[2])) {
18736 $dom[$key]['border']['B']['width'] = $this->getCSSBorderWidth($brd_widths[2]);
18739 if (isset($dom[$key]['style']['border-style'])) {
18740 $brd_styles = preg_split('/[\s]+/', trim($dom[$key]['style']['border-style']));
18741 if (isset($brd_styles[3])) {
18742 $dom[$key]['border']['L']['cap'] = 'square';
18743 $dom[$key]['border']['L']['join'] = 'miter';
18744 $dom[$key]['border']['L']['dash'] = $this->getCSSBorderDashStyle($brd_styles[3]);
18745 if ($dom[$key]['border']['L']['dash'] < 0) {
18746 $dom[$key]['border']['L'] = array();
18749 if (isset($brd_styles[1])) {
18750 $dom[$key]['border']['R']['cap'] = 'square';
18751 $dom[$key]['border']['R']['join'] = 'miter';
18752 $dom[$key]['border']['R']['dash'] = $this->getCSSBorderDashStyle($brd_styles[1]);
18753 if ($dom[$key]['border']['R']['dash'] < 0) {
18754 $dom[$key]['border']['R'] = array();
18757 if (isset($brd_styles[0])) {
18758 $dom[$key]['border']['T']['cap'] = 'square';
18759 $dom[$key]['border']['T']['join'] = 'miter';
18760 $dom[$key]['border']['T']['dash'] = $this->getCSSBorderDashStyle($brd_styles[0]);
18761 if ($dom[$key]['border']['T']['dash'] < 0) {
18762 $dom[$key]['border']['T'] = array();
18765 if (isset($brd_styles[2])) {
18766 $dom[$key]['border']['B']['cap'] = 'square';
18767 $dom[$key]['border']['B']['join'] = 'miter';
18768 $dom[$key]['border']['B']['dash'] = $this->getCSSBorderDashStyle($brd_styles[2]);
18769 if ($dom[$key]['border']['B']['dash'] < 0) {
18770 $dom[$key]['border']['B'] = array();
18774 $cellside = array('L' => 'left', 'R' => 'right', 'T' => 'top', 'B' => 'bottom');
18775 foreach ($cellside as $bsk => $bsv) {
18776 if (isset($dom[$key]['style']['border-'.$bsv])) {
18777 $borderstyle = $this->getCSSBorderStyle($dom[$key]['style']['border-'.$bsv]);
18778 if (!empty($borderstyle)) {
18779 $dom[$key]['border'][$bsk] = $borderstyle;
18782 if (isset($dom[$key]['style']['border-'.$bsv.'-color'])) {
18783 $dom[$key]['border'][$bsk]['color'] = $this->convertHTMLColorToDec($dom[$key]['style']['border-'.$bsv.'-color']);
18785 if (isset($dom[$key]['style']['border-'.$bsv.'-width'])) {
18786 $dom[$key]['border'][$bsk]['width'] = $this->getCSSBorderWidth($dom[$key]['style']['border-'.$bsv.'-width']);
18788 if (isset($dom[$key]['style']['border-'.$bsv.'-style'])) {
18789 $dom[$key]['border'][$bsk]['dash'] = $this->getCSSBorderDashStyle($dom[$key]['style']['border-'.$bsv.'-style']);
18790 if ($dom[$key]['border'][$bsk]['dash'] < 0) {
18791 $dom[$key]['border'][$bsk] = array();
18795 // check for CSS padding properties
18796 if (isset($dom[$key]['style']['padding'])) {
18797 $dom[$key]['padding'] = $this->getCSSPadding($dom[$key]['style']['padding']);
18799 $dom[$key]['padding'] = $this->cell_padding
;
18801 foreach ($cellside as $psk => $psv) {
18802 if (isset($dom[$key]['style']['padding-'.$psv])) {
18803 $dom[$key]['padding'][$psk] = $this->getHTMLUnitToUnits($dom[$key]['style']['padding-'.$psv], 0, 'px', false);
18806 // check for CSS margin properties
18807 if (isset($dom[$key]['style']['margin'])) {
18808 $dom[$key]['margin'] = $this->getCSSMargin($dom[$key]['style']['margin']);
18810 $dom[$key]['margin'] = $this->cell_margin
;
18812 foreach ($cellside as $psk => $psv) {
18813 if (isset($dom[$key]['style']['margin-'.$psv])) {
18814 $dom[$key]['margin'][$psk] = $this->getHTMLUnitToUnits(str_replace('auto', '0', $dom[$key]['style']['margin-'.$psv]), 0, 'px', false);
18817 // check for CSS border-spacing properties
18818 if (isset($dom[$key]['style']['border-spacing'])) {
18819 $dom[$key]['border-spacing'] = $this->getCSSBorderMargin($dom[$key]['style']['border-spacing']);
18821 // page-break-inside
18822 if (isset($dom[$key]['style']['page-break-inside']) AND ($dom[$key]['style']['page-break-inside'] == 'avoid')) {
18823 $dom[$key]['attribute']['nobr'] = 'true';
18825 // page-break-before
18826 if (isset($dom[$key]['style']['page-break-before'])) {
18827 if ($dom[$key]['style']['page-break-before'] == 'always') {
18828 $dom[$key]['attribute']['pagebreak'] = 'true';
18829 } elseif ($dom[$key]['style']['page-break-before'] == 'left') {
18830 $dom[$key]['attribute']['pagebreak'] = 'left';
18831 } elseif ($dom[$key]['style']['page-break-before'] == 'right') {
18832 $dom[$key]['attribute']['pagebreak'] = 'right';
18835 // page-break-after
18836 if (isset($dom[$key]['style']['page-break-after'])) {
18837 if ($dom[$key]['style']['page-break-after'] == 'always') {
18838 $dom[$key]['attribute']['pagebreakafter'] = 'true';
18839 } elseif ($dom[$key]['style']['page-break-after'] == 'left') {
18840 $dom[$key]['attribute']['pagebreakafter'] = 'left';
18841 } elseif ($dom[$key]['style']['page-break-after'] == 'right') {
18842 $dom[$key]['attribute']['pagebreakafter'] = 'right';
18846 if (isset($dom[$key]['attribute']['border']) AND ($dom[$key]['attribute']['border'] != 0)) {
18847 $borderstyle = $this->getCSSBorderStyle($dom[$key]['attribute']['border'].' solid black');
18848 if (!empty($borderstyle)) {
18849 $dom[$key]['border']['LTRB'] = $borderstyle;
18852 // check for font tag
18853 if ($dom[$key]['value'] == 'font') {
18855 if (isset($dom[$key]['attribute']['face'])) {
18856 $dom[$key]['fontname'] = $this->getFontFamilyName($dom[$key]['attribute']['face']);
18859 if (isset($dom[$key]['attribute']['size'])) {
18861 if ($dom[$key]['attribute']['size']{0} == '+') {
18862 $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] +
intval(substr($dom[$key]['attribute']['size'], 1));
18863 } elseif ($dom[$key]['attribute']['size']{0} == '-') {
18864 $dom[$key]['fontsize'] = $dom[($dom[$key]['parent'])]['fontsize'] - intval(substr($dom[$key]['attribute']['size'], 1));
18866 $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
18869 $dom[$key]['fontsize'] = intval($dom[$key]['attribute']['size']);
18873 // force natural alignment for lists
18874 if ((($dom[$key]['value'] == 'ul') OR ($dom[$key]['value'] == 'ol') OR ($dom[$key]['value'] == 'dl'))
18875 AND (!isset($dom[$key]['align']) OR $this->empty_string($dom[$key]['align']) OR ($dom[$key]['align'] != 'J'))) {
18877 $dom[$key]['align'] = 'R';
18879 $dom[$key]['align'] = 'L';
18882 if (($dom[$key]['value'] == 'small') OR ($dom[$key]['value'] == 'sup') OR ($dom[$key]['value'] == 'sub')) {
18883 if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
18884 $dom[$key]['fontsize'] = $dom[$key]['fontsize'] * K_SMALL_RATIO
;
18887 if (($dom[$key]['value'] == 'strong') OR ($dom[$key]['value'] == 'b')) {
18888 $dom[$key]['fontstyle'] .= 'B';
18890 if (($dom[$key]['value'] == 'em') OR ($dom[$key]['value'] == 'i')) {
18891 $dom[$key]['fontstyle'] .= 'I';
18893 if ($dom[$key]['value'] == 'u') {
18894 $dom[$key]['fontstyle'] .= 'U';
18896 if (($dom[$key]['value'] == 'del') OR ($dom[$key]['value'] == 's') OR ($dom[$key]['value'] == 'strike')) {
18897 $dom[$key]['fontstyle'] .= 'D';
18899 if (!isset($dom[$key]['style']['text-decoration']) AND ($dom[$key]['value'] == 'a')) {
18900 $dom[$key]['fontstyle'] = $this->htmlLinkFontStyle
;
18902 if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
18903 $dom[$key]['fontname'] = $this->default_monospaced_font
;
18905 if (($dom[$key]['value']{0} == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
18906 // headings h1, h2, h3, h4, h5, h6
18907 if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
18908 $headsize = (4 - intval($dom[$key]['value']{1})) * 2;
18909 $dom[$key]['fontsize'] = $dom[0]['fontsize'] +
$headsize;
18911 if (!isset($dom[$key]['style']['font-weight'])) {
18912 $dom[$key]['fontstyle'] .= 'B';
18915 if (($dom[$key]['value'] == 'table')) {
18916 $dom[$key]['rows'] = 0; // number of rows
18917 $dom[$key]['trids'] = array(); // IDs of TR elements
18918 $dom[$key]['thead'] = ''; // table header rows
18920 if (($dom[$key]['value'] == 'tr')) {
18921 $dom[$key]['cols'] = 0;
18923 $dom[$key]['thead'] = true;
18924 // rows on thead block are printed as a separate table
18926 $dom[$key]['thead'] = false;
18927 // store the number of rows on table element
18928 ++
$dom[($dom[$key]['parent'])]['rows'];
18929 // store the TR elements IDs on table element
18930 array_push($dom[($dom[$key]['parent'])]['trids'], $key);
18933 if (($dom[$key]['value'] == 'th') OR ($dom[$key]['value'] == 'td')) {
18934 if (isset($dom[$key]['attribute']['colspan'])) {
18935 $colspan = intval($dom[$key]['attribute']['colspan']);
18939 $dom[$key]['attribute']['colspan'] = $colspan;
18940 $dom[($dom[$key]['parent'])]['cols'] +
= $colspan;
18943 if (isset($dom[$key]['attribute']['dir'])) {
18944 $dom[$key]['dir'] = $dom[$key]['attribute']['dir'];
18946 // set foreground color attribute
18947 if (isset($dom[$key]['attribute']['color']) AND (!$this->empty_string($dom[$key]['attribute']['color']))) {
18948 $dom[$key]['fgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['color']);
18949 } elseif (!isset($dom[$key]['style']['color']) AND ($dom[$key]['value'] == 'a')) {
18950 $dom[$key]['fgcolor'] = $this->htmlLinkColorArray
;
18952 // set background color attribute
18953 if (isset($dom[$key]['attribute']['bgcolor']) AND (!$this->empty_string($dom[$key]['attribute']['bgcolor']))) {
18954 $dom[$key]['bgcolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['bgcolor']);
18956 // set stroke color attribute
18957 if (isset($dom[$key]['attribute']['strokecolor']) AND (!$this->empty_string($dom[$key]['attribute']['strokecolor']))) {
18958 $dom[$key]['strokecolor'] = $this->convertHTMLColorToDec($dom[$key]['attribute']['strokecolor']);
18960 // check for width attribute
18961 if (isset($dom[$key]['attribute']['width'])) {
18962 $dom[$key]['width'] = $dom[$key]['attribute']['width'];
18964 // check for height attribute
18965 if (isset($dom[$key]['attribute']['height'])) {
18966 $dom[$key]['height'] = $dom[$key]['attribute']['height'];
18968 // check for text alignment
18969 if (isset($dom[$key]['attribute']['align']) AND (!$this->empty_string($dom[$key]['attribute']['align'])) AND ($dom[$key]['value'] !== 'img')) {
18970 $dom[$key]['align'] = strtoupper($dom[$key]['attribute']['align']{0});
18972 // check for text rendering mode (the following attributes do not exist in HTML)
18973 if (isset($dom[$key]['attribute']['stroke'])) {
18974 // font stroke width
18975 $dom[$key]['stroke'] = $this->getHTMLUnitToUnits($dom[$key]['attribute']['stroke'], $dom[$key]['fontsize'], 'pt', true);
18977 if (isset($dom[$key]['attribute']['fill'])) {
18979 if ($dom[$key]['attribute']['fill'] == 'true') {
18980 $dom[$key]['fill'] = true;
18982 $dom[$key]['fill'] = false;
18985 if (isset($dom[$key]['attribute']['clip'])) {
18987 if ($dom[$key]['attribute']['clip'] == 'true') {
18988 $dom[$key]['clip'] = true;
18990 $dom[$key]['clip'] = false;
18993 } // end opening tag
18996 $dom[$key]['tag'] = false;
18997 $dom[$key]['block'] = false;
18998 $element = str_replace('$nbsp;', $this->unichr(160), $element);
18999 $dom[$key]['value'] = stripslashes($this->unhtmlentities($element));
19000 $dom[$key]['parent'] = end($level);
19001 $dom[$key]['dir'] = $dom[$dom[$key]['parent']]['dir'];
19010 * Returns the string used to find spaces
19013 * @author Nicola Asuni
19014 * @since 4.8.024 (2010-01-15)
19016 protected function getSpaceString() {
19017 $spacestr = chr(32);
19018 if ($this->isUnicodeFont()) {
19019 $spacestr = chr(0).chr(32);
19025 * Prints a cell (rectangular area) with optional borders, background color and html text string.
19026 * 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 />
19027 * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
19028 * @param $w (float) Cell width. If 0, the cell extends up to the right margin.
19029 * @param $h (float) Cell minimum height. The cell extends automatically if needed.
19030 * @param $x (float) upper-left corner X coordinate
19031 * @param $y (float) upper-left corner Y coordinate
19032 * @param $html (string) html text to print. Default value: empty string.
19033 * @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)))
19034 * @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>
19035 Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
19036 * @param $fill (boolean) Indicates if the cell background must be painted (true) or transparent (false).
19037 * @param $reseth (boolean) if true reset the last cell height (default true).
19038 * @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>
19039 * @param $autopadding (boolean) if true, uses internal padding and automatically adjust it to account for line width.
19040 * @see Multicell(), writeHTML()
19043 public function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true) {
19044 return $this->MultiCell($w, $h, $html, $border, $align, $fill, $ln, $x, $y, $reseth, 0, true, $autopadding, 0);
19048 * Allows to preserve some HTML formatting (limited support).<br />
19049 * IMPORTANT: The HTML must be well formatted - try to clean-up it using an application like HTML-Tidy before submitting.
19050 * 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
19051 * @param $html (string) text to display
19052 * @param $ln (boolean) if true add a new line after text (default = true)
19053 * @param $fill (boolean) Indicates if the background must be painted (true) or transparent (false).
19054 * @param $reseth (boolean) if true reset the last cell height (default false).
19055 * @param $cell (boolean) if true add the current left (or right for RTL) padding to each Write (default false).
19056 * @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>
19059 public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='') {
19060 $gvars = $this->getGraphicVars();
19061 // store current values
19062 $prev_cell_margin = $this->cell_margin
;
19063 $prev_cell_padding = $this->cell_padding
;
19064 $prevPage = $this->page
;
19065 $prevlMargin = $this->lMargin
;
19066 $prevrMargin = $this->rMargin
;
19067 $curfontname = $this->FontFamily
;
19068 $curfontstyle = $this->FontStyle
;
19069 $curfontsize = $this->FontSizePt
;
19070 $curfontascent = $this->getFontAscent($curfontname, $curfontstyle, $curfontsize);
19071 $curfontdescent = $this->getFontDescent($curfontname, $curfontstyle, $curfontsize);
19072 $curfontstretcing = $this->font_stretching
;
19073 $curfontkerning = $this->font_spacing
;
19074 $this->newline
= true;
19076 $startlinepage = $this->page
;
19077 $minstartliney = $this->y
;
19078 $maxbottomliney = 0;
19079 $startlinex = $this->x
;
19080 $startliney = $this->y
;
19084 $this_method_vars = array();
19086 $fontaligned = false;
19087 $reverse_dir = false; // true when the text direction is reversed
19088 $this->premode
= false;
19089 if ($this->inxobj
) {
19090 // we are inside an XObject template
19091 $pask = count($this->xobjects
[$this->xobjid
]['annotations']);
19092 } elseif (isset($this->PageAnnots
[$this->page
])) {
19093 $pask = count($this->PageAnnots
[$this->page
]);
19097 if ($this->inxobj
) {
19098 // we are inside an XObject template
19099 $startlinepos = strlen($this->xobjects
[$this->xobjid
]['outdata']);
19100 } elseif (!$this->InFooter
) {
19101 if (isset($this->footerlen
[$this->page
])) {
19102 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerlen
[$this->page
];
19104 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
19106 $startlinepos = $this->footerpos
[$this->page
];
19108 // we are inside the footer
19109 $startlinepos = $this->pagelen
[$this->page
];
19114 $w = $this->x
- $this->lMargin
;
19116 $w = $this->w
- $this->rMargin
- $this->x
;
19118 $w -= ($this->cell_padding
['L'] +
$this->cell_padding
['R']);
19121 $this->x
-= $this->cell_padding
['R'];
19122 $this->lMargin +
= $this->cell_padding
['R'];
19124 $this->x +
= $this->cell_padding
['L'];
19125 $this->rMargin +
= $this->cell_padding
['L'];
19128 if ($this->customlistindent
>= 0) {
19129 $this->listindent
= $this->customlistindent
;
19131 $this->listindent
= $this->GetStringWidth('0000');
19133 $this->listindentlevel
= 0;
19134 // save previous states
19135 $prev_cell_height_ratio = $this->cell_height_ratio
;
19136 $prev_listnum = $this->listnum
;
19137 $prev_listordered = $this->listordered
;
19138 $prev_listcount = $this->listcount
;
19139 $prev_lispacer = $this->lispacer
;
19140 $this->listnum
= 0;
19141 $this->listordered
= array();
19142 $this->listcount
= array();
19143 $this->lispacer
= '';
19144 if (($this->empty_string($this->lasth
)) OR ($reseth)) {
19145 // reset row height
19146 $this->resetLastH();
19148 $dom = $this->getHtmlDomArray($html);
19149 $maxel = count($dom);
19151 while ($key < $maxel) {
19152 if ($dom[$key]['tag'] AND isset($dom[$key]['attribute']['pagebreak'])) {
19153 // check for pagebreak
19154 if (($dom[$key]['attribute']['pagebreak'] == 'true') OR ($dom[$key]['attribute']['pagebreak'] == 'left') OR ($dom[$key]['attribute']['pagebreak'] == 'right')) {
19155 // add a page (or trig AcceptPageBreak() for multicolumn mode)
19156 $this->checkPageBreak($this->PageBreakTrigger +
1);
19158 if ((($dom[$key]['attribute']['pagebreak'] == 'left') AND (((!$this->rtl
) AND (($this->page %
2) == 0)) OR (($this->rtl
) AND (($this->page %
2) != 0))))
19159 OR (($dom[$key]['attribute']['pagebreak'] == 'right') AND (((!$this->rtl
) AND (($this->page %
2) != 0)) OR (($this->rtl
) AND (($this->page %
2) == 0))))) {
19160 // add a page (or trig AcceptPageBreak() for multicolumn mode)
19161 $this->checkPageBreak($this->PageBreakTrigger +
1);
19164 if ($dom[$key]['tag'] AND $dom[$key]['opening'] AND isset($dom[$key]['attribute']['nobr']) AND ($dom[$key]['attribute']['nobr'] == 'true')) {
19165 if (isset($dom[($dom[$key]['parent'])]['attribute']['nobr']) AND ($dom[($dom[$key]['parent'])]['attribute']['nobr'] == 'true')) {
19166 $dom[$key]['attribute']['nobr'] = false;
19168 // store current object
19169 $this->startTransaction();
19170 // save this method vars
19171 $this_method_vars['html'] = $html;
19172 $this_method_vars['ln'] = $ln;
19173 $this_method_vars['fill'] = $fill;
19174 $this_method_vars['reseth'] = $reseth;
19175 $this_method_vars['cell'] = $cell;
19176 $this_method_vars['align'] = $align;
19177 $this_method_vars['gvars'] = $gvars;
19178 $this_method_vars['prevPage'] = $prevPage;
19179 $this_method_vars['prev_cell_margin'] = $prev_cell_margin;
19180 $this_method_vars['prev_cell_padding'] = $prev_cell_padding;
19181 $this_method_vars['prevlMargin'] = $prevlMargin;
19182 $this_method_vars['prevrMargin'] = $prevrMargin;
19183 $this_method_vars['curfontname'] = $curfontname;
19184 $this_method_vars['curfontstyle'] = $curfontstyle;
19185 $this_method_vars['curfontsize'] = $curfontsize;
19186 $this_method_vars['curfontascent'] = $curfontascent;
19187 $this_method_vars['curfontdescent'] = $curfontdescent;
19188 $this_method_vars['curfontstretcing'] = $curfontstretcing;
19189 $this_method_vars['curfontkerning'] = $curfontkerning;
19190 $this_method_vars['minstartliney'] = $minstartliney;
19191 $this_method_vars['maxbottomliney'] = $maxbottomliney;
19192 $this_method_vars['yshift'] = $yshift;
19193 $this_method_vars['startlinepage'] = $startlinepage;
19194 $this_method_vars['startlinepos'] = $startlinepos;
19195 $this_method_vars['startlinex'] = $startlinex;
19196 $this_method_vars['startliney'] = $startliney;
19197 $this_method_vars['newline'] = $newline;
19198 $this_method_vars['loop'] = $loop;
19199 $this_method_vars['curpos'] = $curpos;
19200 $this_method_vars['pask'] = $pask;
19201 $this_method_vars['lalign'] = $lalign;
19202 $this_method_vars['plalign'] = $plalign;
19203 $this_method_vars['w'] = $w;
19204 $this_method_vars['prev_cell_height_ratio'] = $prev_cell_height_ratio;
19205 $this_method_vars['prev_listnum'] = $prev_listnum;
19206 $this_method_vars['prev_listordered'] = $prev_listordered;
19207 $this_method_vars['prev_listcount'] = $prev_listcount;
19208 $this_method_vars['prev_lispacer'] = $prev_lispacer;
19209 $this_method_vars['fontaligned'] = $fontaligned;
19210 $this_method_vars['key'] = $key;
19211 $this_method_vars['dom'] = $dom;
19214 // print THEAD block
19215 if (($dom[$key]['value'] == 'tr') AND isset($dom[$key]['thead']) AND $dom[$key]['thead']) {
19216 if (isset($dom[$key]['parent']) AND isset($dom[$dom[$key]['parent']]['thead']) AND !$this->empty_string($dom[$dom[$key]['parent']]['thead'])) {
19217 $this->inthead
= true;
19218 // print table header (thead)
19219 $this->writeHTML($this->thead
, false, false, false, false, '');
19220 // check if we are on a new page or on a new column
19221 if (($this->y
< $this->start_transaction_y
) OR ($this->checkPageBreak($this->lasth
, '', false))) {
19222 // we are on a new page or on a new column and the total object height is less than the available vertical space.
19223 // restore previous object
19224 $this->rollbackTransaction(true);
19225 // restore previous values
19226 foreach ($this_method_vars as $vkey => $vval) {
19229 // disable table header
19230 $tmp_thead = $this->thead
;
19232 // add a page (or trig AcceptPageBreak() for multicolumn mode)
19234 if ((!$this->checkPageBreak($this->PageBreakTrigger +
1)) AND ($this->y
< $pre_y)) {
19235 // fix for multicolumn mode
19236 $startliney = $this->y
;
19238 $this->start_transaction_page
= $this->page
;
19239 $this->start_transaction_y
= $this->y
;
19240 // restore table header
19241 $this->thead
= $tmp_thead;
19242 // fix table border properties
19243 if (isset($dom[$dom[$key]['parent']]['attribute']['cellspacing'])) {
19244 $tmp_cellspacing = $this->getHTMLUnitToUnits($dom[$dom[$key]['parent']]['attribute']['cellspacing'], 1, 'px');
19245 } elseif (isset($dom[$dom[$key]['parent']]['border-spacing'])) {
19246 $tmp_cellspacing = $dom[$dom[$key]['parent']]['border-spacing']['V'];
19248 $tmp_cellspacing = 0;
19250 $dom[$dom[$key]['parent']]['borderposition']['page'] = $this->page
;
19251 $dom[$dom[$key]['parent']]['borderposition']['column'] = $this->current_column
;
19252 $dom[$dom[$key]['parent']]['borderposition']['y'] = $this->y +
$tmp_cellspacing;
19253 $xoffset = ($this->x
- $dom[$dom[$key]['parent']]['borderposition']['x']);
19254 $dom[$dom[$key]['parent']]['borderposition']['x'] +
= $xoffset;
19255 $dom[$dom[$key]['parent']]['borderposition']['xmax'] +
= $xoffset;
19256 // print table header (thead)
19257 $this->writeHTML($this->thead
, false, false, false, false, '');
19260 // move $key index forward to skip THEAD block
19261 while ( ($key < $maxel) AND (!(
19262 ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'tr') AND (!isset($dom[$key]['thead']) OR !$dom[$key]['thead']))
19263 OR ($dom[$key]['tag'] AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == 'table'))) )) {
19267 if ($dom[$key]['tag'] OR ($key == 0)) {
19268 if ((($dom[$key]['value'] == 'table') OR ($dom[$key]['value'] == 'tr')) AND (isset($dom[$key]['align']))) {
19269 $dom[$key]['align'] = ($this->rtl
) ?
'R' : 'L';
19271 // vertically align image in line
19272 if ((!$this->newline
) AND ($dom[$key]['value'] == 'img') AND (isset($dom[$key]['height'])) AND ($dom[$key]['height'] > 0)) {
19273 // get image height
19274 $imgh = $this->getHTMLUnitToUnits($dom[$key]['height'], $this->lasth
, 'px');
19275 // check for automatic line break
19276 $autolinebreak = false;
19277 if (isset($dom[$key]['width']) AND ($dom[$key]['width'] > 0)) {
19278 $imgw = $this->getHTMLUnitToUnits($dom[$key]['width'], 1, 'px', false);
19279 if (($this->rtl
AND (($this->x
- $imgw) < ($this->lMargin +
$this->cell_padding
['L'])))
19280 OR (!$this->rtl
AND (($this->x +
$imgw) > ($this->w
- $this->rMargin
- $this->cell_padding
['R'])))) {
19281 // add automatic line break
19282 $autolinebreak = true;
19283 $this->Ln('', $cell);
19284 // go back to evaluate this line break
19288 if (!$autolinebreak) {
19289 if (!$this->InFooter
) {
19291 // check for page break
19292 if ((!$this->checkPageBreak($imgh)) AND ($this->y
< $pre_y)) {
19293 // fix for multicolumn mode
19294 $startliney = $this->y
;
19297 if ($this->page
> $startlinepage) {
19298 // fix line splitted over two pages
19299 if (isset($this->footerlen
[$startlinepage])) {
19300 $curpos = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
19302 // line to be moved one page forward
19303 $pagebuff = $this->getPageBuffer($startlinepage);
19304 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
19305 $tstart = substr($pagebuff, 0, $startlinepos);
19306 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
19307 // remove line from previous page
19308 $this->setPageBuffer($startlinepage, $tstart.''.$tend);
19309 $pagebuff = $this->getPageBuffer($this->page
);
19310 $tstart = substr($pagebuff, 0, $this->cntmrk
[$this->page
]);
19311 $tend = substr($pagebuff, $this->cntmrk
[$this->page
]);
19312 // add line start to current page
19313 $yshift = $minstartliney - $this->y
;
19314 if ($fontaligned) {
19315 $yshift +
= ($curfontsize / $this->k
);
19317 $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k
));
19318 $this->setPageBuffer($this->page
, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
19319 // shift the annotations and links
19320 if (isset($this->PageAnnots
[$this->page
])) {
19321 $next_pask = count($this->PageAnnots
[$this->page
]);
19325 if (isset($this->PageAnnots
[$startlinepage])) {
19326 foreach ($this->PageAnnots
[$startlinepage] as $pak => $pac) {
19327 if ($pak >= $pask) {
19328 $this->PageAnnots
[$this->page
][] = $pac;
19329 unset($this->PageAnnots
[$startlinepage][$pak]);
19330 $npak = count($this->PageAnnots
[$this->page
]) - 1;
19331 $this->PageAnnots
[$this->page
][$npak]['y'] -= $yshift;
19335 $pask = $next_pask;
19336 $startlinepos = $this->cntmrk
[$this->page
];
19337 $startlinepage = $this->page
;
19338 $startliney = $this->y
;
19339 $this->newline
= false;
19341 $this->y +
= ((($curfontsize * $this->cell_height_ratio
/ $this->k
) +
$curfontascent - $curfontdescent) / 2) - $imgh;
19342 $minstartliney = min($this->y
, $minstartliney);
19343 $maxbottomliney = ($startliney +
($this->FontSize
* $this->cell_height_ratio
));
19345 } elseif (isset($dom[$key]['fontname']) OR isset($dom[$key]['fontstyle']) OR isset($dom[$key]['fontsize']) OR isset($dom[$key]['line-height'])) {
19346 // account for different font size
19347 $pfontname = $curfontname;
19348 $pfontstyle = $curfontstyle;
19349 $pfontsize = $curfontsize;
19350 $fontname = isset($dom[$key]['fontname']) ?
$dom[$key]['fontname'] : $curfontname;
19351 $fontstyle = isset($dom[$key]['fontstyle']) ?
$dom[$key]['fontstyle'] : $curfontstyle;
19352 $fontsize = isset($dom[$key]['fontsize']) ?
$dom[$key]['fontsize'] : $curfontsize;
19353 $fontascent = $this->getFontAscent($fontname, $fontstyle, $fontsize);
19354 $fontdescent = $this->getFontDescent($fontname, $fontstyle, $fontsize);
19355 if ( ($fontname != $curfontname) OR ($fontstyle != $curfontstyle) OR ($fontsize != $curfontsize)
19356 OR ($this->cell_height_ratio
!= $dom[$key]['line-height'])
19357 OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
19358 if ((!$this->newline
) AND ($key < ($maxel - 1))
19359 AND ( (is_numeric($fontsize) AND ($fontsize >= 0) AND is_numeric($curfontsize) AND ($curfontsize >= 0) AND ($fontsize != $curfontsize))
19360 OR ($this->cell_height_ratio
!= $dom[$key]['line-height']))
19361 OR ($dom[$key]['tag'] AND $dom[$key]['opening'] AND ($dom[$key]['value'] == 'li')) ) {
19362 if ($this->page
> $startlinepage) {
19363 // fix lines splitted over two pages
19364 if (isset($this->footerlen
[$startlinepage])) {
19365 $curpos = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
19367 // line to be moved one page forward
19368 $pagebuff = $this->getPageBuffer($startlinepage);
19369 $linebeg = substr($pagebuff, $startlinepos, ($curpos - $startlinepos));
19370 $tstart = substr($pagebuff, 0, $startlinepos);
19371 $tend = substr($this->getPageBuffer($startlinepage), $curpos);
19372 // remove line start from previous page
19373 $this->setPageBuffer($startlinepage, $tstart.''.$tend);
19374 $pagebuff = $this->getPageBuffer($this->page
);
19375 $tstart = substr($pagebuff, 0, $this->cntmrk
[$this->page
]);
19376 $tend = substr($pagebuff, $this->cntmrk
[$this->page
]);
19377 // add line start to current page
19378 $yshift = $minstartliney - $this->y
;
19379 $try = sprintf('1 0 0 1 0 %.3F cm', ($yshift * $this->k
));
19380 $this->setPageBuffer($this->page
, $tstart."\nq\n".$try."\n".$linebeg."\nQ\n".$tend);
19381 // shift the annotations and links
19382 if (isset($this->PageAnnots
[$this->page
])) {
19383 $next_pask = count($this->PageAnnots
[$this->page
]);
19387 if (isset($this->PageAnnots
[$startlinepage])) {
19388 foreach ($this->PageAnnots
[$startlinepage] as $pak => $pac) {
19389 if ($pak >= $pask) {
19390 $this->PageAnnots
[$this->page
][] = $pac;
19391 unset($this->PageAnnots
[$startlinepage][$pak]);
19392 $npak = count($this->PageAnnots
[$this->page
]) - 1;
19393 $this->PageAnnots
[$this->page
][$npak]['y'] -= $yshift;
19397 $pask = $next_pask;
19398 $startlinepos = $this->cntmrk
[$this->page
];
19399 $startlinepage = $this->page
;
19400 $startliney = $this->y
;
19402 if (!isset($dom[$key]['line-height'])) {
19403 $dom[$key]['line-height'] = $this->cell_height_ratio
;
19405 if (!$dom[$key]['block']) {
19406 $this->y +
= (((($curfontsize * $this->cell_height_ratio
) - ($fontsize * $dom[$key]['line-height'])) / $this->k
) +
$curfontascent - $fontascent - $curfontdescent +
$fontdescent) / 2;
19407 if (($dom[$key]['value'] != 'sup') AND ($dom[$key]['value'] != 'sub')) {
19408 $minstartliney = min($this->y
, $minstartliney);
19409 $maxbottomliney = max(($this->y +
(($fontsize * $this->cell_height_ratio
) / $this->k
)), $maxbottomliney);
19412 $this->cell_height_ratio
= $dom[$key]['line-height'];
19413 $fontaligned = true;
19415 $this->SetFont($fontname, $fontstyle, $fontsize);
19416 // reset row height
19417 $this->resetLastH();
19418 $curfontname = $fontname;
19419 $curfontstyle = $fontstyle;
19420 $curfontsize = $fontsize;
19421 $curfontascent = $fontascent;
19422 $curfontdescent = $fontdescent;
19425 // set text rendering mode
19426 $textstroke = isset($dom[$key]['stroke']) ?
$dom[$key]['stroke'] : $this->textstrokewidth
;
19427 $textfill = isset($dom[$key]['fill']) ?
$dom[$key]['fill'] : (($this->textrendermode %
2) == 0);
19428 $textclip = isset($dom[$key]['clip']) ?
$dom[$key]['clip'] : ($this->textrendermode
> 3);
19429 $this->setTextRenderingMode($textstroke, $textfill, $textclip);
19430 if (isset($dom[$key]['font-stretch']) AND ($dom[$key]['font-stretch'] !== false)) {
19431 $this->setFontStretching($dom[$key]['font-stretch']);
19433 if (isset($dom[$key]['letter-spacing']) AND ($dom[$key]['letter-spacing'] !== false)) {
19434 $this->setFontSpacing($dom[$key]['letter-spacing']);
19436 if (($plalign == 'J') AND $dom[$key]['block']) {
19439 // get current position on page buffer
19440 $curpos = $this->pagelen
[$startlinepage];
19441 if (isset($dom[$key]['bgcolor']) AND ($dom[$key]['bgcolor'] !== false)) {
19442 $this->SetFillColorArray($dom[$key]['bgcolor']);
19445 $wfill = $fill |
false;
19447 if (isset($dom[$key]['fgcolor']) AND ($dom[$key]['fgcolor'] !== false)) {
19448 $this->SetTextColorArray($dom[$key]['fgcolor']);
19450 if (isset($dom[$key]['strokecolor']) AND ($dom[$key]['strokecolor'] !== false)) {
19451 $this->SetDrawColorArray($dom[$key]['strokecolor']);
19453 if (isset($dom[$key]['align'])) {
19454 $lalign = $dom[$key]['align'];
19456 if ($this->empty_string($lalign)) {
19461 if ($this->newline
AND (strlen($dom[$key]['value']) > 0) AND ($dom[$key]['value'] != 'td') AND ($dom[$key]['value'] != 'th')) {
19463 $fontaligned = false;
19464 // we are at the beginning of a new line
19465 if (isset($startlinex)) {
19466 $yshift = $minstartliney - $startliney;
19467 if (($yshift > 0) OR ($this->page
> $startlinepage)) {
19471 // the last line must be shifted to be aligned as requested
19472 $linew = abs($this->endlinex
- $startlinex);
19473 if ($this->inxobj
) {
19474 // we are inside an XObject template
19475 $pstart = substr($this->xobjects
[$this->xobjid
]['outdata'], 0, $startlinepos);
19476 if (isset($opentagpos)) {
19477 $midpos = $opentagpos;
19482 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos, ($midpos - $startlinepos));
19483 $pend = substr($this->xobjects
[$this->xobjid
]['outdata'], $midpos);
19485 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos);
19489 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
19490 if (isset($opentagpos) AND isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
19491 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
19492 $midpos = min($opentagpos, $this->footerpos
[$startlinepage]);
19493 } elseif (isset($opentagpos)) {
19494 $midpos = $opentagpos;
19495 } elseif (isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
19496 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
19497 $midpos = $this->footerpos
[$startlinepage];
19502 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
19503 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
19505 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
19509 if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl
)) OR (($plalign == 'L') AND ($this->rtl
)))))) {
19510 // calculate shifting amount
19512 if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns
> 1)) {
19513 $tw +
= $this->cell_padding
['R'];
19515 if ($this->lMargin
!= $prevlMargin) {
19516 $tw +
= ($prevlMargin - $this->lMargin
);
19518 if ($this->rMargin
!= $prevrMargin) {
19519 $tw +
= ($prevrMargin - $this->rMargin
);
19521 $one_space_width = $this->GetStringWidth(chr(32));
19522 $no = 0; // number of spaces on a line contained on a single block
19523 if ($this->isRTLTextDir()) { // RTL
19524 // remove left space if exist
19525 $pos1 = $this->revstrpos($pmid, '[(');
19527 $pos1 = intval($pos1);
19528 if ($this->isUnicodeFont()) {
19529 $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
19532 $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
19535 if ($pos1 == $pos2) {
19536 $pmid = substr($pmid, 0, ($pos1 +
2)).substr($pmid, ($pos1 +
2 +
$spacelen));
19537 if (substr($pmid, $pos1, 4) == '[()]') {
19538 $linew -= $one_space_width;
19539 } elseif ($pos1 == strpos($pmid, '[(')) {
19545 // remove right space if exist
19546 $pos1 = $this->revstrpos($pmid, ')]');
19548 $pos1 = intval($pos1);
19549 if ($this->isUnicodeFont()) {
19550 $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) +
2;
19553 $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) +
1;
19556 if ($pos1 == $pos2) {
19557 $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
19558 $linew -= $one_space_width;
19562 $mdiff = ($tw - $linew);
19563 if ($plalign == 'C') {
19565 $t_x = -($mdiff / 2);
19567 $t_x = ($mdiff / 2);
19569 } elseif ($plalign == 'R') {
19570 // right alignment on LTR document
19572 } elseif ($plalign == 'L') {
19573 // left alignment on RTL document
19575 } elseif (($plalign == 'J') AND ($plalign == $lalign)) {
19577 if ($this->isRTLTextDir()) {
19578 // align text on the left
19581 $ns = 0; // number of spaces
19583 // escape special characters
19584 $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
19585 $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
19587 if (preg_match_all('/\[\(([^\)]*)\)\]/x', $pmidtemp, $lnstring, PREG_PATTERN_ORDER
)) {
19588 $spacestr = $this->getSpaceString();
19589 $maxkk = count($lnstring[1]) - 1;
19590 for ($kk=0; $kk <= $maxkk; ++
$kk) {
19591 // restore special characters
19592 $lnstring[1][$kk] = str_replace('#!#OP#!#', '(', $lnstring[1][$kk]);
19593 $lnstring[1][$kk] = str_replace('#!#CP#!#', ')', $lnstring[1][$kk]);
19594 // store number of spaces on the strings
19595 $lnstring[2][$kk] = substr_count($lnstring[1][$kk], $spacestr);
19596 // count total spaces on line
19597 $ns +
= $lnstring[2][$kk];
19598 $lnstring[3][$kk] = $ns;
19603 // calculate additional space to add to each existing space
19604 $spacewidth = ($mdiff / ($ns - $no)) * $this->k
;
19605 $spacewidthu = -1000 * ($mdiff +
(($ns +
$no) * $one_space_width)) / $ns / $this->FontSize
;
19606 if ($this->font_spacing
!= 0) {
19607 // fixed spacing mode
19608 $osw = -1000 * $this->font_spacing
/ $this->FontSize
;
19609 $spacewidthu +
= $osw;
19616 $prev_epsposbeg = 0;
19618 if ($this->isRTLTextDir()) {
19619 $textpos = $this->wPt
;
19622 while (preg_match('/([0-9\.\+\-]*)[\s](Td|cm|m|l|c|re)[\s]/x', $pmid, $strpiece, PREG_OFFSET_CAPTURE
, $offset) == 1) {
19623 // check if we are inside a string section '[( ... )]'
19624 $stroffset = strpos($pmid, '[(', $offset);
19625 if (($stroffset !== false) AND ($stroffset <= $strpiece[2][1])) {
19626 // set offset to the end of string section
19627 $offset = strpos($pmid, ')]', $stroffset);
19628 while (($offset !== false) AND ($pmid{($offset - 1)} == '\\')) {
19629 $offset = strpos($pmid, ')]', ($offset +
1));
19631 if ($offset === false) {
19632 $this->Error('HTML Justification: malformed PDF code.');
19636 if ($this->isRTLTextDir()) {
19637 $spacew = ($spacewidth * ($nsmax - $ns));
19639 $spacew = ($spacewidth * $ns);
19641 $offset = $strpiece[2][1] +
strlen($strpiece[2][0]);
19642 $epsposbeg = strpos($pmid, 'q'.$this->epsmarker
, $offset);
19643 $epsposend = strpos($pmid, $this->epsmarker
.'Q', $offset) +
strlen($this->epsmarker
.'Q');
19644 if ((($epsposbeg > 0) AND ($epsposend > 0) AND ($offset > $epsposbeg) AND ($offset < $epsposend))
19645 OR (($epsposbeg === false) AND ($epsposend > 0) AND ($offset < $epsposend))) {
19646 // shift EPS images
19647 $trx = sprintf('1 0 0 1 %.3F 0 cm', $spacew);
19648 $epsposbeg = strpos($pmid, 'q'.$this->epsmarker
, ($prev_epsposbeg - 6));
19649 $pmid_b = substr($pmid, 0, $epsposbeg);
19650 $pmid_m = substr($pmid, $epsposbeg, ($epsposend - $epsposbeg));
19651 $pmid_e = substr($pmid, $epsposend);
19652 $pmid = $pmid_b."\nq\n".$trx."\n".$pmid_m."\nQ\n".$pmid_e;
19653 $offset = $epsposend;
19657 $prev_epsposbeg = $epsposbeg;
19659 // shift blocks of code
19660 switch ($strpiece[2][0]) {
19665 // get current X position
19666 preg_match('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x', $pmid, $xmatches);
19667 $currentxpos = $xmatches[1];
19668 $textpos = $currentxpos;
19669 if (($strcount <= $maxkk) AND ($strpiece[2][0] == 'Td')) {
19670 $ns = $lnstring[3][$strcount];
19671 if ($this->isRTLTextDir()) {
19672 $spacew = ($spacewidth * ($nsmax - $ns));
19677 $pmid = preg_replace_callback('/([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s]('.$strpiece[2][0].')([\s]*)/x',
19678 create_function('$matches', 'global $spacew;
19679 $newx = sprintf("%.2F",(floatval($matches[1]) + $spacew));
19680 return "".$newx." ".$matches[2]." x*#!#*x".$matches[3].$matches[4];'), $pmid, 1);
19685 if (!$this->empty_string($this->lispacer
)) {
19686 $this->lispacer
= '';
19689 preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
19690 $currentxpos = $xmatches[1];
19691 global $x_diff, $w_diff;
19694 if ($this->isRTLTextDir()) { // RTL
19695 if ($currentxpos < $textpos) {
19696 $x_diff = ($spacewidth * ($nsmax - $lnstring[3][$strcount]));
19697 $w_diff = ($spacewidth * $lnstring[2][$strcount]);
19699 if ($strcount > 0) {
19700 $x_diff = ($spacewidth * ($nsmax - $lnstring[3][($strcount - 1)]));
19701 $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
19705 if ($currentxpos > $textpos) {
19706 if ($strcount > 0) {
19707 $x_diff = ($spacewidth * $lnstring[3][($strcount - 1)]);
19709 $w_diff = ($spacewidth * $lnstring[2][$strcount]);
19711 if ($strcount > 1) {
19712 $x_diff = ($spacewidth * $lnstring[3][($strcount - 2)]);
19714 if ($strcount > 0) {
19715 $w_diff = ($spacewidth * $lnstring[2][($strcount - 1)]);
19719 $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x',
19720 create_function('$matches', 'global $x_diff, $w_diff;
19721 $newx = sprintf("%.2F",(floatval($matches[1]) + $x_diff));
19722 $neww = sprintf("%.2F",(floatval($matches[3]) + $w_diff));
19723 return "".$newx." ".$matches[2]." ".$neww." ".$matches[4]." x*#!#*x".$matches[5].$matches[6];'), $pmid, 1);
19727 // get current X position
19728 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);
19729 $currentxpos = $xmatches[1];
19731 $pmid = preg_replace_callback('/('.$xmatches[1].')[\s]('.$xmatches[2].')[\s]('.$xmatches[3].')[\s]('.$xmatches[4].')[\s]('.$xmatches[5].')[\s]('.$strpiece[1][0].')[\s](c)([\s]*)/x',
19732 create_function('$matches', 'global $spacew;
19733 $newx1 = sprintf("%.3F",(floatval($matches[1]) + $spacew));
19734 $newx2 = sprintf("%.3F",(floatval($matches[3]) + $spacew));
19735 $newx3 = sprintf("%.3F",(floatval($matches[5]) + $spacew));
19736 return "".$newx1." ".$matches[2]." ".$newx2." ".$matches[4]." ".$newx3." ".$matches[6]." x*#!#*x".$matches[7].$matches[8];'), $pmid, 1);
19740 // shift the annotations and links
19741 $cxpos = ($currentxpos / $this->k
);
19742 $lmpos = ($this->lMargin +
$this->cell_padding
['L'] +
$this->feps
);
19743 if ($this->inxobj
) {
19744 // we are inside an XObject template
19745 foreach ($this->xobjects
[$this->xobjid
]['annotations'] as $pak => $pac) {
19746 if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k
) >= ($currentxpos - $this->feps
)) AND (($pac['x'] * $this->k
) <= ($currentxpos +
$this->feps
))) {
19747 if ($cxpos > $lmpos) {
19748 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['x'] +
= ($spacew / $this->k
);
19749 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
19751 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
19756 } elseif (isset($this->PageAnnots
[$this->page
])) {
19757 foreach ($this->PageAnnots
[$this->page
] as $pak => $pac) {
19758 if (($pac['y'] >= $minstartliney) AND (($pac['x'] * $this->k
) >= ($currentxpos - $this->feps
)) AND (($pac['x'] * $this->k
) <= ($currentxpos +
$this->feps
))) {
19759 if ($cxpos > $lmpos) {
19760 $this->PageAnnots
[$this->page
][$pak]['x'] +
= ($spacew / $this->k
);
19761 $this->PageAnnots
[$this->page
][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
19763 $this->PageAnnots
[$this->page
][$pak]['w'] +
= (($spacewidth * $pac['numspaces']) / $this->k
);
19771 $pmid = str_replace('x*#!#*x', '', $pmid);
19772 if ($this->isUnicodeFont()) {
19773 // multibyte characters
19774 $spacew = $spacewidthu;
19775 if ($this->font_stretching
!= 100) {
19776 // word spacing is affected by stretching
19777 $spacew /= ($this->font_stretching
/ 100);
19780 // escape special characters
19781 $pmidtemp = preg_replace('/[\\\][\(]/x', '\\#!#OP#!#', $pmidtemp);
19782 $pmidtemp = preg_replace('/[\\\][\)]/x', '\\#!#CP#!#', $pmidtemp);
19783 $pmid = preg_replace_callback("/\[\(([^\)]*)\)\]/x",
19784 create_function('$matches', 'global $spacew;
19785 $matches[1] = str_replace("#!#OP#!#", "(", $matches[1]);
19786 $matches[1] = str_replace("#!#CP#!#", ")", $matches[1]);
19787 return "[(".str_replace(chr(0).chr(32), ") ".sprintf("%.3F", $spacew)." (", $matches[1]).")]";'), $pmidtemp);
19788 if ($this->inxobj
) {
19789 // we are inside an XObject template
19790 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart."\n".$pmid."\n".$pend;
19792 $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\n".$pend);
19794 $endlinepos = strlen($pstart."\n".$pmid."\n");
19796 // non-unicode (single-byte characters)
19797 if ($this->font_stretching
!= 100) {
19798 // word spacing (Tw) is affected by stretching
19799 $spacewidth /= ($this->font_stretching
/ 100);
19801 $rs = sprintf('%.3F Tw', $spacewidth);
19802 $pmid = preg_replace("/\[\(/x", $rs.' [(', $pmid);
19803 if ($this->inxobj
) {
19804 // we are inside an XObject template
19805 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend;
19807 $this->setPageBuffer($startlinepage, $pstart."\n".$pmid."\nBT 0 Tw ET\n".$pend);
19809 $endlinepos = strlen($pstart."\n".$pmid."\nBT 0 Tw ET\n");
19813 } // end if $startlinex
19814 if (($t_x != 0) OR ($yshift < 0)) {
19816 $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k
), ($yshift * $this->k
));
19817 $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
19818 $endlinepos = strlen($pstart);
19819 if ($this->inxobj
) {
19820 // we are inside an XObject template
19821 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$pend;
19822 foreach ($this->xobjects
[$this->xobjid
]['annotations'] as $pak => $pac) {
19823 if ($pak >= $pask) {
19824 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['x'] +
= $t_x;
19825 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['y'] -= $yshift;
19829 $this->setPageBuffer($startlinepage, $pstart.$pend);
19830 // shift the annotations and links
19831 if (isset($this->PageAnnots
[$this->page
])) {
19832 foreach ($this->PageAnnots
[$this->page
] as $pak => $pac) {
19833 if ($pak >= $pask) {
19834 $this->PageAnnots
[$this->page
][$pak]['x'] +
= $t_x;
19835 $this->PageAnnots
[$this->page
][$pak]['y'] -= $yshift;
19840 $this->y
-= $yshift;
19843 $pbrk = $this->checkPageBreak($this->lasth
);
19844 $this->newline
= false;
19845 $startlinex = $this->x
;
19846 $startliney = $this->y
;
19847 if ($dom[$dom[$key]['parent']]['value'] == 'sup') {
19848 $startliney -= ((0.3 * $this->FontSizePt
) / $this->k
);
19849 } elseif ($dom[$dom[$key]['parent']]['value'] == 'sub') {
19850 $startliney -= (($this->FontSizePt
/ 0.7) / $this->k
);
19852 $minstartliney = $startliney;
19853 $maxbottomliney = ($this->y +
(($fontsize * $this->cell_height_ratio
) / $this->k
));
19855 $startlinepage = $this->page
;
19856 if (isset($endlinepos) AND (!$pbrk)) {
19857 $startlinepos = $endlinepos;
19859 if ($this->inxobj
) {
19860 // we are inside an XObject template
19861 $startlinepos = strlen($this->xobjects
[$this->xobjid
]['outdata']);
19862 } elseif (!$this->InFooter
) {
19863 if (isset($this->footerlen
[$this->page
])) {
19864 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerlen
[$this->page
];
19866 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
19868 $startlinepos = $this->footerpos
[$this->page
];
19870 $startlinepos = $this->pagelen
[$this->page
];
19873 unset($endlinepos);
19874 $plalign = $lalign;
19875 if (isset($this->PageAnnots
[$this->page
])) {
19876 $pask = count($this->PageAnnots
[$this->page
]);
19880 if (!($dom[$key]['tag'] AND !$dom[$key]['opening'] AND ($dom[$key]['value'] == 'table')
19881 AND (isset($this->emptypagemrk
[$this->page
]))
19882 AND ($this->emptypagemrk
[$this->page
] == $this->pagelen
[$this->page
]))) {
19883 $this->SetFont($fontname, $fontstyle, $fontsize);
19885 $this->SetFillColorArray($this->bgcolor
);
19889 if (isset($opentagpos)) {
19890 unset($opentagpos);
19892 if ($dom[$key]['tag']) {
19893 if ($dom[$key]['opening']) {
19894 // get text indentation (if any)
19895 if (isset($dom[$key]['text-indent']) AND $dom[$key]['block']) {
19896 $this->textindent
= $dom[$key]['text-indent'];
19897 $this->newline
= true;
19900 if ($dom[$key]['value'] == 'table') {
19901 // available page width
19903 $wtmp = $this->x
- $this->lMargin
;
19905 $wtmp = $this->w
- $this->rMargin
- $this->x
;
19907 // get cell spacing
19908 if (isset($dom[$key]['attribute']['cellspacing'])) {
19909 $clsp = $this->getHTMLUnitToUnits($dom[$key]['attribute']['cellspacing'], 1, 'px');
19910 $cellspacing = array('H' => $clsp, 'V' => $clsp);
19911 } elseif (isset($dom[$key]['border-spacing'])) {
19912 $cellspacing = $dom[$key]['border-spacing'];
19914 $cellspacing = array('H' => 0, 'V' => 0);
19917 if (isset($dom[$key]['width'])) {
19918 $table_width = $this->getHTMLUnitToUnits($dom[$key]['width'], $wtmp, 'px');
19920 $table_width = $wtmp;
19922 $table_width -= (2 * $cellspacing['H']);
19923 if (!$this->inthead
) {
19924 $this->y +
= $cellspacing['V'];
19927 $cellspacingx = -$cellspacing['H'];
19929 $cellspacingx = $cellspacing['H'];
19931 // total table width without cellspaces
19932 $table_columns_width = ($table_width - ($cellspacing['H'] * ($dom[$key]['cols'] - 1)));
19933 // minimum column width
19934 $table_min_column_width = ($table_columns_width / $dom[$key]['cols']);
19935 // array of custom column widths
19936 $table_colwidths = array_fill(0, $dom[$key]['cols'], $table_min_column_width);
19939 if ($dom[$key]['value'] == 'tr') {
19940 // reset column counter
19944 if (($dom[$key]['value'] == 'td') OR ($dom[$key]['value'] == 'th')) {
19945 $trid = $dom[$key]['parent'];
19946 $table_el = $dom[$trid]['parent'];
19947 if (!isset($dom[$table_el]['cols'])) {
19948 $dom[$table_el]['cols'] = $dom[$trid]['cols'];
19950 // store border info
19952 if (isset($dom[$key]['border']) AND !empty($dom[$key]['border'])) {
19953 $tdborder = $dom[$key]['border'];
19955 $colspan = $dom[$key]['attribute']['colspan'];
19956 $old_cell_padding = $this->cell_padding
;
19957 if (isset($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'])) {
19958 $crclpd = $this->getHTMLUnitToUnits($dom[($dom[$trid]['parent'])]['attribute']['cellpadding'], 1, 'px');
19959 $current_cell_padding = array('L' => $crclpd, 'T' => $crclpd, 'R' => $crclpd, 'B' => $crclpd);
19960 } elseif (isset($dom[($dom[$trid]['parent'])]['padding'])) {
19961 $current_cell_padding = $dom[($dom[$trid]['parent'])]['padding'];
19963 $current_cell_padding = array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0);
19965 $this->cell_padding
= $current_cell_padding;
19966 if (isset($dom[$key]['height'])) {
19967 // minimum cell height
19968 $cellh = $this->getHTMLUnitToUnits($dom[$key]['height'], 0, 'px');
19972 if (isset($dom[$key]['content'])) {
19973 $cell_content = $dom[$key]['content'];
19975 $cell_content = ' ';
19977 $tagtype = $dom[$key]['value'];
19979 while (($key < $maxel) AND (!(($dom[$key]['tag']) AND (!$dom[$key]['opening']) AND ($dom[$key]['value'] == $tagtype) AND ($dom[$key]['parent'] == $parentid)))) {
19980 // move $key index forward
19983 if (!isset($dom[$trid]['startpage'])) {
19984 $dom[$trid]['startpage'] = $this->page
;
19986 $this->setPage($dom[$trid]['startpage']);
19988 if (!isset($dom[$trid]['startcolumn'])) {
19989 $dom[$trid]['startcolumn'] = $this->current_column
;
19990 } elseif ($this->current_column
!= $dom[$trid]['startcolumn']) {
19992 $this->selectColumn($dom[$trid]['startcolumn']);
19995 if (!isset($dom[$trid]['starty'])) {
19996 $dom[$trid]['starty'] = $this->y
;
19998 $this->y
= $dom[$trid]['starty'];
20000 if (!isset($dom[$trid]['startx'])) {
20001 $dom[$trid]['startx'] = $this->x
;
20002 $this->x +
= $cellspacingx;
20004 $this->x +
= ($cellspacingx / 2);
20006 if (isset($dom[$parentid]['attribute']['rowspan'])) {
20007 $rowspan = intval($dom[$parentid]['attribute']['rowspan']);
20011 // skip row-spanned cells started on the previous rows
20012 if (isset($dom[$table_el]['rowspans'])) {
20014 $rskmax = count($dom[$table_el]['rowspans']);
20015 while ($rsk < $rskmax) {
20016 $trwsp = $dom[$table_el]['rowspans'][$rsk];
20017 $rsstartx = $trwsp['startx'];
20018 $rsendx = $trwsp['endx'];
20019 // account for margin changes
20020 if ($trwsp['startpage'] < $this->page
) {
20021 if (($this->rtl
) AND ($this->pagedim
[$this->page
]['orm'] != $this->pagedim
[$trwsp['startpage']]['orm'])) {
20022 $dl = ($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$trwsp['startpage']]['orm']);
20025 } elseif ((!$this->rtl
) AND ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$trwsp['startpage']]['olm'])) {
20026 $dl = ($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$trwsp['startpage']]['olm']);
20031 if (($trwsp['rowspan'] > 0)
20032 AND ($rsstartx > ($this->x
- $cellspacing['H'] - $current_cell_padding['L'] - $this->feps
))
20033 AND ($rsstartx < ($this->x +
$cellspacing['H'] +
$current_cell_padding['R'] +
$this->feps
))
20034 AND (($trwsp['starty'] < ($this->y
- $this->feps
)) OR ($trwsp['startpage'] < $this->page
) OR ($trwsp['startcolumn'] < $this->current_column
))) {
20035 // set the starting X position of the current cell
20036 $this->x
= $rsendx +
$cellspacingx;
20037 // increment column indicator
20038 $colid +
= $trwsp['colspan'];
20039 if (($trwsp['rowspan'] == 1)
20040 AND (isset($dom[$trid]['endy']))
20041 AND (isset($dom[$trid]['endpage']))
20042 AND (isset($dom[$trid]['endcolumn']))
20043 AND ($trwsp['endpage'] == $dom[$trid]['endpage'])
20044 AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
20045 // set ending Y position for row
20046 $dom[$table_el]['rowspans'][$rsk]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
20047 $dom[$trid]['endy'] = $dom[$table_el]['rowspans'][$rsk]['endy'];
20055 if (isset($dom[$parentid]['width'])) {
20056 // user specified width
20057 $cellw = $this->getHTMLUnitToUnits($dom[$parentid]['width'], $table_columns_width, 'px');
20058 $tmpcw = ($cellw / $colspan);
20059 for ($i = 0; $i < $colspan; ++
$i) {
20060 $table_colwidths[($colid +
$i)] = $tmpcw;
20063 // inherit column width
20065 for ($i = 0; $i < $colspan; ++
$i) {
20066 $cellw +
= $table_colwidths[($colid +
$i)];
20069 $cellw +
= (($colspan - 1) * $cellspacing['H']);
20070 // increment column indicator
20071 $colid +
= $colspan;
20072 // add rowspan information to table element
20073 if ($rowspan > 1) {
20074 $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
));
20076 $cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x
));
20077 if ($rowspan > 1) {
20078 $dom[$trid]['cellpos'][($cellid - 1)]['rowspanid'] = ($trsid - 1);
20080 // push background colors
20081 if (isset($dom[$parentid]['bgcolor']) AND ($dom[$parentid]['bgcolor'] !== false)) {
20082 $dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
20084 // store border info
20085 if (isset($tdborder) AND !empty($tdborder)) {
20086 $dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
20088 $prevLastH = $this->lasth
;
20089 // store some info for multicolumn mode
20091 $this->colxshift
['x'] = $this->w
- $this->x
- $this->rMargin
;
20093 $this->colxshift
['x'] = $this->x
- $this->lMargin
;
20095 $this->colxshift
['s'] = $cellspacing;
20096 $this->colxshift
['p'] = $current_cell_padding;
20097 // ****** write the cell content ******
20098 $this->MultiCell($cellw, $cellh, $cell_content, false, $lalign, false, 2, '', '', true, 0, true);
20099 // restore some values
20100 $this->colxshift
= array('x' => 0, 's' => array('H' => 0, 'V' => 0), 'p' => array('L' => 0, 'T' => 0, 'R' => 0, 'B' => 0));
20101 $this->lasth
= $prevLastH;
20102 $this->cell_padding
= $old_cell_padding;
20103 $dom[$trid]['cellpos'][($cellid - 1)]['endx'] = $this->x
;
20104 // update the end of row position
20105 if ($rowspan <= 1) {
20106 if (isset($dom[$trid]['endy'])) {
20107 if (($this->page
== $dom[$trid]['endpage']) AND ($this->current_column
== $dom[$trid]['endcolumn'])) {
20108 $dom[$trid]['endy'] = max($this->y
, $dom[$trid]['endy']);
20109 } elseif (($this->page
> $dom[$trid]['endpage']) OR ($this->current_column
> $dom[$trid]['endcolumn'])) {
20110 $dom[$trid]['endy'] = $this->y
;
20113 $dom[$trid]['endy'] = $this->y
;
20115 if (isset($dom[$trid]['endpage'])) {
20116 $dom[$trid]['endpage'] = max($this->page
, $dom[$trid]['endpage']);
20118 $dom[$trid]['endpage'] = $this->page
;
20120 if (isset($dom[$trid]['endcolumn'])) {
20121 $dom[$trid]['endcolumn'] = max($this->current_column
, $dom[$trid]['endcolumn']);
20123 $dom[$trid]['endcolumn'] = $this->current_column
;
20126 // account for row-spanned cells
20127 $dom[$table_el]['rowspans'][($trsid - 1)]['endx'] = $this->x
;
20128 $dom[$table_el]['rowspans'][($trsid - 1)]['endy'] = $this->y
;
20129 $dom[$table_el]['rowspans'][($trsid - 1)]['endpage'] = $this->page
;
20130 $dom[$table_el]['rowspans'][($trsid - 1)]['endcolumn'] = $this->current_column
;
20132 if (isset($dom[$table_el]['rowspans'])) {
20133 // update endy and endpage on rowspanned cells
20134 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
20135 if ($trwsp['rowspan'] > 0) {
20136 if (isset($dom[$trid]['endpage'])) {
20137 if (($trwsp['endpage'] == $dom[$trid]['endpage']) AND ($trwsp['endcolumn'] == $dom[$trid]['endcolumn'])) {
20138 $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$trid]['endy'], $trwsp['endy']);
20139 } elseif (($trwsp['endpage'] < $dom[$trid]['endpage']) OR ($trwsp['endcolumn'] < $dom[$trid]['endcolumn'])) {
20140 $dom[$table_el]['rowspans'][$k]['endy'] = $dom[$trid]['endy'];
20141 $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[$trid]['endpage'];
20142 $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[$trid]['endcolumn'];
20144 $dom[$trid]['endy'] = $this->pagedim
[$dom[$trid]['endpage']]['hk'] - $this->pagedim
[$dom[$trid]['endpage']]['bm'];
20150 $this->x +
= ($cellspacingx / 2);
20152 // opening tag (or self-closing tag)
20153 if (!isset($opentagpos)) {
20154 if ($this->inxobj
) {
20155 // we are inside an XObject template
20156 $opentagpos = strlen($this->xobjects
[$this->xobjid
]['outdata']);
20157 } elseif (!$this->InFooter
) {
20158 if (isset($this->footerlen
[$this->page
])) {
20159 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
] - $this->footerlen
[$this->page
];
20161 $this->footerpos
[$this->page
] = $this->pagelen
[$this->page
];
20163 $opentagpos = $this->footerpos
[$this->page
];
20166 $this->openHTMLTagHandler($dom, $key, $cell);
20168 } else { // closing tag
20169 $prev_numpages = $this->numpages
;
20170 $old_bordermrk = $this->bordermrk
[$this->page
];
20171 $this->closeHTMLTagHandler($dom, $key, $cell, $maxbottomliney);
20172 if ($this->bordermrk
[$this->page
] > $old_bordermrk) {
20173 $startlinepos +
= ($this->bordermrk
[$this->page
] - $old_bordermrk);
20175 if ($prev_numpages > $this->numpages
) {
20176 $startlinepage = $this->page
;
20179 } elseif (strlen($dom[$key]['value']) > 0) {
20181 if (!$this->empty_string($this->lispacer
) AND ($this->lispacer
!= '^')) {
20182 $this->SetFont($pfontname, $pfontstyle, $pfontsize);
20183 $this->resetLastH();
20184 $minstartliney = $this->y
;
20185 $maxbottomliney = ($startliney +
($this->FontSize
* $this->cell_height_ratio
));
20186 $this->putHtmlListBullet($this->listnum
, $this->lispacer
, $pfontsize);
20187 $this->SetFont($curfontname, $curfontstyle, $curfontsize);
20188 $this->resetLastH();
20189 if (is_numeric($pfontsize) AND ($pfontsize > 0) AND is_numeric($curfontsize) AND ($curfontsize > 0) AND ($pfontsize != $curfontsize)) {
20190 $pfontascent = $this->getFontAscent($pfontname, $pfontstyle, $pfontsize);
20191 $pfontdescent = $this->getFontDescent($pfontname, $pfontstyle, $pfontsize);
20192 $this->y +
= ((($pfontsize - $curfontsize) * $this->cell_height_ratio
/ $this->k
) +
$pfontascent - $curfontascent - $pfontdescent +
$curfontdescent) / 2;
20193 $minstartliney = min($this->y
, $minstartliney);
20194 $maxbottomliney = max(($this->y +
(($pfontsize * $this->cell_height_ratio
) / $this->k
)), $maxbottomliney);
20198 $this->htmlvspace
= 0;
20199 if ((!$this->premode
) AND $this->isRTLTextDir()) {
20200 // reverse spaces order
20201 $lsp = ''; // left spaces
20202 $rsp = ''; // right spaces
20203 if (preg_match('/^('.$this->re_space
['p'].'+)/'.$this->re_space
['m'], $dom[$key]['value'], $matches)) {
20204 $lsp = $matches[1];
20206 if (preg_match('/('.$this->re_space
['p'].'+)$/'.$this->re_space
['m'], $dom[$key]['value'], $matches)) {
20207 $rsp = $matches[1];
20209 $dom[$key]['value'] = $rsp.$this->stringTrim($dom[$key]['value']).$lsp;
20212 if (!$this->premode
) {
20213 $prelen = strlen($dom[$key]['value']);
20214 if ($this->isRTLTextDir()) {
20215 // right trim except non-breaking space
20216 $dom[$key]['value'] = $this->stringRightTrim($dom[$key]['value']);
20218 // left trim except non-breaking space
20219 $dom[$key]['value'] = $this->stringLeftTrim($dom[$key]['value']);
20221 $postlen = strlen($dom[$key]['value']);
20222 if (($postlen == 0) AND ($prelen > 0)) {
20223 $dom[$key]['trimmed_space'] = true;
20227 $firstblock = true;
20229 $firstblock = false;
20230 // replace empty multiple spaces string with a single space
20231 $dom[$key]['value'] = preg_replace('/^'.$this->re_space
['p'].'+$/'.$this->re_space
['m'], chr(32), $dom[$key]['value']);
20235 $this->x
-= $this->textindent
;
20237 $this->x +
= $this->textindent
;
20239 if (!isset($dom[$key]['trimmed_space']) OR !$dom[$key]['trimmed_space']) {
20240 $strlinelen = $this->GetStringWidth($dom[$key]['value']);
20241 if (!empty($this->HREF
) AND (isset($this->HREF
['url']))) {
20244 if (isset($dom[($dom[$key]['parent'])]['fgcolor']) AND ($dom[($dom[$key]['parent'])]['fgcolor'] !== false)) {
20245 $hrefcolor = $dom[($dom[$key]['parent'])]['fgcolor'];
20248 if (isset($dom[($dom[$key]['parent'])]['fontstyle']) AND ($dom[($dom[$key]['parent'])]['fontstyle'] !== false)) {
20249 $hrefstyle = $dom[($dom[$key]['parent'])]['fontstyle'];
20251 $strrest = $this->addHtmlLink($this->HREF
['url'], $dom[$key]['value'], $wfill, true, $hrefcolor, $hrefstyle, true);
20253 $wadj = 0; // space to leave for block continuity
20254 $adjblks = 0; // number of blocks
20256 $cwa = $this->x
- $this->lMargin
;
20258 $cwa = $this->w
- $this->rMargin
- $this->x
;
20260 if ($strlinelen < $cwa) {
20261 // check the next text blocks for continuity
20262 $nkey = ($key +
1);
20263 $write_block = true;
20264 $same_textdir = true;
20265 $tmp_fontname = $this->FontFamily
;
20266 $tmp_fontstyle = $this->FontStyle
;
20267 $tmp_fontsize = $this->FontSizePt
;
20268 while ($write_block AND isset($dom[$nkey])) {
20269 if ($dom[$nkey]['tag']) {
20270 if ($dom[$nkey]['block']) {
20272 $write_block = false;
20274 $tmp_fontname = isset($dom[$nkey]['fontname']) ?
$dom[$nkey]['fontname'] : $this->FontFamily
;
20275 $tmp_fontstyle = isset($dom[$nkey]['fontstyle']) ?
$dom[$nkey]['fontstyle'] : $this->FontStyle
;
20276 $tmp_fontsize = isset($dom[$nkey]['fontsize']) ?
$dom[$nkey]['fontsize'] : $this->FontSizePt
;
20277 $same_textdir = ($dom[$nkey]['dir'] == $dom[$key]['dir']);
20279 $nextstr = preg_split('/'.$this->re_space
['p'].'+/'.$this->re_space
['m'], $dom[$nkey]['value']);
20280 if (isset($nextstr[0])) {
20281 if ($same_textdir) {
20282 $wadj +
= $this->GetStringWidth($nextstr[0], $tmp_fontname, $tmp_fontstyle, $tmp_fontsize);
20286 if (isset($nextstr[1])) {
20287 $write_block = false;
20293 // check for reversed text direction
20294 if (($wadj > 0) AND (($this->rtl
AND ($this->tmprtl
=== 'L')) OR (!$this->rtl
AND ($this->tmprtl
=== 'R')))) {
20295 // LTR text on RTL direction or RTL text on LTR direction
20296 $reverse_dir = true;
20297 $this->rtl
= !$this->rtl
;
20298 $revshift = ($strlinelen +
$wadj +
0.000001); // add little quantity for rounding problems
20300 $this->x +
= $revshift;
20302 $this->x
-= $revshift;
20306 // ****** write only until the end of the line and get the rest ******
20307 $strrest = $this->Write($this->lasth
, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
20308 // restore default direction
20309 if ($reverse_dir AND ($wadj == 0)) {
20311 $this->rtl
= !$this->rtl
;
20312 $reverse_dir = false;
20316 $this->textindent
= 0;
20317 if (strlen($strrest) > 0) {
20318 // store the remaining string on the previous $key position
20319 $this->newline
= true;
20320 if ($strrest == $dom[$key]['value']) {
20321 // used to avoid infinite loop
20326 $dom[$key]['value'] = $strrest;
20329 $this->x
-= $this->cell_padding
['R'];
20331 $this->x +
= $this->cell_padding
['L'];
20342 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')) {
20343 // check if we are on a new page or on a new column
20344 if ((!$undo) AND ($this->y
< $this->start_transaction_y
)) {
20345 // we are on a new page or on a new column and the total object height is less than the available vertical space.
20346 // restore previous object
20347 $this->rollbackTransaction(true);
20348 // restore previous values
20349 foreach ($this_method_vars as $vkey => $vval) {
20352 // add a page (or trig AcceptPageBreak() for multicolumn mode)
20354 if ((!$this->checkPageBreak($this->PageBreakTrigger +
1)) AND ($this->y
< $pre_y)) {
20355 $startliney = $this->y
;
20357 $undo = true; // avoid infinite loop
20362 } // end for each $key
20363 // align the last line
20364 if (isset($startlinex)) {
20365 $yshift = $minstartliney - $startliney;
20366 if (($yshift > 0) OR ($this->page
> $startlinepage)) {
20370 // the last line must be shifted to be aligned as requested
20371 $linew = abs($this->endlinex
- $startlinex);
20372 if ($this->inxobj
) {
20373 // we are inside an XObject template
20374 $pstart = substr($this->xobjects
[$this->xobjid
]['outdata'], 0, $startlinepos);
20375 if (isset($opentagpos)) {
20376 $midpos = $opentagpos;
20381 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos, ($midpos - $startlinepos));
20382 $pend = substr($this->xobjects
[$this->xobjid
]['outdata'], $midpos);
20384 $pmid = substr($this->xobjects
[$this->xobjid
]['outdata'], $startlinepos);
20388 $pstart = substr($this->getPageBuffer($startlinepage), 0, $startlinepos);
20389 if (isset($opentagpos) AND isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
20390 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
20391 $midpos = min($opentagpos, $this->footerpos
[$startlinepage]);
20392 } elseif (isset($opentagpos)) {
20393 $midpos = $opentagpos;
20394 } elseif (isset($this->footerlen
[$startlinepage]) AND (!$this->InFooter
)) {
20395 $this->footerpos
[$startlinepage] = $this->pagelen
[$startlinepage] - $this->footerlen
[$startlinepage];
20396 $midpos = $this->footerpos
[$startlinepage];
20401 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos, ($midpos - $startlinepos));
20402 $pend = substr($this->getPageBuffer($startlinepage), $midpos);
20404 $pmid = substr($this->getPageBuffer($startlinepage), $startlinepos);
20408 if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl
)) OR (($plalign == 'L') AND ($this->rtl
)))))) {
20409 // calculate shifting amount
20411 if ($this->lMargin
!= $prevlMargin) {
20412 $tw +
= ($prevlMargin - $this->lMargin
);
20414 if ($this->rMargin
!= $prevrMargin) {
20415 $tw +
= ($prevrMargin - $this->rMargin
);
20417 $one_space_width = $this->GetStringWidth(chr(32));
20418 $no = 0; // number of spaces on a line contained on a single block
20419 if ($this->isRTLTextDir()) { // RTL
20420 // remove left space if exist
20421 $pos1 = $this->revstrpos($pmid, '[(');
20423 $pos1 = intval($pos1);
20424 if ($this->isUnicodeFont()) {
20425 $pos2 = intval($this->revstrpos($pmid, '[('.chr(0).chr(32)));
20428 $pos2 = intval($this->revstrpos($pmid, '[('.chr(32)));
20431 if ($pos1 == $pos2) {
20432 $pmid = substr($pmid, 0, ($pos1 +
2)).substr($pmid, ($pos1 +
2 +
$spacelen));
20433 if (substr($pmid, $pos1, 4) == '[()]') {
20434 $linew -= $one_space_width;
20435 } elseif ($pos1 == strpos($pmid, '[(')) {
20441 // remove right space if exist
20442 $pos1 = $this->revstrpos($pmid, ')]');
20444 $pos1 = intval($pos1);
20445 if ($this->isUnicodeFont()) {
20446 $pos2 = intval($this->revstrpos($pmid, chr(0).chr(32).')]')) +
2;
20449 $pos2 = intval($this->revstrpos($pmid, chr(32).')]')) +
1;
20452 if ($pos1 == $pos2) {
20453 $pmid = substr($pmid, 0, ($pos1 - $spacelen)).substr($pmid, $pos1);
20454 $linew -= $one_space_width;
20458 $mdiff = ($tw - $linew);
20459 if ($plalign == 'C') {
20461 $t_x = -($mdiff / 2);
20463 $t_x = ($mdiff / 2);
20465 } elseif ($plalign == 'R') {
20466 // right alignment on LTR document
20468 } elseif ($plalign == 'L') {
20469 // left alignment on RTL document
20472 } // end if startlinex
20473 if (($t_x != 0) OR ($yshift < 0)) {
20475 $trx = sprintf('1 0 0 1 %.3F %.3F cm', ($t_x * $this->k
), ($yshift * $this->k
));
20476 $pstart .= "\nq\n".$trx."\n".$pmid."\nQ\n";
20477 $endlinepos = strlen($pstart);
20478 if ($this->inxobj
) {
20479 // we are inside an XObject template
20480 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$pend;
20481 foreach ($this->xobjects
[$this->xobjid
]['annotations'] as $pak => $pac) {
20482 if ($pak >= $pask) {
20483 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['x'] +
= $t_x;
20484 $this->xobjects
[$this->xobjid
]['annotations'][$pak]['y'] -= $yshift;
20488 $this->setPageBuffer($startlinepage, $pstart.$pend);
20489 // shift the annotations and links
20490 if (isset($this->PageAnnots
[$this->page
])) {
20491 foreach ($this->PageAnnots
[$this->page
] as $pak => $pac) {
20492 if ($pak >= $pask) {
20493 $this->PageAnnots
[$this->page
][$pak]['x'] +
= $t_x;
20494 $this->PageAnnots
[$this->page
][$pak]['y'] -= $yshift;
20499 $this->y
-= $yshift;
20502 // restore previous values
20503 $this->setGraphicVars($gvars);
20504 if ($this->num_columns
> 1) {
20505 $this->selectColumn();
20506 } elseif ($this->page
> $prevPage) {
20507 $this->lMargin
= $this->pagedim
[$this->page
]['olm'];
20508 $this->rMargin
= $this->pagedim
[$this->page
]['orm'];
20510 // restore previous list state
20511 $this->cell_height_ratio
= $prev_cell_height_ratio;
20512 $this->listnum
= $prev_listnum;
20513 $this->listordered
= $prev_listordered;
20514 $this->listcount
= $prev_listcount;
20515 $this->lispacer
= $prev_lispacer;
20516 if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
20517 $this->Ln($this->lasth
);
20518 if ($this->y
< $maxbottomliney) {
20519 $this->y
= $maxbottomliney;
20526 * Process opening tags.
20527 * @param $dom (array) html dom array
20528 * @param $key (int) current element id
20529 * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
20532 protected function openHTMLTagHandler(&$dom, $key, $cell) {
20534 $parent = $dom[($dom[$key]['parent'])];
20535 $firsttag = ($key == 1);
20536 // check for text direction attribute
20537 if (isset($tag['dir'])) {
20538 $this->setTempRTL($tag['dir']);
20540 $this->tmprtl
= false;
20542 if ($tag['block']) {
20543 $hbz = 0; // distance from y to line bottom
20544 $hb = 0; // vertical space between block tags
20545 // calculate vertical space for block tags
20546 if (isset($this->tagvspaces
[$tag['value']][0]['h']) AND ($this->tagvspaces
[$tag['value']][0]['h'] >= 0)) {
20547 $cur_h = $this->tagvspaces
[$tag['value']][0]['h'];
20548 } elseif (isset($tag['fontsize'])) {
20549 $cur_h = ($tag['fontsize'] / $this->k
) * $this->cell_height_ratio
;
20551 $cur_h = $this->FontSize
* $this->cell_height_ratio
;
20553 if (isset($this->tagvspaces
[$tag['value']][0]['n'])) {
20554 $n = $this->tagvspaces
[$tag['value']][0]['n'];
20555 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
20560 $hb = ($n * $cur_h);
20561 if (($this->htmlvspace
<= 0) AND ($n > 0)) {
20562 if (isset($parent['fontsize'])) {
20563 $hbz = (($parent['fontsize'] / $this->k
) * $this->cell_height_ratio
);
20565 $hbz = $this->FontSize
* $this->cell_height_ratio
;
20570 switch($tag['value']) {
20574 $dom[$key]['rowspans'] = array();
20575 if (!isset($dom[$key]['attribute']['nested']) OR ($dom[$key]['attribute']['nested'] != 'true')) {
20576 // set table header
20577 if (!$this->empty_string($dom[$key]['thead'])) {
20578 // set table header
20579 $this->thead
= $dom[$key]['thead'];
20580 if (!isset($this->theadMargins
) OR (empty($this->theadMargins
))) {
20581 $this->theadMargins
= array();
20582 $this->theadMargins
['cell_padding'] = $this->cell_padding
;
20583 $this->theadMargins
['lmargin'] = $this->lMargin
;
20584 $this->theadMargins
['rmargin'] = $this->rMargin
;
20585 $this->theadMargins
['page'] = $this->page
;
20589 // store current margins and page
20590 $dom[$key]['old_cell_padding'] = $this->cell_padding
;
20591 if (isset($tag['attribute']['cellpadding'])) {
20592 $pad = $this->getHTMLUnitToUnits($tag['attribute']['cellpadding'], 1, 'px');
20593 $this->SetCellPadding($pad);
20594 } elseif (isset($tag['padding'])) {
20595 $this->cell_padding
= $tag['padding'];
20597 if (isset($tag['attribute']['cellspacing'])) {
20598 $cs = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
20599 } elseif (isset($tag['border-spacing'])) {
20600 $cs = $tag['border-spacing']['V'];
20602 $prev_y = $this->y
;
20603 if ($this->checkPageBreak(((2 * $cp) +
(2 * $cs) +
$this->lasth
), '', false) OR ($this->y
< $prev_y)) {
20604 $this->inthead
= true;
20605 // add a page (or trig AcceptPageBreak() for multicolumn mode)
20606 $this->checkPageBreak($this->PageBreakTrigger +
1);
20611 // array of columns positions
20612 $dom[$key]['cellpos'] = array();
20616 if ((isset($tag['height'])) AND ($tag['height'] != '')) {
20617 $hrHeight = $this->getHTMLUnitToUnits($tag['height'], 1, 'px');
20619 $hrHeight = $this->GetLineWidth();
20621 $this->addHTMLVertSpace($hbz, ($hrHeight / 2), $cell, $firsttag);
20622 $x = $this->GetX();
20623 $y = $this->GetY();
20624 $wtmp = $this->w
- $this->lMargin
- $this->rMargin
;
20626 $wtmp -= ($this->cell_padding
['L'] +
$this->cell_padding
['R']);
20628 if ((isset($tag['width'])) AND ($tag['width'] != '')) {
20629 $hrWidth = $this->getHTMLUnitToUnits($tag['width'], $wtmp, 'px');
20633 $prevlinewidth = $this->GetLineWidth();
20634 $this->SetLineWidth($hrHeight);
20635 $this->Line($x, $y, $x +
$hrWidth, $y);
20636 $this->SetLineWidth($prevlinewidth);
20637 $this->addHTMLVertSpace(($hrHeight / 2), 0, $cell, !isset($dom[($key +
1)]));
20641 if (array_key_exists('href', $tag['attribute'])) {
20642 $this->HREF
['url'] = $tag['attribute']['href'];
20647 if (isset($tag['attribute']['src'])) {
20648 // replace relative path with real server path
20649 if (($tag['attribute']['src'][0] == '/') AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
20650 $findroot = strpos($tag['attribute']['src'], $_SERVER['DOCUMENT_ROOT']);
20651 if (($findroot === false) OR ($findroot > 1)) {
20652 $tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
20655 $tag['attribute']['src'] = urldecode($tag['attribute']['src']);
20656 $type = $this->getImageFileType($tag['attribute']['src']);
20657 $testscrtype = @parse_url
($tag['attribute']['src']);
20658 if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
20659 // convert URL to server path
20660 $tag['attribute']['src'] = str_replace(K_PATH_URL
, K_PATH_MAIN
, $tag['attribute']['src']);
20662 if (!isset($tag['width'])) {
20665 if (!isset($tag['height'])) {
20666 $tag['height'] = 0;
20668 //if (!isset($tag['attribute']['align'])) {
20669 // the only alignment supported is "bottom"
20670 // further development is required for other modes.
20671 $tag['attribute']['align'] = 'bottom';
20673 switch($tag['attribute']['align']) {
20693 // eliminate marker spaces
20694 if (isset($dom[($key - 1)])) {
20695 if (($dom[($key - 1)]['value'] == ' ') OR (isset($dom[($key - 1)]['trimmed_space']))) {
20696 $xpos -= $this->GetStringWidth(chr(32));
20697 } elseif ($this->rtl
AND $dom[($key - 1)]['value'] == ' ') {
20698 $xpos +
= (2 * $this->GetStringWidth(chr(32)));
20702 if (isset($this->HREF
['url']) AND !$this->empty_string($this->HREF
['url'])) {
20703 $imglink = $this->HREF
['url'];
20704 if ($imglink{0} == '#') {
20705 // convert url to internal link
20706 $lnkdata = explode(',', $imglink);
20707 if (isset($lnkdata[0])) {
20708 $page = intval(substr($lnkdata[0], 1));
20709 if (empty($page) OR ($page <= 0)) {
20710 $page = $this->page
;
20712 if (isset($lnkdata[1]) AND (strlen($lnkdata[1]) > 0)) {
20713 $lnky = floatval($lnkdata[1]);
20717 $imglink = $this->AddLink();
20718 $this->SetLink($imglink, $lnky, $page);
20723 if (isset($tag['border']) AND !empty($tag['border'])) {
20724 // currently only support 1 (frame) or a combination of 'LTRB'
20725 $border = $tag['border'];
20728 if (isset($tag['width'])) {
20729 $iw = $this->getHTMLUnitToUnits($tag['width'], 1, 'px', false);
20732 if (isset($tag['height'])) {
20733 $ih = $this->getHTMLUnitToUnits($tag['height'], 1, 'px', false);
20735 if (($type == 'eps') OR ($type == 'ai')) {
20736 $this->ImageEps($tag['attribute']['src'], $xpos, $this->y
, $iw, $ih, $imglink, true, $align, '', $border, true);
20737 } elseif ($type == 'svg') {
20738 $this->ImageSVG($tag['attribute']['src'], $xpos, $this->y
, $iw, $ih, $imglink, $align, '', $border, true);
20740 $this->Image($tag['attribute']['src'], $xpos, $this->y
, $iw, $ih, '', $imglink, $align, false, 300, '', false, false, $border, false, false, true);
20748 $this->y
= (($this->img_rb_y +
$prevy - ($tag['fontsize'] / $this->k
)) / 2) ;
20752 $this->y
= $this->img_rb_y
- ($tag['fontsize'] / $this->k
);
20761 if ($this->listnum
== 1) {
20762 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
20764 $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
20769 $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
20774 $this->rMargin +
= $this->listindent
;
20776 $this->lMargin +
= $this->listindent
;
20778 ++
$this->listindentlevel
;
20779 $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
20785 if ($tag['value'] == 'ol') {
20786 $this->listordered
[$this->listnum
] = true;
20788 $this->listordered
[$this->listnum
] = false;
20790 if (isset($tag['attribute']['start'])) {
20791 $this->listcount
[$this->listnum
] = intval($tag['attribute']['start']) - 1;
20793 $this->listcount
[$this->listnum
] = 0;
20796 $this->rMargin +
= $this->listindent
;
20797 $this->x
-= $this->listindent
;
20799 $this->lMargin +
= $this->listindent
;
20800 $this->x +
= $this->listindent
;
20802 ++
$this->listindentlevel
;
20803 if ($this->listnum
== 1) {
20804 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
20806 $this->addHTMLVertSpace(0, 0, $cell, $firsttag);
20811 $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
20812 if ($this->listordered
[$this->listnum
]) {
20814 if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
20815 $this->lispacer
= $parent['attribute']['type'];
20816 } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
20817 $this->lispacer
= $parent['listtype'];
20818 } elseif (isset($this->lisymbol
) AND !$this->empty_string($this->lisymbol
)) {
20819 $this->lispacer
= $this->lisymbol
;
20821 $this->lispacer
= '#';
20823 ++
$this->listcount
[$this->listnum
];
20824 if (isset($tag['attribute']['value'])) {
20825 $this->listcount
[$this->listnum
] = intval($tag['attribute']['value']);
20829 if (isset($parent['attribute']['type']) AND !$this->empty_string($parent['attribute']['type'])) {
20830 $this->lispacer
= $parent['attribute']['type'];
20831 } elseif (isset($parent['listtype']) AND !$this->empty_string($parent['listtype'])) {
20832 $this->lispacer
= $parent['listtype'];
20833 } elseif (isset($this->lisymbol
) AND !$this->empty_string($this->lisymbol
)) {
20834 $this->lispacer
= $this->lisymbol
;
20836 $this->lispacer
= '!';
20841 case 'blockquote': {
20843 $this->rMargin +
= $this->listindent
;
20845 $this->lMargin +
= $this->listindent
;
20847 ++
$this->listindentlevel
;
20848 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
20852 $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
20856 $this->addHTMLVertSpace($hbz, 0, $cell, $firsttag);
20860 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
20864 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
20865 $this->premode
= true;
20869 $this->SetXY($this->GetX(), $this->GetY() - ((0.7 * $this->FontSizePt
) / $this->k
));
20873 $this->SetXY($this->GetX(), $this->GetY() +
((0.3 * $this->FontSizePt
) / $this->k
));
20882 $this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
20885 // Form fields (since 4.8.000 - 2009-09-07)
20887 if (isset($tag['attribute']['action'])) {
20888 $this->form_action
= $tag['attribute']['action'];
20890 $this->form_action
= K_PATH_URL
.$_SERVER['SCRIPT_NAME'];
20892 if (isset($tag['attribute']['enctype'])) {
20893 $this->form_enctype
= $tag['attribute']['enctype'];
20895 $this->form_enctype
= 'application/x-www-form-urlencoded';
20897 if (isset($tag['attribute']['method'])) {
20898 $this->form_mode
= $tag['attribute']['method'];
20900 $this->form_mode
= 'post';
20905 if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
20906 $name = $tag['attribute']['name'];
20912 if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
20913 $prop['readonly'] = true;
20915 if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
20916 $value = $tag['attribute']['value'];
20918 if (isset($tag['attribute']['maxlength']) AND !$this->empty_string($tag['attribute']['maxlength'])) {
20919 $opt['maxlen'] = intval($tag['attribute']['value']);
20921 $h = $this->FontSize
* $this->cell_height_ratio
;
20922 if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
20923 $w = intval($tag['attribute']['size']) * $this->GetStringWidth(chr(32)) * 2;
20927 if (isset($tag['attribute']['checked']) AND (($tag['attribute']['checked'] == 'checked') OR ($tag['attribute']['checked'] == 'true'))) {
20932 switch ($tag['attribute']['type']) {
20934 if (isset($value)) {
20935 $opt['v'] = $value;
20937 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
20941 if (isset($value)) {
20942 $opt['v'] = $value;
20944 $prop['password'] = 'true';
20945 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
20949 $this->CheckBox($name, $w, $checked, $prop, $opt, $value, '', '', false);
20953 $this->RadioButton($name, $w, $prop, $opt, $value, $checked, '', '', false);
20957 $w = $this->GetStringWidth($value) * 1.5;
20959 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
20961 $action['S'] = 'SubmitForm';
20962 $action['F'] = $this->form_action
;
20963 if ($this->form_enctype
!= 'FDF') {
20964 $action['Flags'] = array('ExportFormat');
20966 if ($this->form_mode
== 'get') {
20967 $action['Flags'] = array('GetMethod');
20969 $this->Button($name, $w, $h, $value, $action, $prop, $opt, '', '', false);
20973 $w = $this->GetStringWidth($value) * 1.5;
20975 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
20976 $this->Button($name, $w, $h, $value, array('S'=>'ResetForm'), $prop, $opt, '', '', false);
20980 $prop['fileSelect'] = 'true';
20981 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
20982 if (!isset($value)) {
20985 $w = $this->GetStringWidth($value) * 2;
20987 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
20988 $jsaction = 'var f=this.getField(\''.$name.'\'); f.browseForFileToSubmit();';
20989 $this->Button('FB_'.$name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
20993 if (isset($value)) {
20994 $opt['v'] = $value;
20996 $opt['f'] = array('invisible', 'hidden');
20997 $this->TextField($name, 0, 0, $prop, $opt, '', '', false);
21001 // THIS TYPE MUST BE FIXED
21002 if (isset($tag['attribute']['src']) AND !$this->empty_string($tag['attribute']['src'])) {
21003 $img = $tag['attribute']['src'];
21008 //$opt['mk'] = array('i'=>$img, 'tp'=>1, 'if'=>array('sw'=>'A', 's'=>'A', 'fb'=>false));
21009 if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
21010 $jsaction = $tag['attribute']['onclick'];
21014 $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
21018 $w = $this->GetStringWidth($value) * 1.5;
21020 $prop = array('lineWidth'=>1, 'borderStyle'=>'beveled', 'fillColor'=>array(196, 196, 196), 'strokeColor'=>array(255, 255, 255));
21021 if (isset($tag['attribute']['onclick']) AND !empty($tag['attribute']['onclick'])) {
21022 $jsaction = $tag['attribute']['onclick'];
21026 $this->Button($name, $w, $h, $value, $jsaction, $prop, $opt, '', '', false);
21035 if (isset($tag['attribute']['readonly']) AND !$this->empty_string($tag['attribute']['readonly'])) {
21036 $prop['readonly'] = true;
21038 if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
21039 $name = $tag['attribute']['name'];
21043 if (isset($tag['attribute']['value']) AND !$this->empty_string($tag['attribute']['value'])) {
21044 $opt['v'] = $tag['attribute']['value'];
21046 if (isset($tag['attribute']['cols']) AND !$this->empty_string($tag['attribute']['cols'])) {
21047 $w = intval($tag['attribute']['cols']) * $this->GetStringWidth(chr(32)) * 2;
21051 if (isset($tag['attribute']['rows']) AND !$this->empty_string($tag['attribute']['rows'])) {
21052 $h = intval($tag['attribute']['rows']) * $this->FontSize
* $this->cell_height_ratio
;
21056 $prop['multiline'] = 'true';
21057 $this->TextField($name, $w, $h, $prop, $opt, '', '', false);
21061 $h = $this->FontSize
* $this->cell_height_ratio
;
21062 if (isset($tag['attribute']['size']) AND !$this->empty_string($tag['attribute']['size'])) {
21063 $h *= ($tag['attribute']['size'] +
1);
21067 if (isset($tag['attribute']['name']) AND !$this->empty_string($tag['attribute']['name'])) {
21068 $name = $tag['attribute']['name'];
21073 if (isset($tag['attribute']['opt']) AND !$this->empty_string($tag['attribute']['opt'])) {
21074 $options = explode('#!NwL!#', $tag['attribute']['opt']);
21076 foreach ($options as $val) {
21077 if (strpos($val, '#!TaB!#') !== false) {
21078 $opts = explode('#!TaB!#', $val);
21080 $w = max($w, $this->GetStringWidth($opts[1]));
21083 $w = max($w, $this->GetStringWidth($val));
21090 if (isset($tag['attribute']['multiple']) AND ($tag['attribute']['multiple']='multiple')) {
21091 $prop['multipleSelection'] = 'true';
21092 $this->ListBox($name, $w, $h, $values, $prop, $opt, '', '', false);
21094 $this->ComboBox($name, $w, $h, $values, $prop, $opt, '', '', false);
21099 if (defined('K_TCPDF_CALLS_IN_HTML') AND (K_TCPDF_CALLS_IN_HTML
=== true)) {
21100 // Special tag used to call TCPDF methods
21101 if (isset($tag['attribute']['method'])) {
21102 $tcpdf_method = $tag['attribute']['method'];
21103 if (method_exists($this, $tcpdf_method)) {
21104 if (isset($tag['attribute']['params']) AND (!empty($tag['attribute']['params']))) {
21105 $params = unserialize(urldecode($tag['attribute']['params']));
21106 call_user_func_array(array($this, $tcpdf_method), $params);
21108 $this->$tcpdf_method();
21110 $this->newline
= true;
21120 // define tags that support borders and background colors
21121 $bordertags = array('blockquote','br','dd','dl','div','dt','h1','h2','h3','h4','h5','h6','hr','li','ol','p','pre','ul','tcpdf','table');
21122 if (in_array($tag['value'], $bordertags)) {
21124 $dom[$key]['borderposition'] = $this->getBorderStartPosition();
21126 if ($dom[$key]['self'] AND isset($dom[$key]['attribute']['pagebreakafter'])) {
21127 $pba = $dom[$key]['attribute']['pagebreakafter'];
21128 // check for pagebreak
21129 if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
21130 // add a page (or trig AcceptPageBreak() for multicolumn mode)
21131 $this->checkPageBreak($this->PageBreakTrigger +
1);
21133 if ((($pba == 'left') AND (((!$this->rtl
) AND (($this->page %
2) == 0)) OR (($this->rtl
) AND (($this->page %
2) != 0))))
21134 OR (($pba == 'right') AND (((!$this->rtl
) AND (($this->page %
2) != 0)) OR (($this->rtl
) AND (($this->page %
2) == 0))))) {
21135 // add a page (or trig AcceptPageBreak() for multicolumn mode)
21136 $this->checkPageBreak($this->PageBreakTrigger +
1);
21142 * Process closing tags.
21143 * @param $dom (array) html dom array
21144 * @param $key (int) current element id
21145 * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
21146 * @param $maxbottomliney (int) maximum y value of current line
21149 protected function closeHTMLTagHandler(&$dom, $key, $cell, $maxbottomliney=0) {
21151 $parent = $dom[($dom[$key]['parent'])];
21152 $lasttag = ((!isset($dom[($key +
1)])) OR ((!isset($dom[($key +
2)])) AND ($dom[($key +
1)]['value'] == 'marker')));
21153 $in_table_head = false;
21154 // maximum x position (used to draw borders)
21160 if ($tag['block']) {
21161 $hbz = 0; // distance from y to line bottom
21162 $hb = 0; // vertical space between block tags
21163 // calculate vertical space for block tags
21164 if (isset($this->tagvspaces
[$tag['value']][1]['h']) AND ($this->tagvspaces
[$tag['value']][1]['h'] >= 0)) {
21165 $pre_h = $this->tagvspaces
[$tag['value']][1]['h'];
21166 } elseif (isset($parent['fontsize'])) {
21167 $pre_h = (($parent['fontsize'] / $this->k
) * $this->cell_height_ratio
);
21169 $pre_h = $this->FontSize
* $this->cell_height_ratio
;
21171 if (isset($this->tagvspaces
[$tag['value']][1]['n'])) {
21172 $n = $this->tagvspaces
[$tag['value']][1]['n'];
21173 } elseif (preg_match('/[h][0-9]/', $tag['value']) > 0) {
21178 $hb = ($n * $pre_h);
21179 if ($this->y
< $maxbottomliney) {
21180 $hbz = ($maxbottomliney - $this->y
);
21184 switch($tag['value']) {
21186 $table_el = $dom[($dom[$key]['parent'])]['parent'];
21187 if (!isset($parent['endy'])) {
21188 $dom[($dom[$key]['parent'])]['endy'] = $this->y
;
21189 $parent['endy'] = $this->y
;
21191 if (!isset($parent['endpage'])) {
21192 $dom[($dom[$key]['parent'])]['endpage'] = $this->page
;
21193 $parent['endpage'] = $this->page
;
21195 if (!isset($parent['endcolumn'])) {
21196 $dom[($dom[$key]['parent'])]['endcolumn'] = $this->current_column
;
21197 $parent['endcolumn'] = $this->current_column
;
21199 // update row-spanned cells
21200 if (isset($dom[$table_el]['rowspans'])) {
21201 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
21202 $dom[$table_el]['rowspans'][$k]['rowspan'] -= 1;
21203 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
21204 if (($dom[$table_el]['rowspans'][$k]['endpage'] == $parent['endpage']) AND ($dom[$table_el]['rowspans'][$k]['endcolumn'] == $parent['endcolumn'])) {
21205 $dom[($dom[$key]['parent'])]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $parent['endy']);
21206 } elseif (($dom[$table_el]['rowspans'][$k]['endpage'] > $parent['endpage']) OR ($dom[$table_el]['rowspans'][$k]['endcolumn'] > $parent['endcolumn'])) {
21207 $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
21208 $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
21209 $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
21213 // report new endy and endpage to the rowspanned cells
21214 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
21215 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
21216 $dom[$table_el]['rowspans'][$k]['endpage'] = max($dom[$table_el]['rowspans'][$k]['endpage'], $dom[($dom[$key]['parent'])]['endpage']);
21217 $dom[($dom[$key]['parent'])]['endpage'] = $dom[$table_el]['rowspans'][$k]['endpage'];
21218 $dom[$table_el]['rowspans'][$k]['endcolumn'] = max($dom[$table_el]['rowspans'][$k]['endcolumn'], $dom[($dom[$key]['parent'])]['endcolumn']);
21219 $dom[($dom[$key]['parent'])]['endcolumn'] = $dom[$table_el]['rowspans'][$k]['endcolumn'];
21220 $dom[$table_el]['rowspans'][$k]['endy'] = max($dom[$table_el]['rowspans'][$k]['endy'], $dom[($dom[$key]['parent'])]['endy']);
21221 $dom[($dom[$key]['parent'])]['endy'] = $dom[$table_el]['rowspans'][$k]['endy'];
21224 // update remaining rowspanned cells
21225 foreach ($dom[$table_el]['rowspans'] as $k => $trwsp) {
21226 if ($dom[$table_el]['rowspans'][$k]['rowspan'] == 0) {
21227 $dom[$table_el]['rowspans'][$k]['endpage'] = $dom[($dom[$key]['parent'])]['endpage'];
21228 $dom[$table_el]['rowspans'][$k]['endcolumn'] = $dom[($dom[$key]['parent'])]['endcolumn'];
21229 $dom[$table_el]['rowspans'][$k]['endy'] = $dom[($dom[$key]['parent'])]['endy'];
21233 $this->setPage($dom[($dom[$key]['parent'])]['endpage']);
21234 if ($this->num_columns
> 1) {
21235 $this->selectColumn($dom[($dom[$key]['parent'])]['endcolumn']);
21237 $this->y
= $dom[($dom[$key]['parent'])]['endy'];
21238 if (isset($dom[$table_el]['attribute']['cellspacing'])) {
21239 $this->y +
= $this->getHTMLUnitToUnits($dom[$table_el]['attribute']['cellspacing'], 1, 'px');
21240 } elseif (isset($dom[$table_el]['border-spacing'])) {
21241 $this->y +
= $dom[$table_el]['border-spacing']['V'];
21243 $this->Ln(0, $cell);
21244 if ($this->current_column
== $parent['startcolumn']) {
21245 $this->x
= $parent['startx'];
21247 // account for booklet mode
21248 if ($this->page
> $parent['startpage']) {
21249 if (($this->rtl
) AND ($this->pagedim
[$this->page
]['orm'] != $this->pagedim
[$parent['startpage']]['orm'])) {
21250 $this->x
-= ($this->pagedim
[$this->page
]['orm'] - $this->pagedim
[$parent['startpage']]['orm']);
21251 } elseif ((!$this->rtl
) AND ($this->pagedim
[$this->page
]['olm'] != $this->pagedim
[$parent['startpage']]['olm'])) {
21252 $this->x +
= ($this->pagedim
[$this->page
]['olm'] - $this->pagedim
[$parent['startpage']]['olm']);
21258 // closing tag used for the thead part
21259 $in_table_head = true;
21260 $this->inthead
= false;
21262 $table_el = $parent;
21263 // set default border
21264 if (isset($table_el['attribute']['border']) AND ($table_el['attribute']['border'] > 0)) {
21265 // set default border
21266 $border = array('LTRB' => array('width' => $this->getCSSBorderWidth($table_el['attribute']['border']), 'cap'=>'square', 'join'=>'miter', 'dash'=> 0, 'color'=>array(0,0,0)));
21270 $default_border = $border;
21271 // fix bottom line alignment of last line before page break
21272 foreach ($dom[($dom[$key]['parent'])]['trids'] as $j => $trkey) {
21273 // update row-spanned cells
21274 if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
21275 foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
21276 if ($trwsp['trid'] == $trkey) {
21277 $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] -= 1;
21279 if (isset($prevtrkey) AND ($trwsp['trid'] == $prevtrkey) AND ($trwsp['mrowspan'] >= 0)) {
21280 $dom[($dom[$key]['parent'])]['rowspans'][$k]['trid'] = $trkey;
21284 if (isset($prevtrkey) AND ($dom[$trkey]['startpage'] > $dom[$prevtrkey]['endpage'])) {
21285 $pgendy = $this->pagedim
[$dom[$prevtrkey]['endpage']]['hk'] - $this->pagedim
[$dom[$prevtrkey]['endpage']]['bm'];
21286 $dom[$prevtrkey]['endy'] = $pgendy;
21287 // update row-spanned cells
21288 if (isset($dom[($dom[$key]['parent'])]['rowspans'])) {
21289 foreach ($dom[($dom[$key]['parent'])]['rowspans'] as $k => $trwsp) {
21290 if (($trwsp['trid'] == $trkey) AND ($trwsp['mrowspan'] > 1) AND ($trwsp['endpage'] == $dom[$prevtrkey]['endpage'])) {
21291 $dom[($dom[$key]['parent'])]['rowspans'][$k]['endy'] = $pgendy;
21292 $dom[($dom[$key]['parent'])]['rowspans'][$k]['mrowspan'] = -1;
21297 $prevtrkey = $trkey;
21298 $table_el = $dom[($dom[$key]['parent'])];
21302 foreach ($table_el['trids'] as $j => $trkey) {
21303 $parent = $dom[$trkey];
21304 if (!isset($xmax)) {
21305 $xmax = $parent['cellpos'][(count($parent['cellpos']) - 1)]['endx'];
21307 // for each cell on the row
21308 foreach ($parent['cellpos'] as $k => $cellpos) {
21309 if (isset($cellpos['rowspanid']) AND ($cellpos['rowspanid'] >= 0)) {
21310 $cellpos['startx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['startx'];
21311 $cellpos['endx'] = $table_el['rowspans'][($cellpos['rowspanid'])]['endx'];
21312 $endy = $table_el['rowspans'][($cellpos['rowspanid'])]['endy'];
21313 $startpage = $table_el['rowspans'][($cellpos['rowspanid'])]['startpage'];
21314 $endpage = $table_el['rowspans'][($cellpos['rowspanid'])]['endpage'];
21315 $startcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['startcolumn'];
21316 $endcolumn = $table_el['rowspans'][($cellpos['rowspanid'])]['endcolumn'];
21318 $endy = $parent['endy'];
21319 $startpage = $parent['startpage'];
21320 $endpage = $parent['endpage'];
21321 $startcolumn = $parent['startcolumn'];
21322 $endcolumn = $parent['endcolumn'];
21324 if ($this->num_columns
== 0) {
21325 $this->num_columns
= 1;
21327 if (isset($cellpos['border'])) {
21328 $border = $cellpos['border'];
21330 if (isset($cellpos['bgcolor']) AND ($cellpos['bgcolor']) !== false) {
21331 $this->SetFillColorArray($cellpos['bgcolor']);
21336 $x = $cellpos['startx'];
21337 $y = $parent['starty'];
21339 $w = abs($cellpos['endx'] - $cellpos['startx']);
21340 // get border modes
21341 $border_start = $this->getBorderMode($border, $position='start');
21342 $border_end = $this->getBorderMode($border, $position='end');
21343 $border_middle = $this->getBorderMode($border, $position='middle');
21344 // design borders around HTML cells.
21345 for ($page = $startpage; $page <= $endpage; ++
$page) { // for each page
21347 $this->setPage($page);
21348 if ($this->num_columns
< 2) {
21349 // single-column mode
21351 $this->y
= $this->tMargin
;
21353 // account for margin changes
21354 if ($page > $startpage) {
21355 if (($this->rtl
) AND ($this->pagedim
[$page]['orm'] != $this->pagedim
[$startpage]['orm'])) {
21356 $this->x
-= ($this->pagedim
[$page]['orm'] - $this->pagedim
[$startpage]['orm']);
21357 } elseif ((!$this->rtl
) AND ($this->pagedim
[$page]['olm'] != $this->pagedim
[$startpage]['olm'])) {
21358 $this->x +
= ($this->pagedim
[$page]['olm'] - $this->pagedim
[$startpage]['olm']);
21361 if ($startpage == $endpage) { // single page
21364 for ($column = $startcolumn; $column <= $endcolumn; ++
$column) { // for each column
21365 $this->selectColumn($column);
21366 if ($startcolumn == $endcolumn) { // single column
21367 $cborder = $border;
21368 $h = $endy - $parent['starty'];
21371 } elseif ($column == $startcolumn) { // first column
21372 $cborder = $border_start;
21373 $this->y
= $starty;
21375 $h = $this->h
- $this->y
- $this->bMargin
;
21377 $deltacol = $this->x +
$this->rMargin
- $this->w
;
21379 $deltacol = $this->x
- $this->lMargin
;
21381 } elseif ($column == $endcolumn) { // end column
21382 $cborder = $border_end;
21383 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
21384 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
21386 $this->x +
= $deltacol;
21387 $h = $endy - $this->y
;
21388 } else { // middle column
21389 $cborder = $border_middle;
21390 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
21391 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
21393 $this->x +
= $deltacol;
21394 $h = $this->h
- $this->y
- $this->bMargin
;
21396 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21397 } // end for each column
21398 } elseif ($page == $startpage) { // first page
21401 for ($column = $startcolumn; $column < $this->num_columns
; ++
$column) { // for each column
21402 $this->selectColumn($column);
21403 if ($column == $startcolumn) { // first column
21404 $cborder = $border_start;
21405 $this->y
= $starty;
21407 $h = $this->h
- $this->y
- $this->bMargin
;
21409 $deltacol = $this->x +
$this->rMargin
- $this->w
;
21411 $deltacol = $this->x
- $this->lMargin
;
21413 } else { // middle column
21414 $cborder = $border_middle;
21415 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
21416 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
21418 $this->x +
= $deltacol;
21419 $h = $this->h
- $this->y
- $this->bMargin
;
21421 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21422 } // end for each column
21423 } elseif ($page == $endpage) { // last page
21426 for ($column = 0; $column <= $endcolumn; ++
$column) { // for each column
21427 $this->selectColumn($column);
21428 if ($column == $endcolumn) { // end column
21429 $cborder = $border_end;
21430 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
21431 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
21433 $this->x +
= $deltacol;
21434 $h = $endy - $this->y
;
21435 } else { // middle column
21436 $cborder = $border_middle;
21437 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
21438 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
21440 $this->x +
= $deltacol;
21441 $h = $this->h
- $this->y
- $this->bMargin
;
21443 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21444 } // end for each column
21445 } else { // middle page
21448 for ($column = 0; $column < $this->num_columns
; ++
$column) { // for each column
21449 $this->selectColumn($column);
21450 $cborder = $border_middle;
21451 if (isset($this->columns
[$column]['th']['\''.$page.'\''])) {
21452 $this->y
= $this->columns
[$column]['th']['\''.$page.'\''];
21454 $this->x +
= $deltacol;
21455 $h = $this->h
- $this->y
- $this->bMargin
;
21456 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21457 } // end for each column
21459 if ($cborder OR $fill) {
21460 // draw border and fill
21461 if ($this->inxobj
) {
21462 // we are inside an XObject template
21463 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
21464 $pagemarkkey = key($this->xobjects
[$this->xobjid
]['transfmrk']);
21465 $pagemark = &$this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey];
21467 $pagemark = &$this->xobjects
[$this->xobjid
]['intmrk'];
21469 $pagebuff = $this->xobjects
[$this->xobjid
]['outdata'];
21470 $pstart = substr($pagebuff, 0, $pagemark);
21471 $pend = substr($pagebuff, $pagemark);
21472 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$ccode.$pend;
21473 $pagemark +
= strlen($ccode);
21475 // draw border and fill
21476 if (end($this->transfmrk
[$this->page
]) !== false) {
21477 $pagemarkkey = key($this->transfmrk
[$this->page
]);
21478 $pagemark = &$this->transfmrk
[$this->page
][$pagemarkkey];
21479 } elseif ($this->InFooter
) {
21480 $pagemark = &$this->footerpos
[$this->page
];
21482 $pagemark = &$this->intmrk
[$this->page
];
21484 $pagebuff = $this->getPageBuffer($this->page
);
21485 $pstart = substr($pagebuff, 0, $pagemark);
21486 $pend = substr($pagebuff, $pagemark);
21487 $this->setPageBuffer($this->page
, $pstart.$ccode.$pend);
21488 $pagemark +
= strlen($ccode);
21491 } // end for each page
21492 // restore default border
21493 $border = $default_border;
21494 } // end for each cell on the row
21495 if (isset($table_el['attribute']['cellspacing'])) {
21496 $this->y +
= $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');
21497 } elseif (isset($table_el['border-spacing'])) {
21498 $this->y +
= $table_el['border-spacing']['V'];
21500 $this->Ln(0, $cell);
21501 $this->x
= $parent['startx'];
21502 if ($endpage > $startpage) {
21503 if (($this->rtl
) AND ($this->pagedim
[$endpage]['orm'] != $this->pagedim
[$startpage]['orm'])) {
21504 $this->x +
= ($this->pagedim
[$endpage]['orm'] - $this->pagedim
[$startpage]['orm']);
21505 } elseif ((!$this->rtl
) AND ($this->pagedim
[$endpage]['olm'] != $this->pagedim
[$startpage]['olm'])) {
21506 $this->x +
= ($this->pagedim
[$endpage]['olm'] - $this->pagedim
[$startpage]['olm']);
21510 if (!$in_table_head) { // we are not inside a thead section
21511 $this->cell_padding
= $table_el['old_cell_padding'];
21512 // reset row height
21513 $this->resetLastH();
21514 if (($this->page
== ($this->numpages
- 1)) AND ($this->pageopen
[$this->numpages
]) AND ($this->emptypagemrk
[$this->numpages
] == $this->pagelen
[$this->numpages
])) {
21515 // remove last blank page
21516 $this->deletePage($this->numpages
);
21518 if (isset($this->theadMargins
['top'])) {
21519 // restore top margin
21520 $this->tMargin
= $this->theadMargins
['top'];
21521 $this->pagedim
[$this->page
]['tm'] = $this->tMargin
;
21523 if (!isset($table_el['attribute']['nested']) OR ($table_el['attribute']['nested'] != 'true')) {
21524 // reset main table header
21526 $this->theadMargins
= array();
21529 $parent = $table_el;
21537 $this->SetXY($this->GetX(), $this->GetY() +
((0.7 * $parent['fontsize']) / $this->k
));
21541 $this->SetXY($this->GetX(), $this->GetY() - ((0.3 * $parent['fontsize'])/$this->k
));
21545 $this->addHTMLVertSpace($hbz, 0, $cell, false, $lasttag);
21548 case 'blockquote': {
21550 $this->rMargin
-= $this->listindent
;
21552 $this->lMargin
-= $this->listindent
;
21554 --$this->listindentlevel
;
21555 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
21559 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
21563 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
21564 $this->premode
= false;
21569 if ($this->listnum
<= 0) {
21570 $this->listnum
= 0;
21571 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
21573 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
21575 $this->resetLastH();
21579 $this->lispacer
= '';
21580 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
21584 $this->lispacer
= '';
21586 $this->rMargin
-= $this->listindent
;
21588 $this->lMargin
-= $this->listindent
;
21590 --$this->listindentlevel
;
21591 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
21597 $this->lispacer
= '';
21599 $this->rMargin
-= $this->listindent
;
21601 $this->lMargin
-= $this->listindent
;
21603 --$this->listindentlevel
;
21604 if ($this->listnum
<= 0) {
21605 $this->listnum
= 0;
21606 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
21608 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
21610 $this->resetLastH();
21614 $this->lispacer
= '';
21615 $this->addHTMLVertSpace(0, 0, $cell, false, $lasttag);
21624 $this->addHTMLVertSpace($hbz, $hb, $cell, false, $lasttag);
21627 // Form fields (since 4.8.000 - 2009-09-07)
21629 $this->form_action
= '';
21630 $this->form_enctype
= 'application/x-www-form-urlencoded';
21637 // draw border and background (if any)
21638 $this->drawHTMLTagBorder($parent, $xmax);
21639 if (isset($dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'])) {
21640 $pba = $dom[($dom[$key]['parent'])]['attribute']['pagebreakafter'];
21641 // check for pagebreak
21642 if (($pba == 'true') OR ($pba == 'left') OR ($pba == 'right')) {
21643 // add a page (or trig AcceptPageBreak() for multicolumn mode)
21644 $this->checkPageBreak($this->PageBreakTrigger +
1);
21646 if ((($pba == 'left') AND (((!$this->rtl
) AND (($this->page %
2) == 0)) OR (($this->rtl
) AND (($this->page %
2) != 0))))
21647 OR (($pba == 'right') AND (((!$this->rtl
) AND (($this->page %
2) != 0)) OR (($this->rtl
) AND (($this->page %
2) == 0))))) {
21648 // add a page (or trig AcceptPageBreak() for multicolumn mode)
21649 $this->checkPageBreak($this->PageBreakTrigger +
1);
21652 $this->tmprtl
= false;
21656 * Add vertical spaces if needed.
21657 * @param $hbz (string) Distance between current y and line bottom.
21658 * @param $hb (string) The height of the break.
21659 * @param $cell (boolean) if true add the default left (or right if RTL) padding to each new line (default false).
21660 * @param $firsttag (boolean) set to true when the tag is the first.
21661 * @param $lasttag (boolean) set to true when the tag is the last.
21664 protected function addHTMLVertSpace($hbz=0, $hb=0, $cell=false, $firsttag=false, $lasttag=false) {
21666 $this->Ln(0, $cell);
21667 $this->htmlvspace
= 0;
21671 $this->Ln($hbz, $cell);
21672 $this->htmlvspace
= 0;
21675 if ($hb < $this->htmlvspace
) {
21678 $hd = $hb - $this->htmlvspace
;
21679 $this->htmlvspace
= $hb;
21681 $this->Ln(($hbz +
$hd), $cell);
21685 * Return the starting coordinates to draw an html border
21686 * @return array containing top-left border coordinates
21688 * @since 5.7.000 (2010-08-03)
21690 protected function getBorderStartPosition() {
21692 $xmax = $this->lMargin
;
21694 $xmax = $this->w
- $this->rMargin
;
21696 return array('page' => $this->page
, 'column' => $this->current_column
, 'x' => $this->x
, 'y' => $this->y
, 'xmax' => $xmax);
21700 * Draw an HTML block border and fill
21701 * @param $tag (array) array of tag properties.
21702 * @param $xmax (int) end X coordinate for border.
21704 * @since 5.7.000 (2010-08-03)
21706 protected function drawHTMLTagBorder($tag, $xmax) {
21707 if (!isset($tag['borderposition'])) {
21711 $prev_x = $this->x
;
21712 $prev_y = $this->y
;
21713 $prev_lasth = $this->lasth
;
21717 if (isset($tag['border']) AND !empty($tag['border'])) {
21718 // get border style
21719 $border = $tag['border'];
21720 if (!$this->empty_string($this->thead
) AND (!$this->inthead
)) {
21721 // border for table header
21722 $border = $this->getBorderMode($border, $position='middle');
21725 if (isset($tag['bgcolor']) AND ($tag['bgcolor'] !== false)) {
21726 // get background color
21727 $old_bgcolor = $this->bgcolor
;
21728 $this->SetFillColorArray($tag['bgcolor']);
21731 if (!$border AND !$fill) {
21735 if (isset($tag['attribute']['cellspacing'])) {
21736 $clsp = $this->getHTMLUnitToUnits($tag['attribute']['cellspacing'], 1, 'px');
21737 $cellspacing = array('H' => $clsp, 'V' => $clsp);
21738 } elseif (isset($tag['border-spacing'])) {
21739 $cellspacing = $tag['border-spacing'];
21741 $cellspacing = array('H' => 0, 'V' => 0);
21743 if (($tag['value'] != 'table') AND (is_array($border)) AND (!empty($border))) {
21744 // draw the border externally respect the sqare edge.
21745 $border['mode'] = 'ext';
21748 if ($xmax >= $tag['borderposition']['x']) {
21749 $xmax = $tag['borderposition']['xmax'];
21751 $w = ($tag['borderposition']['x'] - $xmax);
21753 if ($xmax <= $tag['borderposition']['x']) {
21754 $xmax = $tag['borderposition']['xmax'];
21756 $w = ($xmax - $tag['borderposition']['x']);
21761 $w +
= $cellspacing['H'];
21762 $startpage = $tag['borderposition']['page'];
21763 $startcolumn = $tag['borderposition']['column'];
21764 $x = $tag['borderposition']['x'];
21765 $y = $tag['borderposition']['y'];
21766 $endpage = $this->page
;
21767 $starty = $tag['borderposition']['y'] - $cellspacing['V'];
21768 $currentY = $this->y
;
21770 // get latest column
21771 $endcolumn = $this->current_column
;
21772 if ($this->num_columns
== 0) {
21773 $this->num_columns
= 1;
21775 // get border modes
21776 $border_start = $this->getBorderMode($border, $position='start');
21777 $border_end = $this->getBorderMode($border, $position='end');
21778 $border_middle = $this->getBorderMode($border, $position='middle');
21779 // temporary disable page regions
21780 $temp_page_regions = $this->page_regions
;
21781 $this->page_regions
= array();
21782 // design borders around HTML cells.
21783 for ($page = $startpage; $page <= $endpage; ++
$page) { // for each page
21785 $this->setPage($page);
21786 if ($this->num_columns
< 2) {
21787 // single-column mode
21789 $this->y
= $this->tMargin
;
21791 // account for margin changes
21792 if ($page > $startpage) {
21793 if (($this->rtl
) AND ($this->pagedim
[$page]['orm'] != $this->pagedim
[$startpage]['orm'])) {
21794 $this->x
-= ($this->pagedim
[$page]['orm'] - $this->pagedim
[$startpage]['orm']);
21795 } elseif ((!$this->rtl
) AND ($this->pagedim
[$page]['olm'] != $this->pagedim
[$startpage]['olm'])) {
21796 $this->x +
= ($this->pagedim
[$page]['olm'] - $this->pagedim
[$startpage]['olm']);
21799 if ($startpage == $endpage) {
21801 for ($column = $startcolumn; $column <= $endcolumn; ++
$column) { // for each column
21802 $this->selectColumn($column);
21803 if ($startcolumn == $endcolumn) { // single column
21804 $cborder = $border;
21805 $h = ($currentY - $y) +
$cellspacing['V'];
21806 $this->y
= $starty;
21807 } elseif ($column == $startcolumn) { // first column
21808 $cborder = $border_start;
21809 $this->y
= $starty;
21810 $h = $this->h
- $this->y
- $this->bMargin
;
21811 } elseif ($column == $endcolumn) { // end column
21812 $cborder = $border_end;
21813 $h = $currentY - $this->y
;
21814 } else { // middle column
21815 $cborder = $border_middle;
21816 $h = $this->h
- $this->y
- $this->bMargin
;
21818 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21819 } // end for each column
21820 } elseif ($page == $startpage) { // first page
21821 for ($column = $startcolumn; $column < $this->num_columns
; ++
$column) { // for each column
21822 $this->selectColumn($column);
21823 if ($column == $startcolumn) { // first column
21824 $cborder = $border_start;
21825 $this->y
= $starty;
21826 $h = $this->h
- $this->y
- $this->bMargin
;
21827 } else { // middle column
21828 $cborder = $border_middle;
21829 $h = $this->h
- $this->y
- $this->bMargin
;
21831 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21832 } // end for each column
21833 } elseif ($page == $endpage) { // last page
21834 for ($column = 0; $column <= $endcolumn; ++
$column) { // for each column
21835 $this->selectColumn($column);
21836 if ($column == $endcolumn) {
21838 $cborder = $border_end;
21839 $h = $currentY - $this->y
;
21842 $cborder = $border_middle;
21843 $h = $this->h
- $this->y
- $this->bMargin
;
21845 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21846 } // end for each column
21847 } else { // middle page
21848 for ($column = 0; $column < $this->num_columns
; ++
$column) { // for each column
21849 $this->selectColumn($column);
21850 $cborder = $border_middle;
21851 $h = $this->h
- $this->y
- $this->bMargin
;
21852 $ccode .= $this->getCellCode($w, $h, '', $cborder, 1, '', $fill, '', 0, true)."\n";
21853 } // end for each column
21855 if ($cborder OR $fill) {
21856 // draw border and fill
21857 if ($this->inxobj
) {
21858 // we are inside an XObject template
21859 if (end($this->xobjects
[$this->xobjid
]['transfmrk']) !== false) {
21860 $pagemarkkey = key($this->xobjects
[$this->xobjid
]['transfmrk']);
21861 $pagemark = &$this->xobjects
[$this->xobjid
]['transfmrk'][$pagemarkkey];
21863 $pagemark = &$this->xobjects
[$this->xobjid
]['intmrk'];
21865 $pagebuff = $this->xobjects
[$this->xobjid
]['outdata'];
21866 $pstart = substr($pagebuff, 0, $pagemark);
21867 $pend = substr($pagebuff, $pagemark);
21868 $this->xobjects
[$this->xobjid
]['outdata'] = $pstart.$ccode.$pend;
21869 $pagemark +
= strlen($ccode);
21871 if (end($this->transfmrk
[$this->page
]) !== false) {
21872 $pagemarkkey = key($this->transfmrk
[$this->page
]);
21873 $pagemark = &$this->transfmrk
[$this->page
][$pagemarkkey];
21874 } elseif ($this->InFooter
) {
21875 $pagemark = &$this->footerpos
[$this->page
];
21877 $pagemark = &$this->intmrk
[$this->page
];
21879 $pagebuff = $this->getPageBuffer($this->page
);
21880 $pstart = substr($pagebuff, 0, $this->bordermrk
[$this->page
]);
21881 $pend = substr($pagebuff, $this->bordermrk
[$this->page
]);
21882 $this->setPageBuffer($this->page
, $pstart.$ccode.$pend);
21883 $offsetlen = strlen($ccode);
21884 $this->bordermrk
[$this->page
] +
= $offsetlen;
21885 $this->cntmrk
[$this->page
] +
= $offsetlen;
21886 $pagemark +
= $offsetlen;
21889 } // end for each page
21890 // restore page regions
21891 $this->page_regions
= $temp_page_regions;
21892 if (isset($old_bgcolor)) {
21893 // restore background color
21894 $this->SetFillColorArray($old_bgcolor);
21896 // restore pointer position
21897 $this->x
= $prev_x;
21898 $this->y
= $prev_y;
21899 $this->lasth
= $prev_lasth;
21903 * Set the default bullet to be used as LI bullet symbol
21904 * @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')
21906 * @since 4.0.028 (2008-09-26)
21908 public function setLIsymbol($symbol='!') {
21909 // check for custom image symbol
21910 if (substr($symbol, 0, 4) == 'img|') {
21911 $this->lisymbol
= $symbol;
21914 $symbol = strtolower($symbol);
21923 case 'decimal-leading-zero':
21925 case 'lower-roman':
21927 case 'upper-roman':
21929 case 'lower-alpha':
21930 case 'lower-latin':
21932 case 'upper-alpha':
21933 case 'upper-latin':
21934 case 'lower-greek': {
21935 $this->lisymbol
= $symbol;
21939 $this->lisymbol
= '';
21945 * Set the booklet mode for double-sided pages.
21946 * @param $booklet (boolean) true set the booklet mode on, false otherwise.
21947 * @param $inner (float) Inner page margin.
21948 * @param $outer (float) Outer page margin.
21950 * @since 4.2.000 (2008-10-29)
21952 public function SetBooklet($booklet=true, $inner=-1, $outer=-1) {
21953 $this->booklet
= $booklet;
21955 $this->lMargin
= $inner;
21958 $this->rMargin
= $outer;
21963 * Swap the left and right margins.
21964 * @param $reverse (boolean) if true swap left and right margins.
21966 * @since 4.2.000 (2008-10-29)
21968 protected function swapMargins($reverse=true) {
21970 // swap left and right margins
21971 $mtemp = $this->original_lMargin
;
21972 $this->original_lMargin
= $this->original_rMargin
;
21973 $this->original_rMargin
= $mtemp;
21974 $deltam = $this->original_lMargin
- $this->original_rMargin
;
21975 $this->lMargin +
= $deltam;
21976 $this->rMargin
-= $deltam;
21981 * Set the vertical spaces for HTML tags.
21982 * The array must have the following structure (example):
21983 * $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
21984 * The first array level contains the tag names,
21985 * the second level contains 0 for opening tags or 1 for closing tags,
21986 * the third level contains the vertical space unit (h) and the number spaces to add (n).
21987 * If the h parameter is not specified, default values are used.
21988 * @param $tagvs (array) array of tags and relative vertical spaces.
21990 * @since 4.2.001 (2008-10-30)
21992 public function setHtmlVSpace($tagvs) {
21993 $this->tagvspaces
= $tagvs;
21997 * Set custom width for list indentation.
21998 * @param $width (float) width of the indentation. Use negative value to disable it.
22000 * @since 4.2.007 (2008-11-12)
22002 public function setListIndentWidth($width) {
22003 return $this->customlistindent
= floatval($width);
22007 * Set the top/bottom cell sides to be open or closed when the cell cross the page.
22008 * @param $isopen (boolean) if true keeps the top/bottom border open for the cell sides that cross the page.
22010 * @since 4.2.010 (2008-11-14)
22012 public function setOpenCell($isopen) {
22013 $this->opencell
= $isopen;
22017 * Set the color and font style for HTML links.
22018 * @param $color (array) RGB array of colors
22019 * @param $fontstyle (string) additional font styles to add
22021 * @since 4.4.003 (2008-12-09)
22023 public function setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U') {
22024 $this->htmlLinkColorArray
= $color;
22025 $this->htmlLinkFontStyle
= $fontstyle;
22029 * Convert HTML string containing value and unit of measure to user's units or points.
22030 * @param $htmlval (string) string containing values and unit
22031 * @param $refsize (string) reference value in points
22032 * @param $defaultunit (string) default unit (can be one of the following: %, em, ex, px, in, mm, pc, pt).
22033 * @param $points (boolean) if true returns points, otherwise returns value in user's units
22034 * @return float value in user's unit or point if $points=true
22036 * @since 4.4.004 (2008-12-10)
22038 public function getHTMLUnitToUnits($htmlval, $refsize=1, $defaultunit='px', $points=false) {
22039 $supportedunits = array('%', 'em', 'ex', 'px', 'in', 'cm', 'mm', 'pc', 'pt');
22047 if (in_array($defaultunit, $supportedunits)) {
22048 $unit = $defaultunit;
22050 if (is_numeric($htmlval)) {
22051 $value = floatval($htmlval);
22052 } elseif (preg_match('/([0-9\.\-\+]+)/', $htmlval, $mnum)) {
22053 $value = floatval($mnum[1]);
22054 if (preg_match('/([a-z%]+)/', $htmlval, $munit)) {
22055 if (in_array($munit[1], $supportedunits)) {
22063 $retval = (($value * $refsize) / 100);
22068 $retval = ($value * $refsize);
22071 // height of lower case 'x' (about half the font-size)
22073 $retval = $value * ($refsize / 2);
22078 $retval = ($value * $this->dpi
) / $k;
22083 $retval = ($value / 2.54 * $this->dpi
) / $k;
22088 $retval = ($value / 25.4 * $this->dpi
) / $k;
22091 // one pica is 12 points
22093 $retval = ($value * 12) / $k;
22098 $retval = $value / $k;
22103 $retval = $this->pixelsToUnits($value);
22111 * Returns the Roman representation of an integer number
22112 * @param $number (int) number to convert
22113 * @return string roman representation of the specified number
22114 * @since 4.4.004 (2008-12-10)
22117 public function intToRoman($number) {
22119 while ($number >= 1000) {
22123 while ($number >= 900) {
22127 while ($number >= 500) {
22131 while ($number >= 400) {
22135 while ($number >= 100) {
22139 while ($number >= 90) {
22143 while ($number >= 50) {
22147 while ($number >= 40) {
22151 while ($number >= 10) {
22155 while ($number >= 9) {
22159 while ($number >= 5) {
22163 while ($number >= 4) {
22167 while ($number >= 1) {
22175 * Output an HTML list bullet or ordered item symbol
22176 * @param $listdepth (int) list nesting level
22177 * @param $listtype (string) type of list
22178 * @param $size (float) current font size
22180 * @since 4.4.004 (2008-12-10)
22182 protected function putHtmlListBullet($listdepth, $listtype='', $size=10) {
22185 $color = $this->fgcolor
;
22189 $lspace = $this->GetStringWidth(' ');
22190 if ($listtype == '^') {
22191 // special symbol used for avoid justification of rect bullet
22192 $this->lispacer
= '';
22194 } elseif ($listtype == '!') {
22195 // set default list type for unordered list
22196 $deftypes = array('disc', 'circle', 'square');
22197 $listtype = $deftypes[($listdepth - 1) %
3];
22198 } elseif ($listtype == '#') {
22199 // set default list type for ordered list
22200 $listtype = 'decimal';
22201 } elseif(substr($listtype, 0, 4) == 'img|') {
22202 // custom image type ('img|type|width|height|image.ext')
22203 $img = explode('|', $listtype);
22206 switch ($listtype) {
22217 $lspace +
= (2 * $r);
22219 $this->x +
= $lspace;
22221 $this->x
-= $lspace;
22223 $this->Circle(($this->x +
$r), ($this->y +
($this->lasth
/ 2)), $r, 0, 360, $fill, array('color'=>$color), $color, 8);
22230 $this->x +
= $lspace;
22232 $this->x
-= $lspace;
22234 $this->Rect($this->x
, ($this->y +
(($this->lasth
- $l) / 2)), $l, $l, 'F', array(), $color);
22238 // 1=>type, 2=>width, 3=>height, 4=>image.ext
22239 $lspace +
= $img[2];
22241 $this->x +
= $lspace;
22243 $this->x
-= $lspace;
22245 $imgtype = strtolower($img[1]);
22246 $prev_y = $this->y
;
22247 switch ($imgtype) {
22249 $this->ImageSVG($img[4], $this->x
, ($this->y +
(($this->lasth
- $img[3]) / 2)), $img[2], $img[3], '', 'T', '', 0, false);
22254 $this->ImageEps($img[4], $this->x
, ($this->y +
(($this->lasth
- $img[3]) / 2)), $img[2], $img[3], '', true, 'T', '', 0, false);
22258 $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);
22262 $this->y
= $prev_y;
22266 // $this->listcount[$this->listnum];
22270 $textitem = $this->listcount
[$this->listnum
];
22273 case 'decimal-leading-zero': {
22274 $textitem = sprintf('%02d', $this->listcount
[$this->listnum
]);
22278 case 'lower-roman': {
22279 $textitem = strtolower($this->intToRoman($this->listcount
[$this->listnum
]));
22283 case 'upper-roman': {
22284 $textitem = $this->intToRoman($this->listcount
[$this->listnum
]);
22288 case 'lower-alpha':
22289 case 'lower-latin': {
22290 $textitem = chr(97 +
$this->listcount
[$this->listnum
] - 1);
22294 case 'upper-alpha':
22295 case 'upper-latin': {
22296 $textitem = chr(65 +
$this->listcount
[$this->listnum
] - 1);
22299 case 'lower-greek': {
22300 $textitem = $this->unichr(945 +
$this->listcount
[$this->listnum
] - 1);
22304 // Types to be implemented (special handling)
22314 case 'cjk-ideographic': {
22323 case 'hiragana-iroha': {
22326 case 'katakana-iroha': {
22331 $textitem = $this->listcount
[$this->listnum
];
22334 if (!$this->empty_string($textitem)) {
22335 // Check whether we need a new page or new column
22336 $prev_y = $this->y
;
22337 $h = ($this->FontSize
* $this->cell_height_ratio
) +
$this->cell_padding
['T'] +
$this->cell_padding
['B'];
22338 if ($this->checkPageBreak($h) OR ($this->y
< $prev_y)) {
22341 // print ordered item
22343 $textitem = '.'.$textitem;
22345 $textitem = $textitem.'.';
22347 $lspace +
= $this->GetStringWidth($textitem);
22349 $this->x +
= $lspace;
22351 $this->x
-= $lspace;
22353 $this->Write($this->lasth
, $textitem, '', false, '', false, 0, false);
22356 $this->lispacer
= '^';
22360 * Returns current graphic variables as array.
22361 * @return array of graphic variables
22363 * @since 4.2.010 (2008-11-14)
22365 protected function getGraphicVars() {
22367 'FontFamily' => $this->FontFamily
,
22368 'FontStyle' => $this->FontStyle
,
22369 'FontSizePt' => $this->FontSizePt
,
22370 'rMargin' => $this->rMargin
,
22371 'lMargin' => $this->lMargin
,
22372 'cell_padding' => $this->cell_padding
,
22373 'cell_margin' => $this->cell_margin
,
22374 'LineWidth' => $this->LineWidth
,
22375 'linestyleWidth' => $this->linestyleWidth
,
22376 'linestyleCap' => $this->linestyleCap
,
22377 'linestyleJoin' => $this->linestyleJoin
,
22378 'linestyleDash' => $this->linestyleDash
,
22379 'textrendermode' => $this->textrendermode
,
22380 'textstrokewidth' => $this->textstrokewidth
,
22381 'DrawColor' => $this->DrawColor
,
22382 'FillColor' => $this->FillColor
,
22383 'TextColor' => $this->TextColor
,
22384 'ColorFlag' => $this->ColorFlag
,
22385 'bgcolor' => $this->bgcolor
,
22386 'fgcolor' => $this->fgcolor
,
22387 'htmlvspace' => $this->htmlvspace
,
22388 'listindent' => $this->listindent
,
22389 'listindentlevel' => $this->listindentlevel
,
22390 'listnum' => $this->listnum
,
22391 'listordered' => $this->listordered
,
22392 'listcount' => $this->listcount
,
22393 'lispacer' => $this->lispacer
,
22394 'cell_height_ratio' => $this->cell_height_ratio
,
22395 'font_stretching' => $this->font_stretching
,
22396 'font_spacing' => $this->font_spacing
,
22398 'lasth' => $this->lasth
,
22399 'tMargin' => $this->tMargin
,
22400 'bMargin' => $this->bMargin
,
22401 'AutoPageBreak' => $this->AutoPageBreak
,
22402 'PageBreakTrigger' => $this->PageBreakTrigger
,
22407 'wPt' => $this->wPt
,
22408 'hPt' => $this->hPt
,
22409 'fwPt' => $this->fwPt
,
22410 'fhPt' => $this->fhPt
,
22411 'page' => $this->page
,
22412 'current_column' => $this->current_column
,
22413 'num_columns' => $this->num_columns
22419 * Set graphic variables.
22420 * @param $gvars (array) array of graphic variablesto restore
22421 * @param $extended (boolean) if true restore extended graphic variables
22423 * @since 4.2.010 (2008-11-14)
22425 protected function setGraphicVars($gvars, $extended=false) {
22426 $this->FontFamily
= $gvars['FontFamily'];
22427 $this->FontStyle
= $gvars['FontStyle'];
22428 $this->FontSizePt
= $gvars['FontSizePt'];
22429 $this->rMargin
= $gvars['rMargin'];
22430 $this->lMargin
= $gvars['lMargin'];
22431 $this->cell_padding
= $gvars['cell_padding'];
22432 $this->cell_margin
= $gvars['cell_margin'];
22433 $this->LineWidth
= $gvars['LineWidth'];
22434 $this->linestyleWidth
= $gvars['linestyleWidth'];
22435 $this->linestyleCap
= $gvars['linestyleCap'];
22436 $this->linestyleJoin
= $gvars['linestyleJoin'];
22437 $this->linestyleDash
= $gvars['linestyleDash'];
22438 $this->textrendermode
= $gvars['textrendermode'];
22439 $this->textstrokewidth
= $gvars['textstrokewidth'];
22440 $this->DrawColor
= $gvars['DrawColor'];
22441 $this->FillColor
= $gvars['FillColor'];
22442 $this->TextColor
= $gvars['TextColor'];
22443 $this->ColorFlag
= $gvars['ColorFlag'];
22444 $this->bgcolor
= $gvars['bgcolor'];
22445 $this->fgcolor
= $gvars['fgcolor'];
22446 $this->htmlvspace
= $gvars['htmlvspace'];
22447 $this->listindent
= $gvars['listindent'];
22448 $this->listindentlevel
= $gvars['listindentlevel'];
22449 $this->listnum
= $gvars['listnum'];
22450 $this->listordered
= $gvars['listordered'];
22451 $this->listcount
= $gvars['listcount'];
22452 $this->lispacer
= $gvars['lispacer'];
22453 $this->cell_height_ratio
= $gvars['cell_height_ratio'];
22454 $this->font_stretching
= $gvars['font_stretching'];
22455 $this->font_spacing
= $gvars['font_spacing'];
22457 // restore extended values
22458 $this->lasth
= $gvars['lasth'];
22459 $this->tMargin
= $gvars['tMargin'];
22460 $this->bMargin
= $gvars['bMargin'];
22461 $this->AutoPageBreak
= $gvars['AutoPageBreak'];
22462 $this->PageBreakTrigger
= $gvars['PageBreakTrigger'];
22463 $this->x
= $gvars['x'];
22464 $this->y
= $gvars['y'];
22465 $this->w
= $gvars['w'];
22466 $this->h
= $gvars['h'];
22467 $this->wPt
= $gvars['wPt'];
22468 $this->hPt
= $gvars['hPt'];
22469 $this->fwPt
= $gvars['fwPt'];
22470 $this->fhPt
= $gvars['fhPt'];
22471 $this->page
= $gvars['page'];
22472 $this->current_column
= $gvars['current_column'];
22473 $this->num_columns
= $gvars['num_columns'];
22475 $this->_out(''.$this->linestyleWidth
.' '.$this->linestyleCap
.' '.$this->linestyleJoin
.' '.$this->linestyleDash
.' '.$this->DrawColor
.' '.$this->FillColor
.'');
22476 if (!$this->empty_string($this->FontFamily
)) {
22477 $this->SetFont($this->FontFamily
, $this->FontStyle
, $this->FontSizePt
);
22482 * Returns a temporary filename for caching object on filesystem.
22483 * @param $name (string) prefix to add to filename
22484 * @return string filename.
22485 * @since 4.5.000 (2008-12-31)
22488 protected function getObjFilename($name) {
22489 return tempnam(K_PATH_CACHE
, $name.'_');
22493 * Writes data to a temporary file on filesystem.
22494 * @param $filename (string) file name
22495 * @param $data (mixed) data to write on file
22496 * @param $append (boolean) if true append data, false replace.
22497 * @since 4.5.000 (2008-12-31)
22500 protected function writeDiskCache($filename, $data, $append=false) {
22506 $f = @fopen
($filename, $fmode);
22508 $this->Error('Unable to write cache file: '.$filename);
22513 // update file length (needed for transactions)
22514 if (!isset($this->cache_file_length
['_'.$filename])) {
22515 $this->cache_file_length
['_'.$filename] = strlen($data);
22517 $this->cache_file_length
['_'.$filename] +
= strlen($data);
22522 * Read data from a temporary file on filesystem.
22523 * @param $filename (string) file name
22524 * @return mixed retrieved data
22525 * @since 4.5.000 (2008-12-31)
22528 protected function readDiskCache($filename) {
22529 return file_get_contents($filename);
22533 * Set buffer content (always append data).
22534 * @param $data (string) data
22536 * @since 4.5.000 (2009-01-02)
22538 protected function setBuffer($data) {
22539 $this->bufferlen +
= strlen($data);
22540 if ($this->diskcache
) {
22541 if (!isset($this->buffer
) OR $this->empty_string($this->buffer
)) {
22542 $this->buffer
= $this->getObjFilename('buffer');
22544 $this->writeDiskCache($this->buffer
, $data, true);
22546 $this->buffer
.= $data;
22551 * Replace the buffer content
22552 * @param $data (string) data
22554 * @since 5.5.000 (2010-06-22)
22556 protected function replaceBuffer($data) {
22557 $this->bufferlen
= strlen($data);
22558 if ($this->diskcache
) {
22559 if (!isset($this->buffer
) OR $this->empty_string($this->buffer
)) {
22560 $this->buffer
= $this->getObjFilename('buffer');
22562 $this->writeDiskCache($this->buffer
, $data, false);
22564 $this->buffer
= $data;
22569 * Get buffer content.
22570 * @return string buffer content
22572 * @since 4.5.000 (2009-01-02)
22574 protected function getBuffer() {
22575 if ($this->diskcache
) {
22576 return $this->readDiskCache($this->buffer
);
22578 return $this->buffer
;
22583 * Set page buffer content.
22584 * @param $page (int) page number
22585 * @param $data (string) page data
22586 * @param $append (boolean) if true append data, false replace.
22588 * @since 4.5.000 (2008-12-31)
22590 protected function setPageBuffer($page, $data, $append=false) {
22591 if ($this->diskcache
) {
22592 if (!isset($this->pages
[$page])) {
22593 $this->pages
[$page] = $this->getObjFilename('page'.$page);
22595 $this->writeDiskCache($this->pages
[$page], $data, $append);
22598 $this->pages
[$page] .= $data;
22600 $this->pages
[$page] = $data;
22603 if ($append AND isset($this->pagelen
[$page])) {
22604 $this->pagelen
[$page] +
= strlen($data);
22606 $this->pagelen
[$page] = strlen($data);
22611 * Get page buffer content.
22612 * @param $page (int) page number
22613 * @return string page buffer content or false in case of error
22615 * @since 4.5.000 (2008-12-31)
22617 protected function getPageBuffer($page) {
22618 if ($this->diskcache
) {
22619 return $this->readDiskCache($this->pages
[$page]);
22620 } elseif (isset($this->pages
[$page])) {
22621 return $this->pages
[$page];
22627 * Set image buffer content.
22628 * @param $image (string) image key
22629 * @param $data (array) image data
22631 * @since 4.5.000 (2008-12-31)
22633 protected function setImageBuffer($image, $data) {
22634 if ($this->diskcache
) {
22635 if (!isset($this->images
[$image])) {
22636 $this->images
[$image] = $this->getObjFilename('image'.$image);
22638 $this->writeDiskCache($this->images
[$image], serialize($data));
22640 $this->images
[$image] = $data;
22642 if (!in_array($image, $this->imagekeys
)) {
22643 $this->imagekeys
[] = $image;
22644 ++
$this->numimages
;
22649 * Set image buffer content for a specified sub-key.
22650 * @param $image (string) image key
22651 * @param $key (string) image sub-key
22652 * @param $data (array) image data
22654 * @since 4.5.000 (2008-12-31)
22656 protected function setImageSubBuffer($image, $key, $data) {
22657 if (!isset($this->images
[$image])) {
22658 $this->setImageBuffer($image, array());
22660 if ($this->diskcache
) {
22661 $tmpimg = $this->getImageBuffer($image);
22662 $tmpimg[$key] = $data;
22663 $this->writeDiskCache($this->images
[$image], serialize($tmpimg));
22665 $this->images
[$image][$key] = $data;
22670 * Get image buffer content.
22671 * @param $image (string) image key
22672 * @return string image buffer content or false in case of error
22674 * @since 4.5.000 (2008-12-31)
22676 protected function getImageBuffer($image) {
22677 if ($this->diskcache
AND isset($this->images
[$image])) {
22678 return unserialize($this->readDiskCache($this->images
[$image]));
22679 } elseif (isset($this->images
[$image])) {
22680 return $this->images
[$image];
22686 * Set font buffer content.
22687 * @param $font (string) font key
22688 * @param $data (array) font data
22690 * @since 4.5.000 (2009-01-02)
22692 protected function setFontBuffer($font, $data) {
22693 if ($this->diskcache
) {
22694 if (!isset($this->fonts
[$font])) {
22695 $this->fonts
[$font] = $this->getObjFilename('font');
22697 $this->writeDiskCache($this->fonts
[$font], serialize($data));
22699 $this->fonts
[$font] = $data;
22701 if (!in_array($font, $this->fontkeys
)) {
22702 $this->fontkeys
[] = $font;
22703 // store object ID for current font
22705 $this->font_obj_ids
[$font] = $this->n
;
22706 $this->setFontSubBuffer($font, 'n', $this->n
);
22711 * Set font buffer content.
22712 * @param $font (string) font key
22713 * @param $key (string) font sub-key
22714 * @param $data (array) font data
22716 * @since 4.5.000 (2009-01-02)
22718 protected function setFontSubBuffer($font, $key, $data) {
22719 if (!isset($this->fonts
[$font])) {
22720 $this->setFontBuffer($font, array());
22722 if ($this->diskcache
) {
22723 $tmpfont = $this->getFontBuffer($font);
22724 $tmpfont[$key] = $data;
22725 $this->writeDiskCache($this->fonts
[$font], serialize($tmpfont));
22727 $this->fonts
[$font][$key] = $data;
22732 * Get font buffer content.
22733 * @param $font (string) font key
22734 * @return string font buffer content or false in case of error
22736 * @since 4.5.000 (2009-01-02)
22738 protected function getFontBuffer($font) {
22739 if ($this->diskcache
AND isset($this->fonts
[$font])) {
22740 return unserialize($this->readDiskCache($this->fonts
[$font]));
22741 } elseif (isset($this->fonts
[$font])) {
22742 return $this->fonts
[$font];
22748 * Move a page to a previous position.
22749 * @param $frompage (int) number of the source page
22750 * @param $topage (int) number of the destination page (must be less than $frompage)
22751 * @return true in case of success, false in case of error.
22753 * @since 4.5.000 (2009-01-02)
22755 public function movePage($frompage, $topage) {
22756 if (($frompage > $this->numpages
) OR ($frompage <= $topage)) {
22759 if ($frompage == $this->page
) {
22760 // close the page before moving it
22763 // move all page-related states
22764 $tmppage = $this->pages
[$frompage];
22765 $tmppagedim = $this->pagedim
[$frompage];
22766 $tmppagelen = $this->pagelen
[$frompage];
22767 $tmpintmrk = $this->intmrk
[$frompage];
22768 $tmpbordermrk = $this->bordermrk
[$frompage];
22769 $tmpcntmrk = $this->cntmrk
[$frompage];
22770 if (isset($this->footerpos
[$frompage])) {
22771 $tmpfooterpos = $this->footerpos
[$frompage];
22773 if (isset($this->footerlen
[$frompage])) {
22774 $tmpfooterlen = $this->footerlen
[$frompage];
22776 if (isset($this->transfmrk
[$frompage])) {
22777 $tmptransfmrk = $this->transfmrk
[$frompage];
22779 if (isset($this->PageAnnots
[$frompage])) {
22780 $tmpannots = $this->PageAnnots
[$frompage];
22782 if (isset($this->newpagegroup
[$frompage])) {
22783 $tmpnewpagegroup = $this->newpagegroup
[$frompage];
22785 for ($i = $frompage; $i > $topage; --$i) {
22787 // shift pages down
22788 $this->pages
[$i] = $this->pages
[$j];
22789 $this->pagedim
[$i] = $this->pagedim
[$j];
22790 $this->pagelen
[$i] = $this->pagelen
[$j];
22791 $this->intmrk
[$i] = $this->intmrk
[$j];
22792 $this->bordermrk
[$i] = $this->bordermrk
[$j];
22793 $this->cntmrk
[$i] = $this->cntmrk
[$j];
22794 if (isset($this->footerpos
[$j])) {
22795 $this->footerpos
[$i] = $this->footerpos
[$j];
22796 } elseif (isset($this->footerpos
[$i])) {
22797 unset($this->footerpos
[$i]);
22799 if (isset($this->footerlen
[$j])) {
22800 $this->footerlen
[$i] = $this->footerlen
[$j];
22801 } elseif (isset($this->footerlen
[$i])) {
22802 unset($this->footerlen
[$i]);
22804 if (isset($this->transfmrk
[$j])) {
22805 $this->transfmrk
[$i] = $this->transfmrk
[$j];
22806 } elseif (isset($this->transfmrk
[$i])) {
22807 unset($this->transfmrk
[$i]);
22809 if (isset($this->PageAnnots
[$j])) {
22810 $this->PageAnnots
[$i] = $this->PageAnnots
[$j];
22811 } elseif (isset($this->PageAnnots
[$i])) {
22812 unset($this->PageAnnots
[$i]);
22814 if (isset($this->newpagegroup
[$j])) {
22815 $this->newpagegroup
[$i] = $this->newpagegroup
[$j];
22816 } elseif (isset($this->newpagegroup
[$i])) {
22817 unset($this->newpagegroup
[$i]);
22820 $this->pages
[$topage] = $tmppage;
22821 $this->pagedim
[$topage] = $tmppagedim;
22822 $this->pagelen
[$topage] = $tmppagelen;
22823 $this->intmrk
[$topage] = $tmpintmrk;
22824 $this->bordermrk
[$topage] = $tmpbordermrk;
22825 $this->cntmrk
[$topage] = $tmpcntmrk;
22826 if (isset($tmpfooterpos)) {
22827 $this->footerpos
[$topage] = $tmpfooterpos;
22828 } elseif (isset($this->footerpos
[$topage])) {
22829 unset($this->footerpos
[$topage]);
22831 if (isset($tmpfooterlen)) {
22832 $this->footerlen
[$topage] = $tmpfooterlen;
22833 } elseif (isset($this->footerlen
[$topage])) {
22834 unset($this->footerlen
[$topage]);
22836 if (isset($tmptransfmrk)) {
22837 $this->transfmrk
[$topage] = $tmptransfmrk;
22838 } elseif (isset($this->transfmrk
[$topage])) {
22839 unset($this->transfmrk
[$topage]);
22841 if (isset($tmpannots)) {
22842 $this->PageAnnots
[$topage] = $tmpannots;
22843 } elseif (isset($this->PageAnnots
[$topage])) {
22844 unset($this->PageAnnots
[$topage]);
22846 if (isset($tmpnewpagegroup)) {
22847 $this->newpagegroup
[$topage] = $tmpnewpagegroup;
22848 } elseif (isset($this->newpagegroup
[$topage])) {
22849 unset($this->newpagegroup
[$topage]);
22852 $tmpoutlines = $this->outlines
;
22853 foreach ($tmpoutlines as $key => $outline) {
22854 if (($outline['p'] >= $topage) AND ($outline['p'] < $frompage)) {
22855 $this->outlines
[$key]['p'] = $outline['p'] +
1;
22856 } elseif ($outline['p'] == $frompage) {
22857 $this->outlines
[$key]['p'] = $topage;
22861 $tmplinks = $this->links
;
22862 foreach ($tmplinks as $key => $link) {
22863 if (($link[0] >= $topage) AND ($link[0] < $frompage)) {
22864 $this->links
[$key][0] = $link[0] +
1;
22865 } elseif ($link[0] == $frompage) {
22866 $this->links
[$key][0] = $topage;
22869 // adjust javascript
22870 $tmpjavascript = $this->javascript
;
22871 global $jfrompage, $jtopage;
22872 $jfrompage = $frompage;
22873 $jtopage = $topage;
22874 $this->javascript
= preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
22875 create_function('$matches', 'global $jfrompage, $jtopage;
22876 $pagenum = intval($matches[3]) + 1;
22877 if (($pagenum >= $jtopage) AND ($pagenum < $jfrompage)) {
22878 $newpage = ($pagenum + 1);
22879 } elseif ($pagenum == $jfrompage) {
22880 $newpage = $jtopage;
22882 $newpage = $pagenum;
22885 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
22886 // return to last page
22887 $this->lastPage(true);
22892 * Remove the specified page.
22893 * @param $page (int) page to remove
22894 * @return true in case of success, false in case of error.
22896 * @since 4.6.004 (2009-04-23)
22898 public function deletePage($page) {
22899 if (($page < 1) OR ($page > $this->numpages
)) {
22902 // delete current page
22903 unset($this->pages
[$page]);
22904 unset($this->pagedim
[$page]);
22905 unset($this->pagelen
[$page]);
22906 unset($this->intmrk
[$page]);
22907 unset($this->bordermrk
[$page]);
22908 unset($this->cntmrk
[$page]);
22909 if (isset($this->footerpos
[$page])) {
22910 unset($this->footerpos
[$page]);
22912 if (isset($this->footerlen
[$page])) {
22913 unset($this->footerlen
[$page]);
22915 if (isset($this->transfmrk
[$page])) {
22916 unset($this->transfmrk
[$page]);
22918 if (isset($this->PageAnnots
[$page])) {
22919 unset($this->PageAnnots
[$page]);
22921 if (isset($this->newpagegroup
[$page])) {
22922 unset($this->newpagegroup
[$page]);
22924 if (isset($this->pageopen
[$page])) {
22925 unset($this->pageopen
[$page]);
22927 // update remaining pages
22928 for ($i = $page; $i < $this->numpages
; ++
$i) {
22931 $this->pages
[$i] = $this->pages
[$j];
22932 $this->pagedim
[$i] = $this->pagedim
[$j];
22933 $this->pagelen
[$i] = $this->pagelen
[$j];
22934 $this->intmrk
[$i] = $this->intmrk
[$j];
22935 $this->bordermrk
[$i] = $this->bordermrk
[$j];
22936 $this->cntmrk
[$i] = $this->cntmrk
[$j];
22937 if (isset($this->footerpos
[$j])) {
22938 $this->footerpos
[$i] = $this->footerpos
[$j];
22939 } elseif (isset($this->footerpos
[$i])) {
22940 unset($this->footerpos
[$i]);
22942 if (isset($this->footerlen
[$j])) {
22943 $this->footerlen
[$i] = $this->footerlen
[$j];
22944 } elseif (isset($this->footerlen
[$i])) {
22945 unset($this->footerlen
[$i]);
22947 if (isset($this->transfmrk
[$j])) {
22948 $this->transfmrk
[$i] = $this->transfmrk
[$j];
22949 } elseif (isset($this->transfmrk
[$i])) {
22950 unset($this->transfmrk
[$i]);
22952 if (isset($this->PageAnnots
[$j])) {
22953 $this->PageAnnots
[$i] = $this->PageAnnots
[$j];
22954 } elseif (isset($this->PageAnnots
[$i])) {
22955 unset($this->PageAnnots
[$i]);
22957 if (isset($this->newpagegroup
[$j])) {
22958 $this->newpagegroup
[$i] = $this->newpagegroup
[$j];
22959 } elseif (isset($this->newpagegroup
[$i])) {
22960 unset($this->newpagegroup
[$i]);
22962 if (isset($this->pageopen
[$j])) {
22963 $this->pageopen
[$i] = $this->pageopen
[$j];
22964 } elseif (isset($this->pageopen
[$i])) {
22965 unset($this->pageopen
[$i]);
22968 // remove last page
22969 unset($this->pages
[$this->numpages
]);
22970 unset($this->pagedim
[$this->numpages
]);
22971 unset($this->pagelen
[$this->numpages
]);
22972 unset($this->intmrk
[$this->numpages
]);
22973 unset($this->bordermrk
[$this->numpages
]);
22974 unset($this->cntmrk
[$this->numpages
]);
22975 if (isset($this->footerpos
[$this->numpages
])) {
22976 unset($this->footerpos
[$this->numpages
]);
22978 if (isset($this->footerlen
[$this->numpages
])) {
22979 unset($this->footerlen
[$this->numpages
]);
22981 if (isset($this->transfmrk
[$this->numpages
])) {
22982 unset($this->transfmrk
[$this->numpages
]);
22984 if (isset($this->PageAnnots
[$this->numpages
])) {
22985 unset($this->PageAnnots
[$this->numpages
]);
22987 if (isset($this->newpagegroup
[$this->numpages
])) {
22988 unset($this->newpagegroup
[$this->numpages
]);
22990 if (isset($this->pageopen
[$this->numpages
])) {
22991 unset($this->pageopen
[$this->numpages
]);
22994 $this->page
= $this->numpages
;
22996 $tmpoutlines = $this->outlines
;
22997 foreach ($tmpoutlines as $key => $outline) {
22998 if ($outline['p'] > $page) {
22999 $this->outlines
[$key]['p'] = $outline['p'] - 1;
23000 } elseif ($outline['p'] == $page) {
23001 unset($this->outlines
[$key]);
23005 $tmplinks = $this->links
;
23006 foreach ($tmplinks as $key => $link) {
23007 if ($link[0] > $page) {
23008 $this->links
[$key][0] = $link[0] - 1;
23009 } elseif ($link[0] == $page) {
23010 unset($this->links
[$key]);
23013 // adjust javascript
23014 $tmpjavascript = $this->javascript
;
23017 $this->javascript
= preg_replace_callback('/this\.addField\(\'([^\']*)\',\'([^\']*)\',([0-9]+)/',
23018 create_function('$matches', 'global $jpage;
23019 $pagenum = intval($matches[3]) + 1;
23020 if ($pagenum >= $jpage) {
23021 $newpage = ($pagenum - 1);
23022 } elseif ($pagenum == $jpage) {
23025 $newpage = $pagenum;
23028 return "this.addField(\'".$matches[1]."\',\'".$matches[2]."\',".$newpage."";'), $tmpjavascript);
23029 // return to last page
23030 $this->lastPage(true);
23035 * Clone the specified page to a new page.
23036 * @param $page (int) number of page to copy (0 = current page)
23037 * @return true in case of success, false in case of error.
23039 * @since 4.9.015 (2010-04-20)
23041 public function copyPage($page=0) {
23044 $page = $this->page
;
23046 if (($page < 1) OR ($page > $this->numpages
)) {
23049 if ($page == $this->page
) {
23050 // close the page before cloning it
23053 // copy all page-related states
23055 $this->page
= $this->numpages
;
23056 $this->pages
[$this->page
] = $this->pages
[$page];
23057 $this->pagedim
[$this->page
] = $this->pagedim
[$page];
23058 $this->pagelen
[$this->page
] = $this->pagelen
[$page];
23059 $this->intmrk
[$this->page
] = $this->intmrk
[$page];
23060 $this->bordermrk
[$this->page
] = $this->bordermrk
[$page];
23061 $this->cntmrk
[$this->page
] = $this->cntmrk
[$page];
23062 $this->pageopen
[$this->page
] = false;
23063 if (isset($this->footerpos
[$page])) {
23064 $this->footerpos
[$this->page
] = $this->footerpos
[$page];
23066 if (isset($this->footerlen
[$page])) {
23067 $this->footerlen
[$this->page
] = $this->footerlen
[$page];
23069 if (isset($this->transfmrk
[$page])) {
23070 $this->transfmrk
[$this->page
] = $this->transfmrk
[$page];
23072 if (isset($this->PageAnnots
[$page])) {
23073 $this->PageAnnots
[$this->page
] = $this->PageAnnots
[$page];
23075 if (isset($this->newpagegroup
[$page])) {
23076 $this->newpagegroup
[$this->page
] = $this->newpagegroup
[$page];
23079 $tmpoutlines = $this->outlines
;
23080 foreach ($tmpoutlines as $key => $outline) {
23081 if ($outline['p'] == $page) {
23082 $this->outlines
[] = array('t' => $outline['t'], 'l' => $outline['l'], 'y' => $outline['y'], 'p' => $this->page
);
23086 $tmplinks = $this->links
;
23087 foreach ($tmplinks as $key => $link) {
23088 if ($link[0] == $page) {
23089 $this->links
[] = array($this->page
, $link[1]);
23092 // return to last page
23093 $this->lastPage(true);
23098 * Output a Table of Content Index (TOC).
23099 * Before calling this method you have to open the page using the addTOCPage() method.
23100 * After calling this method you have to call endTOCPage() to close the TOC page.
23101 * You can override this method to achieve different styles.
23102 * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
23103 * @param $numbersfont (string) set the font for page numbers (please use monospaced font for better alignment).
23104 * @param $filler (string) string used to fill the space between text and page number.
23105 * @param $toc_name (string) name to use for TOC bookmark.
23107 * @author Nicola Asuni
23108 * @since 4.5.000 (2009-01-02)
23109 * @see addTOCPage(), endTOCPage(), addHTMLTOC()
23111 public function addTOC($page='', $numbersfont='', $filler='.', $toc_name='TOC') {
23112 $fontsize = $this->FontSizePt
;
23113 $fontfamily = $this->FontFamily
;
23114 $fontstyle = $this->FontStyle
;
23115 $w = $this->w
- $this->lMargin
- $this->rMargin
;
23116 $spacer = $this->GetStringWidth(chr(32)) * 4;
23117 $page_first = $this->getPage();
23118 $lmargin = $this->lMargin
;
23119 $rmargin = $this->rMargin
;
23120 $x_start = $this->GetX();
23121 $current_page = $this->page
;
23122 $current_column = $this->current_column
;
23123 if ($this->empty_string($numbersfont)) {
23124 $numbersfont = $this->default_monospaced_font
;
23126 if ($this->empty_string($filler)) {
23129 if ($this->empty_string($page)) {
23137 foreach ($this->outlines
as $key => $outline) {
23145 if ($outline['l'] == 0) {
23146 $this->SetFont($fontfamily, $fontstyle.'B', $fontsize);
23148 $this->SetFont($fontfamily, $fontstyle, $fontsize - $outline['l']);
23150 // check for page break
23151 $this->checkPageBreak(($this->FontSize
* $this->cell_height_ratio
));
23152 // set margins and X position
23153 if (($this->page
== $current_page) AND ($this->current_column
== $current_column)) {
23154 $this->lMargin
= $lmargin;
23155 $this->rMargin
= $rmargin;
23157 if ($this->current_column
!= $current_column) {
23159 $x_start = $this->w
- $this->columns
[$this->current_column
]['x'];
23161 $x_start = $this->columns
[$this->current_column
]['x'];
23164 $lmargin = $this->lMargin
;
23165 $rmargin = $this->rMargin
;
23166 $current_page = $this->page
;
23167 $current_column = $this->current_column
;
23169 $this->SetX($x_start);
23170 $indent = ($spacer * $outline['l']);
23172 $this->rMargin +
= $indent;
23173 $this->x
-= $indent;
23175 $this->lMargin +
= $indent;
23176 $this->x +
= $indent;
23178 $link = $this->AddLink();
23179 $this->SetLink($link, $outline['y'], $outline['p']);
23181 $this->Write(0, $outline['t'], $link, 0, $aligntext, false, 0, false, false, 0);
23182 $this->SetFont($numbersfont, $fontstyle, $fontsize);
23183 if ($this->empty_string($page)) {
23184 $pagenum = $outline['p'];
23186 // placemark to be replaced with the correct number
23187 $pagenum = '{#'.($outline['p']).'}';
23188 if ($this->isUnicodeFont()) {
23189 $pagenum = '{'.$pagenum.'}';
23192 $numwidth = $this->GetStringWidth($pagenum);
23194 $tw = $this->x
- $this->lMargin
;
23196 $tw = $this->w
- $this->rMargin
- $this->x
;
23198 $fw = $tw - $numwidth - $this->GetStringWidth(chr(32));
23199 $numfills = floor($fw / $this->GetStringWidth($filler));
23200 if ($numfills > 0) {
23201 $rowfill = str_repeat($filler, $numfills);
23206 $pagenum = $pagenum.$gap.$rowfill.' ';
23208 $pagenum = ' '.$rowfill.$gap.$pagenum;
23210 // write the number
23211 $this->Cell($tw, 0, $pagenum, 0, 1, $alignnum, 0, $link, 0);
23213 $page_last = $this->getPage();
23214 $numpages = $page_last - $page_first +
1;
23215 if (!$this->empty_string($page)) {
23216 for ($p = $page_first; $p <= $page_last; ++
$p) {
23218 $temppage = $this->getPageBuffer($p);
23219 for ($n = 1; $n <= $this->numpages
; ++
$n) {
23220 // update page numbers
23223 $alias_a = $this->_escape($k);
23224 $alias_au = $this->_escape($ku);
23225 if ($this->isunicode
) {
23226 $alias_b = $this->_escape($this->UTF8ToLatin1($k));
23227 $alias_bu = $this->_escape($this->UTF8ToLatin1($ku));
23228 $alias_c = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl
));
23229 $alias_cu = $this->_escape($this->utf8StrRev($ku, false, $this->tmprtl
));
23232 $np = $n +
$numpages;
23236 $ns = $this->formatTOCPageNumber($np);
23238 $sdiff = strlen($k) - strlen($ns) - 1;
23239 $sdiffu = strlen($ku) - strlen($ns) - 1;
23240 $sfill = str_repeat($filler, $sdiff);
23241 $sfillu = str_repeat($filler, $sdiffu);
23243 $ns = $ns.' '.$sfill;
23244 $nu = $nu.' '.$sfillu;
23246 $ns = $sfill.' '.$ns;
23247 $nu = $sfillu.' '.$nu;
23249 $nu = $this->UTF8ToUTF16BE($nu, false);
23250 $temppage = str_replace($alias_au, $nu, $temppage);
23251 if ($this->isunicode
) {
23252 $temppage = str_replace($alias_bu, $nu, $temppage);
23253 $temppage = str_replace($alias_cu, $nu, $temppage);
23254 $temppage = str_replace($alias_b, $ns, $temppage);
23255 $temppage = str_replace($alias_c, $ns, $temppage);
23257 $temppage = str_replace($alias_a, $ns, $temppage);
23260 $this->setPageBuffer($p, $temppage);
23263 $this->Bookmark($toc_name, 0, 0, $page_first);
23264 for ($i = 0; $i < $numpages; ++
$i) {
23265 $this->movePage($page_last, $page);
23271 * Output a Table Of Content Index (TOC) using HTML templates.
23272 * Before calling this method you have to open the page using the addTOCPage() method.
23273 * After calling this method you have to call endTOCPage() to close the TOC page.
23274 * @param $page (int) page number where this TOC should be inserted (leave empty for current page).
23275 * @param $toc_name (string) name to use for TOC bookmark.
23276 * @param $templates (array) array of html templates. Use: "#TOC_DESCRIPTION#" for bookmark title, "#TOC_PAGE_NUMBER#" for page number.
23277 * @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)
23279 * @author Nicola Asuni
23280 * @since 5.0.001 (2010-05-06)
23281 * @see addTOCPage(), endTOCPage(), addTOC()
23283 public function addHTMLTOC($page='', $toc_name='TOC', $templates=array(), $correct_align=true) {
23284 $prev_htmlLinkColorArray = $this->htmlLinkColorArray
;
23285 $prev_htmlLinkFontStyle = $this->htmlLinkFontStyle
;
23286 // set new style for link
23287 $this->htmlLinkColorArray
= array();
23288 $this->htmlLinkFontStyle
= '';
23289 $page_first = $this->getPage();
23290 // get the font type used for numbers in each template
23291 $current_font = $this->FontFamily
;
23292 foreach ($templates as $level => $html) {
23293 $dom = $this->getHtmlDomArray($html);
23294 foreach ($dom as $key => $value) {
23295 if ($value['value'] == '#TOC_PAGE_NUMBER#') {
23296 $this->SetFont($dom[($key - 1)]['fontname']);
23297 $templates['F'.$level] = $this->isUnicodeFont();
23301 $this->SetFont($current_font);
23302 foreach ($this->outlines
as $key => $outline) {
23303 // get HTML template
23304 $row = $templates[$outline['l']];
23305 if ($this->empty_string($page)) {
23306 $pagenum = $outline['p'];
23308 // placemark to be replaced with the correct number
23309 $pagenum = '{#'.($outline['p']).'}';
23310 if ($templates['F'.$outline['l']]) {
23311 $pagenum = '{'.$pagenum.'}';
23314 // replace templates with current values
23315 $row = str_replace('#TOC_DESCRIPTION#', $outline['t'], $row);
23316 $row = str_replace('#TOC_PAGE_NUMBER#', $pagenum, $row);
23317 // add link to page
23318 $row = '<a href="#'.$outline['p'].','.$outline['y'].'">'.$row.'</a>';
23319 // write bookmark entry
23320 $this->writeHTML($row, false, false, true, false, '');
23322 // restore link styles
23323 $this->htmlLinkColorArray
= $prev_htmlLinkColorArray;
23324 $this->htmlLinkFontStyle
= $prev_htmlLinkFontStyle;
23325 // move TOC page and replace numbers
23326 $page_last = $this->getPage();
23327 $numpages = $page_last - $page_first +
1;
23328 if (!$this->empty_string($page)) {
23329 for ($p = $page_first; $p <= $page_last; ++
$p) {
23331 $temppage = $this->getPageBuffer($p);
23332 for ($n = 1; $n <= $this->numpages
; ++
$n) {
23333 // update page numbers
23336 $alias_a = $this->_escape($k);
23337 $alias_au = $this->_escape('{'.$k.'}');
23338 if ($this->isunicode
) {
23339 $alias_b = $this->_escape($this->UTF8ToLatin1($k));
23340 $alias_bu = $this->_escape($this->UTF8ToLatin1($ku));
23341 $alias_c = $this->_escape($this->utf8StrRev($k, false, $this->tmprtl
));
23342 $alias_cu = $this->_escape($this->utf8StrRev($ku, false, $this->tmprtl
));
23345 $np = $n +
$numpages;
23349 $ns = $this->formatTOCPageNumber($np);
23351 if ($correct_align) {
23352 $sdiff = strlen($k) - strlen($ns);
23353 $sdiffu = strlen($ku) - strlen($ns);
23354 $sfill = str_repeat(' ', $sdiff);
23355 $sfillu = str_repeat(' ', $sdiffu);
23364 $nu = $this->UTF8ToUTF16BE($nu, false);
23365 $temppage = str_replace($alias_au, $nu, $temppage);
23366 if ($this->isunicode
) {
23367 $temppage = str_replace($alias_bu, $nu, $temppage);
23368 $temppage = str_replace($alias_cu, $nu, $temppage);
23369 $temppage = str_replace($alias_b, $ns, $temppage);
23370 $temppage = str_replace($alias_c, $ns, $temppage);
23372 $temppage = str_replace($alias_a, $ns, $temppage);
23375 $this->setPageBuffer($p, $temppage);
23378 $this->Bookmark($toc_name, 0, 0, $page_first);
23379 for ($i = 0; $i < $numpages; ++
$i) {
23380 $this->movePage($page_last, $page);
23386 * Stores a copy of the current TCPDF object used for undo operation.
23388 * @since 4.5.029 (2009-03-19)
23390 public function startTransaction() {
23391 if (isset($this->objcopy
)) {
23392 // remove previous copy
23393 $this->commitTransaction();
23395 // record current page number and Y position
23396 $this->start_transaction_page
= $this->page
;
23397 $this->start_transaction_y
= $this->y
;
23398 // clone current object
23399 $this->objcopy
= $this->objclone($this);
23403 * Delete the copy of the current TCPDF object used for undo operation.
23405 * @since 4.5.029 (2009-03-19)
23407 public function commitTransaction() {
23408 if (isset($this->objcopy
)) {
23409 $this->objcopy
->_destroy(true, true);
23410 unset($this->objcopy
);
23415 * This method allows to undo the latest transaction by returning the latest saved TCPDF object with startTransaction().
23416 * @param $self (boolean) if true restores current class object to previous state without the need of reassignment via the returned value.
23417 * @return TCPDF object.
23419 * @since 4.5.029 (2009-03-19)
23421 public function rollbackTransaction($self=false) {
23422 if (isset($this->objcopy
)) {
23423 if (isset($this->objcopy
->diskcache
) AND $this->objcopy
->diskcache
) {
23424 // truncate files to previous values
23425 foreach ($this->objcopy
->cache_file_length
as $file => $length) {
23426 $file = substr($file, 1);
23427 $handle = fopen($file, 'r+');
23428 ftruncate($handle, $length);
23431 $this->_destroy(true, true);
23433 $objvars = get_object_vars($this->objcopy
);
23434 foreach ($objvars as $key => $value) {
23435 $this->$key = $value;
23438 return $this->objcopy
;
23444 * Creates a copy of a class object
23445 * @param $object (object) class object to be cloned
23446 * @return cloned object
23448 * @since 4.5.029 (2009-03-19)
23450 public function objclone($object) {
23451 return @clone
($object);
23455 * Determine whether a string is empty.
23456 * @param $str (string) string to be checked
23457 * @return boolean true if string is empty
23459 * @since 4.5.044 (2009-04-16)
23461 public function empty_string($str) {
23462 return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
23466 * Find position of last occurrence of a substring in a string
23467 * @param $haystack (string) The string to search in.
23468 * @param $needle (string) substring to search.
23469 * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string.
23470 * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
23472 * @since 4.8.038 (2010-03-13)
23474 public function revstrpos($haystack, $needle, $offset = 0) {
23475 $length = strlen($haystack);
23476 $offset = ($offset > 0)?
($length - $offset):abs($offset);
23477 $pos = strpos(strrev($haystack), strrev($needle), $offset);
23478 return ($pos === false)?
false:($length - $pos - strlen($needle));
23481 // --- MULTI COLUMNS METHODS -----------------------
23484 * Set multiple columns of the same size
23485 * @param $numcols (int) number of columns (set to zero to disable columns mode)
23486 * @param $width (int) column width
23487 * @param $y (int) column starting Y position (leave empty for current Y position)
23489 * @since 4.9.001 (2010-03-28)
23491 public function setEqualColumns($numcols=0, $width=0, $y='') {
23492 $this->columns
= array();
23493 if ($numcols < 2) {
23495 $this->columns
= array();
23497 // maximum column width
23498 $maxwidth = ($this->w
- $this->original_lMargin
- $this->original_rMargin
) / $numcols;
23499 if (($width == 0) OR ($width > $maxwidth)) {
23500 $width = $maxwidth;
23502 if ($this->empty_string($y)) {
23505 // space between columns
23506 $space = (($this->w
- $this->original_lMargin
- $this->original_rMargin
- ($numcols * $width)) / ($numcols - 1));
23507 // fill the columns array (with, space, starting Y position)
23508 for ($i = 0; $i < $numcols; ++
$i) {
23509 $this->columns
[$i] = array('w' => $width, 's' => $space, 'y' => $y);
23512 $this->num_columns
= $numcols;
23513 $this->current_column
= 0;
23514 $this->column_start_page
= $this->page
;
23518 * Set columns array.
23519 * Each column is represented by an array of arrays with the following keys: (w = width, s = space between columns, y = column top position).
23520 * @param $columns (array)
23522 * @since 4.9.001 (2010-03-28)
23524 public function setColumnsArray($columns) {
23525 $this->columns
= $columns;
23526 $this->num_columns
= count($columns);
23527 $this->current_column
= 0;
23528 $this->column_start_page
= $this->page
;
23532 * Set position at a given column
23533 * @param $col (int) column number (from 0 to getNumberOfColumns()-1); empty string = current column.
23535 * @since 4.9.001 (2010-03-28)
23537 public function selectColumn($col='') {
23538 if (is_string($col)) {
23539 $col = $this->current_column
;
23540 } elseif($col >= $this->num_columns
) {
23544 $enable_thead = false;
23545 if ($this->num_columns
> 1) {
23546 if ($col != $this->current_column
) {
23547 // move Y pointer at the top of the column
23548 if ($this->column_start_page
== $this->page
) {
23549 $this->y
= $this->columns
[$col]['y'];
23551 $this->y
= $this->tMargin
;
23553 // Avoid to write table headers more than once
23554 if (($this->page
> $this->maxselcol
['page']) OR (($this->page
== $this->maxselcol
['page']) AND ($col > $this->maxselcol
['column']))) {
23555 $enable_thead = true;
23556 $this->maxselcol
['page'] = $this->page
;
23557 $this->maxselcol
['column'] = $col;
23560 $xshift = $this->colxshift
;
23561 // set X position of the current column by case
23562 $listindent = ($this->listindentlevel
* $this->listindent
);
23563 $colpos = ($col * ($this->columns
[$col]['w'] +
$this->columns
[$col]['s']));
23565 $x = $this->w
- $this->original_rMargin
- $colpos;
23566 $this->rMargin
= ($this->w
- $x +
$listindent);
23567 $this->lMargin
= ($x - $this->columns
[$col]['w']);
23568 $this->x
= $x - $listindent;
23570 $x = $this->original_lMargin +
$colpos;
23571 $this->lMargin
= ($x +
$listindent);
23572 $this->rMargin
= ($this->w
- $x - $this->columns
[$col]['w']);
23573 $this->x
= $x +
$listindent;
23575 $this->columns
[$col]['x'] = $x;
23577 $this->current_column
= $col;
23578 // fix for HTML mode
23579 $this->newline
= true;
23580 // print HTML table header (if any)
23581 if ((!$this->empty_string($this->thead
)) AND (!$this->inthead
)) {
23582 if ($enable_thead) {
23583 // print table header
23584 $this->writeHTML($this->thead
, false, false, false, false, '');
23585 $this->y +
= $xshift['s']['V'];
23586 // store end of header position
23587 if (!isset($this->columns
[$col]['th'])) {
23588 $this->columns
[$col]['th'] = array();
23590 $this->columns
[$col]['th']['\''.$this->page
.'\''] = $this->y
;
23592 } elseif (isset($this->columns
[$col]['th']['\''.$this->page
.'\''])) {
23593 $this->y
= $this->columns
[$col]['th']['\''.$this->page
.'\''];
23596 // account for an html table cell over multiple columns
23598 $this->rMargin +
= $xshift['x'];
23599 $this->x
-= ($xshift['x'] +
$xshift['p']['R']);
23601 $this->lMargin +
= $xshift['x'];
23602 $this->x +
= $xshift['x'] +
$xshift['p']['L'];
23607 * Return the current column number
23608 * @return int current column number
23610 * @since 5.5.011 (2010-07-08)
23612 public function getColumn() {
23613 return $this->current_column
;
23617 * Return the current number of columns.
23618 * @return int number of columns
23620 * @since 5.8.018 (2010-08-25)
23622 public function getNumberOfColumns() {
23623 return $this->num_columns
;
23627 * Serialize an array of parameters to be used with TCPDF tag in HTML code.
23628 * @param $pararray (array) parameters array
23629 * @return sting containing serialized data
23631 * @since 4.9.006 (2010-04-02)
23633 public function serializeTCPDFtagParameters($pararray) {
23634 return urlencode(serialize($pararray));
23638 * Set Text rendering mode.
23639 * @param $stroke (int) outline size in user units (0 = disable).
23640 * @param $fill (boolean) if true fills the text (default).
23641 * @param $clip (boolean) if true activate clipping mode
23643 * @since 4.9.008 (2009-04-02)
23645 public function setTextRenderingMode($stroke=0, $fill=true, $clip=false) {
23646 // Ref.: PDF 32000-1:2008 - 9.3.6 Text Rendering Mode
23647 // convert text rendering parameters
23651 if ($fill === true) {
23653 if ($clip === true) {
23654 // Fill, then stroke text and add to path for clipping
23655 $textrendermode = 6;
23657 // Fill, then stroke text
23658 $textrendermode = 2;
23660 $textstrokewidth = $stroke;
23662 if ($clip === true) {
23663 // Fill text and add to path for clipping
23664 $textrendermode = 4;
23667 $textrendermode = 0;
23672 if ($clip === true) {
23673 // Stroke text and add to path for clipping
23674 $textrendermode = 5;
23677 $textrendermode = 1;
23679 $textstrokewidth = $stroke;
23681 if ($clip === true) {
23682 // Add text to path for clipping
23683 $textrendermode = 7;
23685 // Neither fill nor stroke text (invisible)
23686 $textrendermode = 3;
23690 $this->textrendermode
= $textrendermode;
23691 $this->textstrokewidth
= $stroke * $this->k
;
23695 * Returns an array of chars containing soft hyphens.
23696 * @param $word (array) array of chars
23697 * @param $patterns (array) Array of hypenation patterns.
23698 * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
23699 * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
23700 * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
23701 * @param $charmin (int) Minimum word lenght to apply the hyphenation algoritm.
23702 * @param $charmax (int) Maximum lenght of broken piece of word.
23703 * @return array text with soft hyphens
23704 * @author Nicola Asuni
23705 * @since 4.9.012 (2010-04-12)
23708 protected function hyphenateWord($word, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
23709 $hyphenword = array(); // hyphens positions
23710 $numchars = count($word);
23711 if ($numchars <= $charmin) {
23714 $word_string = $this->UTF8ArrSubString($word);
23715 // some words will be returned as-is
23716 $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})(\]?)$/';
23717 if (preg_match($pattern, $word_string) > 0) {
23721 $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})(\]?)$/';
23722 if (preg_match($pattern, $word_string) > 0) {
23726 if (isset($dictionary[$word_string])) {
23727 return $this->UTF8StringToArray($dictionary[$word_string]);
23729 // suround word with '_' characters
23730 $tmpword = array_merge(array(95), $word, array(95));
23731 $tmpnumchars = $numchars +
2;
23732 $maxpos = $tmpnumchars - $charmin;
23733 for ($pos = 0; $pos < $maxpos; ++
$pos) {
23734 $imax = min(($tmpnumchars - $pos), $charmax);
23735 for ($i = $charmin; $i <= $imax; ++
$i) {
23736 $subword = strtolower($this->UTF8ArrSubString($tmpword, $pos, $pos +
$i));
23737 if (isset($patterns[$subword])) {
23738 $pattern = $this->UTF8StringToArray($patterns[$subword]);
23739 $pattern_length = count($pattern);
23741 for ($j = 0; $j < $pattern_length; ++
$j) {
23742 // check if $pattern[$j] is a number
23743 if (($pattern[$j] >= 48) AND ($pattern[$j] <= 57)) {
23747 $zero = $pos +
$j - $digits;
23749 if (!isset($hyphenword[$zero]) OR ($hyphenword[$zero] != $pattern[$j])) {
23750 $hyphenword[$zero] = $this->unichr($pattern[$j]);
23759 $maxpos = $numchars - $rightmin;
23760 for($i = $leftmin; $i <= $maxpos; ++
$i) {
23761 if(isset($hyphenword[$i]) AND (($hyphenword[$i] %
2) != 0)) {
23762 // 173 = soft hyphen character
23763 array_splice($word, $i +
$inserted, 0, 173);
23771 * Returns an array of hyphenation patterns.
23772 * @param $file (string) TEX file containing hypenation patterns. TEX pattrns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
23773 * @return array of hyphenation patterns
23774 * @author Nicola Asuni
23775 * @since 4.9.012 (2010-04-12)
23778 public function getHyphenPatternsFromTEX($file) {
23779 // TEX patterns are available at:
23780 // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
23781 $data = file_get_contents($file);
23782 $patterns = array();
23784 $data = preg_replace('/\%[^\n]*/', '', $data);
23785 // extract the patterns part
23786 preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
23787 $data = trim(substr($matches[0], 10, -1));
23788 // extract each pattern
23789 $patterns_array = preg_split('/[\s]+/', $data);
23790 // create new language array of patterns
23791 $patterns = array();
23792 foreach($patterns_array as $val) {
23793 if (!$this->empty_string($val)) {
23795 $val = str_replace('\'', '\\\'', $val);
23796 $key = preg_replace('/[0-9]+/', '', $val);
23797 $patterns[$key] = $val;
23804 * Returns text with soft hyphens.
23805 * @param $text (string) text to process
23806 * @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/
23807 * @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
23808 * @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
23809 * @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
23810 * @param $charmin (int) Minimum word lenght to apply the hyphenation algoritm.
23811 * @param $charmax (int) Maximum lenght of broken piece of word.
23812 * @return array text with soft hyphens
23813 * @author Nicola Asuni
23814 * @since 4.9.012 (2010-04-12)
23817 public function hyphenateText($text, $patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8) {
23818 $text = $this->unhtmlentities($text);
23819 $word = array(); // last word
23820 $txtarr = array(); // text to be returned
23821 $intag = false; // true if we are inside an HTML tag
23822 if (!is_array($patterns)) {
23823 $patterns = $this->getHyphenPatternsFromTEX($patterns);
23825 // get array of characters
23826 $unichars = $this->UTF8StringToArray($text);
23828 foreach ($unichars as $char) {
23829 if ((!$intag) AND $this->unicode
->uni_type
[$char] == 'L') {
23830 // letter character
23833 // other type of character
23834 if (!$this->empty_string($word)) {
23835 // hypenate the word
23836 $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
23840 if (chr($char) == '<') {
23841 // we are inside an HTML tag
23843 } elseif ($intag AND (chr($char) == '>')) {
23849 if (!$this->empty_string($word)) {
23850 // hypenate the word
23851 $txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
23853 // convert char array to string and return
23854 return $this->UTF8ArrSubString($txtarr);
23858 * Enable/disable rasterization of vector images using ImageMagick library.
23859 * @param $mode (boolean) if true enable rasterization, false otherwise.
23861 * @since 5.0.000 (2010-04-27)
23863 public function setRasterizeVectorImages($mode) {
23864 $this->rasterize_vector_images
= $mode;
23868 * Get the Path-Painting Operators.
23869 * @param $style (string) Style of rendering. Possible values are:
23871 * <li>S or D: Stroke the path.</li>
23872 * <li>s or d: Close and stroke the path.</li>
23873 * <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
23874 * <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
23875 * <li>B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
23876 * <li>B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.</li>
23877 * <li>b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
23878 * <li>b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.</li>
23879 * <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
23880 * <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
23881 * <li>n: End the path object without filling or stroking it.</li>
23883 * @param $default (string) default style
23884 * @author Nicola Asuni
23885 * @since 5.0.000 (2010-04-30)
23888 protected function getPathPaintOperator($style, $default='S') {
23948 if (!empty($default)) {
23949 $op = $this->getPathPaintOperator($default, '');
23959 * Enable or disable default option for font subsetting.
23960 * @param $enable (boolean) if true enable font subsetting by default.
23961 * @author Nicola Asuni
23963 * @since 5.3.002 (2010-06-07)
23965 public function setFontSubsetting($enable=true) {
23966 $this->font_subsetting
= $enable ?
true : false;
23970 * Return the default option for font subsetting.
23971 * @return boolean default font subsetting state.
23972 * @author Nicola Asuni
23974 * @since 5.3.002 (2010-06-07)
23976 public function getFontSubsetting() {
23977 return $this->font_subsetting
;
23981 * Left trim the input string
23982 * @param $str (string) string to trim
23983 * @param $replace (string) string that replace spaces.
23984 * @return left trimmed string
23985 * @author Nicola Asuni
23987 * @since 5.8.000 (2010-08-11)
23989 public function stringLeftTrim($str, $replace='') {
23990 return preg_replace('/^'.$this->re_space
['p'].'+/'.$this->re_space
['m'], $replace, $str);
23994 * Right trim the input string
23995 * @param $str (string) string to trim
23996 * @param $replace (string) string that replace spaces.
23997 * @return right trimmed string
23998 * @author Nicola Asuni
24000 * @since 5.8.000 (2010-08-11)
24002 public function stringRightTrim($str, $replace='') {
24003 return preg_replace('/'.$this->re_space
['p'].'+$/'.$this->re_space
['m'], $replace, $str);
24007 * Trim the input string
24008 * @param $str (string) string to trim
24009 * @param $replace (string) string that replace spaces.
24010 * @return trimmed string
24011 * @author Nicola Asuni
24013 * @since 5.8.000 (2010-08-11)
24015 public function stringTrim($str, $replace='') {
24016 $str = $this->stringLeftTrim($str, $replace);
24017 $str = $this->stringRightTrim($str, $replace);
24022 * Return true if the current font is unicode type.
24023 * @return true for unicode font, false otherwise.
24024 * @author Nicola Asuni
24026 * @since 5.8.002 (2010-08-14)
24028 public function isUnicodeFont() {
24029 return (($this->CurrentFont
['type'] == 'TrueTypeUnicode') OR ($this->CurrentFont
['type'] == 'cidfont0'));
24033 * Return normalized font name
24034 * @param $fontfamily (string) property string containing font family names
24035 * @return string normalized font name
24036 * @author Nicola Asuni
24038 * @since 5.8.004 (2010-08-17)
24040 public function getFontFamilyName($fontfamily) {
24041 // remove spaces and symbols
24042 $fontfamily = preg_replace('/[^a-z0-9\,]/', '', strtolower($fontfamily));
24043 // extract all font names
24044 $fontslist = preg_split('/[,]/', $fontfamily);
24045 // find first valid font name
24046 foreach ($fontslist as $font) {
24047 // replace font variations
24048 $font = preg_replace('/italic$/', 'I', $font);
24049 $font = preg_replace('/oblique$/', 'I', $font);
24050 $font = preg_replace('/bold([I]?)$/', 'B\\1', $font);
24051 // replace common family names and core fonts
24052 $pattern = array();
24053 $replacement = array();
24054 $pattern[] = '/^serif|^cursive|^fantasy|^timesnewroman/';
24055 $replacement[] = 'times';
24056 $pattern[] = '/^sansserif/';
24057 $replacement[] = 'helvetica';
24058 $pattern[] = '/^monospace/';
24059 $replacement[] = 'courier';
24060 $font = preg_replace($pattern, $replacement, $font);
24061 if (in_array(strtolower($font), $this->fontlist
) OR in_array($font, $this->fontkeys
)) {
24065 // return current font as default
24066 return $this->CurrentFont
['fontkey'];
24070 * Start a new XObject Template.
24071 * 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).
24072 * 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.
24073 * Note: X,Y coordinates will be reset to 0,0.
24074 * @param $w (int) Template width in user units (empty string or zero = page width less margins)
24075 * @param $h (int) Template height in user units (empty string or zero = page height less margins)
24076 * @return int the XObject Template ID in case of success or false in case of error.
24077 * @author Nicola Asuni
24079 * @since 5.8.017 (2010-08-24)
24080 * @see endTemplate(), printTemplate()
24082 public function startTemplate($w=0, $h=0) {
24083 if ($this->inxobj
) {
24084 // we are already inside an XObject template
24087 $this->inxobj
= true;
24090 $this->xobjid
= 'XT'.$this->n
;
24092 $this->xobjects
[$this->xobjid
] = array('n' => $this->n
);
24093 // store current graphic state
24094 $this->xobjects
[$this->xobjid
]['gvars'] = $this->getGraphicVars();
24096 $this->xobjects
[$this->xobjid
]['intmrk'] = 0;
24097 $this->xobjects
[$this->xobjid
]['transfmrk'] = array();
24098 $this->xobjects
[$this->xobjid
]['outdata'] = '';
24099 $this->xobjects
[$this->xobjid
]['xobjects'] = array();
24100 $this->xobjects
[$this->xobjid
]['images'] = array();
24101 $this->xobjects
[$this->xobjid
]['fonts'] = array();
24102 $this->xobjects
[$this->xobjid
]['annotations'] = array();
24103 // set new environment
24104 $this->num_columns
= 1;
24105 $this->current_column
= 0;
24106 $this->SetAutoPageBreak(false);
24107 if (($w === '') OR ($w <= 0)) {
24108 $w = $this->w
- $this->lMargin
- $this->rMargin
;
24110 if (($h === '') OR ($h <= 0)) {
24111 $h = $this->h
- $this->tMargin
- $this->bMargin
;
24113 $this->xobjects
[$this->xobjid
]['x'] = 0;
24114 $this->xobjects
[$this->xobjid
]['y'] = 0;
24115 $this->xobjects
[$this->xobjid
]['w'] = $w;
24116 $this->xobjects
[$this->xobjid
]['h'] = $h;
24119 $this->wPt
= $this->w
* $this->k
;
24120 $this->hPt
= $this->h
* $this->k
;
24121 $this->fwPt
= $this->wPt
;
24122 $this->fhPt
= $this->hPt
;
24125 $this->lMargin
= 0;
24126 $this->rMargin
= 0;
24127 $this->tMargin
= 0;
24128 $this->bMargin
= 0;
24129 return $this->xobjid
;
24133 * End the current XObject Template started with startTemplate() and restore the previous graphic state.
24134 * 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).
24135 * 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.
24136 * @return int the XObject Template ID in case of success or false in case of error.
24137 * @author Nicola Asuni
24139 * @since 5.8.017 (2010-08-24)
24140 * @see startTemplate(), printTemplate()
24142 public function endTemplate() {
24143 if (!$this->inxobj
) {
24144 // we are not inside a template
24147 $this->inxobj
= false;
24148 // restore previous graphic state
24149 $this->setGraphicVars($this->xobjects
[$this->xobjid
]['gvars'], true);
24150 return $this->xobjid
;
24154 * Print an XObject Template.
24155 * You can print an XObject Template inside the currently opened Template.
24156 * 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).
24157 * 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.
24158 * @param $id (string) The ID of XObject Template to print.
24159 * @param $x (int) X position in user units (empty string = current x position)
24160 * @param $y (int) Y position in user units (empty string = current y position)
24161 * @param $w (int) Width in user units (zero = remaining page width)
24162 * @param $h (int) Height in user units (zero = remaining page height)
24163 * @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>
24164 * @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>
24165 * @param $fitonpage (boolean) if true the template is resized to not exceed page dimensions.
24166 * @author Nicola Asuni
24168 * @since 5.8.017 (2010-08-24)
24169 * @see startTemplate(), endTemplate()
24171 public function printTemplate($id, $x='', $y='', $w=0, $h=0, $align='', $palign='', $fitonpage=false) {
24172 if (!isset($this->xobjects
[$id])) {
24173 $this->Error('The XObject Template \''.$id.'\' doesn\'t exist!');
24175 if ($this->inxobj
) {
24176 if ($id == $this->xobjid
) {
24177 // close current template
24178 $this->endTemplate();
24180 // use the template as resource for the template currently opened
24181 $this->xobjects
[$this->xobjid
]['xobjects'][$id] = $this->xobjects
[$id];
24184 // set default values
24191 // check page for no-write regions and adapt page margins if necessary
24192 $this->checkPageRegions($h, $x, $y);
24193 $ow = $this->xobjects
[$id]['w'];
24194 $oh = $this->xobjects
[$id]['h'];
24195 // calculate template width and height on document
24196 if (($w <= 0) AND ($h <= 0)) {
24199 } elseif ($w <= 0) {
24200 $w = $h * $ow / $oh;
24201 } elseif ($h <= 0) {
24202 $h = $w * $oh / $ow;
24204 // fit the template on available space
24205 $this->fitBlock($w, $h, $x, $y, $fitonpage);
24206 // set page alignment
24210 if ($palign == 'L') {
24211 $xt = $this->lMargin
;
24212 } elseif ($palign == 'C') {
24213 $xt = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
24214 } elseif ($palign == 'R') {
24215 $xt = $this->w
- $this->rMargin
- $w;
24221 if ($palign == 'L') {
24222 $xt = $this->lMargin
;
24223 } elseif ($palign == 'C') {
24224 $xt = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
24225 } elseif ($palign == 'R') {
24226 $xt = $this->w
- $this->rMargin
- $w;
24232 // print XObject Template + Transformation matrix
24233 $this->StartTransform();
24234 // translate and scale
24235 $sx = ($w / $this->xobjects
[$id]['w']);
24236 $sy = ($h / $this->xobjects
[$id]['h']);
24242 $tm[4] = $xt * $this->k
;
24243 $tm[5] = ($this->h
- $h - $y) * $this->k
;
24244 $this->Transform($tm);
24246 $this->_out('/'.$id.' Do');
24247 $this->StopTransform();
24249 if (!empty($this->xobjects
[$id]['annotations'])) {
24250 foreach ($this->xobjects
[$id]['annotations'] as $annot) {
24251 // transform original coordinates
24252 $coordlt = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, ($annot['x'] * $this->k
), (-$annot['y'] * $this->k
)));
24253 $ax = ($coordlt[4] / $this->k
);
24254 $ay = ($this->h
- $h - ($coordlt[5] / $this->k
));
24255 $coordrb = $this->getTransformationMatrixProduct($tm, array(1, 0, 0, 1, (($annot['x'] +
$annot['w']) * $this->k
), ((-$annot['y'] - $annot['h']) * $this->k
)));
24256 $aw = ($coordrb[4] / $this->k
) - $ax;
24257 $ah = ($this->h
- $h - ($coordrb[5] / $this->k
)) - $ay;
24258 $this->Annotation($ax, $ay, $aw, $ah, $annot['text'], $annot['opt'], $annot['spaces']);
24261 // set pointer to align the next text/objects
24269 $this->y
= $y +
round($h/2);
24279 $this->SetY($rb_y);
24289 * Set the percentage of character stretching.
24290 * @param $perc (int) percentage of stretching (100 = no stretching)
24291 * @author Nicola Asuni
24293 * @since 5.9.000 (2010-09-29)
24295 public function setFontStretching($perc=100) {
24296 $this->font_stretching
= $perc;
24300 * Get the percentage of character stretching.
24301 * @return float stretching value
24302 * @author Nicola Asuni
24304 * @since 5.9.000 (2010-09-29)
24306 public function getFontStretching() {
24307 return $this->font_stretching
;
24311 * Set the amount to increase or decrease the space between characters in a text.
24312 * @param $spacing (float) amount to increase or decrease the space between characters in a text (0 = default spacing)
24313 * @author Nicola Asuni
24315 * @since 5.9.000 (2010-09-29)
24317 public function setFontSpacing($spacing=0) {
24318 $this->font_spacing
= $spacing;
24322 * Get the amount to increase or decrease the space between characters in a text.
24323 * @return int font spacing (tracking/kerning) value
24324 * @author Nicola Asuni
24326 * @since 5.9.000 (2010-09-29)
24328 public function getFontSpacing() {
24329 return $this->font_spacing
;
24333 * Return an array of no-write page regions
24334 * @return array of no-write page regions
24335 * @author Nicola Asuni
24337 * @since 5.9.003 (2010-10-13)
24338 * @see setPageRegions(), addPageRegion()
24340 public function getPageRegions() {
24341 return $this->page_regions
;
24345 * Set no-write regions on page.
24346 * 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.
24347 * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
24348 * You can set multiple regions for the same page.
24349 * @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.
24350 * @author Nicola Asuni
24352 * @since 5.9.003 (2010-10-13)
24353 * @see addPageRegion(), getPageRegions()
24355 public function setPageRegions($regions=array()) {
24356 // empty current regions array
24357 $this->page_regions
= array();
24359 foreach ($regions as $data) {
24360 $this->addPageRegion($data);
24365 * Add a single no-write region on selected page.
24366 * 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.
24367 * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
24368 * You can set multiple regions for the same page.
24369 * @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).
24370 * @author Nicola Asuni
24372 * @since 5.9.003 (2010-10-13)
24373 * @see setPageRegions(), getPageRegions()
24375 public function addPageRegion($region) {
24376 if (!isset($region['page']) OR empty($region['page'])) {
24377 $region['page'] = $this->page
;
24379 if (isset($region['xt']) AND isset($region['xb']) AND ($region['xt'] > 0) AND ($region['xb'] > 0)
24380 AND isset($region['yt']) AND isset($region['yb']) AND ($region['yt'] >= 0) AND ($region['yt'] < $region['yb'])
24381 AND isset($region['side']) AND (($region['side'] == 'L') OR ($region['side'] == 'R'))) {
24382 $this->page_regions
[] = $region;
24387 * Remove a single no-write region.
24388 * @param $key (int) region key
24389 * @author Nicola Asuni
24391 * @since 5.9.003 (2010-10-13)
24392 * @see setPageRegions(), getPageRegions()
24394 public function removePageRegion($key) {
24395 if (isset($this->page_regions
[$key])) {
24396 unset($this->page_regions
[$key]);
24401 * Check page for no-write regions and adapt current coordinates and page margins if necessary.
24402 * 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.
24403 * A region is always aligned on the left or right side of the page ad is defined using a vertical segment.
24404 * @param $h (float) height of the text/image/object to print in user units
24405 * @param $x (float) current X coordinate in user units
24406 * @param $y (float) current Y coordinate in user units
24407 * @author Nicola Asuni
24409 * @since 5.9.003 (2010-10-13)
24411 protected function checkPageRegions($h, &$x, &$y) {
24412 // set default values
24419 if (empty($this->page_regions
)) {
24420 // no page regions defined
24424 $h = ($this->FontSize
* $this->cell_height_ratio
) +
$this->cell_padding
['T'] +
$this->cell_padding
['B'];
24426 if ($this->AutoPageBreak
AND (!$this->InFooter
) AND (($y +
$h) > $this->PageBreakTrigger
)) {
24427 // the content will be printed on a new page
24430 if ($this->num_columns
> 1) {
24432 $this->lMargin
= $this->columns
[$this->current_column
]['x'] - $this->columns
[$this->current_column
]['w'];
24434 $this->rMargin
= $this->w
- $this->columns
[$this->current_column
]['x'] - $this->columns
[$this->current_column
]['w'];
24438 $this->lMargin
= $this->original_lMargin
;
24440 $this->rMargin
= $this->original_rMargin
;
24443 // adjust coordinates and page margins
24444 foreach ($this->page_regions
as $regid => $regdata) {
24445 if ($regdata['page'] == $this->page
) {
24446 // check region boundaries
24447 if (($y > ($regdata['yt'] - $h)) AND ($y <= $regdata['yb'])) {
24448 // Y is inside the region
24449 $minv = ($regdata['xb'] - $regdata['xt']) / ($regdata['yb'] - $regdata['yt']); // inverse of angular coefficient
24450 $yt = max($y, $regdata['yt']);
24451 $yb = min(($yt +
$h), $regdata['yb']);
24452 $xt = (($yt - $regdata['yt']) * $minv) +
$regdata['xt'];
24453 $xb = (($yb - $regdata['yt']) * $minv) +
$regdata['xt'];
24454 if ($regdata['side'] == 'L') { // left side
24455 $new_margin = max($xt, $xb);
24456 if ($this->lMargin
< $new_margin) {
24458 // adjust left page margin
24459 $this->lMargin
= $new_margin;
24461 if ($x < $new_margin) {
24462 // adjust x position
24464 if ($new_margin > ($this->w
- $this->rMargin
)) {
24465 // adjust y position
24466 $y = $regdata['yb'] - $h;
24470 } elseif ($regdata['side'] == 'R') { // right side
24471 $new_margin = min($xt, $xb);
24472 if (($this->w
- $this->rMargin
) > $new_margin) {
24474 // adjust right page margin
24475 $this->rMargin
= ($this->w
- $new_margin);
24477 if ($x > $new_margin) {
24478 // adjust x position
24480 if ($new_margin > $this->lMargin
) {
24481 // adjust y position
24482 $y = $regdata['yb'] - $h;
24492 // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
24494 // -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
24497 * Embedd a Scalable Vector Graphics (SVG) image.
24498 * NOTE: SVG standard is not yet fully implemented, use the setRasterizeVectorImages() method to enable/disable rasterization of vector images using ImageMagick library.
24499 * @param $file (string) Name of the SVG file or a '@' character followed by the SVG data string.
24500 * @param $x (float) Abscissa of the upper-left corner.
24501 * @param $y (float) Ordinate of the upper-left corner.
24502 * @param $w (float) Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
24503 * @param $h (float) Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
24504 * @param $link (mixed) URL or identifier returned by AddLink().
24505 * @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.
24506 * @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>
24507 * @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)))
24508 * @param $fitonpage (boolean) if true the image is resized to not exceed page dimensions.
24509 * @author Nicola Asuni
24510 * @since 5.0.000 (2010-05-02)
24513 public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) {
24514 if ($this->rasterize_vector_images
AND ($w > 0) AND ($h > 0)) {
24515 // convert SVG to raster image using GD or ImageMagick libraries
24516 return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
24518 if ($file{0} === '@') { // image from string
24519 $this->svgdir
= '';
24520 $svgdata = substr($file, 1);
24521 } else { // SVG file
24522 $this->svgdir
= dirname($file);
24523 $svgdata = file_get_contents($file);
24525 if ($svgdata === false) {
24526 $this->Error('SVG file not found: '.$file);
24534 // check page for no-write regions and adapt page margins if necessary
24535 $this->checkPageRegions($h, $x, $y);
24541 $aspect_ratio_align = 'xMidYMid';
24542 $aspect_ratio_ms = 'meet';
24544 // get original image width and height
24545 preg_match('/<svg([^\>]*)>/si', $svgdata, $regs);
24546 if (isset($regs[1]) AND !empty($regs[1])) {
24548 if (preg_match('/[\s]+x[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
24549 $ox = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit
, false);
24552 if (preg_match('/[\s]+y[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
24553 $oy = $this->getHTMLUnitToUnits($tmp[1], 0, $this->svgunit
, false);
24556 if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
24557 $ow = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
24560 if (preg_match('/[\s]+height[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
24561 $oh = $this->getHTMLUnitToUnits($tmp[1], 1, $this->svgunit
, false);
24564 $view_box = array();
24565 if (preg_match('/[\s]+viewBox[\s]*=[\s]*"[\s]*([0-9\.\-]+)[\s]+([0-9\.\-]+)[\s]+([0-9\.]+)[\s]+([0-9\.]+)[\s]*"/si', $regs[1], $tmp)) {
24566 if (count($tmp) == 5) {
24568 foreach ($tmp as $key => $val) {
24569 $view_box[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit
, false);
24571 $ox = $view_box[0];
24572 $oy = $view_box[1];
24574 // get aspect ratio
24576 if (preg_match('/[\s]+preserveAspectRatio[\s]*=[\s]*"([^"]*)"/si', $regs[1], $tmp)) {
24577 $aspect_ratio = preg_split('/[\s]+/si', $tmp[1]);
24578 switch (count($aspect_ratio)) {
24580 $aspect_ratio_align = $aspect_ratio[1];
24581 $aspect_ratio_ms = $aspect_ratio[2];
24585 $aspect_ratio_align = $aspect_ratio[0];
24586 $aspect_ratio_ms = $aspect_ratio[1];
24590 $aspect_ratio_align = $aspect_ratio[0];
24591 $aspect_ratio_ms = 'meet';
24598 // calculate image width and height on document
24599 if (($w <= 0) AND ($h <= 0)) {
24600 // convert image size to document unit
24603 } elseif ($w <= 0) {
24604 $w = $h * $ow / $oh;
24605 } elseif ($h <= 0) {
24606 $h = $w * $oh / $ow;
24608 // fit the image on available space
24609 $this->fitBlock($w, $h, $x, $y, $fitonpage);
24610 if ($this->rasterize_vector_images
) {
24611 // convert SVG to raster image using GD or ImageMagick libraries
24612 return $this->Image($file, $x, $y, $w, $h, 'SVG', $link, $align, true, 300, $palign, false, false, $border, false, false, false);
24615 $this->img_rb_y
= $y +
$h;
24618 if ($palign == 'L') {
24619 $ximg = $this->lMargin
;
24620 } elseif ($palign == 'C') {
24621 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
24622 } elseif ($palign == 'R') {
24623 $ximg = $this->w
- $this->rMargin
- $w;
24627 $this->img_rb_x
= $ximg;
24629 if ($palign == 'L') {
24630 $ximg = $this->lMargin
;
24631 } elseif ($palign == 'C') {
24632 $ximg = ($this->w +
$this->lMargin
- $this->rMargin
- $w) / 2;
24633 } elseif ($palign == 'R') {
24634 $ximg = $this->w
- $this->rMargin
- $w;
24638 $this->img_rb_x
= $ximg +
$w;
24640 // store current graphic vars
24641 $gvars = $this->getGraphicVars();
24642 // store SVG position and scale factors
24643 $svgoffset_x = ($ximg - $ox) * $this->k
;
24644 $svgoffset_y = -($y - $oy) * $this->k
;
24645 if (isset($view_box[2]) AND ($view_box[2] > 0) AND ($view_box[3] > 0)) {
24646 $ow = $view_box[2];
24647 $oh = $view_box[3];
24656 $svgscale_x = $w / $ow;
24657 $svgscale_y = $h / $oh;
24658 // scaling and alignment
24659 if ($aspect_ratio_align != 'none') {
24660 // store current scaling values
24661 $svgscale_old_x = $svgscale_x;
24662 $svgscale_old_y = $svgscale_y;
24663 // force uniform scaling
24664 if ($aspect_ratio_ms == 'slice') {
24665 // the entire viewport is covered by the viewBox
24666 if ($svgscale_x > $svgscale_y) {
24667 $svgscale_y = $svgscale_x;
24668 } elseif ($svgscale_x < $svgscale_y) {
24669 $svgscale_x = $svgscale_y;
24672 // the entire viewBox is visible within the viewport
24673 if ($svgscale_x < $svgscale_y) {
24674 $svgscale_y = $svgscale_x;
24675 } elseif ($svgscale_x > $svgscale_y) {
24676 $svgscale_x = $svgscale_y;
24679 // correct X alignment
24680 switch (substr($aspect_ratio_align, 1, 3)) {
24686 $svgoffset_x +
= (($w * $this->k
) - ($ow * $this->k
* $svgscale_x));
24691 $svgoffset_x +
= ((($w * $this->k
) - ($ow * $this->k
* $svgscale_x)) / 2);
24695 // correct Y alignment
24696 switch (substr($aspect_ratio_align, 5)) {
24702 $svgoffset_y -= (($h * $this->k
) - ($oh * $this->k
* $svgscale_y));
24707 $svgoffset_y -= ((($h * $this->k
) - ($oh * $this->k
* $svgscale_y)) / 2);
24712 // store current page break mode
24713 $page_break_mode = $this->AutoPageBreak
;
24714 $page_break_margin = $this->getBreakMargin();
24715 $cell_padding = $this->cell_padding
;
24716 $this->SetCellPadding(0);
24717 $this->SetAutoPageBreak(false);
24718 // save the current graphic state
24719 $this->_out('q'.$this->epsmarker
);
24720 // set initial clipping mask
24721 $this->Rect($x, $y, $w, $h, 'CNZ', array(), array());
24722 // scale and translate
24723 $e = $ox * $this->k
* (1 - $svgscale_x);
24724 $f = ($this->h
- $oy) * $this->k
* (1 - $svgscale_y);
24725 $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $svgscale_x, 0, 0, $svgscale_y, $e +
$svgoffset_x, $f +
$svgoffset_y));
24726 // creates a new XML parser to be used by the other XML functions
24727 $this->parser
= xml_parser_create('UTF-8');
24728 // the following function allows to use parser inside object
24729 xml_set_object($this->parser
, $this);
24730 // disable case-folding for this XML parser
24731 xml_parser_set_option($this->parser
, XML_OPTION_CASE_FOLDING
, 0);
24732 // sets the element handler functions for the XML parser
24733 xml_set_element_handler($this->parser
, 'startSVGElementHandler', 'endSVGElementHandler');
24734 // sets the character data handler function for the XML parser
24735 xml_set_character_data_handler($this->parser
, 'segSVGContentHandler');
24736 // start parsing an XML document
24737 if(!xml_parse($this->parser
, $svgdata)) {
24738 $error_message = sprintf("SVG Error: %s at line %d", xml_error_string(xml_get_error_code($this->parser
)), xml_get_current_line_number($this->parser
));
24739 $this->Error($error_message);
24741 // free this XML parser
24742 xml_parser_free($this->parser
);
24743 // restore previous graphic state
24744 $this->_out($this->epsmarker
.'Q');
24745 // restore graphic vars
24746 $this->setGraphicVars($gvars);
24747 $this->lasth
= $gvars['lasth'];
24748 if (!empty($border)) {
24756 $this->Cell($w, $h, '', $border, 0, '', 0, '', 0, true);
24761 $this->Link($ximg, $y, $w, $h, $link, 0);
24763 // set pointer to align the next text/objects
24767 $this->x
= $this->img_rb_x
;
24771 $this->y
= $y +
round($h/2);
24772 $this->x
= $this->img_rb_x
;
24776 $this->y
= $this->img_rb_y
;
24777 $this->x
= $this->img_rb_x
;
24781 $this->SetY($this->img_rb_y
);
24785 // restore pointer to starting position
24786 $this->x
= $gvars['x'];
24787 $this->y
= $gvars['y'];
24788 $this->page
= $gvars['page'];
24789 $this->current_column
= $gvars['current_column'];
24790 $this->tMargin
= $gvars['tMargin'];
24791 $this->bMargin
= $gvars['bMargin'];
24792 $this->w
= $gvars['w'];
24793 $this->h
= $gvars['h'];
24794 $this->wPt
= $gvars['wPt'];
24795 $this->hPt
= $gvars['hPt'];
24796 $this->fwPt
= $gvars['fwPt'];
24797 $this->fhPt
= $gvars['fhPt'];
24801 $this->endlinex
= $this->img_rb_x
;
24802 // restore page break
24803 $this->SetAutoPageBreak($page_break_mode, $page_break_margin);
24804 $this->cell_padding
= $cell_padding;
24808 * Get the tranformation matrix from SVG transform attribute
24809 * @param $attribute (string) transformation
24810 * @return array of transformations
24811 * @author Nicola Asuni
24812 * @since 5.0.000 (2010-05-02)
24815 protected function getSVGTransformMatrix($attribute) {
24817 $tm = array(1, 0, 0, 1, 0, 0);
24818 $transform = array();
24819 if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER
) > 0) {
24820 foreach ($transform as $key => $data) {
24821 if (!empty($data[2])) {
24829 switch ($data[1]) {
24831 if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
24841 case 'translate': {
24842 if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
24845 } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
24851 if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
24854 } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
24861 if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
24862 $ang = deg2rad($regs[1]);
24869 $e = ($x * (1 - $a)) - ($y * $c);
24870 $f = ($y * (1 - $d)) - ($x * $b);
24871 } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
24872 $ang = deg2rad($regs[1]);
24883 if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
24884 $c = tan(deg2rad($regs[1]));
24889 if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
24890 $b = tan(deg2rad($regs[1]));
24895 $tm = $this->getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
24903 * Get the product of two SVG tranformation matrices
24904 * @param $ta (array) first SVG tranformation matrix
24905 * @param $tb (array) second SVG tranformation matrix
24906 * @return transformation array
24907 * @author Nicola Asuni
24908 * @since 5.0.000 (2010-05-02)
24911 protected function getTransformationMatrixProduct($ta, $tb) {
24913 $tm[0] = ($ta[0] * $tb[0]) +
($ta[2] * $tb[1]);
24914 $tm[1] = ($ta[1] * $tb[0]) +
($ta[3] * $tb[1]);
24915 $tm[2] = ($ta[0] * $tb[2]) +
($ta[2] * $tb[3]);
24916 $tm[3] = ($ta[1] * $tb[2]) +
($ta[3] * $tb[3]);
24917 $tm[4] = ($ta[0] * $tb[4]) +
($ta[2] * $tb[5]) +
$ta[4];
24918 $tm[5] = ($ta[1] * $tb[4]) +
($ta[3] * $tb[5]) +
$ta[5];
24923 * Convert SVG transformation matrix to PDF.
24924 * @param $tm (array) original SVG transformation matrix
24925 * @return array transformation matrix
24927 * @since 5.0.000 (2010-05-02)
24929 protected function convertSVGtMatrix($tm) {
24934 $e = $this->getHTMLUnitToUnits($tm[4], 1, $this->svgunit
, false) * $this->k
;
24935 $f = -$this->getHTMLUnitToUnits($tm[5], 1, $this->svgunit
, false) * $this->k
;
24937 $y = $this->h
* $this->k
;
24938 $e = ($x * (1 - $a)) - ($y * $c) +
$e;
24939 $f = ($y * (1 - $d)) - ($x * $b) +
$f;
24940 return array($a, $b, $c, $d, $e, $f);
24944 * Apply SVG graphic transformation matrix.
24945 * @param $tm (array) original SVG transformation matrix
24947 * @since 5.0.000 (2010-05-02)
24949 protected function SVGTransform($tm) {
24950 $this->Transform($this->convertSVGtMatrix($tm));
24954 * Apply the requested SVG styles (*** TO BE COMPLETED ***)
24955 * @param $svgstyle (array) array of SVG styles to apply
24956 * @param $prevsvgstyle (array) array of previous SVG style
24957 * @param $x (int) X origin of the bounding box
24958 * @param $y (int) Y origin of the bounding box
24959 * @param $w (int) width of the bounding box
24960 * @param $h (int) height of the bounding box
24961 * @param $clip_function (string) clip function
24962 * @param $clip_params (array) array of parameters for clipping function
24963 * @return object style
24964 * @author Nicola Asuni
24965 * @since 5.0.000 (2010-05-02)
24968 protected function setSVGStyles($svgstyle, $prevsvgstyle, $x=0, $y=0, $w=1, $h=1, $clip_function='', $clip_params=array()) {
24970 if(!isset($svgstyle['opacity'])) {
24975 if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['clip-path'], $regs)) {
24976 $clip_path = $this->svgclippaths
[$regs[1]];
24977 foreach ($clip_path as $cp) {
24978 $this->startSVGElementHandler('clip-path', $cp['name'], $cp['attribs'], $cp['tm']);
24982 if ($svgstyle['opacity'] != 1) {
24983 $this->SetAlpha($svgstyle['opacity']);
24986 $fill_color = $this->convertHTMLColorToDec($svgstyle['color']);
24987 $this->SetFillColorArray($fill_color);
24989 $text_color = $this->convertHTMLColorToDec($svgstyle['text-color']);
24990 $this->SetTextColorArray($text_color);
24992 if (preg_match('/rect\(([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)[\s]*([a-z0-9\-\.]*)\)/si', $svgstyle['clip'], $regs)) {
24993 $top = (isset($regs[1])?
$this->getHTMLUnitToUnits($regs[1], 0, $this->svgunit
, false):0);
24994 $right = (isset($regs[2])?
$this->getHTMLUnitToUnits($regs[2], 0, $this->svgunit
, false):0);
24995 $bottom = (isset($regs[3])?
$this->getHTMLUnitToUnits($regs[3], 0, $this->svgunit
, false):0);
24996 $left = (isset($regs[4])?
$this->getHTMLUnitToUnits($regs[4], 0, $this->svgunit
, false):0);
24999 $cw = $w - $left - $right;
25000 $ch = $h - $top - $bottom;
25001 if ($svgstyle['clip-rule'] == 'evenodd') {
25002 $clip_rule = 'CNZ';
25004 $clip_rule = 'CEO';
25006 $this->Rect($cx, $cy, $cw, $ch, $clip_rule, array(), array());
25010 if (preg_match('/url\([\s]*\#([^\)]*)\)/si', $svgstyle['fill'], $regs)) {
25012 $gradient = $this->svggradients
[$regs[1]];
25013 if (isset($gradient['xref'])) {
25014 // reference to another gradient definition
25015 $newgradient = $this->svggradients
[$gradient['xref']];
25016 $newgradient['coords'] = $gradient['coords'];
25017 $newgradient['mode'] = $gradient['mode'];
25018 $newgradient['gradientUnits'] = $gradient['gradientUnits'];
25019 if (isset($gradient['gradientTransform'])) {
25020 $newgradient['gradientTransform'] = $gradient['gradientTransform'];
25022 $gradient = $newgradient;
25024 //save current Graphic State
25026 //set clipping area
25027 if (!empty($clip_function) AND method_exists($this, $clip_function)) {
25028 $bbox = call_user_func_array(array($this, $clip_function), $clip_params);
25029 if (is_array($bbox) AND (count($bbox) == 4)) {
25030 list($x, $y, $w, $h) = $bbox;
25033 if ($gradient['mode'] == 'measure') {
25034 if (isset($gradient['gradientTransform']) AND !empty($gradient['gradientTransform'])) {
25035 $gtm = $gradient['gradientTransform'];
25036 // apply transformation matrix
25037 $xa = ($gtm[0] * $gradient['coords'][0]) +
($gtm[2] * $gradient['coords'][1]) +
$gtm[4];
25038 $ya = ($gtm[1] * $gradient['coords'][0]) +
($gtm[3] * $gradient['coords'][1]) +
$gtm[5];
25039 $xb = ($gtm[0] * $gradient['coords'][2]) +
($gtm[2] * $gradient['coords'][3]) +
$gtm[4];
25040 $yb = ($gtm[1] * $gradient['coords'][2]) +
($gtm[3] * $gradient['coords'][3]) +
$gtm[5];
25041 if (isset($gradient['coords'][4])) {
25042 $gradient['coords'][4] = sqrt(pow(($gtm[0] * $gradient['coords'][4]), 2) +
pow(($gtm[1] * $gradient['coords'][4]), 2));
25044 $gradient['coords'][0] = $xa;
25045 $gradient['coords'][1] = $ya;
25046 $gradient['coords'][2] = $xb;
25047 $gradient['coords'][3] = $yb;
25049 // convert SVG coordinates to user units
25050 $gradient['coords'][0] = $this->getHTMLUnitToUnits($gradient['coords'][0], 0, $this->svgunit
, false);
25051 $gradient['coords'][1] = $this->getHTMLUnitToUnits($gradient['coords'][1], 0, $this->svgunit
, false);
25052 $gradient['coords'][2] = $this->getHTMLUnitToUnits($gradient['coords'][2], 0, $this->svgunit
, false);
25053 $gradient['coords'][3] = $this->getHTMLUnitToUnits($gradient['coords'][3], 0, $this->svgunit
, false);
25054 if (isset($gradient['coords'][4])) {
25055 $gradient['coords'][4] = $this->getHTMLUnitToUnits($gradient['coords'][4], 0, $this->svgunit
, false);
25058 if ($gradient['gradientUnits'] == 'objectBoundingBox') {
25059 // convert to SVG coordinate system
25060 $gradient['coords'][0] +
= $x;
25061 $gradient['coords'][1] +
= $y;
25062 $gradient['coords'][2] +
= $x;
25063 $gradient['coords'][3] +
= $y;
25071 // calculate percentages
25072 $gradient['coords'][0] = ($gradient['coords'][0] - $x) / $w;
25073 $gradient['coords'][1] = ($gradient['coords'][1] - $y) / $h;
25074 $gradient['coords'][2] = ($gradient['coords'][2] - $x) / $w;
25075 $gradient['coords'][3] = ($gradient['coords'][3] - $y) / $h;
25076 if (isset($gradient['coords'][4])) {
25077 $gradient['coords'][4] /= $w;
25079 } elseif ($gradient['mode'] == 'percentage') {
25080 foreach($gradient['coords'] as $key => $val) {
25081 $gradient['coords'][$key] = (intval($val) / 100);
25085 foreach($gradient['coords'] as $key => $val) {
25087 $gradient['coords'][$key] = 0;
25088 } elseif ($val > 1) {
25089 $gradient['coords'][$key] = 1;
25092 if (($gradient['type'] == 2) AND ($gradient['coords'][0] == $gradient['coords'][2]) AND ($gradient['coords'][1] == $gradient['coords'][3])) {
25093 // single color (no shading)
25094 $gradient['coords'][0] = 1;
25095 $gradient['coords'][1] = 0;
25096 $gradient['coords'][2] = 0.999;
25097 $gradient['coords'][3] = 0;
25099 // swap Y coordinates
25100 $tmp = $gradient['coords'][1];
25101 $gradient['coords'][1] = $gradient['coords'][3];
25102 $gradient['coords'][3] = $tmp;
25103 // set transformation map for gradient
25104 if ($gradient['type'] == 3) {
25105 // gradient is always circular
25106 $cy = $this->h
- $y - ($gradient['coords'][1] * ($w +
$h));
25107 $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k
, $w*$this->k
, $x*$this->k
, $cy*$this->k
));
25109 $this->_out(sprintf('%.3F 0 0 %.3F %.3F %.3F cm', $w*$this->k
, $h*$this->k
, $x*$this->k
, ($this->h
-($y+
$h))*$this->k
));
25111 if (count($gradient['stops']) > 1) {
25112 $this->Gradient($gradient['type'], $gradient['coords'], $gradient['stops'], array(), false);
25114 } elseif ($svgstyle['fill'] != 'none') {
25115 $fill_color = $this->convertHTMLColorToDec($svgstyle['fill']);
25116 if ($svgstyle['fill-opacity'] != 1) {
25117 $this->SetAlpha($svgstyle['fill-opacity']);
25119 $this->SetFillColorArray($fill_color);
25120 if ($svgstyle['fill-rule'] == 'evenodd') {
25127 if ($svgstyle['stroke'] != 'none') {
25128 $stroke_style = array(
25129 'color' => $this->convertHTMLColorToDec($svgstyle['stroke']),
25130 'width' => $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit
, false),
25131 'cap' => $svgstyle['stroke-linecap'],
25132 'join' => $svgstyle['stroke-linejoin']
25134 if (isset($svgstyle['stroke-dasharray']) AND !empty($svgstyle['stroke-dasharray']) AND ($svgstyle['stroke-dasharray'] != 'none')) {
25135 $stroke_style['dash'] = $svgstyle['stroke-dasharray'];
25137 $this->SetLineStyle($stroke_style);
25142 if (!empty($svgstyle['font'])) {
25143 if (preg_match('/font-family[\s]*:[\s]*([^\;\"]*)/si', $svgstyle['font'], $regs)) {
25144 $font_family = $this->getFontFamilyName($regs[1]);
25146 $font_family = $svgstyle['font-family'];
25148 if (preg_match('/font-size[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
25149 $font_size = trim($regs[1]);
25151 $font_size = $svgstyle['font-size'];
25153 if (preg_match('/font-style[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
25154 $font_style = trim($regs[1]);
25156 $font_style = $svgstyle['font-style'];
25158 if (preg_match('/font-weight[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
25159 $font_weight = trim($regs[1]);
25161 $font_weight = $svgstyle['font-weight'];
25163 if (preg_match('/font-stretch[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
25164 $font_stretch = trim($regs[1]);
25166 $font_stretch = $svgstyle['font-stretch'];
25168 if (preg_match('/letter-spacing[\s]*:[\s]*([^\s\;\"]*)/si', $svgstyle['font'], $regs)) {
25169 $font_spacing = trim($regs[1]);
25171 $font_spacing = $svgstyle['letter-spacing'];
25174 $font_family = $this->getFontFamilyName($svgstyle['font-family']);
25175 $font_size = $svgstyle['font-size'];
25176 $font_style = $svgstyle['font-style'];
25177 $font_weight = $svgstyle['font-weight'];
25178 $font_stretch = $svgstyle['font-stretch'];
25179 $font_spacing = $svgstyle['letter-spacing'];
25181 $font_size = $this->getHTMLUnitToUnits($font_size, $prevsvgstyle['font-size'], $this->svgunit
, false) * $this->k
;
25182 $font_stretch = $this->getCSSFontStretching($font_stretch, $svgstyle['font-stretch']);
25183 $font_spacing = $this->getCSSFontSpacing($font_spacing, $svgstyle['letter-spacing']);
25184 switch ($font_style) {
25199 switch ($font_weight) {
25202 $font_style .= 'B';
25206 switch ($svgstyle['text-decoration']) {
25207 case 'underline': {
25208 $font_style .= 'U';
25212 $font_style .= 'O';
25215 case 'line-through': {
25216 $font_style .= 'D';
25224 $this->SetFont($font_family, $font_style, $font_size);
25225 $this->setFontStretching($font_stretch);
25226 $this->setFontSpacing($font_spacing);
25231 * Draws an SVG path
25232 * @param $d (string) attribute d of the path SVG element
25233 * @param $style (string) Style of rendering. Possible values are:
25235 * <li>D or empty string: Draw (default).</li>
25236 * <li>F: Fill.</li>
25237 * <li>F*: Fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
25238 * <li>DF or FD: Draw and fill.</li>
25239 * <li>DF* or FD*: Draw and fill using the even-odd rule to determine which regions lie inside the clipping path.</li>
25240 * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li>
25241 * <li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li>
25243 * @return array of container box measures (x, y, w, h)
25244 * @author Nicola Asuni
25245 * @since 5.0.000 (2010-05-02)
25248 protected function SVGPath($d, $style='') {
25249 // set fill/stroke style
25250 $op = $this->getPathPaintOperator($style, '');
25255 $d = preg_replace('/([0-9ACHLMQSTVZ])([\-\+])/si', '\\1 \\2', $d);
25256 preg_match_all('/([ACHLMQSTVZ])[\s]*([^ACHLMQSTVZ\"]*)/si', $d, $paths, PREG_SET_ORDER
);
25263 $xmin = 2147483647;
25265 $ymin = 2147483647;
25268 // draw curve pieces
25269 foreach ($paths as $key => $val) {
25271 $cmd = trim($val[1]);
25272 if (strtolower($cmd) == $cmd) {
25273 // use relative coordinated instead of absolute
25283 if (isset($val[2])) {
25284 // get curve parameters
25285 $rawparams = preg_split('/([\,\s]+)/si', trim($val[2]));
25287 foreach ($rawparams as $ck => $cp) {
25288 $params[$ck] = $this->getHTMLUnitToUnits($cp, 0, $this->svgunit
, false);
25291 switch (strtoupper($cmd)) {
25292 case 'M': { // moveto
25293 foreach ($params as $ck => $cp) {
25294 if (($ck %
2) == 0) {
25295 $x = $cp +
$xoffset;
25297 $y = $cp +
$yoffset;
25299 $this->_outPoint($x, $y);
25301 $this->_outLine($x, $y);
25303 $xmin = min($xmin, $x);
25304 $ymin = min($ymin, $y);
25305 $xmax = max($xmax, $x);
25306 $ymax = max($ymax, $y);
25315 case 'L': { // lineto
25316 foreach ($params as $ck => $cp) {
25317 if (($ck %
2) == 0) {
25318 $x = $cp +
$xoffset;
25320 $y = $cp +
$yoffset;
25321 $this->_outLine($x, $y);
25322 $xmin = min($xmin, $x);
25323 $ymin = min($ymin, $y);
25324 $xmax = max($xmax, $x);
25325 $ymax = max($ymax, $y);
25334 case 'H': { // horizontal lineto
25335 foreach ($params as $ck => $cp) {
25336 $x = $cp +
$xoffset;
25337 $this->_outLine($x, $y);
25338 $xmin = min($xmin, $x);
25339 $xmax = max($xmax, $x);
25346 case 'V': { // vertical lineto
25347 foreach ($params as $ck => $cp) {
25348 $y = $cp +
$yoffset;
25349 $this->_outLine($x, $y);
25350 $ymin = min($ymin, $y);
25351 $ymax = max($ymax, $y);
25358 case 'C': { // curveto
25359 foreach ($params as $ck => $cp) {
25360 $params[$ck] = $cp;
25361 if ((($ck +
1) %
6) == 0) {
25362 $x1 = $params[($ck - 5)] +
$xoffset;
25363 $y1 = $params[($ck - 4)] +
$yoffset;
25364 $x2 = $params[($ck - 3)] +
$xoffset;
25365 $y2 = $params[($ck - 2)] +
$yoffset;
25366 $x = $params[($ck - 1)] +
$xoffset;
25367 $y = $params[($ck)] +
$yoffset;
25368 $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
25369 $xmin = min($xmin, $x, $x1, $x2);
25370 $ymin = min($ymin, $y, $y1, $y2);
25371 $xmax = max($xmax, $x, $x1, $x2);
25372 $ymax = max($ymax, $y, $y1, $y2);
25381 case 'S': { // shorthand/smooth curveto
25382 foreach ($params as $ck => $cp) {
25383 $params[$ck] = $cp;
25384 if ((($ck +
1) %
4) == 0) {
25385 if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'C') OR (strtoupper($paths[($key - 1)][1]) == 'S'))) {
25386 $x1 = (2 * $x) - $x2;
25387 $y1 = (2 * $y) - $y2;
25392 $x2 = $params[($ck - 3)] +
$xoffset;
25393 $y2 = $params[($ck - 2)] +
$yoffset;
25394 $x = $params[($ck - 1)] +
$xoffset;
25395 $y = $params[($ck)] +
$yoffset;
25396 $this->_outCurve($x1, $y1, $x2, $y2, $x, $y);
25397 $xmin = min($xmin, $x, $x1, $x2);
25398 $ymin = min($ymin, $y, $y1, $y2);
25399 $xmax = max($xmax, $x, $x1, $x2);
25400 $ymax = max($ymax, $y, $y1, $y2);
25409 case 'Q': { // quadratic Bézier curveto
25410 foreach ($params as $ck => $cp) {
25411 $params[$ck] = $cp;
25412 if ((($ck +
1) %
4) == 0) {
25413 // convert quadratic points to cubic points
25414 $x1 = $params[($ck - 3)] +
$xoffset;
25415 $y1 = $params[($ck - 2)] +
$yoffset;
25416 $xa = ($x +
(2 * $x1)) / 3;
25417 $ya = ($y +
(2 * $y1)) / 3;
25418 $x = $params[($ck - 1)] +
$xoffset;
25419 $y = $params[($ck)] +
$yoffset;
25420 $xb = ($x +
(2 * $x1)) / 3;
25421 $yb = ($y +
(2 * $y1)) / 3;
25422 $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
25423 $xmin = min($xmin, $x, $xa, $xb);
25424 $ymin = min($ymin, $y, $ya, $yb);
25425 $xmax = max($xmax, $x, $xa, $xb);
25426 $ymax = max($ymax, $y, $ya, $yb);
25435 case 'T': { // shorthand/smooth quadratic Bézier curveto
25436 foreach ($params as $ck => $cp) {
25437 $params[$ck] = $cp;
25438 if (($ck %
2) != 0) {
25439 if (($key > 0) AND ((strtoupper($paths[($key - 1)][1]) == 'Q') OR (strtoupper($paths[($key - 1)][1]) == 'T'))) {
25440 $x1 = (2 * $x) - $x1;
25441 $y1 = (2 * $y) - $y1;
25446 // convert quadratic points to cubic points
25447 $xa = ($x +
(2 * $x1)) / 3;
25448 $ya = ($y +
(2 * $y1)) / 3;
25449 $x = $params[($ck - 1)] +
$xoffset;
25450 $y = $params[($ck)] +
$yoffset;
25451 $xb = ($x +
(2 * $x1)) / 3;
25452 $yb = ($y +
(2 * $y1)) / 3;
25453 $this->_outCurve($xa, $ya, $xb, $yb, $x, $y);
25454 $xmin = min($xmin, $x, $xa, $xb);
25455 $ymin = min($ymin, $y, $ya, $yb);
25456 $xmax = max($xmax, $x, $xa, $xb);
25457 $ymax = max($ymax, $y, $ya, $yb);
25466 case 'A': { // elliptical arc
25467 foreach ($params as $ck => $cp) {
25468 $params[$ck] = $cp;
25469 if ((($ck +
1) %
7) == 0) {
25472 $rx = abs($params[($ck - 6)]);
25473 $ry = abs($params[($ck - 5)]);
25474 $ang = -$rawparams[($ck - 4)];
25475 $angle = deg2rad($ang);
25476 $fa = $rawparams[($ck - 3)]; // large-arc-flag
25477 $fs = $rawparams[($ck - 2)]; // sweep-flag
25478 $x = $params[($ck - 1)] +
$xoffset;
25479 $y = $params[$ck] +
$yoffset;
25480 $cos_ang = cos($angle);
25481 $sin_ang = sin($angle);
25482 $a = ($x0 - $x) / 2;
25483 $b = ($y0 - $y) / 2;
25484 $xa = ($a * $cos_ang) - ($b * $sin_ang);
25485 $ya = ($a * $sin_ang) +
($b * $cos_ang);
25490 $delta = ($xa2 / $rx2) +
($ya2 / $ry2);
25492 $rx *= sqrt($delta);
25493 $ry *= sqrt($delta);
25497 $numerator = (($rx2 * $ry2) - ($rx2 * $ya2) - ($ry2 * $xa2));
25498 if ($numerator < 0) {
25501 $root = sqrt($numerator / (($rx2 * $ya2) +
($ry2 * $xa2)));
25506 $cax = $root * (($rx * $ya) / $ry);
25507 $cay = -$root * (($ry * $xa) / $rx);
25508 // coordinates of ellipse center
25509 $cx = ($cax * $cos_ang) - ($cay * $sin_ang) +
(($x0 +
$x) / 2);
25510 $cy = ($cax * $sin_ang) +
($cay * $cos_ang) +
(($y0 +
$y) / 2);
25512 $angs = $this->getVectorsAngle(1, 0, (($xa - $cax) / $rx), (($cay - $ya) / $ry));
25513 $dang = $this->getVectorsAngle((($xa - $cax) / $rx), (($ya - $cay) / $ry), ((-$xa - $cax) / $rx), ((-$ya - $cay) / $ry));
25514 if (($fs == 0) AND ($dang > 0)) {
25515 $dang -= (2 * M_PI
);
25516 } elseif (($fs == 1) AND ($dang < 0)) {
25517 $dang +
= (2 * M_PI
);
25519 $angf = $angs - $dang;
25520 if ((($fs == 0) AND ($angs > $angf)) OR (($fs == 1) AND ($angs < $angf))) {
25526 $angs = round(rad2deg($angs), 6);
25527 $angf = round(rad2deg($angf), 6);
25528 // covent angles to positive values
25529 if (($angs < 0) AND ($angf < 0)) {
25534 if (($key==0) AND (isset($paths[($key +
1)][1])) AND (trim($paths[($key +
1)][1]) == 'z')) {
25537 list($axmin, $aymin, $axmax, $aymax) = $this->_outellipticalarc($cx, $cy, $rx, $ry, $ang, $angs, $angf, $pie, 2, false, ($fs == 0));
25538 $xmin = min($xmin, $x, $axmin);
25539 $ymin = min($ymin, $y, $aymin);
25540 $xmax = max($xmax, $x, $axmax);
25541 $ymax = max($ymax, $y, $aymax);
25559 return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
25563 * Returns the angle in radiants between two vectors
25564 * @param $x1 (int) X coordiante of first vector point
25565 * @param $y1 (int) Y coordiante of first vector point
25566 * @param $x2 (int) X coordiante of second vector point
25567 * @param $y2 (int) Y coordiante of second vector point
25568 * @author Nicola Asuni
25569 * @since 5.0.000 (2010-05-04)
25572 protected function getVectorsAngle($x1, $y1, $x2, $y2) {
25573 $dprod = ($x1 * $x2) +
($y1 * $y2);
25574 $dist1 = sqrt(($x1 * $x1) +
($y1 * $y1));
25575 $dist2 = sqrt(($x2 * $x2) +
($y2 * $y2));
25576 $angle = acos($dprod / ($dist1 * $dist2));
25577 if (is_nan($angle)) {
25580 if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
25587 * Sets the opening SVG element handler function for the XML parser. (*** TO BE COMPLETED ***)
25588 * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
25589 * @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.
25590 * @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.
25591 * @param $ctm (array) tranformation matrix for clipping mode (starting transformation matrix).
25592 * @author Nicola Asuni
25593 * @since 5.0.000 (2010-05-02)
25596 protected function startSVGElementHandler($parser, $name, $attribs, $ctm=array()) {
25597 // check if we are in clip mode
25598 if ($this->svgclipmode
) {
25599 $this->svgclippaths
[$this->svgclipid
][] = array('name' => $name, 'attribs' => $attribs, 'tm' => $this->svgcliptm
[$this->svgclipid
]);
25602 if ($this->svgdefsmode
AND !in_array($name, array('clipPath', 'linearGradient', 'radialGradient', 'stop'))) {
25603 if (!isset($attribs['id'])) {
25604 $attribs['id'] = 'DF_'.(count($this->svgdefs
) +
1);
25606 $this->svgdefs
[$attribs['id']] = array('name' => $name, 'attribs' => $attribs);
25610 if ($parser == 'clip-path') {
25611 // set clipping mode
25614 // get styling properties
25615 $prev_svgstyle = $this->svgstyles
[(count($this->svgstyles
) - 1)]; // previous style
25616 $svgstyle = $this->svgstyles
[0]; // set default style
25617 if (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
25618 // fix style for regular expression
25619 $attribs['style'] = ';'.$attribs['style'];
25621 foreach ($prev_svgstyle as $key => $val) {
25622 if (in_array($key, $this->svginheritprop
)) {
25623 // inherit previous value
25624 $svgstyle[$key] = $val;
25626 if (isset($attribs[$key]) AND !$this->empty_string($attribs[$key])) {
25627 // specific attribute settings
25628 if ($attribs[$key] == 'inherit') {
25629 $svgstyle[$key] = $val;
25631 $svgstyle[$key] = $attribs[$key];
25633 } elseif (isset($attribs['style']) AND !$this->empty_string($attribs['style'])) {
25634 // CSS style syntax
25635 $attrval = array();
25636 if (preg_match('/[;\"\s]{1}'.$key.'[\s]*:[\s]*([^;\"]*)/si', $attribs['style'], $attrval) AND isset($attrval[1])) {
25637 if ($attrval[1] == 'inherit') {
25638 $svgstyle[$key] = $val;
25640 $svgstyle[$key] = $attrval[1];
25645 // transformation matrix
25646 if (!empty($ctm)) {
25649 $tm = $this->svgstyles
[(count($this->svgstyles
) - 1)]['transfmatrix'];
25651 if (isset($attribs['transform']) AND !empty($attribs['transform'])) {
25652 $tm = $this->getTransformationMatrixProduct($tm, $this->getSVGTransformMatrix($attribs['transform']));
25654 $svgstyle['transfmatrix'] = $tm;
25655 $invisible = false;
25656 if (($svgstyle['visibility'] == 'hidden') OR ($svgstyle['visibility'] == 'collapse') OR ($svgstyle['display'] == 'none')) {
25657 // the current graphics element is invisible (nothing is painted)
25663 $this->svgdefsmode
= true;
25671 $this->svgclipmode
= true;
25672 if (!isset($attribs['id'])) {
25673 $attribs['id'] = 'CP_'.(count($this->svgcliptm
) +
1);
25675 $this->svgclipid
= $attribs['id'];
25676 $this->svgclippaths
[$this->svgclipid
] = array();
25677 $this->svgcliptm
[$this->svgclipid
] = $tm;
25681 // start of SVG object
25685 // group together related graphics elements
25686 array_push($this->svgstyles
, $svgstyle);
25687 $this->StartTransform();
25688 $this->setSVGStyles($svgstyle, $prev_svgstyle);
25691 case 'linearGradient': {
25692 if (!isset($attribs['id'])) {
25693 $attribs['id'] = 'GR_'.(count($this->svggradients
) +
1);
25695 $this->svggradientid
= $attribs['id'];
25696 $this->svggradients
[$this->svggradientid
] = array();
25697 $this->svggradients
[$this->svggradientid
]['type'] = 2;
25698 $this->svggradients
[$this->svggradientid
]['stops'] = array();
25699 if (isset($attribs['gradientUnits'])) {
25700 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = $attribs['gradientUnits'];
25702 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = 'objectBoundingBox';
25704 //$attribs['spreadMethod']
25705 $x1 = (isset($attribs['x1'])?
$attribs['x1']:'0%');
25706 $y1 = (isset($attribs['y1'])?
$attribs['y1']:'0%');
25707 $x2 = (isset($attribs['x2'])?
$attribs['x2']:'100%');
25708 $y2 = (isset($attribs['y2'])?
$attribs['y2']:'0%');
25709 if (substr($x1, -1) != '%') {
25710 $this->svggradients
[$this->svggradientid
]['mode'] = 'measure';
25712 $this->svggradients
[$this->svggradientid
]['mode'] = 'percentage';
25714 if (isset($attribs['gradientTransform'])) {
25715 $this->svggradients
[$this->svggradientid
]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
25717 $this->svggradients
[$this->svggradientid
]['coords'] = array($x1, $y1, $x2, $y2);
25718 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
25719 // gradient is defined on another place
25720 $this->svggradients
[$this->svggradientid
]['xref'] = substr($attribs['xlink:href'], 1);
25724 case 'radialGradient': {
25725 if (!isset($attribs['id'])) {
25726 $attribs['id'] = 'GR_'.(count($this->svggradients
) +
1);
25728 $this->svggradientid
= $attribs['id'];
25729 $this->svggradients
[$this->svggradientid
] = array();
25730 $this->svggradients
[$this->svggradientid
]['type'] = 3;
25731 $this->svggradients
[$this->svggradientid
]['stops'] = array();
25732 if (isset($attribs['gradientUnits'])) {
25733 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = $attribs['gradientUnits'];
25735 $this->svggradients
[$this->svggradientid
]['gradientUnits'] = 'objectBoundingBox';
25737 //$attribs['spreadMethod']
25738 $cx = (isset($attribs['cx'])?
$attribs['cx']:0.5);
25739 $cy = (isset($attribs['cy'])?
$attribs['cy']:0.5);
25740 $fx = (isset($attribs['fx'])?
$attribs['fx']:$cx);
25741 $fy = (isset($attribs['fy'])?
$attribs['fy']:$cy);
25742 $r = (isset($attribs['r'])?
$attribs['r']:0.5);
25743 if (isset($attribs['cx']) AND (substr($attribs['cx'], -1) != '%')) {
25744 $this->svggradients
[$this->svggradientid
]['mode'] = 'measure';
25746 $this->svggradients
[$this->svggradientid
]['mode'] = 'percentage';
25748 if (isset($attribs['gradientTransform'])) {
25749 $this->svggradients
[$this->svggradientid
]['gradientTransform'] = $this->getSVGTransformMatrix($attribs['gradientTransform']);
25751 $this->svggradients
[$this->svggradientid
]['coords'] = array($cx, $cy, $fx, $fy, $r);
25752 if (isset($attribs['xlink:href']) AND !empty($attribs['xlink:href'])) {
25753 // gradient is defined on another place
25754 $this->svggradients
[$this->svggradientid
]['xref'] = substr($attribs['xlink:href'], 1);
25760 if (substr($attribs['offset'], -1) == '%') {
25761 $offset = floatval(substr($attribs['offset'], -1)) / 100;
25763 $offset = floatval($attribs['offset']);
25768 $stop_color = isset($svgstyle['stop-color'])?
$this->convertHTMLColorToDec($svgstyle['stop-color']):'black';
25769 $opacity = isset($svgstyle['stop-opacity'])?
$svgstyle['stop-opacity']:1;
25770 $this->svggradients
[$this->svggradientid
]['stops'][] = array('offset' => $offset, 'color' => $stop_color, 'opacity' => $opacity);
25778 if (isset($attribs['d'])) {
25779 $d = trim($attribs['d']);
25782 $this->SVGTransform($tm);
25783 $this->SVGPath($d, 'CNZ');
25785 $this->StartTransform();
25786 $this->SVGTransform($tm);
25787 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, 0, 0, 1, 1, 'SVGPath', array($d, 'CNZ'));
25788 if (!empty($obstyle)) {
25789 $this->SVGPath($d, $obstyle);
25791 $this->StopTransform();
25802 $x = (isset($attribs['x'])?
$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false):0);
25803 $y = (isset($attribs['y'])?
$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false):0);
25804 $w = (isset($attribs['width'])?
$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit
, false):0);
25805 $h = (isset($attribs['height'])?
$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit
, false):0);
25806 $rx = (isset($attribs['rx'])?
$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit
, false):0);
25807 $ry = (isset($attribs['ry'])?
$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit
, false):$rx);
25809 $this->SVGTransform($tm);
25810 $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ', array(), array());
25812 $this->StartTransform();
25813 $this->SVGTransform($tm);
25814 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'RoundedRectXY', array($x, $y, $w, $h, $rx, $ry, '1111', 'CNZ'));
25815 if (!empty($obstyle)) {
25816 $this->RoundedRectXY($x, $y, $w, $h, $rx, $ry, '1111', $obstyle, array(), array());
25818 $this->StopTransform();
25826 $cx = (isset($attribs['cx'])?
$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit
, false):0);
25827 $cy = (isset($attribs['cy'])?
$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit
, false):0);
25828 $r = (isset($attribs['r'])?
$this->getHTMLUnitToUnits($attribs['r'], 0, $this->svgunit
, false):0);
25834 $this->SVGTransform($tm);
25835 $this->Circle($cx, $cy, $r, 0, 360, 'CNZ', array(), array(), 8);
25837 $this->StartTransform();
25838 $this->SVGTransform($tm);
25839 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Circle', array($cx, $cy, $r, 0, 360, 'CNZ'));
25840 if (!empty($obstyle)) {
25841 $this->Circle($cx, $cy, $r, 0, 360, $obstyle, array(), array(), 8);
25843 $this->StopTransform();
25851 $cx = (isset($attribs['cx'])?
$this->getHTMLUnitToUnits($attribs['cx'], 0, $this->svgunit
, false):0);
25852 $cy = (isset($attribs['cy'])?
$this->getHTMLUnitToUnits($attribs['cy'], 0, $this->svgunit
, false):0);
25853 $rx = (isset($attribs['rx'])?
$this->getHTMLUnitToUnits($attribs['rx'], 0, $this->svgunit
, false):0);
25854 $ry = (isset($attribs['ry'])?
$this->getHTMLUnitToUnits($attribs['ry'], 0, $this->svgunit
, false):0);
25860 $this->SVGTransform($tm);
25861 $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ', array(), array(), 8);
25863 $this->StartTransform();
25864 $this->SVGTransform($tm);
25865 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Ellipse', array($cx, $cy, $rx, $ry, 0, 0, 360, 'CNZ'));
25866 if (!empty($obstyle)) {
25867 $this->Ellipse($cx, $cy, $rx, $ry, 0, 0, 360, $obstyle, array(), array(), 8);
25869 $this->StopTransform();
25877 $x1 = (isset($attribs['x1'])?
$this->getHTMLUnitToUnits($attribs['x1'], 0, $this->svgunit
, false):0);
25878 $y1 = (isset($attribs['y1'])?
$this->getHTMLUnitToUnits($attribs['y1'], 0, $this->svgunit
, false):0);
25879 $x2 = (isset($attribs['x2'])?
$this->getHTMLUnitToUnits($attribs['x2'], 0, $this->svgunit
, false):0);
25880 $y2 = (isset($attribs['y2'])?
$this->getHTMLUnitToUnits($attribs['y2'], 0, $this->svgunit
, false):0);
25883 $w = abs($x2 - $x1);
25884 $h = abs($y2 - $y1);
25886 $this->StartTransform();
25887 $this->SVGTransform($tm);
25888 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Line', array($x1, $y1, $x2, $y2));
25889 $this->Line($x1, $y1, $x2, $y2);
25890 $this->StopTransform();
25899 $points = (isset($attribs['points'])?
$attribs['points']:'0 0');
25900 $points = trim($points);
25901 // note that point may use a complex syntax not covered here
25902 $points = preg_split('/[\,\s]+/si', $points);
25903 if (count($points) < 4) {
25907 $xmin = 2147483647;
25909 $ymin = 2147483647;
25911 foreach ($points as $key => $val) {
25912 $p[$key] = $this->getHTMLUnitToUnits($val, 0, $this->svgunit
, false);
25913 if (($key %
2) == 0) {
25915 $xmin = min($xmin, $p[$key]);
25916 $xmax = max($xmax, $p[$key]);
25919 $ymin = min($ymin, $p[$key]);
25920 $ymax = max($ymax, $p[$key]);
25925 $w = ($xmax - $xmin);
25926 $h = ($ymax - $ymin);
25927 if ($name == 'polyline') {
25928 $this->StartTransform();
25929 $this->SVGTransform($tm);
25930 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'PolyLine', array($p, 'CNZ'));
25931 $this->PolyLine($p, 'D', array(), array());
25932 $this->StopTransform();
25933 } else { // polygon
25935 $this->SVGTransform($tm);
25936 $this->Polygon($p, 'CNZ', array(), array(), true);
25938 $this->StartTransform();
25939 $this->SVGTransform($tm);
25940 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h, 'Polygon', array($p, 'CNZ'));
25941 if (!empty($obstyle)) {
25942 $this->Polygon($p, $obstyle, array(), array(), true);
25944 $this->StopTransform();
25954 if (!isset($attribs['xlink:href']) OR empty($attribs['xlink:href'])) {
25957 $x = (isset($attribs['x'])?
$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false):0);
25958 $y = (isset($attribs['y'])?
$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false):0);
25959 $w = (isset($attribs['width'])?
$this->getHTMLUnitToUnits($attribs['width'], 0, $this->svgunit
, false):0);
25960 $h = (isset($attribs['height'])?
$this->getHTMLUnitToUnits($attribs['height'], 0, $this->svgunit
, false):0);
25961 $img = $attribs['xlink:href'];
25963 $this->StartTransform();
25964 $this->SVGTransform($tm);
25965 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, $w, $h);
25967 if (!$this->empty_string($this->svgdir
) AND (($img{0} == '.') OR (basename($img) == $img))) {
25968 // replace relative path with full server path
25969 $img = $this->svgdir
.'/'.$img;
25971 if (($img{0} == '/') AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
25972 $findroot = strpos($img, $_SERVER['DOCUMENT_ROOT']);
25973 if (($findroot === false) OR ($findroot > 1)) {
25974 // replace relative path with full server path
25975 $img = $_SERVER['DOCUMENT_ROOT'].$img;
25978 $img = urldecode($img);
25979 $testscrtype = @parse_url
($img);
25980 if (!isset($testscrtype['query']) OR empty($testscrtype['query'])) {
25981 // convert URL to server path
25982 $img = str_replace(K_PATH_URL
, K_PATH_MAIN
, $img);
25984 $this->Image($img, $x, $y, $w, $h);
25985 $this->StopTransform();
25992 $this->svgtextmode
['invisible'] = $invisible;
25996 array_push($this->svgstyles
, $svgstyle);
25997 // only basic support - advanced features must be implemented
25998 $x = (isset($attribs['x'])?
$this->getHTMLUnitToUnits($attribs['x'], 0, $this->svgunit
, false):$this->x
);
25999 $y = (isset($attribs['y'])?
$this->getHTMLUnitToUnits($attribs['y'], 0, $this->svgunit
, false):$this->y
);
26000 $svgstyle['text-color'] = $svgstyle['fill'];
26001 $this->svgtext
= '';
26002 if (isset($svgstyle['text-anchor'])) {
26003 $this->svgtextmode
['text-anchor'] = $svgstyle['text-anchor'];
26005 $this->svgtextmode
['text-anchor'] = 'start';
26007 if (isset($svgstyle['direction'])) {
26008 if ($svgstyle['direction'] == 'rtl') {
26009 $this->svgtextmode
['rtl'] = true;
26011 $this->svgtextmode
['rtl'] = false;
26014 $this->svgtextmode
['rtl'] = false;
26016 if (isset($svgstyle['stroke']) AND ($svgstyle['stroke'] != 'none') AND isset($svgstyle['stroke-width']) AND ($svgstyle['stroke-width'] > 0)) {
26017 $this->svgtextmode
['stroke'] = $this->getHTMLUnitToUnits($svgstyle['stroke-width'], 0, $this->svgunit
, false);
26019 $this->svgtextmode
['stroke'] = false;
26021 $this->StartTransform();
26022 $this->SVGTransform($tm);
26023 $obstyle = $this->setSVGStyles($svgstyle, $prev_svgstyle, $x, $y, 1, 1);
26030 if (isset($attribs['xlink:href'])) {
26031 $use = $this->svgdefs
[substr($attribs['xlink:href'], 1)];
26032 if (isset($attribs['xlink:href'])) {
26033 unset($attribs['xlink:href']);
26035 if (isset($attribs['id'])) {
26036 unset($attribs['id']);
26038 $attribs = array_merge($use['attribs'], $attribs);
26039 $this->startSVGElementHandler($parser, $use['name'], $use['attribs']);
26050 * Sets the closing SVG element handler function for the XML parser.
26051 * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
26052 * @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.
26053 * @author Nicola Asuni
26054 * @since 5.0.000 (2010-05-02)
26057 protected function endSVGElementHandler($parser, $name) {
26060 $this->svgdefsmode
= false;
26065 $this->svgclipmode
= false;
26069 // ungroup: remove last style from array
26070 array_pop($this->svgstyles
);
26071 $this->StopTransform();
26076 if ($this->svgtextmode
['invisible']) {
26077 // This implementation must be fixed to following the rule:
26078 // 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.
26082 $text = $this->stringTrim($this->svgtext
);
26083 if ($this->svgtextmode
['text-anchor'] != 'start') {
26084 $textlen = $this->GetStringWidth($text);
26085 // check if string is RTL text
26086 if ($this->svgtextmode
['text-anchor'] == 'end') {
26087 if ($this->svgtextmode
['rtl']) {
26088 $this->x +
= $textlen;
26090 $this->x
-= $textlen;
26092 } elseif ($this->svgtextmode
['text-anchor'] == 'middle') {
26093 if ($this->svgtextmode
['rtl']) {
26094 $this->x +
= ($textlen / 2);
26096 $this->x
-= ($textlen / 2);
26100 $textrendermode = $this->textrendermode
;
26101 $textstrokewidth = $this->textstrokewidth
;
26102 $this->setTextRenderingMode($this->svgtextmode
['stroke'], true, false);
26103 $this->Cell(0, 0, $text, 0, 0, '', false, '', 0, false, 'L', 'T');
26104 // restore previous rendering mode
26105 $this->textrendermode
= $textrendermode;
26106 $this->textstrokewidth
= $textstrokewidth;
26107 $this->svgtext
= '';
26108 $this->StopTransform();
26109 array_pop($this->svgstyles
);
26119 * Sets the character data handler function for the XML parser.
26120 * @param $parser (resource) The first parameter, parser, is a reference to the XML parser calling the handler.
26121 * @param $data (string) The second parameter, data, contains the character data as a string.
26122 * @author Nicola Asuni
26123 * @since 5.0.000 (2010-05-02)
26126 protected function segSVGContentHandler($parser, $data) {
26127 $this->svgtext
.= $data;
26130 // --- END SVG METHODS -----------------------------
26132 } // END OF TCPDF CLASS
26134 //============================================================+
26136 //============================================================+