2 //============================================================+
3 // File name : tcpdf_static.php
6 // Last Update : 2014-12-10
7 // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
8 // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
9 // -------------------------------------------------------------------
10 // Copyright (C) 2002-2014 Nicola Asuni - Tecnick.com LTD
12 // This file is part of TCPDF software library.
14 // TCPDF is free software: you can redistribute it and/or modify it
15 // under the terms of the GNU Lesser General Public License as
16 // published by the Free Software Foundation, either version 3 of the
17 // License, or (at your option) any later version.
19 // TCPDF is distributed in the hope that it will be useful, but
20 // WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 // See the GNU Lesser General Public License for more details.
24 // You should have received a copy of the License
25 // along with TCPDF. If not, see
26 // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
28 // See LICENSE.TXT file for more information.
29 // -------------------------------------------------------------------
32 // Static methods used by the TCPDF class.
34 //============================================================+
38 * This is a PHP class that contains static methods for the TCPDF class.<br>
39 * @package com.tecnick.tcpdf
40 * @author Nicola Asuni
46 * Static methods used by the TCPDF class.
47 * @package com.tecnick.tcpdf
48 * @brief PHP class for generating PDF documents without requiring external extensions.
50 * @author Nicola Asuni - info@tecnick.com
55 * Current TCPDF version.
58 private static $tcpdf_version = '6.2.3';
61 * String alias for total number of pages.
64 public static $alias_tot_pages = '{:ptp:}';
67 * String alias for page number.
70 public static $alias_num_page = '{:pnp:}';
73 * String alias for total number of pages in a single group.
76 public static $alias_group_tot_pages = '{:ptg:}';
79 * String alias for group page number.
82 public static $alias_group_num_page = '{:png:}';
85 * String alias for right shift compensation used to correctly align page numbers on the right.
88 public static $alias_right_shift = '{rsc:';
91 * Encryption padding string.
94 public static $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";
97 * ByteRange placemark used during digital signature process.
98 * @since 4.6.028 (2009-08-25)
101 public static $byterange_string = '/ByteRange[0 ********** ********** **********]';
104 * Array page boxes names
107 public static $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
110 * Array of page formats
111 * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4)
114 public static $page_formats = array(
115 // ISO 216 A Series + 2 SIS 014711 extensions
116 'A0' => array( 2383.937, 3370.394), // = ( 841 x 1189 ) mm = ( 33.11 x 46.81 ) in
117 'A1' => array( 1683.780, 2383.937), // = ( 594 x 841 ) mm = ( 23.39 x 33.11 ) in
118 'A2' => array( 1190.551, 1683.780), // = ( 420 x 594 ) mm = ( 16.54 x 23.39 ) in
119 'A3' => array( 841.890, 1190.551), // = ( 297 x 420 ) mm = ( 11.69 x 16.54 ) in
120 'A4' => array( 595.276, 841.890), // = ( 210 x 297 ) mm = ( 8.27 x 11.69 ) in
121 'A5' => array( 419.528, 595.276), // = ( 148 x 210 ) mm = ( 5.83 x 8.27 ) in
122 'A6' => array( 297.638, 419.528), // = ( 105 x 148 ) mm = ( 4.13 x 5.83 ) in
123 'A7' => array( 209.764, 297.638), // = ( 74 x 105 ) mm = ( 2.91 x 4.13 ) in
124 'A8' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
125 'A9' => array( 104.882, 147.402), // = ( 37 x 52 ) mm = ( 1.46 x 2.05 ) in
126 'A10' => array( 73.701, 104.882), // = ( 26 x 37 ) mm = ( 1.02 x 1.46 ) in
127 'A11' => array( 51.024, 73.701), // = ( 18 x 26 ) mm = ( 0.71 x 1.02 ) in
128 'A12' => array( 36.850, 51.024), // = ( 13 x 18 ) mm = ( 0.51 x 0.71 ) in
129 // ISO 216 B Series + 2 SIS 014711 extensions
130 'B0' => array( 2834.646, 4008.189), // = ( 1000 x 1414 ) mm = ( 39.37 x 55.67 ) in
131 'B1' => array( 2004.094, 2834.646), // = ( 707 x 1000 ) mm = ( 27.83 x 39.37 ) in
132 'B2' => array( 1417.323, 2004.094), // = ( 500 x 707 ) mm = ( 19.69 x 27.83 ) in
133 'B3' => array( 1000.630, 1417.323), // = ( 353 x 500 ) mm = ( 13.90 x 19.69 ) in
134 'B4' => array( 708.661, 1000.630), // = ( 250 x 353 ) mm = ( 9.84 x 13.90 ) in
135 'B5' => array( 498.898, 708.661), // = ( 176 x 250 ) mm = ( 6.93 x 9.84 ) in
136 'B6' => array( 354.331, 498.898), // = ( 125 x 176 ) mm = ( 4.92 x 6.93 ) in
137 'B7' => array( 249.449, 354.331), // = ( 88 x 125 ) mm = ( 3.46 x 4.92 ) in
138 'B8' => array( 175.748, 249.449), // = ( 62 x 88 ) mm = ( 2.44 x 3.46 ) in
139 'B9' => array( 124.724, 175.748), // = ( 44 x 62 ) mm = ( 1.73 x 2.44 ) in
140 'B10' => array( 87.874, 124.724), // = ( 31 x 44 ) mm = ( 1.22 x 1.73 ) in
141 'B11' => array( 62.362, 87.874), // = ( 22 x 31 ) mm = ( 0.87 x 1.22 ) in
142 'B12' => array( 42.520, 62.362), // = ( 15 x 22 ) mm = ( 0.59 x 0.87 ) in
143 // ISO 216 C Series + 2 SIS 014711 extensions + 5 EXTENSION
144 'C0' => array( 2599.370, 3676.535), // = ( 917 x 1297 ) mm = ( 36.10 x 51.06 ) in
145 'C1' => array( 1836.850, 2599.370), // = ( 648 x 917 ) mm = ( 25.51 x 36.10 ) in
146 'C2' => array( 1298.268, 1836.850), // = ( 458 x 648 ) mm = ( 18.03 x 25.51 ) in
147 'C3' => array( 918.425, 1298.268), // = ( 324 x 458 ) mm = ( 12.76 x 18.03 ) in
148 'C4' => array( 649.134, 918.425), // = ( 229 x 324 ) mm = ( 9.02 x 12.76 ) in
149 'C5' => array( 459.213, 649.134), // = ( 162 x 229 ) mm = ( 6.38 x 9.02 ) in
150 'C6' => array( 323.150, 459.213), // = ( 114 x 162 ) mm = ( 4.49 x 6.38 ) in
151 'C7' => array( 229.606, 323.150), // = ( 81 x 114 ) mm = ( 3.19 x 4.49 ) in
152 'C8' => array( 161.575, 229.606), // = ( 57 x 81 ) mm = ( 2.24 x 3.19 ) in
153 'C9' => array( 113.386, 161.575), // = ( 40 x 57 ) mm = ( 1.57 x 2.24 ) in
154 'C10' => array( 79.370, 113.386), // = ( 28 x 40 ) mm = ( 1.10 x 1.57 ) in
155 'C11' => array( 56.693, 79.370), // = ( 20 x 28 ) mm = ( 0.79 x 1.10 ) in
156 'C12' => array( 39.685, 56.693), // = ( 14 x 20 ) mm = ( 0.55 x 0.79 ) in
157 'C76' => array( 229.606, 459.213), // = ( 81 x 162 ) mm = ( 3.19 x 6.38 ) in
158 'DL' => array( 311.811, 623.622), // = ( 110 x 220 ) mm = ( 4.33 x 8.66 ) in
159 'DLE' => array( 323.150, 637.795), // = ( 114 x 225 ) mm = ( 4.49 x 8.86 ) in
160 'DLX' => array( 340.158, 666.142), // = ( 120 x 235 ) mm = ( 4.72 x 9.25 ) in
161 'DLP' => array( 280.630, 595.276), // = ( 99 x 210 ) mm = ( 3.90 x 8.27 ) in (1/3 A4)
162 // SIS 014711 E Series
163 'E0' => array( 2491.654, 3517.795), // = ( 879 x 1241 ) mm = ( 34.61 x 48.86 ) in
164 'E1' => array( 1757.480, 2491.654), // = ( 620 x 879 ) mm = ( 24.41 x 34.61 ) in
165 'E2' => array( 1247.244, 1757.480), // = ( 440 x 620 ) mm = ( 17.32 x 24.41 ) in
166 'E3' => array( 878.740, 1247.244), // = ( 310 x 440 ) mm = ( 12.20 x 17.32 ) in
167 'E4' => array( 623.622, 878.740), // = ( 220 x 310 ) mm = ( 8.66 x 12.20 ) in
168 'E5' => array( 439.370, 623.622), // = ( 155 x 220 ) mm = ( 6.10 x 8.66 ) in
169 'E6' => array( 311.811, 439.370), // = ( 110 x 155 ) mm = ( 4.33 x 6.10 ) in
170 'E7' => array( 221.102, 311.811), // = ( 78 x 110 ) mm = ( 3.07 x 4.33 ) in
171 'E8' => array( 155.906, 221.102), // = ( 55 x 78 ) mm = ( 2.17 x 3.07 ) in
172 'E9' => array( 110.551, 155.906), // = ( 39 x 55 ) mm = ( 1.54 x 2.17 ) in
173 'E10' => array( 76.535, 110.551), // = ( 27 x 39 ) mm = ( 1.06 x 1.54 ) in
174 'E11' => array( 53.858, 76.535), // = ( 19 x 27 ) mm = ( 0.75 x 1.06 ) in
175 'E12' => array( 36.850, 53.858), // = ( 13 x 19 ) mm = ( 0.51 x 0.75 ) in
176 // SIS 014711 G Series
177 'G0' => array( 2715.591, 3838.110), // = ( 958 x 1354 ) mm = ( 37.72 x 53.31 ) in
178 'G1' => array( 1919.055, 2715.591), // = ( 677 x 958 ) mm = ( 26.65 x 37.72 ) in
179 'G2' => array( 1357.795, 1919.055), // = ( 479 x 677 ) mm = ( 18.86 x 26.65 ) in
180 'G3' => array( 958.110, 1357.795), // = ( 338 x 479 ) mm = ( 13.31 x 18.86 ) in
181 'G4' => array( 677.480, 958.110), // = ( 239 x 338 ) mm = ( 9.41 x 13.31 ) in
182 'G5' => array( 479.055, 677.480), // = ( 169 x 239 ) mm = ( 6.65 x 9.41 ) in
183 'G6' => array( 337.323, 479.055), // = ( 119 x 169 ) mm = ( 4.69 x 6.65 ) in
184 'G7' => array( 238.110, 337.323), // = ( 84 x 119 ) mm = ( 3.31 x 4.69 ) in
185 'G8' => array( 167.244, 238.110), // = ( 59 x 84 ) mm = ( 2.32 x 3.31 ) in
186 'G9' => array( 119.055, 167.244), // = ( 42 x 59 ) mm = ( 1.65 x 2.32 ) in
187 'G10' => array( 82.205, 119.055), // = ( 29 x 42 ) mm = ( 1.14 x 1.65 ) in
188 'G11' => array( 59.528, 82.205), // = ( 21 x 29 ) mm = ( 0.83 x 1.14 ) in
189 'G12' => array( 39.685, 59.528), // = ( 14 x 21 ) mm = ( 0.55 x 0.83 ) in
191 'RA0' => array( 2437.795, 3458.268), // = ( 860 x 1220 ) mm = ( 33.86 x 48.03 ) in
192 'RA1' => array( 1729.134, 2437.795), // = ( 610 x 860 ) mm = ( 24.02 x 33.86 ) in
193 'RA2' => array( 1218.898, 1729.134), // = ( 430 x 610 ) mm = ( 16.93 x 24.02 ) in
194 'RA3' => array( 864.567, 1218.898), // = ( 305 x 430 ) mm = ( 12.01 x 16.93 ) in
195 'RA4' => array( 609.449, 864.567), // = ( 215 x 305 ) mm = ( 8.46 x 12.01 ) in
196 'SRA0' => array( 2551.181, 3628.346), // = ( 900 x 1280 ) mm = ( 35.43 x 50.39 ) in
197 'SRA1' => array( 1814.173, 2551.181), // = ( 640 x 900 ) mm = ( 25.20 x 35.43 ) in
198 'SRA2' => array( 1275.591, 1814.173), // = ( 450 x 640 ) mm = ( 17.72 x 25.20 ) in
199 'SRA3' => array( 907.087, 1275.591), // = ( 320 x 450 ) mm = ( 12.60 x 17.72 ) in
200 'SRA4' => array( 637.795, 907.087), // = ( 225 x 320 ) mm = ( 8.86 x 12.60 ) in
202 '4A0' => array( 4767.874, 6740.787), // = ( 1682 x 2378 ) mm = ( 66.22 x 93.62 ) in
203 '2A0' => array( 3370.394, 4767.874), // = ( 1189 x 1682 ) mm = ( 46.81 x 66.22 ) in
204 // Variations on the ISO Standard
205 'A2_EXTRA' => array( 1261.417, 1754.646), // = ( 445 x 619 ) mm = ( 17.52 x 24.37 ) in
206 'A3+' => array( 932.598, 1369.134), // = ( 329 x 483 ) mm = ( 12.95 x 19.02 ) in
207 'A3_EXTRA' => array( 912.756, 1261.417), // = ( 322 x 445 ) mm = ( 12.68 x 17.52 ) in
208 'A3_SUPER' => array( 864.567, 1440.000), // = ( 305 x 508 ) mm = ( 12.01 x 20.00 ) in
209 'SUPER_A3' => array( 864.567, 1380.472), // = ( 305 x 487 ) mm = ( 12.01 x 19.17 ) in
210 'A4_EXTRA' => array( 666.142, 912.756), // = ( 235 x 322 ) mm = ( 9.25 x 12.68 ) in
211 'A4_SUPER' => array( 649.134, 912.756), // = ( 229 x 322 ) mm = ( 9.02 x 12.68 ) in
212 'SUPER_A4' => array( 643.465, 1009.134), // = ( 227 x 356 ) mm = ( 8.94 x 14.02 ) in
213 'A4_LONG' => array( 595.276, 986.457), // = ( 210 x 348 ) mm = ( 8.27 x 13.70 ) in
214 'F4' => array( 595.276, 935.433), // = ( 210 x 330 ) mm = ( 8.27 x 12.99 ) in
215 'SO_B5_EXTRA' => array( 572.598, 782.362), // = ( 202 x 276 ) mm = ( 7.95 x 10.87 ) in
216 'A5_EXTRA' => array( 490.394, 666.142), // = ( 173 x 235 ) mm = ( 6.81 x 9.25 ) in
218 'ANSI_E' => array( 2448.000, 3168.000), // = ( 864 x 1118 ) mm = ( 34.00 x 44.00 ) in
219 'ANSI_D' => array( 1584.000, 2448.000), // = ( 559 x 864 ) mm = ( 22.00 x 34.00 ) in
220 'ANSI_C' => array( 1224.000, 1584.000), // = ( 432 x 559 ) mm = ( 17.00 x 22.00 ) in
221 'ANSI_B' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
222 'ANSI_A' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
223 // Traditional 'Loose' North American Paper Sizes
224 'USLEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
225 'LEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
226 'ORGANIZERK' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
227 'BIBLE' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
228 'USTABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
229 'TABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
230 'ORGANIZERM' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
231 'USLETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
232 'LETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
233 'USLEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
234 'LEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
235 'GOVERNMENTLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
236 'GLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
237 'JUNIORLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
238 'JLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
239 // Other North American Paper Sizes
240 'QUADDEMY' => array( 2520.000, 3240.000), // = ( 889 x 1143 ) mm = ( 35.00 x 45.00 ) in
241 'SUPER_B' => array( 936.000, 1368.000), // = ( 330 x 483 ) mm = ( 13.00 x 19.00 ) in
242 'QUARTO' => array( 648.000, 792.000), // = ( 229 x 279 ) mm = ( 9.00 x 11.00 ) in
243 'GOVERNMENTLEGAL' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
244 'FOLIO' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
245 'MONARCH' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
246 'EXECUTIVE' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
247 'ORGANIZERL' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
248 'STATEMENT' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
249 'MEMO' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
250 'FOOLSCAP' => array( 595.440, 936.000), // = ( 210 x 330 ) mm = ( 8.27 x 13.00 ) in
251 'COMPACT' => array( 306.000, 486.000), // = ( 108 x 171 ) mm = ( 4.25 x 6.75 ) in
252 'ORGANIZERJ' => array( 198.000, 360.000), // = ( 70 x 127 ) mm = ( 2.75 x 5.00 ) in
253 // Canadian standard CAN 2-9.60M
254 'P1' => array( 1587.402, 2437.795), // = ( 560 x 860 ) mm = ( 22.05 x 33.86 ) in
255 'P2' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
256 'P3' => array( 793.701, 1218.898), // = ( 280 x 430 ) mm = ( 11.02 x 16.93 ) in
257 'P4' => array( 609.449, 793.701), // = ( 215 x 280 ) mm = ( 8.46 x 11.02 ) in
258 'P5' => array( 396.850, 609.449), // = ( 140 x 215 ) mm = ( 5.51 x 8.46 ) in
259 'P6' => array( 303.307, 396.850), // = ( 107 x 140 ) mm = ( 4.21 x 5.51 ) in
260 // North American Architectural Sizes
261 'ARCH_E' => array( 2592.000, 3456.000), // = ( 914 x 1219 ) mm = ( 36.00 x 48.00 ) in
262 'ARCH_E1' => array( 2160.000, 3024.000), // = ( 762 x 1067 ) mm = ( 30.00 x 42.00 ) in
263 'ARCH_D' => array( 1728.000, 2592.000), // = ( 610 x 914 ) mm = ( 24.00 x 36.00 ) in
264 'BROADSHEET' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
265 'ARCH_C' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
266 'ARCH_B' => array( 864.000, 1296.000), // = ( 305 x 457 ) mm = ( 12.00 x 18.00 ) in
267 'ARCH_A' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
268 // -- North American Envelope Sizes
269 // - Announcement Envelopes
270 'ANNENV_A2' => array( 314.640, 414.000), // = ( 111 x 146 ) mm = ( 4.37 x 5.75 ) in
271 'ANNENV_A6' => array( 342.000, 468.000), // = ( 121 x 165 ) mm = ( 4.75 x 6.50 ) in
272 'ANNENV_A7' => array( 378.000, 522.000), // = ( 133 x 184 ) mm = ( 5.25 x 7.25 ) in
273 'ANNENV_A8' => array( 396.000, 584.640), // = ( 140 x 206 ) mm = ( 5.50 x 8.12 ) in
274 'ANNENV_A10' => array( 450.000, 692.640), // = ( 159 x 244 ) mm = ( 6.25 x 9.62 ) in
275 'ANNENV_SLIM' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
276 // - Commercial Envelopes
277 'COMMENV_N6_1/4' => array( 252.000, 432.000), // = ( 89 x 152 ) mm = ( 3.50 x 6.00 ) in
278 'COMMENV_N6_3/4' => array( 260.640, 468.000), // = ( 92 x 165 ) mm = ( 3.62 x 6.50 ) in
279 'COMMENV_N8' => array( 278.640, 540.000), // = ( 98 x 191 ) mm = ( 3.87 x 7.50 ) in
280 'COMMENV_N9' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
281 'COMMENV_N10' => array( 296.640, 684.000), // = ( 105 x 241 ) mm = ( 4.12 x 9.50 ) in
282 'COMMENV_N11' => array( 324.000, 746.640), // = ( 114 x 263 ) mm = ( 4.50 x 10.37 ) in
283 'COMMENV_N12' => array( 342.000, 792.000), // = ( 121 x 279 ) mm = ( 4.75 x 11.00 ) in
284 'COMMENV_N14' => array( 360.000, 828.000), // = ( 127 x 292 ) mm = ( 5.00 x 11.50 ) in
285 // - Catalogue Envelopes
286 'CATENV_N1' => array( 432.000, 648.000), // = ( 152 x 229 ) mm = ( 6.00 x 9.00 ) in
287 'CATENV_N1_3/4' => array( 468.000, 684.000), // = ( 165 x 241 ) mm = ( 6.50 x 9.50 ) in
288 'CATENV_N2' => array( 468.000, 720.000), // = ( 165 x 254 ) mm = ( 6.50 x 10.00 ) in
289 'CATENV_N3' => array( 504.000, 720.000), // = ( 178 x 254 ) mm = ( 7.00 x 10.00 ) in
290 'CATENV_N6' => array( 540.000, 756.000), // = ( 191 x 267 ) mm = ( 7.50 x 10.50 ) in
291 'CATENV_N7' => array( 576.000, 792.000), // = ( 203 x 279 ) mm = ( 8.00 x 11.00 ) in
292 'CATENV_N8' => array( 594.000, 810.000), // = ( 210 x 286 ) mm = ( 8.25 x 11.25 ) in
293 'CATENV_N9_1/2' => array( 612.000, 756.000), // = ( 216 x 267 ) mm = ( 8.50 x 10.50 ) in
294 'CATENV_N9_3/4' => array( 630.000, 810.000), // = ( 222 x 286 ) mm = ( 8.75 x 11.25 ) in
295 'CATENV_N10_1/2' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
296 'CATENV_N12_1/2' => array( 684.000, 900.000), // = ( 241 x 318 ) mm = ( 9.50 x 12.50 ) in
297 'CATENV_N13_1/2' => array( 720.000, 936.000), // = ( 254 x 330 ) mm = ( 10.00 x 13.00 ) in
298 'CATENV_N14_1/4' => array( 810.000, 882.000), // = ( 286 x 311 ) mm = ( 11.25 x 12.25 ) in
299 'CATENV_N14_1/2' => array( 828.000, 1044.000), // = ( 292 x 368 ) mm = ( 11.50 x 14.50 ) in
300 // Japanese (JIS P 0138-61) Standard B-Series
301 'JIS_B0' => array( 2919.685, 4127.244), // = ( 1030 x 1456 ) mm = ( 40.55 x 57.32 ) in
302 'JIS_B1' => array( 2063.622, 2919.685), // = ( 728 x 1030 ) mm = ( 28.66 x 40.55 ) in
303 'JIS_B2' => array( 1459.843, 2063.622), // = ( 515 x 728 ) mm = ( 20.28 x 28.66 ) in
304 'JIS_B3' => array( 1031.811, 1459.843), // = ( 364 x 515 ) mm = ( 14.33 x 20.28 ) in
305 'JIS_B4' => array( 728.504, 1031.811), // = ( 257 x 364 ) mm = ( 10.12 x 14.33 ) in
306 'JIS_B5' => array( 515.906, 728.504), // = ( 182 x 257 ) mm = ( 7.17 x 10.12 ) in
307 'JIS_B6' => array( 362.835, 515.906), // = ( 128 x 182 ) mm = ( 5.04 x 7.17 ) in
308 'JIS_B7' => array( 257.953, 362.835), // = ( 91 x 128 ) mm = ( 3.58 x 5.04 ) in
309 'JIS_B8' => array( 181.417, 257.953), // = ( 64 x 91 ) mm = ( 2.52 x 3.58 ) in
310 'JIS_B9' => array( 127.559, 181.417), // = ( 45 x 64 ) mm = ( 1.77 x 2.52 ) in
311 'JIS_B10' => array( 90.709, 127.559), // = ( 32 x 45 ) mm = ( 1.26 x 1.77 ) in
312 'JIS_B11' => array( 62.362, 90.709), // = ( 22 x 32 ) mm = ( 0.87 x 1.26 ) in
313 'JIS_B12' => array( 45.354, 62.362), // = ( 16 x 22 ) mm = ( 0.63 x 0.87 ) in
315 'PA0' => array( 2381.102, 3174.803), // = ( 840 x 1120 ) mm = ( 33.07 x 44.09 ) in
316 'PA1' => array( 1587.402, 2381.102), // = ( 560 x 840 ) mm = ( 22.05 x 33.07 ) in
317 'PA2' => array( 1190.551, 1587.402), // = ( 420 x 560 ) mm = ( 16.54 x 22.05 ) in
318 'PA3' => array( 793.701, 1190.551), // = ( 280 x 420 ) mm = ( 11.02 x 16.54 ) in
319 'PA4' => array( 595.276, 793.701), // = ( 210 x 280 ) mm = ( 8.27 x 11.02 ) in
320 'PA5' => array( 396.850, 595.276), // = ( 140 x 210 ) mm = ( 5.51 x 8.27 ) in
321 'PA6' => array( 297.638, 396.850), // = ( 105 x 140 ) mm = ( 4.13 x 5.51 ) in
322 'PA7' => array( 198.425, 297.638), // = ( 70 x 105 ) mm = ( 2.76 x 4.13 ) in
323 'PA8' => array( 147.402, 198.425), // = ( 52 x 70 ) mm = ( 2.05 x 2.76 ) in
324 'PA9' => array( 99.213, 147.402), // = ( 35 x 52 ) mm = ( 1.38 x 2.05 ) in
325 'PA10' => array( 73.701, 99.213), // = ( 26 x 35 ) mm = ( 1.02 x 1.38 ) in
326 // Standard Photographic Print Sizes
327 'PASSPORT_PHOTO' => array( 99.213, 127.559), // = ( 35 x 45 ) mm = ( 1.38 x 1.77 ) in
328 'E' => array( 233.858, 340.157), // = ( 82 x 120 ) mm = ( 3.25 x 4.72 ) in
329 'L' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
330 '3R' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
331 'KG' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
332 '4R' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
333 '4D' => array( 340.157, 430.866), // = ( 120 x 152 ) mm = ( 4.72 x 5.98 ) in
334 '2L' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
335 '5R' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
336 '8P' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
337 '6R' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
338 '6P' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
339 '8R' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
340 '6PW' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
341 'S8R' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
342 '4P' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
343 '10R' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
344 '4PW' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
345 'S10R' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
346 '11R' => array( 790.866, 1009.134), // = ( 279 x 356 ) mm = ( 10.98 x 14.02 ) in
347 'S11R' => array( 790.866, 1224.567), // = ( 279 x 432 ) mm = ( 10.98 x 17.01 ) in
348 '12R' => array( 864.567, 1080.000), // = ( 305 x 381 ) mm = ( 12.01 x 15.00 ) in
349 'S12R' => array( 864.567, 1292.598), // = ( 305 x 456 ) mm = ( 12.01 x 17.95 ) in
350 // Common Newspaper Sizes
351 'NEWSPAPER_BROADSHEET' => array( 2125.984, 1700.787), // = ( 750 x 600 ) mm = ( 29.53 x 23.62 ) in
352 'NEWSPAPER_BERLINER' => array( 1332.283, 892.913), // = ( 470 x 315 ) mm = ( 18.50 x 12.40 ) in
353 'NEWSPAPER_TABLOID' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
354 'NEWSPAPER_COMPACT' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
356 'CREDIT_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
357 'BUSINESS_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
358 'BUSINESS_CARD_ISO7810' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
359 'BUSINESS_CARD_ISO216' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
360 'BUSINESS_CARD_IT' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
361 'BUSINESS_CARD_UK' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
362 'BUSINESS_CARD_FR' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
363 'BUSINESS_CARD_DE' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
364 'BUSINESS_CARD_ES' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
365 'BUSINESS_CARD_CA' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
366 'BUSINESS_CARD_US' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
367 'BUSINESS_CARD_JP' => array( 155.906, 257.953), // = ( 55 x 91 ) mm = ( 2.17 x 3.58 ) in
368 'BUSINESS_CARD_HK' => array( 153.071, 255.118), // = ( 54 x 90 ) mm = ( 2.13 x 3.54 ) in
369 'BUSINESS_CARD_AU' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
370 'BUSINESS_CARD_DK' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
371 'BUSINESS_CARD_SE' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
372 'BUSINESS_CARD_RU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
373 'BUSINESS_CARD_CZ' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
374 'BUSINESS_CARD_FI' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
375 'BUSINESS_CARD_HU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
376 'BUSINESS_CARD_IL' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
378 '4SHEET' => array( 2880.000, 4320.000), // = ( 1016 x 1524 ) mm = ( 40.00 x 60.00 ) in
379 '6SHEET' => array( 3401.575, 5102.362), // = ( 1200 x 1800 ) mm = ( 47.24 x 70.87 ) in
380 '12SHEET' => array( 8640.000, 4320.000), // = ( 3048 x 1524 ) mm = (120.00 x 60.00 ) in
381 '16SHEET' => array( 5760.000, 8640.000), // = ( 2032 x 3048 ) mm = ( 80.00 x 120.00) in
382 '32SHEET' => array(11520.000, 8640.000), // = ( 4064 x 3048 ) mm = (160.00 x 120.00) in
383 '48SHEET' => array(17280.000, 8640.000), // = ( 6096 x 3048 ) mm = (240.00 x 120.00) in
384 '64SHEET' => array(23040.000, 8640.000), // = ( 8128 x 3048 ) mm = (320.00 x 120.00) in
385 '96SHEET' => array(34560.000, 8640.000), // = (12192 x 3048 ) mm = (480.00 x 120.00) in
386 // -- Old European Sizes
387 // - Old Imperial English Sizes
388 'EN_EMPEROR' => array( 3456.000, 5184.000), // = ( 1219 x 1829 ) mm = ( 48.00 x 72.00 ) in
389 'EN_ANTIQUARIAN' => array( 2232.000, 3816.000), // = ( 787 x 1346 ) mm = ( 31.00 x 53.00 ) in
390 'EN_GRAND_EAGLE' => array( 2070.000, 3024.000), // = ( 730 x 1067 ) mm = ( 28.75 x 42.00 ) in
391 'EN_DOUBLE_ELEPHANT' => array( 1926.000, 2880.000), // = ( 679 x 1016 ) mm = ( 26.75 x 40.00 ) in
392 'EN_ATLAS' => array( 1872.000, 2448.000), // = ( 660 x 864 ) mm = ( 26.00 x 34.00 ) in
393 'EN_COLOMBIER' => array( 1692.000, 2484.000), // = ( 597 x 876 ) mm = ( 23.50 x 34.50 ) in
394 'EN_ELEPHANT' => array( 1656.000, 2016.000), // = ( 584 x 711 ) mm = ( 23.00 x 28.00 ) in
395 'EN_DOUBLE_DEMY' => array( 1620.000, 2556.000), // = ( 572 x 902 ) mm = ( 22.50 x 35.50 ) in
396 'EN_IMPERIAL' => array( 1584.000, 2160.000), // = ( 559 x 762 ) mm = ( 22.00 x 30.00 ) in
397 'EN_PRINCESS' => array( 1548.000, 2016.000), // = ( 546 x 711 ) mm = ( 21.50 x 28.00 ) in
398 'EN_CARTRIDGE' => array( 1512.000, 1872.000), // = ( 533 x 660 ) mm = ( 21.00 x 26.00 ) in
399 'EN_DOUBLE_LARGE_POST' => array( 1512.000, 2376.000), // = ( 533 x 838 ) mm = ( 21.00 x 33.00 ) in
400 'EN_ROYAL' => array( 1440.000, 1800.000), // = ( 508 x 635 ) mm = ( 20.00 x 25.00 ) in
401 'EN_SHEET' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
402 'EN_HALF_POST' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
403 'EN_SUPER_ROYAL' => array( 1368.000, 1944.000), // = ( 483 x 686 ) mm = ( 19.00 x 27.00 ) in
404 'EN_DOUBLE_POST' => array( 1368.000, 2196.000), // = ( 483 x 775 ) mm = ( 19.00 x 30.50 ) in
405 'EN_MEDIUM' => array( 1260.000, 1656.000), // = ( 445 x 584 ) mm = ( 17.50 x 23.00 ) in
406 'EN_DEMY' => array( 1260.000, 1620.000), // = ( 445 x 572 ) mm = ( 17.50 x 22.50 ) in
407 'EN_LARGE_POST' => array( 1188.000, 1512.000), // = ( 419 x 533 ) mm = ( 16.50 x 21.00 ) in
408 'EN_COPY_DRAUGHT' => array( 1152.000, 1440.000), // = ( 406 x 508 ) mm = ( 16.00 x 20.00 ) in
409 'EN_POST' => array( 1116.000, 1386.000), // = ( 394 x 489 ) mm = ( 15.50 x 19.25 ) in
410 'EN_CROWN' => array( 1080.000, 1440.000), // = ( 381 x 508 ) mm = ( 15.00 x 20.00 ) in
411 'EN_PINCHED_POST' => array( 1062.000, 1332.000), // = ( 375 x 470 ) mm = ( 14.75 x 18.50 ) in
412 'EN_BRIEF' => array( 972.000, 1152.000), // = ( 343 x 406 ) mm = ( 13.50 x 16.00 ) in
413 'EN_FOOLSCAP' => array( 972.000, 1224.000), // = ( 343 x 432 ) mm = ( 13.50 x 17.00 ) in
414 'EN_SMALL_FOOLSCAP' => array( 954.000, 1188.000), // = ( 337 x 419 ) mm = ( 13.25 x 16.50 ) in
415 'EN_POTT' => array( 900.000, 1080.000), // = ( 318 x 381 ) mm = ( 12.50 x 15.00 ) in
416 // - Old Imperial Belgian Sizes
417 'BE_GRAND_AIGLE' => array( 1984.252, 2948.031), // = ( 700 x 1040 ) mm = ( 27.56 x 40.94 ) in
418 'BE_COLOMBIER' => array( 1757.480, 2409.449), // = ( 620 x 850 ) mm = ( 24.41 x 33.46 ) in
419 'BE_DOUBLE_CARRE' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
420 'BE_ELEPHANT' => array( 1746.142, 2182.677), // = ( 616 x 770 ) mm = ( 24.25 x 30.31 ) in
421 'BE_PETIT_AIGLE' => array( 1700.787, 2381.102), // = ( 600 x 840 ) mm = ( 23.62 x 33.07 ) in
422 'BE_GRAND_JESUS' => array( 1559.055, 2069.291), // = ( 550 x 730 ) mm = ( 21.65 x 28.74 ) in
423 'BE_JESUS' => array( 1530.709, 2069.291), // = ( 540 x 730 ) mm = ( 21.26 x 28.74 ) in
424 'BE_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
425 'BE_GRAND_MEDIAN' => array( 1303.937, 1714.961), // = ( 460 x 605 ) mm = ( 18.11 x 23.82 ) in
426 'BE_DOUBLE_POSTE' => array( 1233.071, 1601.575), // = ( 435 x 565 ) mm = ( 17.13 x 22.24 ) in
427 'BE_COQUILLE' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
428 'BE_PETIT_MEDIAN' => array( 1176.378, 1502.362), // = ( 415 x 530 ) mm = ( 16.34 x 20.87 ) in
429 'BE_RUCHE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
430 'BE_PROPATRIA' => array( 977.953, 1218.898), // = ( 345 x 430 ) mm = ( 13.58 x 16.93 ) in
431 'BE_LYS' => array( 898.583, 1125.354), // = ( 317 x 397 ) mm = ( 12.48 x 15.63 ) in
432 'BE_POT' => array( 870.236, 1088.504), // = ( 307 x 384 ) mm = ( 12.09 x 15.12 ) in
433 'BE_ROSETTE' => array( 765.354, 983.622), // = ( 270 x 347 ) mm = ( 10.63 x 13.66 ) in
434 // - Old Imperial French Sizes
435 'FR_UNIVERS' => array( 2834.646, 3685.039), // = ( 1000 x 1300 ) mm = ( 39.37 x 51.18 ) in
436 'FR_DOUBLE_COLOMBIER' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
437 'FR_GRANDE_MONDE' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
438 'FR_DOUBLE_SOLEIL' => array( 2267.717, 3401.575), // = ( 800 x 1200 ) mm = ( 31.50 x 47.24 ) in
439 'FR_DOUBLE_JESUS' => array( 2154.331, 3174.803), // = ( 760 x 1120 ) mm = ( 29.92 x 44.09 ) in
440 'FR_GRAND_AIGLE' => array( 2125.984, 3004.724), // = ( 750 x 1060 ) mm = ( 29.53 x 41.73 ) in
441 'FR_PETIT_AIGLE' => array( 1984.252, 2664.567), // = ( 700 x 940 ) mm = ( 27.56 x 37.01 ) in
442 'FR_DOUBLE_RAISIN' => array( 1842.520, 2834.646), // = ( 650 x 1000 ) mm = ( 25.59 x 39.37 ) in
443 'FR_JOURNAL' => array( 1842.520, 2664.567), // = ( 650 x 940 ) mm = ( 25.59 x 37.01 ) in
444 'FR_COLOMBIER_AFFICHE' => array( 1785.827, 2551.181), // = ( 630 x 900 ) mm = ( 24.80 x 35.43 ) in
445 'FR_DOUBLE_CAVALIER' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
446 'FR_CLOCHE' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
447 'FR_SOLEIL' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
448 'FR_DOUBLE_CARRE' => array( 1587.402, 2551.181), // = ( 560 x 900 ) mm = ( 22.05 x 35.43 ) in
449 'FR_DOUBLE_COQUILLE' => array( 1587.402, 2494.488), // = ( 560 x 880 ) mm = ( 22.05 x 34.65 ) in
450 'FR_JESUS' => array( 1587.402, 2154.331), // = ( 560 x 760 ) mm = ( 22.05 x 29.92 ) in
451 'FR_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
452 'FR_CAVALIER' => array( 1303.937, 1757.480), // = ( 460 x 620 ) mm = ( 18.11 x 24.41 ) in
453 'FR_DOUBLE_COURONNE' => array( 1303.937, 2040.945), // = ( 460 x 720 ) mm = ( 18.11 x 28.35 ) in
454 'FR_CARRE' => array( 1275.591, 1587.402), // = ( 450 x 560 ) mm = ( 17.72 x 22.05 ) in
455 'FR_COQUILLE' => array( 1247.244, 1587.402), // = ( 440 x 560 ) mm = ( 17.32 x 22.05 ) in
456 'FR_DOUBLE_TELLIERE' => array( 1247.244, 1927.559), // = ( 440 x 680 ) mm = ( 17.32 x 26.77 ) in
457 'FR_DOUBLE_CLOCHE' => array( 1133.858, 1700.787), // = ( 400 x 600 ) mm = ( 15.75 x 23.62 ) in
458 'FR_DOUBLE_POT' => array( 1133.858, 1757.480), // = ( 400 x 620 ) mm = ( 15.75 x 24.41 ) in
459 'FR_ECU' => array( 1133.858, 1474.016), // = ( 400 x 520 ) mm = ( 15.75 x 20.47 ) in
460 'FR_COURONNE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
461 'FR_TELLIERE' => array( 963.780, 1247.244), // = ( 340 x 440 ) mm = ( 13.39 x 17.32 ) in
462 'FR_POT' => array( 878.740, 1133.858), // = ( 310 x 400 ) mm = ( 12.20 x 15.75 ) in
465 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
468 * Return the current TCPDF version.
469 * @return TCPDF version string
470 * @since 5.9.012 (2010-11-10)
473 public static function getTCPDFVersion() {
474 return self
::$tcpdf_version;
478 * Return the current TCPDF producer.
479 * @return TCPDF producer string
480 * @since 6.0.000 (2013-03-16)
483 public static function getTCPDFProducer() {
484 return "\x54\x43\x50\x44\x46\x20".self
::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
488 * Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
489 * @param $mqr (boolean) FALSE for off, TRUE for on.
490 * @since 4.6.025 (2009-08-17)
493 public static function set_mqr($mqr) {
494 if (!defined('PHP_VERSION_ID')) {
495 $version = PHP_VERSION
;
496 define('PHP_VERSION_ID', (($version[0] * 10000) +
($version[2] * 100) +
$version[4]));
498 if (PHP_VERSION_ID
< 50300) {
499 @set_magic_quotes_runtime
($mqr);
504 * Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
505 * @return Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
506 * @since 4.6.025 (2009-08-17)
509 public static function get_mqr() {
510 if (!defined('PHP_VERSION_ID')) {
511 $version = PHP_VERSION
;
512 define('PHP_VERSION_ID', (($version[0] * 10000) +
($version[2] * 100) +
$version[4]));
514 if (PHP_VERSION_ID
< 50300) {
515 return @get_magic_quotes_runtime
();
521 * Get page dimensions from format name.
522 * @param $format (mixed) The format name @see self::$page_format<ul>
523 * @return array containing page width and height in points
524 * @since 5.0.010 (2010-05-17)
527 public static function getPageSizeFromFormat($format) {
528 if (isset(self
::$page_formats[$format])) {
529 return self
::$page_formats[$format];
531 return self
::$page_formats['A4'];
535 * Set page boundaries.
536 * @param $page (int) page number
537 * @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>
538 * @param $llx (float) lower-left x coordinate in user units.
539 * @param $lly (float) lower-left y coordinate in user units.
540 * @param $urx (float) upper-right x coordinate in user units.
541 * @param $ury (float) upper-right y coordinate in user units.
542 * @param $points (boolean) If true uses user units as unit of measure, otherwise uses PDF points.
543 * @param $k (float) Scale factor (number of points in user unit).
544 * @param $pagedim (array) Array of page dimensions.
545 * @return pagedim array of page dimensions.
546 * @since 5.0.010 (2010-05-17)
549 public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false, $k, $pagedim=array()) {
550 if (!isset($pagedim[$page])) {
552 $pagedim[$page] = array();
554 if (!in_array($type, self
::$pageboxes)) {
560 $pagedim[$page][$type]['llx'] = ($llx * $k);
561 $pagedim[$page][$type]['lly'] = ($lly * $k);
562 $pagedim[$page][$type]['urx'] = ($urx * $k);
563 $pagedim[$page][$type]['ury'] = ($ury * $k);
568 * Swap X and Y coordinates of page boxes (change page boxes orientation).
569 * @param $page (int) page number
570 * @param $pagedim (array) Array of page dimensions.
571 * @return pagedim array of page dimensions.
572 * @since 5.0.010 (2010-05-17)
575 public static function swapPageBoxCoordinates($page, $pagedim) {
576 foreach (self
::$pageboxes as $type) {
577 // swap X and Y coordinates
578 if (isset($pagedim[$page][$type])) {
579 $tmp = $pagedim[$page][$type]['llx'];
580 $pagedim[$page][$type]['llx'] = $pagedim[$page][$type]['lly'];
581 $pagedim[$page][$type]['lly'] = $tmp;
582 $tmp = $pagedim[$page][$type]['urx'];
583 $pagedim[$page][$type]['urx'] = $pagedim[$page][$type]['ury'];
584 $pagedim[$page][$type]['ury'] = $tmp;
591 * Get the canonical page layout mode.
592 * @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>
593 * @return (string) Canonical page layout name.
596 public static function getPageLayoutMode($layout='SinglePage') {
601 $layout_mode = 'SinglePage';
606 $layout_mode = 'OneColumn';
610 case 'TwoColumnLeft': {
611 $layout_mode = 'TwoColumnLeft';
614 case 'TwoColumnRight': {
615 $layout_mode = 'TwoColumnRight';
618 case 'TwoPageLeft': {
619 $layout_mode = 'TwoPageLeft';
622 case 'TwoPageRight': {
623 $layout_mode = 'TwoPageRight';
627 $layout_mode = 'SinglePage';
634 * Get the canonical page layout mode.
635 * @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>
636 * @return (string) Canonical page mode name.
639 public static function getPageMode($mode='UseNone') {
642 $page_mode = 'UseNone';
645 case 'UseOutlines': {
646 $page_mode = 'UseOutlines';
650 $page_mode = 'UseThumbs';
654 $page_mode = 'FullScreen';
658 $page_mode = 'UseOC';
662 $page_mode = 'UseAttachments';
666 $page_mode = 'UseNone';
673 * Check if the URL exist.
674 * @param $url (string) URL to check.
675 * @return Boolean true if the URl exist, false otherwise.
676 * @since 5.9.204 (2013-01-28)
679 public static function isValidURL($url) {
680 $headers = @get_headers
($url);
681 return (strpos($headers[0], '200') !== false);
685 * Removes SHY characters from text.
687 * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
688 * <li>HTML Entity (decimal): "&#173;"</li>
689 * <li>HTML Entity (hex): "&#xad;"</li>
690 * <li>HTML Entity (named): "&shy;"</li>
691 * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
692 * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
693 * <li>UTF-8 character: chr(194).chr(173)</li>
695 * @param $txt (string) input string
696 * @param $unicode (boolean) True if we are in unicode mode, false otherwise.
697 * @return string without SHY characters.
698 * @since (4.5.019) 2009-02-28
701 public static function removeSHY($txt='', $unicode=true) {
702 $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
704 $txt = preg_replace('/([\\xad]{1})/', '', $txt);
711 * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
712 * @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)))
713 * @param $position (string) multicell position: 'start', 'middle', 'end'
714 * @param $opencell (boolean) True when the cell is left open at the page bottom, false otherwise.
715 * @return border mode array
716 * @since 4.4.002 (2008-12-09)
719 public static function getBorderMode($brd, $position='start', $opencell=true) {
720 if ((!$opencell) OR empty($brd)) {
726 if (is_string($brd)) {
727 // convert string to array
728 $slen = strlen($brd);
730 for ($i = 0; $i < $slen; ++
$i) {
731 $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
735 foreach ($brd as $border => $style) {
738 if (strpos($border, 'B') !== false) {
739 // remove bottom line
740 $newkey = str_replace('B', '', $border);
741 if (strlen($newkey) > 0) {
742 $brd[$newkey] = $style;
744 unset($brd[$border]);
749 if (strpos($border, 'B') !== false) {
750 // remove bottom line
751 $newkey = str_replace('B', '', $border);
752 if (strlen($newkey) > 0) {
753 $brd[$newkey] = $style;
755 unset($brd[$border]);
758 if (strpos($border, 'T') !== false) {
759 // remove bottom line
760 $newkey = str_replace('T', '', $border);
761 if (strlen($newkey) > 0) {
762 $brd[$newkey] = $style;
764 unset($brd[$border]);
769 if (strpos($border, 'T') !== false) {
770 // remove bottom line
771 $newkey = str_replace('T', '', $border);
772 if (strlen($newkey) > 0) {
773 $brd[$newkey] = $style;
775 unset($brd[$border]);
785 * Determine whether a string is empty.
786 * @param $str (string) string to be checked
787 * @return boolean true if string is empty
788 * @since 4.5.044 (2009-04-16)
791 public static function empty_string($str) {
792 return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
796 * Returns a temporary filename for caching object on filesystem.
797 * @param $type (string) Type of file (name of the subdir on the tcpdf cache folder).
798 * @param $file_id (string) TCPDF file_id.
799 * @return string filename.
800 * @since 4.5.000 (2008-12-31)
803 public static function getObjFilename($type='tmp', $file_id='') {
804 return tempnam(K_PATH_CACHE
, '__tcpdf_'.$file_id.'_'.$type.'_'.md5(TCPDF_STATIC
::getRandomSeed()).'_');
808 * Add "\" before "\", "(" and ")"
809 * @param $s (string) string to escape.
810 * @return string escaped string.
813 public static function _escape($s) {
814 // the chr(13) substitution fixes the Bugs item #1421290.
815 return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
819 * Escape some special characters (< > &) for XML output.
820 * @param $str (string) Input string to convert.
821 * @return converted string
822 * @since 5.9.121 (2011-09-28)
825 public static function _escapeXML($str) {
826 $replaceTable = array("\0" => '', '&' => '&', '<' => '<', '>' => '>');
827 $str = strtr($str, $replaceTable);
832 * Creates a copy of a class object
833 * @param $object (object) class object to be cloned
834 * @return cloned object
835 * @since 4.5.029 (2009-03-19)
838 public static function objclone($object) {
839 if (($object instanceof Imagick
) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) {
840 // on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword
841 return @$object->clone();
843 return @clone
($object);
847 * Output input data and compress it if possible.
848 * @param $data (string) Data to output.
849 * @param $length (int) Data length in bytes.
853 public static function sendOutputData($data, $length) {
854 if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
855 // the content length may vary if the server is using compression
856 header('Content-Length: '.$length);
862 * Replace page number aliases with number.
863 * @param $page (string) Page content.
864 * @param $replace (array) Array of replacements (array keys are replacement strings, values are alias arrays).
865 * @param $diff (int) If passed, this will be set to the total char number difference between alias and replacements.
866 * @return replaced page content and updated $diff parameter as array.
869 public static function replacePageNumAliases($page, $replace, $diff=0) {
870 foreach ($replace as $rep) {
871 foreach ($rep[3] as $a) {
872 if (strpos($page, $a) !== false) {
873 $page = str_replace($a, $rep[0], $page);
874 $diff +
= ($rep[2] - $rep[1]);
878 return array($page, $diff);
882 * Returns timestamp in seconds from formatted date-time.
883 * @param $date (string) Formatted date-time.
884 * @return int seconds.
885 * @since 5.9.152 (2012-03-23)
888 public static function getTimestamp($date) {
889 if (($date[0] == 'D') AND ($date[1] == ':')) {
890 // remove date prefix if present
891 $date = substr($date, 2);
893 return strtotime($date);
897 * Returns a formatted date-time.
898 * @param $time (int) Time in seconds.
899 * @return string escaped date string.
900 * @since 5.9.152 (2012-03-23)
903 public static function getFormattedDate($time) {
904 return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
908 * Get ULONG from string (Big Endian 32-bit unsigned integer).
909 * @param $str (string) string from where to extract value
910 * @param $offset (int) point from where to read the data
911 * @return int 32 bit value
912 * @author Nicola Asuni
913 * @since 5.2.000 (2010-06-02)
916 public static function _getULONG($str, $offset) {
917 $v = unpack('Ni', substr($str, $offset, 4));
922 * Get USHORT from string (Big Endian 16-bit unsigned integer).
923 * @param $str (string) string from where to extract value
924 * @param $offset (int) point from where to read the data
925 * @return int 16 bit value
926 * @author Nicola Asuni
927 * @since 5.2.000 (2010-06-02)
930 public static function _getUSHORT($str, $offset) {
931 $v = unpack('ni', substr($str, $offset, 2));
936 * Get SHORT from string (Big Endian 16-bit signed integer).
937 * @param $str (string) String from where to extract value.
938 * @param $offset (int) Point from where to read the data.
939 * @return int 16 bit value
940 * @author Nicola Asuni
941 * @since 5.2.000 (2010-06-02)
944 public static function _getSHORT($str, $offset) {
945 $v = unpack('si', substr($str, $offset, 2));
950 * Get FWORD from string (Big Endian 16-bit signed integer).
951 * @param $str (string) String from where to extract value.
952 * @param $offset (int) Point from where to read the data.
953 * @return int 16 bit value
954 * @author Nicola Asuni
955 * @since 5.9.123 (2011-09-30)
958 public static function _getFWORD($str, $offset) {
959 $v = self
::_getUSHORT($str, $offset);
967 * Get UFWORD from string (Big Endian 16-bit unsigned integer).
968 * @param $str (string) string from where to extract value
969 * @param $offset (int) point from where to read the data
970 * @return int 16 bit value
971 * @author Nicola Asuni
972 * @since 5.9.123 (2011-09-30)
975 public static function _getUFWORD($str, $offset) {
976 $v = self
::_getUSHORT($str, $offset);
981 * Get FIXED from string (32-bit signed fixed-point number (16.16).
982 * @param $str (string) string from where to extract value
983 * @param $offset (int) point from where to read the data
984 * @return int 16 bit value
985 * @author Nicola Asuni
986 * @since 5.9.123 (2011-09-30)
989 public static function _getFIXED($str, $offset) {
991 $m = self
::_getFWORD($str, $offset);
993 $f = self
::_getUSHORT($str, ($offset +
2));
994 $v = floatval(''.$m.'.'.$f.'');
999 * Get BYTE from string (8-bit unsigned integer).
1000 * @param $str (string) String from where to extract value.
1001 * @param $offset (int) Point from where to read the data.
1002 * @return int 8 bit value
1003 * @author Nicola Asuni
1004 * @since 5.2.000 (2010-06-02)
1007 public static function _getBYTE($str, $offset) {
1008 $v = unpack('Ci', substr($str, $offset, 1));
1012 * Binary-safe and URL-safe file read.
1013 * 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.
1014 * @param $handle (resource)
1015 * @param $length (int)
1016 * @return Returns the read string or FALSE in case of error.
1017 * @author Nicola Asuni
1018 * @since 4.5.027 (2009-03-16)
1021 public static function rfread($handle, $length) {
1022 $data = fread($handle, $length);
1023 if ($data === false) {
1026 $rest = ($length - strlen($data));
1028 $data .= self
::rfread($handle, $rest);
1034 * Read a 4-byte (32 bit) integer from file.
1035 * @param $f (string) file name.
1036 * @return 4-byte integer
1039 public static function _freadint($f) {
1040 $a = unpack('Ni', fread($f, 4));
1045 * Returns a string containing random data to be used as a seed for encryption methods.
1046 * @param $seed (string) starting seed value
1047 * @return string containing random data
1048 * @author Nicola Asuni
1049 * @since 5.9.006 (2010-10-19)
1052 public static function getRandomSeed($seed='') {
1053 $rnd = uniqid(rand().microtime(true), true);
1054 if (function_exists('posix_getpid')) {
1055 $rnd .= posix_getpid();
1057 if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS
, 0, 3)) !== 'WIN')) {
1058 // this is not used on windows systems because it is very slow for a know bug
1059 $rnd .= openssl_random_pseudo_bytes(512);
1061 for ($i = 0; $i < 23; ++
$i) {
1062 $rnd .= uniqid('', true);
1065 return $rnd.$seed.__FILE__
.serialize($_SERVER).microtime(true);
1069 * Encrypts a string using MD5 and returns it's value as a binary string.
1070 * @param $str (string) input string
1071 * @return String MD5 encrypted binary string
1072 * @since 2.0.000 (2008-01-02)
1075 public static function _md5_16($str) {
1076 return pack('H*', md5($str));
1080 * Returns the input text exrypted using AES algorithm and the specified key.
1081 * This method requires mcrypt.
1082 * @param $key (string) encryption key
1083 * @param $text (String) input text to be encrypted
1084 * @return String encrypted text
1085 * @author Nicola Asuni
1086 * @since 5.0.005 (2010-05-11)
1089 public static function _AES($key, $text) {
1090 // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
1091 $padding = 16 - (strlen($text) %
16);
1092 $text .= str_repeat(chr($padding), $padding);
1093 $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128
, MCRYPT_MODE_CBC
), MCRYPT_RAND
);
1094 $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128
, $key, $text, MCRYPT_MODE_CBC
, $iv);
1100 * Returns the input text encrypted using RC4 algorithm and the specified key.
1101 * RC4 is the standard encryption algorithm used in PDF format
1102 * @param $key (string) Encryption key.
1103 * @param $text (String) Input text to be encrypted.
1104 * @param $last_enc_key (String) Reference to last RC4 key encrypted.
1105 * @param $last_enc_key_c (String) Reference to last RC4 computed key.
1106 * @return String encrypted text
1107 * @since 2.0.000 (2008-01-02)
1108 * @author Klemen Vodopivec, Nicola Asuni
1111 public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) {
1112 if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt
(MCRYPT_ARCFOUR
, $key, $text, MCRYPT_MODE_STREAM
, ''))) {
1113 // try to use mcrypt function if exist
1116 if ($last_enc_key != $key) {
1117 $k = str_repeat($key, ((256 / strlen($key)) +
1));
1118 $rc4 = range(0, 255);
1120 for ($i = 0; $i < 256; ++
$i) {
1122 $j = ($j +
$t +
ord($k[$i])) %
256;
1123 $rc4[$i] = $rc4[$j];
1126 $last_enc_key = $key;
1127 $last_enc_key_c = $rc4;
1129 $rc4 = $last_enc_key_c;
1131 $len = strlen($text);
1135 for ($i = 0; $i < $len; ++
$i) {
1136 $a = ($a +
1) %
256;
1138 $b = ($b +
$t) %
256;
1139 $rc4[$a] = $rc4[$b];
1141 $k = $rc4[($rc4[$a] +
$rc4[$b]) %
256];
1142 $out .= chr(ord($text[$i]) ^
$k);
1148 * Return the permission code used on encryption (P value).
1149 * @param $permissions (Array) the set of permissions (specify the ones you want to block).
1150 * @param $mode (int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
1151 * @since 5.0.005 (2010-05-12)
1152 * @author Nicola Asuni
1155 public static function getUserPermissionCode($permissions, $mode=0) {
1157 'owner' => 2, // bit 2 -- inverted logic: cleared by default
1158 'print' => 4, // bit 3
1159 'modify' => 8, // bit 4
1160 'copy' => 16, // bit 5
1161 'annot-forms' => 32, // bit 6
1162 'fill-forms' => 256, // bit 9
1163 'extract' => 512, // bit 10
1164 'assemble' => 1024,// bit 11
1165 'print-high' => 2048 // bit 12
1167 $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
1168 foreach ($permissions as $permission) {
1169 if (isset($options[$permission])) {
1170 if (($mode > 0) OR ($options[$permission] <= 32)) {
1171 // set only valid permissions
1172 if ($options[$permission] == 2) {
1173 // the logic for bit 2 is inverted (cleared by default)
1174 $protection +
= $options[$permission];
1176 $protection -= $options[$permission];
1185 * Convert hexadecimal string to string
1186 * @param $bs (string) byte-string to convert
1188 * @since 5.0.005 (2010-05-12)
1189 * @author Nicola Asuni
1192 public static function convertHexStringToString($bs) {
1193 $string = ''; // string to be returned
1194 $bslength = strlen($bs);
1195 if (($bslength %
2) != 0) {
1200 for ($i = 0; $i < $bslength; $i +
= 2) {
1201 $string .= chr(hexdec($bs[$i].$bs[($i +
1)]));
1207 * Convert string to hexadecimal string (byte string)
1208 * @param $s (string) string to convert
1209 * @return byte string
1210 * @since 5.0.010 (2010-05-17)
1211 * @author Nicola Asuni
1214 public static function convertStringToHexString($s) {
1216 $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY
);
1217 foreach ($chars as $c) {
1218 $bs .= sprintf('%02s', dechex(ord($c)));
1224 * Convert encryption P value to a string of bytes, low-order byte first.
1225 * @param $protection (string) 32bit encryption permission value (P value)
1227 * @since 5.0.005 (2010-05-12)
1228 * @author Nicola Asuni
1231 public static function getEncPermissionsString($protection) {
1232 $binprot = sprintf('%032b', $protection);
1233 $str = chr(bindec(substr($binprot, 24, 8)));
1234 $str .= chr(bindec(substr($binprot, 16, 8)));
1235 $str .= chr(bindec(substr($binprot, 8, 8)));
1236 $str .= chr(bindec(substr($binprot, 0, 8)));
1241 * Encode a name object.
1242 * @param $name (string) Name object to encode.
1243 * @return (string) Encoded name object.
1244 * @author Nicola Asuni
1245 * @since 5.9.097 (2011-06-23)
1248 public static function encodeNameObject($name) {
1250 $length = strlen($name);
1251 for ($i = 0; $i < $length; ++
$i) {
1253 if (preg_match('/[0-9a-zA-Z#_=-]/', $chr) == 1) {
1256 $escname .= sprintf('#%02X', ord($chr));
1263 * Convert JavaScript form fields properties array to Annotation Properties array.
1264 * @param $prop (array) javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
1265 * @param $spot_colors (array) Reference to spot colors array.
1266 * @param $rtl (boolean) True if in Right-To-Left text direction mode, false otherwise.
1267 * @return array of annotation properties
1268 * @author Nicola Asuni
1269 * @since 4.8.000 (2009-09-06)
1272 public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) {
1273 if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
1274 // the annotation options area lready defined
1275 return $prop['aopt'];
1277 $opt = array(); // value to be returned
1278 // alignment: Controls how the text is laid out within the text field.
1279 if (isset($prop['alignment'])) {
1280 switch ($prop['alignment']) {
1294 $opt['q'] = ($rtl)?
2:0;
1299 // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
1300 if (isset($prop['lineWidth'])) {
1301 $linewidth = intval($prop['lineWidth']);
1305 // borderStyle: The border style for a field.
1306 if (isset($prop['borderStyle'])) {
1307 switch ($prop['borderStyle']) {
1310 $opt['border'] = array(0, 0, $linewidth, array(3, 2));
1311 $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
1316 $opt['border'] = array(0, 0, $linewidth);
1317 $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
1322 $opt['border'] = array(0, 0, $linewidth);
1323 $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
1328 $opt['border'] = array(0, 0, $linewidth);
1329 $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
1334 $opt['border'] = array(0, 0, $linewidth);
1335 $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
1343 if (isset($prop['border']) AND is_array($prop['border'])) {
1344 $opt['border'] = $prop['border'];
1346 if (!isset($opt['mk'])) {
1347 $opt['mk'] = array();
1349 if (!isset($opt['mk']['if'])) {
1350 $opt['mk']['if'] = array();
1352 $opt['mk']['if']['a'] = array(0.5, 0.5);
1353 // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
1354 if (isset($prop['buttonAlignX'])) {
1355 $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
1357 // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
1358 if (isset($prop['buttonAlignY'])) {
1359 $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
1361 // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
1362 if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
1363 $opt['mk']['if']['fb'] = true;
1365 // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
1366 if (isset($prop['buttonScaleHow'])) {
1367 switch ($prop['buttonScaleHow']) {
1368 case 'scaleHow.proportional': {
1369 $opt['mk']['if']['s'] = 'P';
1372 case 'scaleHow.anamorphic': {
1373 $opt['mk']['if']['s'] = 'A';
1378 // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
1379 if (isset($prop['buttonScaleWhen'])) {
1380 switch ($prop['buttonScaleWhen']) {
1381 case 'scaleWhen.always': {
1382 $opt['mk']['if']['sw'] = 'A';
1385 case 'scaleWhen.never': {
1386 $opt['mk']['if']['sw'] = 'N';
1389 case 'scaleWhen.tooBig': {
1390 $opt['mk']['if']['sw'] = 'B';
1393 case 'scaleWhen.tooSmall': {
1394 $opt['mk']['if']['sw'] = 'S';
1399 // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
1400 if (isset($prop['buttonPosition'])) {
1401 switch ($prop['buttonPosition']) {
1403 case 'position.textOnly': {
1404 $opt['mk']['tp'] = 0;
1408 case 'position.iconOnly': {
1409 $opt['mk']['tp'] = 1;
1413 case 'position.iconTextV': {
1414 $opt['mk']['tp'] = 2;
1418 case 'position.textIconV': {
1419 $opt['mk']['tp'] = 3;
1423 case 'position.iconTextH': {
1424 $opt['mk']['tp'] = 4;
1428 case 'position.textIconH': {
1429 $opt['mk']['tp'] = 5;
1433 case 'position.overlay': {
1434 $opt['mk']['tp'] = 6;
1439 // fillColor: Specifies the background color for a field.
1440 if (isset($prop['fillColor'])) {
1441 if (is_array($prop['fillColor'])) {
1442 $opt['mk']['bg'] = $prop['fillColor'];
1444 $opt['mk']['bg'] = TCPDF_COLORS
::convertHTMLColorToDec($prop['fillColor'], $spot_colors);
1447 // 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.
1448 if (isset($prop['strokeColor'])) {
1449 if (is_array($prop['strokeColor'])) {
1450 $opt['mk']['bc'] = $prop['strokeColor'];
1452 $opt['mk']['bc'] = TCPDF_COLORS
::convertHTMLColorToDec($prop['strokeColor'], $spot_colors);
1455 // rotation: The rotation of a widget in counterclockwise increments.
1456 if (isset($prop['rotation'])) {
1457 $opt['mk']['r'] = $prop['rotation'];
1459 // charLimit: Limits the number of characters that a user can type into a text field.
1460 if (isset($prop['charLimit'])) {
1461 $opt['maxlen'] = intval($prop['charLimit']);
1464 $ff = 0; // default value
1466 // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
1467 if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
1470 // required: Specifies whether a field requires a value.
1471 if (isset($prop['required']) AND ($prop['required'] == 'true')) {
1474 // multiline: Controls how text is wrapped within the field.
1475 if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
1478 // password: Specifies whether the field should display asterisks when data is entered in the field.
1479 if (isset($prop['password']) AND ($prop['password'] == 'true')) {
1482 // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
1483 if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
1486 // Radio: If set, the field is a set of radio buttons.
1487 if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
1490 // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
1491 if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
1494 // Combo: If set, the field is a combo box; if clear, the field is a list box.
1495 if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
1498 // editable: Controls whether a combo box is editable.
1499 if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
1502 // Sort: If set, the field's option items shall be sorted alphabetically.
1503 if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
1506 // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
1507 if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
1510 // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
1511 if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
1514 // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
1515 if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
1518 // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
1519 if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
1522 // 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.
1523 if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
1526 // 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.
1527 if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
1530 // richText: If true, the field allows rich text formatting.
1531 if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
1534 // commitOnSelChange: Controls whether a field value is committed after a selection change.
1535 if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
1539 // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
1540 if (isset($prop['defaultValue'])) {
1541 $opt['dv'] = $prop['defaultValue'];
1543 $f = 4; // default value for annotation flags
1544 // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
1545 if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
1548 // display: Controls whether the field is hidden or visible on screen and in print.
1549 if (isset($prop['display'])) {
1550 if ($prop['display'] == 'display.visible') {
1552 } elseif ($prop['display'] == 'display.hidden') {
1554 } elseif ($prop['display'] == 'display.noPrint') {
1556 } elseif ($prop['display'] == 'display.noView') {
1561 // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
1562 if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
1563 $opt['i'] = $prop['currentValueIndices'];
1565 // value: The value of the field data that the user has entered.
1566 if (isset($prop['value'])) {
1567 if (is_array($prop['value'])) {
1568 $opt['opt'] = array();
1569 foreach ($prop['value'] AS $key => $optval) {
1570 // exportValues: An array of strings representing the export values for the field.
1571 if (isset($prop['exportValues'][$key])) {
1572 $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
1574 $opt['opt'][$key] = $prop['value'][$key];
1578 $opt['v'] = $prop['value'];
1581 // richValue: This property specifies the text contents and formatting of a rich text field.
1582 if (isset($prop['richValue'])) {
1583 $opt['rv'] = $prop['richValue'];
1585 // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
1586 if (isset($prop['submitName'])) {
1587 $opt['tm'] = $prop['submitName'];
1589 // name: Fully qualified field name.
1590 if (isset($prop['name'])) {
1591 $opt['t'] = $prop['name'];
1593 // userName: The user name (short description string) of the field.
1594 if (isset($prop['userName'])) {
1595 $opt['tu'] = $prop['userName'];
1597 // highlight: Defines how a button reacts when a user clicks it.
1598 if (isset($prop['highlight'])) {
1599 switch ($prop['highlight']) {
1601 case 'highlight.n': {
1606 case 'highlight.i': {
1611 case 'highlight.p': {
1616 case 'highlight.o': {
1622 // Unsupported options:
1623 // - calcOrderIndex: Changes the calculation order of fields in the document.
1624 // - delay: Delays the redrawing of a field's appearance.
1625 // - defaultStyle: This property defines the default style attributes for the form field.
1626 // - style: Allows the user to set the glyph style of a check box or radio button.
1627 // - textColor, textFont, textSize
1632 * Format the page numbers.
1633 * This method can be overriden for custom formats.
1634 * @param $num (int) page number
1635 * @since 4.2.005 (2008-11-06)
1638 public static function formatPageNumber($num) {
1639 return number_format((float)$num, 0, '', '.');
1643 * Format the page numbers on the Table Of Content.
1644 * This method can be overriden for custom formats.
1645 * @param $num (int) page number
1646 * @since 4.5.001 (2009-01-04)
1647 * @see addTOC(), addHTMLTOC()
1650 public static function formatTOCPageNumber($num) {
1651 return number_format((float)$num, 0, '', '.');
1655 * Extracts the CSS properties from a CSS string.
1656 * @param $cssdata (string) string containing CSS definitions.
1657 * @return An array where the keys are the CSS selectors and the values are the CSS properties.
1658 * @author Nicola Asuni
1659 * @since 5.1.000 (2010-05-25)
1662 public static function extractCSSproperties($cssdata) {
1663 if (empty($cssdata)) {
1667 $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
1668 // remove newlines and multiple spaces
1669 $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
1670 // remove some spaces
1671 $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
1672 // remove empty blocks
1673 $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
1674 // replace media type parenthesis
1675 $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
1676 $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
1678 $cssdata = trim($cssdata);
1679 // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
1680 $cssblocks = array();
1682 if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
1683 foreach ($matches[1] as $key => $type) {
1684 $cssblocks[$type] = $matches[2][$key];
1686 // remove media blocks
1687 $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
1689 // keep 'all' and 'print' media, other media types are discarded
1690 if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
1691 $cssdata .= $cssblocks['all'];
1693 if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
1694 $cssdata .= $cssblocks['print'];
1696 // reset css blocks array
1697 $cssblocks = array();
1699 // explode css data string into array
1700 if (substr($cssdata, -1) == '}') {
1701 // remove last parethesis
1702 $cssdata = substr($cssdata, 0, -1);
1704 $matches = explode('}', $cssdata);
1705 foreach ($matches as $key => $block) {
1706 // index 0 contains the CSS selector, index 1 contains CSS properties
1707 $cssblocks[$key] = explode('{', $block);
1708 if (!isset($cssblocks[$key][1])) {
1709 // remove empty definitions
1710 unset($cssblocks[$key]);
1713 // split groups of selectors (comma-separated list of selectors)
1714 foreach ($cssblocks as $key => $block) {
1715 if (strpos($block[0], ',') > 0) {
1716 $selectors = explode(',', $block[0]);
1717 foreach ($selectors as $sel) {
1718 $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
1720 unset($cssblocks[$key]);
1723 // covert array to selector => properties
1725 foreach ($cssblocks as $block) {
1726 $selector = $block[0];
1727 // calculate selector's specificity
1729 $a = 0; // the declaration is not from is a 'style' attribute
1730 $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
1731 $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
1732 $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
1733 $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names
1734 $d +
= intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
1735 $specificity = $a.$b.$c.$d;
1736 // add specificity to the beginning of the selector
1737 $cssdata[$specificity.' '.$selector] = $block[1];
1739 // sort selectors alphabetically to account for specificity
1740 ksort($cssdata, SORT_STRING
);
1746 * Cleanup HTML code (requires HTML Tidy library).
1747 * @param $html (string) htmlcode to fix
1748 * @param $default_css (string) CSS commands to add
1749 * @param $tagvs (array) parameters for setHtmlVSpace method
1750 * @param $tidy_options (array) options for tidy_parse_string function
1751 * @param $tagvspaces (array) Array of vertical spaces for tags.
1752 * @return string XHTML code cleaned up
1753 * @author Nicola Asuni
1754 * @since 5.9.017 (2010-11-16)
1755 * @see setHtmlVSpace()
1758 public static function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='', &$tagvspaces) {
1759 // configure parameters for HTML Tidy
1760 if ($tidy_options === '') {
1761 $tidy_options = array (
1763 'drop-empty-paras' => 0,
1764 'drop-proprietary-attributes' => 1,
1765 'fix-backslash' => 1,
1766 'hide-comments' => 1,
1768 'lower-literals' => 1,
1771 'output-xhtml' => 1,
1775 //'char-encoding' => 'utf8',
1776 //'input-encoding' => 'utf8',
1777 //'output-encoding' => 'utf8'
1780 // clean up the HTML code
1781 $tidy = tidy_parse_string($html, $tidy_options);
1783 $tidy->cleanRepair();
1785 $tidy_head = tidy_get_head($tidy);
1786 $css = $tidy_head->value
;
1787 $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
1788 $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
1789 $css = str_replace('/*<![CDATA[*/', '', $css);
1790 $css = str_replace('/*]]>*/', '', $css);
1791 preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
1792 if (isset($matches[1])) {
1793 $css = strtolower($matches[1]);
1797 // include default css
1798 $css = '<style>'.$default_css.$css.'</style>';
1799 // get the body part
1800 $tidy_body = tidy_get_body($tidy);
1801 $html = $tidy_body->value
;
1802 // fix some self-closing tags
1803 $html = str_replace('<br>', '<br />', $html);
1804 // remove some empty tag blocks
1805 $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
1806 $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
1807 if ($tagvs !== '') {
1808 // set vertical space for some XHTML tags
1809 $tagvspaces = $tagvs;
1811 // return the cleaned XHTML code + CSS
1816 * Returns true if the CSS selector is valid for the selected HTML tag
1817 * @param $dom (array) array of HTML tags and properties
1818 * @param $key (int) key of the current HTML tag
1819 * @param $selector (string) CSS selector string
1820 * @return true if the selector is valid, false otherwise
1821 * @since 5.1.000 (2010-05-25)
1824 public static function isValidCSSSelectorForTag($dom, $key, $selector) {
1825 $valid = false; // value to be returned
1826 $tag = $dom[$key]['value'];
1828 if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
1829 $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
1832 if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
1833 $id = strtolower($dom[$key]['attribute']['id']);
1835 $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
1837 if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE
) > 0) {
1838 $parentop = array_pop($matches[1]);
1839 $operator = $parentop[0];
1840 $offset = $parentop[1];
1841 $lasttag = array_pop($matches[2]);
1842 $lasttag = strtolower(trim($lasttag[0]));
1843 if (($lasttag == '*') OR ($lasttag == $tag)) {
1844 // the last element on selector is our tag or 'any tag'
1845 $attrib = array_pop($matches[3]);
1846 $attrib = strtolower(trim($attrib[0]));
1847 if (!empty($attrib)) {
1848 // check if matches class, id, attribute, pseudo-class or pseudo-element
1849 switch ($attrib[0]) {
1850 case '.': { // class
1851 if (in_array(substr($attrib, 1), $class)) {
1857 if (substr($attrib, 1) == $id) {
1862 case '[': { // attribute
1863 $attrmatch = array();
1864 if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
1865 $att = strtolower($attrmatch[1]);
1866 $val = $attrmatch[3];
1867 if (isset($dom[$key]['attribute'][$att])) {
1868 switch ($attrmatch[2]) {
1870 if ($dom[$key]['attribute'][$att] == $val) {
1876 if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
1882 if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
1888 if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
1894 if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
1900 if ($dom[$key]['attribute'][$att] == $val) {
1902 } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
1915 case ':': { // pseudo-class or pseudo-element
1916 if ($attrib[1] == ':') { // pseudo-element
1917 // pseudo-elements are not supported!
1918 // (::first-line, ::first-letter, ::before, ::after)
1919 } else { // pseudo-class
1920 // pseudo-classes are not supported!
1921 // (: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)
1929 if ($valid AND ($offset > 0)) {
1931 // check remaining selector part
1932 $selector = substr($selector, 0, $offset);
1933 switch ($operator) {
1934 case ' ': { // descendant of an element
1935 while ($dom[$key]['parent'] > 0) {
1936 if (self
::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
1940 $key = $dom[$key]['parent'];
1945 case '>': { // child of an element
1946 $valid = self
::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
1949 case '+': { // immediately preceded by an element
1950 for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
1951 if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
1952 $valid = self
::isValidCSSSelectorForTag($dom, $i, $selector);
1958 case '~': { // preceded by an element
1959 for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
1960 if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
1961 if (self
::isValidCSSSelectorForTag($dom, $i, $selector)) {
1976 * Returns the styles array that apply for the selected HTML tag.
1977 * @param $dom (array) array of HTML tags and properties
1978 * @param $key (int) key of the current HTML tag
1979 * @param $css (array) array of CSS properties
1980 * @return array containing CSS properties
1981 * @since 5.1.000 (2010-05-25)
1984 public static function getCSSdataArray($dom, $key, $css) {
1985 $cssarray = array(); // style to be returned
1986 // get parent CSS selectors
1987 $selectors = array();
1988 if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
1989 $selectors = $dom[($dom[$key]['parent'])]['csssel'];
1991 // get all styles that apply
1992 foreach($css as $selector => $style) {
1993 $pos = strpos($selector, ' ');
1995 $specificity = substr($selector, 0, $pos);
1996 // remove specificity
1997 $selector = substr($selector, $pos);
1998 // check if this selector apply to current tag
1999 if (self
::isValidCSSSelectorForTag($dom, $key, $selector)) {
2000 if (!in_array($selector, $selectors)) {
2001 // add style if not already added on parent selector
2002 $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
2003 $selectors[] = $selector;
2007 if (isset($dom[$key]['attribute']['style'])) {
2008 // attach inline style (latest properties have high priority)
2009 $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
2011 // order the css array to account for specificity
2012 $cssordered = array();
2013 foreach ($cssarray as $key => $val) {
2014 $skey = sprintf('%04d', $key);
2015 $cssordered[$val['s'].'_'.$skey] = $val;
2017 // sort selectors alphabetically to account for specificity
2018 ksort($cssordered, SORT_STRING
);
2019 return array($selectors, $cssordered);
2023 * Compact CSS data array into single string.
2024 * @param $css (array) array of CSS properties
2025 * @return string containing merged CSS properties
2026 * @since 5.9.070 (2011-04-19)
2029 public static function getTagStyleFromCSSarray($css) {
2030 $tagstyle = ''; // value to be returned
2031 foreach ($css as $style) {
2032 // split single css commands
2033 $csscmds = explode(';', $style['c']);
2034 foreach ($csscmds as $cmd) {
2036 $pos = strpos($cmd, ':');
2037 if ($pos !== false) {
2038 $cmd = substr($cmd, 0, ($pos +
1));
2039 if (strpos($tagstyle, $cmd) !== false) {
2040 // remove duplicate commands (last commands have high priority)
2041 $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
2046 $tagstyle .= ';'.$style['c'];
2048 // remove multiple semicolons
2049 $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
2054 * Returns the Roman representation of an integer number
2055 * @param $number (int) number to convert
2056 * @return string roman representation of the specified number
2057 * @since 4.4.004 (2008-12-10)
2060 public static function intToRoman($number) {
2062 while ($number >= 1000) {
2066 while ($number >= 900) {
2070 while ($number >= 500) {
2074 while ($number >= 400) {
2078 while ($number >= 100) {
2082 while ($number >= 90) {
2086 while ($number >= 50) {
2090 while ($number >= 40) {
2094 while ($number >= 10) {
2098 while ($number >= 9) {
2102 while ($number >= 5) {
2106 while ($number >= 4) {
2110 while ($number >= 1) {
2118 * Find position of last occurrence of a substring in a string
2119 * @param $haystack (string) The string to search in.
2120 * @param $needle (string) substring to search.
2121 * @param $offset (int) May be specified to begin searching an arbitrary number of characters into the string.
2122 * @return Returns the position where the needle exists. Returns FALSE if the needle was not found.
2123 * @since 4.8.038 (2010-03-13)
2126 public static function revstrpos($haystack, $needle, $offset = 0) {
2127 $length = strlen($haystack);
2128 $offset = ($offset > 0)?
($length - $offset):abs($offset);
2129 $pos = strpos(strrev($haystack), strrev($needle), $offset);
2130 return ($pos === false)?
false:($length - $pos - strlen($needle));
2134 * Returns an array of hyphenation patterns.
2135 * @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/
2136 * @return array of hyphenation patterns
2137 * @author Nicola Asuni
2138 * @since 4.9.012 (2010-04-12)
2141 public static function getHyphenPatternsFromTEX($file) {
2142 // TEX patterns are available at:
2143 // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
2144 $data = file_get_contents($file);
2145 $patterns = array();
2147 $data = preg_replace('/\%[^\n]*/', '', $data);
2148 // extract the patterns part
2149 preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
2150 $data = trim(substr($matches[0], 10, -1));
2151 // extract each pattern
2152 $patterns_array = preg_split('/[\s]+/', $data);
2153 // create new language array of patterns
2154 $patterns = array();
2155 foreach($patterns_array as $val) {
2156 if (!TCPDF_STATIC
::empty_string($val)) {
2158 $val = str_replace('\'', '\\\'', $val);
2159 $key = preg_replace('/[0-9]+/', '', $val);
2160 $patterns[$key] = $val;
2167 * Get the Path-Painting Operators.
2168 * @param $style (string) Style of rendering. Possible values are:
2170 * <li>S or D: Stroke the path.</li>
2171 * <li>s or d: Close and stroke the path.</li>
2172 * <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
2173 * <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
2174 * <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>
2175 * <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>
2176 * <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>
2177 * <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>
2178 * <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
2179 * <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
2180 * <li>n: End the path object without filling or stroking it.</li>
2182 * @param $default (string) default style
2183 * @author Nicola Asuni
2184 * @since 5.0.000 (2010-04-30)
2187 public static function getPathPaintOperator($style, $default='S') {
2247 if (!empty($default)) {
2248 $op = self
::getPathPaintOperator($default, '');
2258 * Get the product of two SVG tranformation matrices
2259 * @param $ta (array) first SVG tranformation matrix
2260 * @param $tb (array) second SVG tranformation matrix
2261 * @return transformation array
2262 * @author Nicola Asuni
2263 * @since 5.0.000 (2010-05-02)
2266 public static function getTransformationMatrixProduct($ta, $tb) {
2268 $tm[0] = ($ta[0] * $tb[0]) +
($ta[2] * $tb[1]);
2269 $tm[1] = ($ta[1] * $tb[0]) +
($ta[3] * $tb[1]);
2270 $tm[2] = ($ta[0] * $tb[2]) +
($ta[2] * $tb[3]);
2271 $tm[3] = ($ta[1] * $tb[2]) +
($ta[3] * $tb[3]);
2272 $tm[4] = ($ta[0] * $tb[4]) +
($ta[2] * $tb[5]) +
$ta[4];
2273 $tm[5] = ($ta[1] * $tb[4]) +
($ta[3] * $tb[5]) +
$ta[5];
2278 * Get the tranformation matrix from SVG transform attribute
2279 * @param $attribute (string) transformation
2280 * @return array of transformations
2281 * @author Nicola Asuni
2282 * @since 5.0.000 (2010-05-02)
2285 public static function getSVGTransformMatrix($attribute) {
2287 $tm = array(1, 0, 0, 1, 0, 0);
2288 $transform = array();
2289 if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER
) > 0) {
2290 foreach ($transform as $key => $data) {
2291 if (!empty($data[2])) {
2301 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)) {
2312 if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2315 } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2321 if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2324 } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2331 if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
2332 $ang = deg2rad($regs[1]);
2339 $e = ($x * (1 - $a)) - ($y * $c);
2340 $f = ($y * (1 - $d)) - ($x * $b);
2341 } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2342 $ang = deg2rad($regs[1]);
2353 if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2354 $c = tan(deg2rad($regs[1]));
2359 if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
2360 $b = tan(deg2rad($regs[1]));
2365 $tm = self
::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
2373 * Returns the angle in radiants between two vectors
2374 * @param $x1 (int) X coordinate of first vector point
2375 * @param $y1 (int) Y coordinate of first vector point
2376 * @param $x2 (int) X coordinate of second vector point
2377 * @param $y2 (int) Y coordinate of second vector point
2378 * @author Nicola Asuni
2379 * @since 5.0.000 (2010-05-04)
2382 public static function getVectorsAngle($x1, $y1, $x2, $y2) {
2383 $dprod = ($x1 * $x2) +
($y1 * $y2);
2384 $dist1 = sqrt(($x1 * $x1) +
($y1 * $y1));
2385 $dist2 = sqrt(($x2 * $x2) +
($y2 * $y2));
2386 $angle = acos($dprod / ($dist1 * $dist2));
2387 if (is_nan($angle)) {
2390 if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
2397 * Split string by a regular expression.
2398 * This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850
2399 * @param $pattern (string) The regular expression pattern to search for without the modifiers, as a string.
2400 * @param $modifiers (string) The modifiers part of the pattern,
2401 * @param $subject (string) The input string.
2402 * @param $limit (int) If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter.
2403 * @param $flags (int) The flags as specified on the preg_split PHP function.
2404 * @return Returns an array containing substrings of subject split along boundaries matched by pattern.modifier
2405 * @author Nicola Asuni
2409 public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
2410 // the bug only happens on PHP 5.2 when using the u modifier
2411 if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY
)) == 2)) {
2412 return preg_split($pattern.$modifiers, $subject, $limit, $flags);
2414 // preg_split is bugged - try alternative solution
2416 while (($nl = strpos($subject, "\n")) !== FALSE) {
2417 $ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags));
2419 $subject = substr($subject, ($nl +
1));
2421 if (strlen($subject) > 0) {
2422 $ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags));
2428 * Wrapper to use fopen only with local files
2429 * @param filename (string) Name of the file to open
2430 * @param $mode (string)
2431 * @return Returns a file pointer resource on success, or FALSE on error.
2434 public static function fopenLocal($filename, $mode) {
2435 if (strpos($filename, '://') === false) {
2436 $filename = 'file://'.$filename;
2437 } elseif (strpos($filename, 'file://') !== 0) {
2438 $this->Error('Unsupported file protocol');
2440 return fopen($filename, $mode);
2444 * Reads entire file into a string.
2445 * The file can be also an URL.
2446 * @param $file (string) Name of the file or URL to read.
2447 * @return The function returns the read data or FALSE on failure.
2448 * @author Nicola Asuni
2452 public static function fileGetContents($file) {
2453 //$file = html_entity_decode($file);
2454 // array of possible alternative paths/URLs
2455 $alt = array($file);
2456 // replace URL relative path with full real server path
2457 if ((strlen($file) > 1)
2458 AND ($file[0] == '/')
2459 AND ($file[1] != '/')
2460 AND !empty($_SERVER['DOCUMENT_ROOT'])
2461 AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {
2462 $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']);
2463 if (($findroot === false) OR ($findroot > 1)) {
2464 if (substr($_SERVER['DOCUMENT_ROOT'], -1) == '/') {
2465 $tmp = substr($_SERVER['DOCUMENT_ROOT'], 0, -1).$file;
2467 $tmp = $_SERVER['DOCUMENT_ROOT'].$file;
2469 $alt[] = htmlspecialchars_decode(urldecode($tmp));
2474 // check for missing protocol
2475 if (preg_match('%^/{2}%', $url)) {
2476 if (preg_match('%^([^:]+:)//%i', K_PATH_URL
, $match)) {
2477 $url = $match[1].str_replace(' ', '%20', $url);
2481 $urldata = @parse_url
($url);
2482 if (!isset($urldata['query']) OR (strlen($urldata['query']) <= 0)) {
2483 if (strpos($url, K_PATH_URL
) === 0) {
2484 // convert URL to full server path
2485 $tmp = str_replace(K_PATH_URL
, K_PATH_MAIN
, $url);
2486 $tmp = htmlspecialchars_decode(urldecode($tmp));
2490 if (isset($_SERVER['SCRIPT_URI'])) {
2491 $urldata = @parse_url
($_SERVER['SCRIPT_URI']);
2492 $alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ?
'' : '/').$file;
2494 foreach ($alt as $f) {
2495 $ret = @file_get_contents
($f);
2496 if (($ret === FALSE)
2497 AND !ini_get('allow_url_fopen')
2498 AND function_exists('curl_init')
2499 AND preg_match('%^(https?|ftp)://%', $f)) {
2500 // try to get remote file data using cURL
2501 $cs = curl_init(); // curl session
2502 curl_setopt($cs, CURLOPT_URL
, $f);
2503 curl_setopt($cs, CURLOPT_BINARYTRANSFER
, true);
2504 curl_setopt($cs, CURLOPT_FAILONERROR
, true);
2505 curl_setopt($cs, CURLOPT_RETURNTRANSFER
, true);
2506 if ((ini_get('open_basedir') == '') AND (!ini_get('safe_mode'))) {
2507 curl_setopt($cs, CURLOPT_FOLLOWLOCATION
, true);
2509 curl_setopt($cs, CURLOPT_CONNECTTIMEOUT
, 5);
2510 curl_setopt($cs, CURLOPT_TIMEOUT
, 30);
2511 curl_setopt($cs, CURLOPT_SSL_VERIFYPEER
, false);
2512 curl_setopt($cs, CURLOPT_SSL_VERIFYHOST
, false);
2513 curl_setopt($cs, CURLOPT_USERAGENT
, 'TCPDF');
2514 $ret = curl_exec($cs);
2517 if ($ret !== FALSE) {
2524 } // END OF TCPDF_STATIC CLASS
2526 //============================================================+
2528 //============================================================+