PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 3ms

/common/libraries/plugin/html2pdf/_tcpdf/tcpdf.php

https://bitbucket.org/cbenelug/chamilo
PHP | 11975 lines | 7847 code | 475 blank | 3653 comment | 1168 complexity | 33edb21baeef4b607f392f3e9431e70d MD5 | raw file
Possible License(s): GPL-3.0, MIT, GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Begin : 2002-08-03
  5. // Last Update : 2010-03-13
  6. // Author : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
  7. // Version : 4.8.038
  8. // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. // ----------------------------------------------------------------------------
  10. // Copyright (C) 2002-2010 Nicola Asuni - Tecnick.com S.r.l.
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU Lesser General Public License as published by
  14. // the Free Software Foundation, either version 2.1 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU Lesser General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU Lesser General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. // See LICENSE.TXT file for more information.
  26. // ----------------------------------------------------------------------------
  27. //
  28. // Description : This is a PHP class for generating PDF documents without
  29. // requiring external extensions.
  30. //
  31. // NOTE:
  32. // This class was originally derived in 2002 from the Public
  33. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org),
  34. // but now is almost entirely rewritten.
  35. //
  36. // Main features:
  37. // * no external libraries are required for the basic functions;
  38. // * supports all ISO page formats;
  39. // * supports custom page formats, margins and units of measure;
  40. // * supports UTF-8 Unicode and Right-To-Left languages;
  41. // * supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
  42. // * supports document encryption;
  43. // * includes methods to publish some XHTML code, including forms;
  44. // * includes graphic (geometric) and transformation methods;
  45. // * includes Javascript and Forms support;
  46. // * includes a method to print various barcode formats: 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;
  47. // * includes methods to set Bookmarks and print a Table of Content;
  48. // * includes methods to move and delete pages;
  49. // * includes methods for automatic page header and footer management;
  50. // * supports automatic page break;
  51. // * supports automatic page numbering and page groups;
  52. // * supports automatic line break and text justification;
  53. // * supports JPEG and PNG 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)
  54. // * supports stroke and clipping mode for text;
  55. // * supports clipping masks;
  56. // * supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  57. // * supports several annotations, including links, text and file attachments;
  58. // * supports page compression (requires zlib extension);
  59. // * supports text hyphenation.
  60. // * supports transactions to UNDO commands.
  61. // * supports signature certifications.
  62. //
  63. // -----------------------------------------------------------
  64. // THANKS TO:
  65. //
  66. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  67. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  68. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  69. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  70. // dullus for text Justification.
  71. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  72. // Patrick Benny for text stretch suggestion on Cell().
  73. // Johannes G�ntert for JavaScript support.
  74. // Denis Van Nuffelen for Dynamic Form.
  75. // Jacek Czekaj for multibyte justification
  76. // Anthony Ferrara for the reintroduction of legacy image methods.
  77. // Sourceforge user 1707880 (hucste) for line-trough mode.
  78. // Larry Stanbery for page groups.
  79. // Martin Hall-May for transparency.
  80. // Aaron C. Spike for Polycurve method.
  81. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  82. // Moritz Wagner and Andreas Wurmser for graphic functions.
  83. // Andrew Whitehead for core fonts support.
  84. // Esteban Jo�l Mar�n for OpenType font conversion.
  85. // Teus Hagen for several suggestions and fixes.
  86. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  87. // Kosmas Papachristos for some CSS improvements.
  88. // Marcel Partap for some fixes.
  89. // Won Kyu Park for several suggestions, fixes and patches.
  90. // Anyone that has reported a bug or sent a suggestion.
  91. //============================================================+
  92. /**
  93. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  94. * 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>
  95. * <h3>TCPDF main features are:</h3>
  96. * <ul>
  97. * <li>no external libraries are required for the basic functions;</li>
  98. * <li>supports all ISO page formats;</li>
  99. * <li>supports custom page formats, margins and units of measure;</li>
  100. * <li>supports UTF-8 Unicode and Right-To-Left languages;</li>
  101. * <li>supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  102. * <li>supports document encryption;</li>
  103. * <li>includes methods to publish some XHTML code, including forms;</li>
  104. * <li>includes graphic (geometric) and transformation methods;</li>
  105. * <li>includes Javascript and Forms support;</li>
  106. * <li>includes a method to print various barcode formats: 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</li>
  107. * <li>includes methods to set Bookmarks and print a Table of Content;</li>
  108. * <li>includes methods to move and delete pages;</li>
  109. * <li>includes methods for automatic page header and footer management;</li>
  110. * <li>supports automatic page break;</li>
  111. * <li>supports automatic page numbering and page groups;</li>
  112. * <li>supports automatic line break and text justification;</li>
  113. * <li>supports JPEG and PNG 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>
  114. * <li>supports stroke and clipping mode for text;</li>
  115. * <li>supports clipping masks;</li>
  116. * <li>supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  117. * <li>supports several annotations, including links, text and file attachments;</li>
  118. * <li>supports page compression (requires zlib extension);</li>
  119. * <li>supports text hyphenation.</li>
  120. * <li>supports transactions to UNDO commands.</li>
  121. * <li>supports signature certifications.</li>
  122. * </ul>
  123. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  124. * @package com.tecnick.tcpdf
  125. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  126. * @author Nicola Asuni
  127. * @copyright 2002-2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  128. * @link http://www.tcpdf.org
  129. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  130. * @version 4.8.038
  131. */
  132. /**
  133. * main configuration file
  134. */
  135. require_once (dirname(__FILE__) . '/config/tcpdf_config.php');
  136. // includes some support files
  137. /**
  138. * unicode data
  139. */
  140. require_once (dirname(__FILE__) . '/unicode_data.php');
  141. /**
  142. * html colors table
  143. */
  144. require_once (dirname(__FILE__) . '/htmlcolors.php');
  145. if (! class_exists('TCPDF', false))
  146. {
  147. /**
  148. * define default PDF document producer
  149. */
  150. define('PDF_PRODUCER', 'TCPDF 4.8.038 (http://www.tcpdf.org)');
  151. /**
  152. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  153. * 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>
  154. * @name TCPDF
  155. * @package com.tecnick.tcpdf
  156. * @version 4.8.038
  157. * @author Nicola Asuni - info@tecnick.com
  158. * @link http://www.tcpdf.org
  159. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  160. */
  161. class TCPDF
  162. {
  163. // protected or Protected properties
  164. /**
  165. * @var current page number
  166. * @access protected
  167. */
  168. protected $page;
  169. /**
  170. * @var current object number
  171. * @access protected
  172. */
  173. protected $n;
  174. /**
  175. * @var array of object offsets
  176. * @access protected
  177. */
  178. protected $offsets;
  179. /**
  180. * @var buffer holding in-memory PDF
  181. * @access protected
  182. */
  183. protected $buffer;
  184. /**
  185. * @var array containing pages
  186. * @access protected
  187. */
  188. protected $pages = array();
  189. /**
  190. * @var current document state
  191. * @access protected
  192. */
  193. protected $state;
  194. /**
  195. * @var compression flag
  196. * @access protected
  197. */
  198. protected $compress;
  199. /**
  200. * @var current page orientation (P = Portrait, L = Landscape)
  201. * @access protected
  202. */
  203. protected $CurOrientation;
  204. /**
  205. * @var array that stores page dimensions and graphic status.<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_points</li><li>$this->pagedim[$this->page]['hk'] => height</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></ul>
  206. * @access protected
  207. */
  208. protected $pagedim = array();
  209. /**
  210. * @var scale factor (number of points in user unit)
  211. * @access protected
  212. */
  213. protected $k;
  214. /**
  215. * @var width of page format in points
  216. * @access protected
  217. */
  218. protected $fwPt;
  219. /**
  220. * @var height of page format in points
  221. * @access protected
  222. */
  223. protected $fhPt;
  224. /**
  225. * @var current width of page in points
  226. * @access protected
  227. */
  228. protected $wPt;
  229. /**
  230. * @var current height of page in points
  231. * @access protected
  232. */
  233. protected $hPt;
  234. /**
  235. * @var current width of page in user unit
  236. * @access protected
  237. */
  238. protected $w;
  239. /**
  240. * @var current height of page in user unit
  241. * @access protected
  242. */
  243. protected $h;
  244. /**
  245. * @var left margin
  246. * @access protected
  247. */
  248. protected $lMargin;
  249. /**
  250. * @var top margin
  251. * @access protected
  252. */
  253. protected $tMargin;
  254. /**
  255. * @var right margin
  256. * @access protected
  257. */
  258. protected $rMargin;
  259. /**
  260. * @var page break margin
  261. * @access protected
  262. */
  263. protected $bMargin;
  264. /**
  265. * @var cell internal padding
  266. * @access protected
  267. */
  268. //protected
  269. public $cMargin;
  270. /**
  271. * @var cell internal padding (previous value)
  272. * @access protected
  273. */
  274. protected $oldcMargin;
  275. /**
  276. * @var current horizontal position in user unit for cell positioning
  277. * @access protected
  278. */
  279. protected $x;
  280. /**
  281. * @var current vertical position in user unit for cell positioning
  282. * @access protected
  283. */
  284. protected $y;
  285. /**
  286. * @var height of last cell printed
  287. * @access protected
  288. */
  289. protected $lasth;
  290. /**
  291. * @var line width in user unit
  292. * @access protected
  293. */
  294. protected $LineWidth;
  295. /**
  296. * @var array of standard font names
  297. * @access protected
  298. */
  299. protected $CoreFonts;
  300. /**
  301. * @var array of used fonts
  302. * @access protected
  303. */
  304. protected $fonts = array();
  305. /**
  306. * @var array of font files
  307. * @access protected
  308. */
  309. protected $FontFiles = array();
  310. /**
  311. * @var array of encoding differences
  312. * @access protected
  313. */
  314. protected $diffs = array();
  315. /**
  316. * @var array of used images
  317. * @access protected
  318. */
  319. protected $images = array();
  320. /**
  321. * @var array of Annotations in pages
  322. * @access protected
  323. */
  324. protected $PageAnnots = array();
  325. /**
  326. * @var array of internal links
  327. * @access protected
  328. */
  329. protected $links = array();
  330. /**
  331. * @var current font family
  332. * @access protected
  333. */
  334. protected $FontFamily;
  335. /**
  336. * @var current font style
  337. * @access protected
  338. */
  339. protected $FontStyle;
  340. /**
  341. * @var current font ascent (distance between font top and baseline)
  342. * @access protected
  343. * @since 2.8.000 (2007-03-29)
  344. */
  345. protected $FontAscent;
  346. /**
  347. * @var current font descent (distance between font bottom and baseline)
  348. * @access protected
  349. * @since 2.8.000 (2007-03-29)
  350. */
  351. protected $FontDescent;
  352. /**
  353. * @var underlining flag
  354. * @access protected
  355. */
  356. protected $underline;
  357. /**
  358. * @var current font info
  359. * @access protected
  360. */
  361. protected $CurrentFont;
  362. /**
  363. * @var current font size in points
  364. * @access protected
  365. */
  366. protected $FontSizePt;
  367. /**
  368. * @var current font size in user unit
  369. * @access protected
  370. */
  371. protected $FontSize;
  372. /**
  373. * @var commands for drawing color
  374. * @access protected
  375. */
  376. protected $DrawColor;
  377. /**
  378. * @var commands for filling color
  379. * @access protected
  380. */
  381. protected $FillColor;
  382. /**
  383. * @var commands for text color
  384. * @access protected
  385. */
  386. protected $TextColor;
  387. /**
  388. * @var indicates whether fill and text colors are different
  389. * @access protected
  390. */
  391. protected $ColorFlag;
  392. /**
  393. * @var automatic page breaking
  394. * @access protected
  395. */
  396. protected $AutoPageBreak;
  397. /**
  398. * @var threshold used to trigger page breaks
  399. * @access protected
  400. */
  401. protected $PageBreakTrigger;
  402. /**
  403. * @var flag set when processing footer
  404. * @access protected
  405. */
  406. protected $InFooter = false;
  407. /**
  408. * @var zoom display mode
  409. * @access protected
  410. */
  411. protected $ZoomMode;
  412. /**
  413. * @var layout display mode
  414. * @access protected
  415. */
  416. protected $LayoutMode;
  417. /**
  418. * @var title
  419. * @access protected
  420. */
  421. protected $title = '';
  422. /**
  423. * @var subject
  424. * @access protected
  425. */
  426. protected $subject = '';
  427. /**
  428. * @var author
  429. * @access protected
  430. */
  431. protected $author = '';
  432. /**
  433. * @var keywords
  434. * @access protected
  435. */
  436. protected $keywords = '';
  437. /**
  438. * @var creator
  439. * @access protected
  440. */
  441. protected $creator = '';
  442. /**
  443. * @var alias for total number of pages
  444. * @access protected
  445. */
  446. protected $AliasNbPages = '{nb}';
  447. /**
  448. * @var alias for page number
  449. * @access protected
  450. */
  451. protected $AliasNumPage = '{pnb}';
  452. /**
  453. * @var right-bottom corner X coordinate of inserted image
  454. * @since 2002-07-31
  455. * @author Nicola Asuni
  456. * @access protected
  457. */
  458. protected $img_rb_x;
  459. /**
  460. * @var right-bottom corner Y coordinate of inserted image
  461. * @since 2002-07-31
  462. * @author Nicola Asuni
  463. * @access protected
  464. */
  465. protected $img_rb_y;
  466. /**
  467. * @var adjusting factor to convert pixels to user units.
  468. * @since 2004-06-14
  469. * @author Nicola Asuni
  470. * @access protected
  471. */
  472. protected $imgscale = 1;
  473. /**
  474. * @var boolean set to true when the input text is unicode (require unicode fonts)
  475. * @since 2005-01-02
  476. * @author Nicola Asuni
  477. * @access protected
  478. */
  479. protected $isunicode = false;
  480. /**
  481. * @var PDF version
  482. * @since 1.5.3
  483. * @access protected
  484. */
  485. protected $PDFVersion = '1.7';
  486. // ----------------------
  487. /**
  488. * @var Minimum distance between header and top page margin.
  489. * @access protected
  490. */
  491. protected $header_margin;
  492. /**
  493. * @var Minimum distance between footer and bottom page margin.
  494. * @access protected
  495. */
  496. protected $footer_margin;
  497. /**
  498. * @var original left margin value
  499. * @access protected
  500. * @since 1.53.0.TC013
  501. */
  502. protected $original_lMargin;
  503. /**
  504. * @var original right margin value
  505. * @access protected
  506. * @since 1.53.0.TC013
  507. */
  508. protected $original_rMargin;
  509. /**
  510. * @var Header font.
  511. * @access protected
  512. */
  513. protected $header_font;
  514. /**
  515. * @var Footer font.
  516. * @access protected
  517. */
  518. protected $footer_font;
  519. /**
  520. * @var Language templates.
  521. * @access protected
  522. */
  523. protected $l;
  524. /**
  525. * @var Barcode to print on page footer (only if set).
  526. * @access protected
  527. */
  528. protected $barcode = false;
  529. /**
  530. * @var If true prints header
  531. * @access protected
  532. */
  533. protected $print_header = true;
  534. /**
  535. * @var If true prints footer.
  536. * @access protected
  537. */
  538. protected $print_footer = true;
  539. /**
  540. * @var Header image logo.
  541. * @access protected
  542. */
  543. protected $header_logo = '';
  544. /**
  545. * @var Header image logo width in mm.
  546. * @access protected
  547. */
  548. protected $header_logo_width = 30;
  549. /**
  550. * @var String to print as title on document header.
  551. * @access protected
  552. */
  553. protected $header_title = '';
  554. /**
  555. * @var String to print on document header.
  556. * @access protected
  557. */
  558. protected $header_string = '';
  559. /**
  560. * @var Default number of columns for html table.
  561. * @access protected
  562. */
  563. protected $default_table_columns = 4;
  564. // variables for html parser
  565. /**
  566. * @var HTML PARSER: array to store current link and rendering styles.
  567. * @access protected
  568. */
  569. protected $HREF = array();
  570. /**
  571. * @var store a list of available fonts on filesystem.
  572. * @access protected
  573. */
  574. protected $fontlist = array();
  575. /**
  576. * @var current foreground color
  577. * @access protected
  578. */
  579. protected $fgcolor;
  580. /**
  581. * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  582. * @access protected
  583. */
  584. protected $listordered = array();
  585. /**
  586. * @var HTML PARSER: array count list items on nested lists.
  587. * @access protected
  588. */
  589. protected $listcount = array();
  590. /**
  591. * @var HTML PARSER: current list nesting level.
  592. * @access protected
  593. */
  594. protected $listnum = 0;
  595. /**
  596. * @var HTML PARSER: indent amount for lists.
  597. * @access protected
  598. */
  599. protected $listindent;
  600. /**
  601. * @var current background color
  602. * @access protected
  603. */
  604. protected $bgcolor;
  605. /**
  606. * @var Store temporary font size in points.
  607. * @access protected
  608. */
  609. protected $tempfontsize = 10;
  610. /**
  611. * @var spacer for LI tags.
  612. * @access protected
  613. */
  614. protected $lispacer = '';
  615. /**
  616. * @var default encoding
  617. * @access protected
  618. * @since 1.53.0.TC010
  619. */
  620. protected $encoding = 'UTF-8';
  621. /**
  622. * @var PHP internal encoding
  623. * @access protected
  624. * @since 1.53.0.TC016
  625. */
  626. protected $internal_encoding;
  627. /**
  628. * @var indicates if the document language is Right-To-Left
  629. * @access protected
  630. * @since 2.0.000
  631. */
  632. protected $rtl = false;
  633. /**
  634. * @var used to force RTL or LTR string inversion
  635. * @access protected
  636. * @since 2.0.000
  637. */
  638. protected $tmprtl = false;
  639. // --- Variables used for document encryption:
  640. /**
  641. * Indicates whether document is protected
  642. * @access protected
  643. * @since 2.0.000 (2008-01-02)
  644. */
  645. protected $encrypted;
  646. /**
  647. * U entry in pdf document
  648. * @access protected
  649. * @since 2.0.000 (2008-01-02)
  650. */
  651. protected $Uvalue;
  652. /**
  653. * O entry in pdf document
  654. * @access protected
  655. * @since 2.0.000 (2008-01-02)
  656. */
  657. protected $Ovalue;
  658. /**
  659. * P entry in pdf document
  660. * @access protected
  661. * @since 2.0.000 (2008-01-02)
  662. */
  663. protected $Pvalue;
  664. /**
  665. * encryption object id
  666. * @access protected
  667. * @since 2.0.000 (2008-01-02)
  668. */
  669. protected $enc_obj_id;
  670. /**
  671. * last RC4 key encrypted (cached for optimisation)
  672. * @access protected
  673. * @since 2.0.000 (2008-01-02)
  674. */
  675. protected $last_rc4_key;
  676. /**
  677. * last RC4 computed key
  678. * @access protected
  679. * @since 2.0.000 (2008-01-02)
  680. */
  681. protected $last_rc4_key_c;
  682. /**
  683. * RC4 padding
  684. * @access protected
  685. */
  686. protected $padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  687. /**
  688. * RC4 encryption key
  689. * @access protected
  690. */
  691. protected $encryption_key;
  692. // --- bookmark ---
  693. /**
  694. * Outlines for bookmark
  695. * @access protected
  696. * @since 2.1.002 (2008-02-12)
  697. */
  698. protected $outlines = array();
  699. /**
  700. * Outline root for bookmark
  701. * @access protected
  702. * @since 2.1.002 (2008-02-12)
  703. */
  704. protected $OutlineRoot;
  705. // --- javascript and form ---
  706. /**
  707. * javascript code
  708. * @access protected
  709. * @since 2.1.002 (2008-02-12)
  710. */
  711. protected $javascript = '';
  712. /**
  713. * javascript counter
  714. * @access protected
  715. * @since 2.1.002 (2008-02-12)
  716. */
  717. protected $n_js;
  718. /**
  719. * line trough state
  720. * @access protected
  721. * @since 2.8.000 (2008-03-19)
  722. */
  723. protected $linethrough;
  724. // --- Variables used for User's Rights ---
  725. // See PDF reference chapter 8.7 Digital Signatures
  726. /**
  727. * If true enables user's rights on PDF reader
  728. * @access protected
  729. * @since 2.9.000 (2008-03-26)
  730. */
  731. protected $ur;
  732. /**
  733. * Names specifying additional document-wide usage rights for the document.
  734. * @access protected
  735. * @since 2.9.000 (2008-03-26)
  736. */
  737. protected $ur_document;
  738. /**
  739. * Names specifying additional annotation-related usage rights for the document.
  740. * @access protected
  741. * @since 2.9.000 (2008-03-26)
  742. */
  743. protected $ur_annots;
  744. /**
  745. * Names specifying additional form-field-related usage rights for the document.
  746. * @access protected
  747. * @since 2.9.000 (2008-03-26)
  748. */
  749. protected $ur_form;
  750. /**
  751. * Names specifying additional signature-related usage rights for the document.
  752. * @access protected
  753. * @since 2.9.000 (2008-03-26)
  754. */
  755. protected $ur_signature;
  756. /**
  757. * Dot Per Inch Document Resolution (do not change)
  758. * @access protected
  759. * @since 3.0.000 (2008-03-27)
  760. */
  761. protected $dpi = 72;
  762. /**
  763. * Array of page numbers were a new page group was started
  764. * @access protected
  765. * @since 3.0.000 (2008-03-27)
  766. */
  767. protected $newpagegroup = array();
  768. /**
  769. * Contains the number of pages of the groups
  770. * @access protected
  771. * @since 3.0.000 (2008-03-27)
  772. */
  773. protected $pagegroups;
  774. /**
  775. * Contains the alias of the current page group
  776. * @access protected
  777. * @since 3.0.000 (2008-03-27)
  778. */
  779. protected $currpagegroup;
  780. /**
  781. * Restrict the rendering of some elements to screen or printout.
  782. * @access protected
  783. * @since 3.0.000 (2008-03-27)
  784. */
  785. protected $visibility = 'all';
  786. /**
  787. * Print visibility.
  788. * @access protected
  789. * @since 3.0.000 (2008-03-27)
  790. */
  791. protected $n_ocg_print;
  792. /**
  793. * View visibility.
  794. * @access protected
  795. * @since 3.0.000 (2008-03-27)
  796. */
  797. protected $n_ocg_view;
  798. /**
  799. * Array of transparency objects and parameters.
  800. * @access protected
  801. * @since 3.0.000 (2008-03-27)
  802. */
  803. protected $extgstates;
  804. /**
  805. * Set the default JPEG compression quality (1-100)
  806. * @access protected
  807. * @since 3.0.000 (2008-03-27)
  808. */
  809. protected $jpeg_quality;
  810. /**
  811. * Default cell height ratio.
  812. * @access protected
  813. * @since 3.0.014 (2008-05-23)
  814. */
  815. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  816. /**
  817. * PDF viewer preferences.
  818. * @access protected
  819. * @since 3.1.000 (2008-06-09)
  820. */
  821. protected $viewer_preferences;
  822. /**
  823. * A name object specifying how the document should be displayed when opened.
  824. * @access protected
  825. * @since 3.1.000 (2008-06-09)
  826. */
  827. protected $PageMode;
  828. /**
  829. * Array for storing gradient information.
  830. * @access protected
  831. * @since 3.1.000 (2008-06-09)
  832. */
  833. protected $gradients = array();
  834. /**
  835. * Array used to store positions inside the pages buffer.
  836. * keys are the page numbers
  837. * @access protected
  838. * @since 3.2.000 (2008-06-26)
  839. */
  840. protected $intmrk = array();
  841. /**
  842. * Array used to store content positions inside the pages buffer.
  843. * keys are the page numbers
  844. * @access protected
  845. * @since 4.6.021 (2009-07-20)
  846. */
  847. protected $cntmrk = array();
  848. /**
  849. * Array used to store footer positions of each page.
  850. * @access protected
  851. * @since 3.2.000 (2008-07-01)
  852. */
  853. protected $footerpos = array();
  854. /**
  855. * Array used to store footer length of each page.
  856. * @access protected
  857. * @since 4.0.014 (2008-07-29)
  858. */
  859. protected $footerlen = array();
  860. /**
  861. * True if a newline is created.
  862. * @access protected
  863. * @since 3.2.000 (2008-07-01)
  864. */
  865. protected $newline = true;
  866. /**
  867. * End position of the latest inserted line
  868. * @access protected
  869. * @since 3.2.000 (2008-07-01)
  870. */
  871. protected $endlinex = 0;
  872. /**
  873. * PDF string for last line width
  874. * @access protected
  875. * @since 4.0.006 (2008-07-16)
  876. */
  877. protected $linestyleWidth = '';
  878. /**
  879. * PDF string for last line width
  880. * @access protected
  881. * @since 4.0.006 (2008-07-16)
  882. */
  883. protected $linestyleCap = '0 J';
  884. /**
  885. * PDF string for last line width
  886. * @access protected
  887. * @since 4.0.006 (2008-07-16)
  888. */
  889. protected $linestyleJoin = '0 j';
  890. /**
  891. * PDF string for last line width
  892. * @access protected
  893. * @since 4.0.006 (2008-07-16)
  894. */
  895. protected $linestyleDash = '[] 0 d';
  896. /**
  897. * True if marked-content sequence is open
  898. * @access protected
  899. * @since 4.0.013 (2008-07-28)
  900. */
  901. protected $openMarkedContent = false;
  902. /**
  903. * Count the latest inserted vertical spaces on HTML
  904. * @access protected
  905. * @since 4.0.021 (2008-08-24)
  906. */
  907. protected $htmlvspace = 0;
  908. /**
  909. * Array of Spot colors
  910. * @access protected
  911. * @since 4.0.024 (2008-09-12)
  912. */
  913. protected $spot_colors = array();
  914. /**
  915. * Symbol used for HTML unordered list items
  916. * @access protected
  917. * @since 4.0.028 (2008-09-26)
  918. */
  919. protected $lisymbol = '';
  920. /**
  921. * String used to mark the beginning and end of EPS image blocks
  922. * @access protected
  923. * @since 4.1.000 (2008-10-18)
  924. */
  925. protected $epsmarker = 'x#!#EPS#!#x';
  926. /**
  927. * Array of transformation matrix
  928. * @access protected
  929. * @since 4.2.000 (2008-10-29)
  930. */
  931. protected $transfmatrix = array();
  932. /**
  933. * Current key for transformation matrix
  934. * @access protected
  935. * @since 4.8.005 (2009-09-17)
  936. */
  937. protected $transfmatrix_key = 0;
  938. /**
  939. * Booklet mode for double-sided pages
  940. * @access protected
  941. * @since 4.2.000 (2008-10-29)
  942. */
  943. protected $booklet = false;
  944. /**
  945. * Epsilon value used for float calculations
  946. * @access protected
  947. * @since 4.2.000 (2008-10-29)
  948. */
  949. protected $feps = 0.005;
  950. /**
  951. * Array used for custom vertical spaces for HTML tags
  952. * @access protected
  953. * @since 4.2.001 (2008-10-30)
  954. */
  955. protected $tagvspaces = array();
  956. /**
  957. * @var HTML PARSER: custom indent amount for lists.
  958. * Negative value means disabled.
  959. * @access protected
  960. * @since 4.2.007 (2008-11-12)
  961. */
  962. protected $customlistindent = - 1;
  963. /**
  964. * @var if true keeps the border open for the cell sides that cross the page.
  965. * @access protected
  966. * @since 4.2.010 (2008-11-14)
  967. */
  968. protected $opencell = true;
  969. /**
  970. * @var array of files to embedd
  971. * @access protected
  972. * @since 4.4.000 (2008-12-07)
  973. */
  974. protected $embeddedfiles = array();
  975. /**
  976. * @var boolean true when inside html pre tag
  977. * @access protected
  978. * @since 4.4.001 (2008-12-08)
  979. */
  980. protected $premode = false;
  981. /**
  982. * Array used to store positions of graphics transformation blocks inside the page buffer.
  983. * keys are the page numbers
  984. * @access protected
  985. * @since 4.4.002 (2008-12-09)
  986. */
  987. protected $transfmrk = array();
  988. /**
  989. * Default color for html links
  990. * @access protected
  991. * @since 4.4.003 (2008-12-09)
  992. */
  993. protected $htmlLinkColorArray = array(0, 0, 255);
  994. /**
  995. * Default font style to add to html links
  996. * @access protected
  997. * @since 4.4.003 (2008-12-09)
  998. */
  999. protected $htmlLinkFontStyle = 'U';
  1000. /**
  1001. * Counts the number of pages.
  1002. * @access protected
  1003. * @since 4.5.000 (2008-12-31)
  1004. */
  1005. protected $numpages = 0;
  1006. /**
  1007. * Array containing page lengths in bytes.
  1008. * @access protected
  1009. * @since 4.5.000 (2008-12-31)
  1010. */
  1011. protected $pagelen = array();
  1012. /**
  1013. * Counts the number of pages.
  1014. * @access protected
  1015. * @since 4.5.000 (2008-12-31)
  1016. */
  1017. protected $numimages = 0;
  1018. /**
  1019. * Store the image keys.
  1020. * @access protected
  1021. * @since 4.5.000 (2008-12-31)
  1022. */
  1023. protected $imagekeys = array();
  1024. /**
  1025. * Length of the buffer in bytes.
  1026. * @access protected
  1027. * @since 4.5.000 (2008-12-31)
  1028. */
  1029. protected $bufferlen = 0;
  1030. /**
  1031. * If true enables disk caching.
  1032. * @access protected
  1033. * @since 4.5.000 (2008-12-31)
  1034. */
  1035. protected $diskcache = false;
  1036. /**
  1037. * Counts the number of fonts.
  1038. * @access protected
  1039. * @since 4.5.000 (2009-01-02)
  1040. */
  1041. protected $numfonts = 0;
  1042. /**
  1043. * Store the font keys.
  1044. * @access protected
  1045. * @since 4.5.000 (2009-01-02)
  1046. */
  1047. protected $fontkeys = array();
  1048. /**
  1049. * Store the font object IDs.
  1050. * @access protected
  1051. * @since 4.8.001 (2009-09-09)
  1052. */
  1053. protected $font_obj_ids = array();
  1054. /**
  1055. * Store the fage status (true when opened, false when closed).
  1056. * @access protected
  1057. * @since 4.5.000 (2009-01-02)
  1058. */
  1059. protected $pageopen = array();
  1060. /**
  1061. * Default monospaced font
  1062. * @access protected
  1063. * @since 4.5.025 (2009-03-10)
  1064. */
  1065. protected $default_monospaced_font = 'courier';
  1066. /**
  1067. * Used to store a cloned copy of the current class object
  1068. * @access protected
  1069. * @since 4.5.029 (2009-03-19)
  1070. */
  1071. protected $objcopy;
  1072. /**
  1073. * Array used to store the lengths of cache files
  1074. * @access protected
  1075. * @since 4.5.029 (2009-03-19)
  1076. */
  1077. protected $cache_file_length = array();
  1078. /**
  1079. * Table header content to be repeated on each new page
  1080. * @access protected
  1081. * @since 4.5.030 (2009-03-20)
  1082. */
  1083. protected $thead = '';
  1084. /**
  1085. * Margins used for table header.
  1086. * @access protected
  1087. * @since 4.5.030 (2009-03-20)
  1088. */
  1089. protected $theadMargins = array();
  1090. /**
  1091. * Cache array for UTF8StringToArray() method.
  1092. * @access protected
  1093. * @since 4.5.037 (2009-04-07)
  1094. */
  1095. protected $cache_UTF8StringToArray = array();
  1096. /**
  1097. * Maximum size of cache array used for UTF8StringToArray() method.
  1098. * @access protected
  1099. * @since 4.5.037 (2009-04-07)
  1100. */
  1101. protected $cache_maxsize_UTF8StringToArray = 8;
  1102. /**
  1103. * Current size of cache array used for UTF8StringToArray() method.
  1104. * @access protected
  1105. * @since 4.5.037 (2009-04-07)
  1106. */
  1107. protected $cache_size_UTF8StringToArray = 0;
  1108. /**
  1109. * If true enables document signing
  1110. * @access protected
  1111. * @since 4.6.005 (2009-04-24)
  1112. */
  1113. protected $sign = false;
  1114. /**
  1115. * Signature data
  1116. * @access protected
  1117. * @since 4.6.005 (2009-04-24)
  1118. */
  1119. protected $signature_data = array();
  1120. /**
  1121. * Signature max length
  1122. * @access protected
  1123. * @since 4.6.005 (2009-04-24)
  1124. */
  1125. protected $signature_max_length = 11742;
  1126. /**
  1127. * Regular expression used to find blank characters used for word-wrapping.
  1128. * @access protected
  1129. * @since 4.6.006 (2009-04-28)
  1130. */
  1131. protected $re_spaces = '/[\s]/';
  1132. /**
  1133. * Signature object ID
  1134. * @access protected
  1135. * @since 4.6.022 (2009-06-23)
  1136. */
  1137. protected $sig_obj_id = 0;
  1138. /**
  1139. * ByteRange placemark used during signature process.
  1140. * @access protected
  1141. * @since 4.6.028 (2009-08-25)
  1142. */
  1143. protected $byterange_string = '/ByteRange[0 ********** ********** **********]';
  1144. /**
  1145. * Placemark used during signature process.
  1146. * @access protected
  1147. * @since 4.6.028 (2009-08-25)
  1148. */
  1149. protected $sig_annot_ref = '***SIGANNREF*** 0 R';
  1150. /**
  1151. * ID of page objects
  1152. * @access protected
  1153. * @since 4.7.000 (2009-08-29)
  1154. */
  1155. protected $page_obj_id = array();
  1156. /**
  1157. * Start ID for embedded file objects
  1158. * @access protected
  1159. * @since 4.7.000 (2009-08-29)
  1160. */
  1161. protected $embedded_start_obj_id = 100000;
  1162. /**
  1163. * Start ID for annotation objects
  1164. * @access protected
  1165. * @since 4.7.000 (2009-08-29)
  1166. */
  1167. protected $annots_start_obj_id = 200000;
  1168. /**
  1169. * Max ID of annotation object
  1170. * @access protected
  1171. * @since 4.7.000 (2009-08-29)
  1172. */
  1173. protected $annot_obj_id = 200000;
  1174. /**
  1175. * Current ID of annotation object
  1176. * @access protected
  1177. * @since 4.8.003 (2009-09-15)
  1178. */
  1179. protected $curr_annot_obj_id = 200000;
  1180. /**
  1181. * List of form annotations IDs
  1182. * @access protected
  1183. * @since 4.8.000 (2009-09-07)
  1184. */
  1185. protected $form_obj_id = array();
  1186. /**
  1187. * 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.
  1188. * @access protected
  1189. * @since 4.8.000 (2009-09-07)
  1190. */
  1191. protected $default_form_prop = array('lineWidth' => 1, 'borderStyle' => 'solid',
  1192. 'fillColor' => array(255, 255, 255), 'strokeColor' => array(128, 128, 128));
  1193. /**
  1194. * Javascript objects array
  1195. * @access protected
  1196. * @since 4.8.000 (2009-09-07)
  1197. */
  1198. protected $js_objects = array();
  1199. /**
  1200. * Start ID for javascript objects
  1201. * @access protected
  1202. * @since 4.8.000 (2009-09-07)
  1203. */
  1204. protected $js_start_obj_id = 300000;
  1205. /**
  1206. * Current ID of javascript object
  1207. * @access protected
  1208. * @since 4.8.000 (2009-09-07)
  1209. */
  1210. protected $js_obj_id = 300000;
  1211. /**
  1212. * Current form action (used during XHTML rendering)
  1213. * @access protected
  1214. * @since 4.8.000 (2009-09-07)
  1215. */
  1216. protected $form_action = '';
  1217. /**
  1218. * Current form encryption type (used during XHTML rendering)
  1219. * @access protected
  1220. * @since 4.8.000 (2009-09-07)
  1221. */
  1222. protected $form_enctype = 'application/x-www-form-urlencoded';
  1223. /**
  1224. * Current method to submit forms.
  1225. * @access protected
  1226. * @since 4.8.000 (2009-09-07)
  1227. */
  1228. protected $form_mode = 'post';
  1229. /**
  1230. * Start ID for appearance streams XObjects
  1231. * @access protected
  1232. * @since 4.8.001 (2009-09-09)
  1233. */
  1234. protected $apxo_start_obj_id = 400000;
  1235. /**
  1236. * Current ID of appearance streams XObjects
  1237. * @access protected
  1238. * @since 4.8.001 (2009-09-09)
  1239. */
  1240. protected $apxo_obj_id = 400000;
  1241. /**
  1242. * List of fonts used on form fields (fontname => fontkey).
  1243. * @access protected
  1244. * @since 4.8.001 (2009-09-09)
  1245. */
  1246. protected $annotation_fonts = array();
  1247. /**
  1248. * List of radio buttons parent objects.
  1249. * @access protected
  1250. * @since 4.8.001 (2009-09-09)
  1251. */
  1252. protected $radiobutton_groups = array();
  1253. /**
  1254. * List of radio group objects IDs
  1255. * @access protected
  1256. * @since 4.8.001 (2009-09-09)
  1257. */
  1258. protected $radio_groups = array();
  1259. /**
  1260. * Text indentation value (used for text-indent CSS attribute)
  1261. * @access protected
  1262. * @since 4.8.006 (2009-09-23)
  1263. */
  1264. protected $textindent = 0;
  1265. /**
  1266. * Store page number when startTransaction() is called.
  1267. * @access protected
  1268. * @since 4.8.006 (2009-09-23)
  1269. */
  1270. protected $start_transaction_page = 0;
  1271. /**
  1272. * True when we are printing the thead section on a new page
  1273. * @access protected
  1274. * @since 4.8.027 (2010-01-25)
  1275. */
  1276. protected $inthead = false;
  1277. //------------------------------------------------------------
  1278. // METHODS
  1279. //------------------------------------------------------------
  1280. /**
  1281. * This is the class constructor.
  1282. * It allows to set up the page format, the orientation and
  1283. * the measure unit used in all the methods (except for the font sizes).
  1284. * @since 1.0
  1285. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  1286. * @param string $unit 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.
  1287. * @param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit).<ul><li>4A0</li><li>2A0</li><li>A0</li><li>A1</li><li>A2</li><li>A3</li><li>A4 (default)</li><li>A5</li><li>A6</li><li>A7</li><li>A8</li><li>A9</li><li>A10</li><li>B0</li><li>B1</li><li>B2</li><li>B3</li><li>B4</li><li>B5</li><li>B6</li><li>B7</li><li>B8</li><li>B9</li><li>B10</li><li>C0</li><li>C1</li><li>C2</li><li>C3</li><li>C4</li><li>C5</li><li>C6</li><li>C7</li><li>C8</li><li>C9</li><li>C10</li><li>RA0</li><li>RA1</li><li>RA2</li><li>RA3</li><li>RA4</li><li>SRA0</li><li>SRA1</li><li>SRA2</li><li>SRA3</li><li>SRA4</li><li>LETTER</li><li>LEGAL</li><li>EXECUTIVE</li><li>FOLIO</li></ul>
  1288. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1289. * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1290. * @param String $encoding charset encoding; default is UTF-8
  1291. * @access public
  1292. */
  1293. public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false)
  1294. {
  1295. /* Set internal character encoding to ASCII */
  1296. if (function_exists('mb_internal_encoding') and mb_internal_encoding())
  1297. {
  1298. $this->internal_encoding = mb_internal_encoding();
  1299. mb_internal_encoding('ASCII');
  1300. }
  1301. // set disk caching
  1302. $this->diskcache = $diskcache ? true : false;
  1303. // set language direction
  1304. $this->rtl = false;
  1305. $this->tmprtl = false;
  1306. //Some checks
  1307. $this->_dochecks();
  1308. //Initialization of properties
  1309. $this->isunicode = $unicode;
  1310. $this->page = 0;
  1311. $this->transfmrk[0] = array();
  1312. $this->pagedim = array();
  1313. $this->n = 2;
  1314. $this->buffer = '';
  1315. $this->pages = array();
  1316. $this->state = 0;
  1317. $this->fonts = array();
  1318. $this->FontFiles = array();
  1319. $this->diffs = array();
  1320. $this->images = array();
  1321. $this->links = array();
  1322. $this->gradients = array();
  1323. $this->InFooter = false;
  1324. $this->lasth = 0;
  1325. $this->FontFamily = 'helvetica';
  1326. $this->FontStyle = '';
  1327. $this->FontSizePt = 12;
  1328. $this->underline = false;
  1329. $this->linethrough = false;
  1330. $this->DrawColor = '0 G';
  1331. $this->FillColor = '0 g';
  1332. $this->TextColor = '0 g';
  1333. $this->ColorFlag = false;
  1334. // encryption values
  1335. $this->encrypted = false;
  1336. $this->last_rc4_key = '';
  1337. $this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  1338. //Standard Unicode fonts
  1339. $this->CoreFonts = array('courier' => 'Courier', 'courierB' => 'Courier-Bold',
  1340. 'courierI' => 'Courier-Oblique', 'courierBI' => 'Courier-BoldOblique', 'helvetica' => 'Helvetica',
  1341. 'helveticaB' => 'Helvetica-Bold', 'helveticaI' => 'Helvetica-Oblique',
  1342. 'helveticaBI' => 'Helvetica-BoldOblique', 'times' => 'Times-Roman', 'timesB' => 'Times-Bold',
  1343. 'timesI' => 'Times-Italic', 'timesBI' => 'Times-BoldItalic', 'symbol' => 'Symbol',
  1344. 'zapfdingbats' => 'ZapfDingbats');
  1345. //Set scale factor
  1346. $this->setPageUnit($unit);
  1347. // set page format and orientation
  1348. $this->setPageFormat($format, $orientation);
  1349. //Page margins (1 cm)
  1350. $margin = 28.35 / $this->k;
  1351. $this->SetMargins($margin, $margin);
  1352. //Interior cell margin
  1353. $this->cMargin = $margin / 10;
  1354. //Line width (0.2 mm)

Large files files are truncated, but you can click here to view the full file