PageRenderTime 72ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 2ms

/include/tcpdf/tcpdf.php

https://bitbucket.org/thomashii/vtigercrm-5.4-for-postgresql
PHP | 13746 lines | 8798 code | 521 blank | 4427 comment | 2027 complexity | 915a05fc764b6d60ecaaeca45bdf6cfa MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.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 : 2009-05-23
  6. // Author : Nicola Asuni - info@tecnick.com - http://www.tcpdf.org
  7. // Version : 4.6.012
  8. // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. // ----------------------------------------------------------------------------
  10. // Copyright (C) 2002-2009 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;
  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. //
  62. // -----------------------------------------------------------
  63. // THANKS TO:
  64. //
  65. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  66. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  67. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  68. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  69. // dullus for text Justification.
  70. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  71. // Patrick Benny for text stretch suggestion on Cell().
  72. // Johannes Güntert for JavaScript support.
  73. // Denis Van Nuffelen for Dynamic Form.
  74. // Jacek Czekaj for multibyte justification
  75. // Anthony Ferrara for the reintroduction of legacy image methods.
  76. // Sourceforge user 1707880 (hucste) for line-trough mode.
  77. // Larry Stanbery for page groups.
  78. // Martin Hall-May for transparency.
  79. // Aaron C. Spike for Polycurve method.
  80. // Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
  81. // Moritz Wagner and Andreas Wurmser for graphic functions.
  82. // Andrew Whitehead for core fonts support.
  83. // Esteban Joël Marín for OpenType font conversion.
  84. // Teus Hagen for several suggestions and fixes.
  85. // Yukihiro Nakadaira for CID-0 CJK fonts fixes.
  86. // Kosmas Papachristos for some CSS improvements.
  87. // Marcel Partap for some fixes.
  88. // Won Kyu Park for several suggestions, fixes and patches.
  89. // Anyone that has reported a bug or sent a suggestion.
  90. //============================================================+
  91. /**
  92. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  93. * 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>
  94. * <h3>TCPDF main features are:</h3>
  95. * <ul>
  96. * <li>no external libraries are required for the basic functions;</li>
  97. * <li>supports all ISO page formats;</li>
  98. * <li>supports custom page formats, margins and units of measure;</li>
  99. * <li>supports UTF-8 Unicode and Right-To-Left languages;</li>
  100. * <li>supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;</li>
  101. * <li>supports document encryption;</li>
  102. * <li>includes methods to publish some XHTML code;</li>
  103. * <li>includes graphic (geometric) and transformation methods;</li>
  104. * <li>includes Javascript and forms support;</li>
  105. * <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>
  106. * <li>includes methods to set Bookmarks and print a Table of Content;</li>
  107. * <li>includes methods to move and delete pages;</li>
  108. * <li>includes methods for automatic page header and footer management;</li>
  109. * <li>supports automatic page break;</li>
  110. * <li>supports automatic page numbering and page groups;</li>
  111. * <li>supports automatic line break and text justification;</li>
  112. * <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>
  113. * <li>supports stroke and clipping mode for text;</li>
  114. * <li>supports clipping masks;</li>
  115. * <li>supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;</li>
  116. * <li>supports several annotations, including links, text and file attachments;</li>
  117. * <li>supports page compression (requires zlib extension);</li>
  118. * <li>supports text hyphenation.</li>
  119. * <li>supports transactions to UNDO commands.</li>
  120. * </ul>
  121. * Tools to encode your unicode fonts are on fonts/utils directory.</p>
  122. * @package com.tecnick.tcpdf
  123. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  124. * @author Nicola Asuni
  125. * @copyright 2002-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  126. * @link http://www.tcpdf.org
  127. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  128. * @version 4.6.012
  129. */
  130. /**
  131. * main configuration file
  132. */
  133. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  134. // includes some support files
  135. /**
  136. * unicode data
  137. */
  138. require_once(dirname(__FILE__).'/unicode_data.php');
  139. /**
  140. * html colors table
  141. */
  142. require_once(dirname(__FILE__).'/htmlcolors.php');
  143. if (!class_exists('TCPDF', false)) {
  144. /**
  145. * define default PDF document producer
  146. */
  147. define('PDF_PRODUCER', 'TCPDF 4.6.012 (http://www.tcpdf.org)');
  148. /**
  149. * This is a PHP class for generating PDF documents without requiring external extensions.<br>
  150. * 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>
  151. * @name TCPDF
  152. * @package com.tecnick.tcpdf
  153. * @version 4.6.012
  154. * @author Nicola Asuni - info@tecnick.com
  155. * @link http://www.tcpdf.org
  156. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  157. */
  158. class TCPDF {
  159. // protected or Protected properties
  160. /**
  161. * @var current page number
  162. * @access protected
  163. */
  164. protected $page;
  165. /**
  166. * @var current object number
  167. * @access protected
  168. */
  169. protected $n;
  170. /**
  171. * @var array of object offsets
  172. * @access protected
  173. */
  174. protected $offsets;
  175. /**
  176. * @var buffer holding in-memory PDF
  177. * @access protected
  178. */
  179. protected $buffer;
  180. /**
  181. * @var array containing pages
  182. * @access protected
  183. */
  184. protected $pages = array();
  185. /**
  186. * @var current document state
  187. * @access protected
  188. */
  189. protected $state;
  190. /**
  191. * @var compression flag
  192. * @access protected
  193. */
  194. protected $compress;
  195. /**
  196. * @var current page orientation (P = Portrait, L = Landscape)
  197. * @access protected
  198. */
  199. protected $CurOrientation;
  200. /**
  201. * @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>
  202. * @access protected
  203. */
  204. protected $pagedim = array();
  205. /**
  206. * @var scale factor (number of points in user unit)
  207. * @access protected
  208. */
  209. protected $k;
  210. /**
  211. * @var width of page format in points
  212. * @access protected
  213. */
  214. protected $fwPt;
  215. /**
  216. * @var height of page format in points
  217. * @access protected
  218. */
  219. protected $fhPt;
  220. /**
  221. * @var current width of page in points
  222. * @access protected
  223. */
  224. protected $wPt;
  225. /**
  226. * @var current height of page in points
  227. * @access protected
  228. */
  229. protected $hPt;
  230. /**
  231. * @var current width of page in user unit
  232. * @access protected
  233. */
  234. protected $w;
  235. /**
  236. * @var current height of page in user unit
  237. * @access protected
  238. */
  239. protected $h;
  240. /**
  241. * @var left margin
  242. * @access protected
  243. */
  244. protected $lMargin;
  245. /**
  246. * @var top margin
  247. * @access protected
  248. */
  249. protected $tMargin;
  250. /**
  251. * @var right margin
  252. * @access protected
  253. */
  254. protected $rMargin;
  255. /**
  256. * @var page break margin
  257. * @access protected
  258. */
  259. protected $bMargin;
  260. /**
  261. * @var cell internal padding
  262. * @access protected
  263. */
  264. //protected
  265. public $cMargin;
  266. /**
  267. * @var cell internal padding (previous value)
  268. * @access protected
  269. */
  270. protected $oldcMargin;
  271. /**
  272. * @var current horizontal position in user unit for cell positioning
  273. * @access protected
  274. */
  275. protected $x;
  276. /**
  277. * @var current vertical position in user unit for cell positioning
  278. * @access protected
  279. */
  280. protected $y;
  281. /**
  282. * @var height of last cell printed
  283. * @access protected
  284. */
  285. protected $lasth;
  286. /**
  287. * @var line width in user unit
  288. * @access protected
  289. */
  290. protected $LineWidth;
  291. /**
  292. * @var array of standard font names
  293. * @access protected
  294. */
  295. protected $CoreFonts;
  296. /**
  297. * @var array of used fonts
  298. * @access protected
  299. */
  300. protected $fonts = array();
  301. /**
  302. * @var array of font files
  303. * @access protected
  304. */
  305. protected $FontFiles = array();
  306. /**
  307. * @var array of encoding differences
  308. * @access protected
  309. */
  310. protected $diffs = array();
  311. /**
  312. * @var array of used images
  313. * @access protected
  314. */
  315. protected $images = array();
  316. /**
  317. * @var array of Annotations in pages
  318. * @access protected
  319. */
  320. protected $PageAnnots = array();
  321. /**
  322. * @var array of internal links
  323. * @access protected
  324. */
  325. protected $links = array();
  326. /**
  327. * @var current font family
  328. * @access protected
  329. */
  330. protected $FontFamily;
  331. /**
  332. * @var current font style
  333. * @access protected
  334. */
  335. protected $FontStyle;
  336. /**
  337. * @var current font ascent (distance between font top and baseline)
  338. * @access protected
  339. * @since 2.8.000 (2007-03-29)
  340. */
  341. protected $FontAscent;
  342. /**
  343. * @var current font descent (distance between font bottom and baseline)
  344. * @access protected
  345. * @since 2.8.000 (2007-03-29)
  346. */
  347. protected $FontDescent;
  348. /**
  349. * @var underlining flag
  350. * @access protected
  351. */
  352. protected $underline;
  353. /**
  354. * @var current font info
  355. * @access protected
  356. */
  357. protected $CurrentFont;
  358. /**
  359. * @var current font size in points
  360. * @access protected
  361. */
  362. protected $FontSizePt;
  363. /**
  364. * @var current font size in user unit
  365. * @access protected
  366. */
  367. protected $FontSize;
  368. /**
  369. * @var commands for drawing color
  370. * @access protected
  371. */
  372. protected $DrawColor;
  373. /**
  374. * @var commands for filling color
  375. * @access protected
  376. */
  377. protected $FillColor;
  378. /**
  379. * @var commands for text color
  380. * @access protected
  381. */
  382. protected $TextColor;
  383. /**
  384. * @var indicates whether fill and text colors are different
  385. * @access protected
  386. */
  387. protected $ColorFlag;
  388. /**
  389. * @var automatic page breaking
  390. * @access protected
  391. */
  392. protected $AutoPageBreak;
  393. /**
  394. * @var threshold used to trigger page breaks
  395. * @access protected
  396. */
  397. protected $PageBreakTrigger;
  398. /**
  399. * @var flag set when processing footer
  400. * @access protected
  401. */
  402. protected $InFooter = false;
  403. /**
  404. * @var zoom display mode
  405. * @access protected
  406. */
  407. protected $ZoomMode;
  408. /**
  409. * @var layout display mode
  410. * @access protected
  411. */
  412. protected $LayoutMode;
  413. /**
  414. * @var title
  415. * @access protected
  416. */
  417. protected $title = '';
  418. /**
  419. * @var subject
  420. * @access protected
  421. */
  422. protected $subject = '';
  423. /**
  424. * @var author
  425. * @access protected
  426. */
  427. protected $author = '';
  428. /**
  429. * @var keywords
  430. * @access protected
  431. */
  432. protected $keywords = '';
  433. /**
  434. * @var creator
  435. * @access protected
  436. */
  437. protected $creator = '';
  438. /**
  439. * @var alias for total number of pages
  440. * @access protected
  441. */
  442. protected $AliasNbPages = '{nb}';
  443. /**
  444. * @var alias for page number
  445. * @access protected
  446. */
  447. protected $AliasNumPage = '{pnb}';
  448. /**
  449. * @var right-bottom corner X coordinate of inserted image
  450. * @since 2002-07-31
  451. * @author Nicola Asuni
  452. * @access protected
  453. */
  454. protected $img_rb_x;
  455. /**
  456. * @var right-bottom corner Y coordinate of inserted image
  457. * @since 2002-07-31
  458. * @author Nicola Asuni
  459. * @access protected
  460. */
  461. protected $img_rb_y;
  462. /**
  463. * @var adjusting factor to convert pixels to user units.
  464. * @since 2004-06-14
  465. * @author Nicola Asuni
  466. * @access protected
  467. */
  468. protected $imgscale = 1;
  469. /**
  470. * @var boolean set to true when the input text is unicode (require unicode fonts)
  471. * @since 2005-01-02
  472. * @author Nicola Asuni
  473. * @access protected
  474. */
  475. protected $isunicode = false;
  476. /**
  477. * @var PDF version
  478. * @since 1.5.3
  479. * @access protected
  480. */
  481. protected $PDFVersion = '1.7';
  482. // ----------------------
  483. /**
  484. * @var Minimum distance between header and top page margin.
  485. * @access protected
  486. */
  487. protected $header_margin;
  488. /**
  489. * @var Minimum distance between footer and bottom page margin.
  490. * @access protected
  491. */
  492. protected $footer_margin;
  493. /**
  494. * @var original left margin value
  495. * @access protected
  496. * @since 1.53.0.TC013
  497. */
  498. protected $original_lMargin;
  499. /**
  500. * @var original right margin value
  501. * @access protected
  502. * @since 1.53.0.TC013
  503. */
  504. protected $original_rMargin;
  505. /**
  506. * @var Header font.
  507. * @access protected
  508. */
  509. protected $header_font;
  510. /**
  511. * @var Footer font.
  512. * @access protected
  513. */
  514. protected $footer_font;
  515. /**
  516. * @var Language templates.
  517. * @access protected
  518. */
  519. protected $l;
  520. /**
  521. * @var Barcode to print on page footer (only if set).
  522. * @access protected
  523. */
  524. protected $barcode = false;
  525. /**
  526. * @var If true prints header
  527. * @access protected
  528. */
  529. protected $print_header = true;
  530. /**
  531. * @var If true prints footer.
  532. * @access protected
  533. */
  534. protected $print_footer = true;
  535. /**
  536. * @var Header image logo.
  537. * @access protected
  538. */
  539. protected $header_logo = '';
  540. /**
  541. * @var Header image logo width in mm.
  542. * @access protected
  543. */
  544. protected $header_logo_width = 30;
  545. /**
  546. * @var String to print as title on document header.
  547. * @access protected
  548. */
  549. protected $header_title = '';
  550. /**
  551. * @var String to print on document header.
  552. * @access protected
  553. */
  554. protected $header_string = '';
  555. /**
  556. * @var Default number of columns for html table.
  557. * @access protected
  558. */
  559. protected $default_table_columns = 4;
  560. // variables for html parser
  561. /**
  562. * @var HTML PARSER: array to store current link and rendering styles.
  563. * @access protected
  564. */
  565. protected $HREF = array();
  566. /**
  567. * @var store a list of available fonts on filesystem.
  568. * @access protected
  569. */
  570. protected $fontlist = array();
  571. /**
  572. * @var current foreground color
  573. * @access protected
  574. */
  575. protected $fgcolor;
  576. /**
  577. * @var HTML PARSER: array of boolean values, true in case of ordered list (OL), false otherwise.
  578. * @access protected
  579. */
  580. protected $listordered = array();
  581. /**
  582. * @var HTML PARSER: array count list items on nested lists.
  583. * @access protected
  584. */
  585. protected $listcount = array();
  586. /**
  587. * @var HTML PARSER: current list nesting level.
  588. * @access protected
  589. */
  590. protected $listnum = 0;
  591. /**
  592. * @var HTML PARSER: indent amount for lists.
  593. * @access protected
  594. */
  595. protected $listindent;
  596. /**
  597. * @var current background color
  598. * @access protected
  599. */
  600. protected $bgcolor;
  601. /**
  602. * @var Store temporary font size in points.
  603. * @access protected
  604. */
  605. protected $tempfontsize = 10;
  606. /**
  607. * @var spacer for LI tags.
  608. * @access protected
  609. */
  610. protected $lispacer = '';
  611. /**
  612. * @var default encoding
  613. * @access protected
  614. * @since 1.53.0.TC010
  615. */
  616. protected $encoding = 'UTF-8';
  617. /**
  618. * @var PHP internal encoding
  619. * @access protected
  620. * @since 1.53.0.TC016
  621. */
  622. protected $internal_encoding;
  623. /**
  624. * @var indicates if the document language is Right-To-Left
  625. * @access protected
  626. * @since 2.0.000
  627. */
  628. protected $rtl = false;
  629. /**
  630. * @var used to force RTL or LTR string inversion
  631. * @access protected
  632. * @since 2.0.000
  633. */
  634. protected $tmprtl = false;
  635. // --- Variables used for document encryption:
  636. /**
  637. * Indicates whether document is protected
  638. * @access protected
  639. * @since 2.0.000 (2008-01-02)
  640. */
  641. protected $encrypted;
  642. /**
  643. * U entry in pdf document
  644. * @access protected
  645. * @since 2.0.000 (2008-01-02)
  646. */
  647. protected $Uvalue;
  648. /**
  649. * O entry in pdf document
  650. * @access protected
  651. * @since 2.0.000 (2008-01-02)
  652. */
  653. protected $Ovalue;
  654. /**
  655. * P entry in pdf document
  656. * @access protected
  657. * @since 2.0.000 (2008-01-02)
  658. */
  659. protected $Pvalue;
  660. /**
  661. * encryption object id
  662. * @access protected
  663. * @since 2.0.000 (2008-01-02)
  664. */
  665. protected $enc_obj_id;
  666. /**
  667. * last RC4 key encrypted (cached for optimisation)
  668. * @access protected
  669. * @since 2.0.000 (2008-01-02)
  670. */
  671. protected $last_rc4_key;
  672. /**
  673. * last RC4 computed key
  674. * @access protected
  675. * @since 2.0.000 (2008-01-02)
  676. */
  677. protected $last_rc4_key_c;
  678. /**
  679. * RC4 padding
  680. * @access protected
  681. */
  682. 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";
  683. /**
  684. * RC4 encryption key
  685. * @access protected
  686. */
  687. protected $encryption_key;
  688. // --- bookmark ---
  689. /**
  690. * Outlines for bookmark
  691. * @access protected
  692. * @since 2.1.002 (2008-02-12)
  693. */
  694. protected $outlines = array();
  695. /**
  696. * Outline root for bookmark
  697. * @access protected
  698. * @since 2.1.002 (2008-02-12)
  699. */
  700. protected $OutlineRoot;
  701. // --- javascript and form ---
  702. /**
  703. * javascript code
  704. * @access protected
  705. * @since 2.1.002 (2008-02-12)
  706. */
  707. protected $javascript = '';
  708. /**
  709. * javascript counter
  710. * @access protected
  711. * @since 2.1.002 (2008-02-12)
  712. */
  713. protected $n_js;
  714. /**
  715. * line trough state
  716. * @access protected
  717. * @since 2.8.000 (2008-03-19)
  718. */
  719. protected $linethrough;
  720. // --- Variables used for User's Rights ---
  721. // See PDF reference chapter 8.7 Digital Signatures
  722. /**
  723. * If true enables user's rights on PDF reader
  724. * @access protected
  725. * @since 2.9.000 (2008-03-26)
  726. */
  727. protected $ur;
  728. /**
  729. * Names specifying additional document-wide usage rights for the document.
  730. * @access protected
  731. * @since 2.9.000 (2008-03-26)
  732. */
  733. protected $ur_document;
  734. /**
  735. * Names specifying additional annotation-related usage rights for the document.
  736. * @access protected
  737. * @since 2.9.000 (2008-03-26)
  738. */
  739. protected $ur_annots;
  740. /**
  741. * Names specifying additional form-field-related usage rights for the document.
  742. * @access protected
  743. * @since 2.9.000 (2008-03-26)
  744. */
  745. protected $ur_form;
  746. /**
  747. * Names specifying additional signature-related usage rights for the document.
  748. * @access protected
  749. * @since 2.9.000 (2008-03-26)
  750. */
  751. protected $ur_signature;
  752. /**
  753. * Dot Per Inch Document Resolution (do not change)
  754. * @access protected
  755. * @since 3.0.000 (2008-03-27)
  756. */
  757. protected $dpi = 72;
  758. /**
  759. * Array of page numbers were a new page group was started
  760. * @access protected
  761. * @since 3.0.000 (2008-03-27)
  762. */
  763. protected $newpagegroup = array();
  764. /**
  765. * Contains the number of pages of the groups
  766. * @access protected
  767. * @since 3.0.000 (2008-03-27)
  768. */
  769. protected $pagegroups;
  770. /**
  771. * Contains the alias of the current page group
  772. * @access protected
  773. * @since 3.0.000 (2008-03-27)
  774. */
  775. protected $currpagegroup;
  776. /**
  777. * Restrict the rendering of some elements to screen or printout.
  778. * @access protected
  779. * @since 3.0.000 (2008-03-27)
  780. */
  781. protected $visibility = 'all';
  782. /**
  783. * Print visibility.
  784. * @access protected
  785. * @since 3.0.000 (2008-03-27)
  786. */
  787. protected $n_ocg_print;
  788. /**
  789. * View visibility.
  790. * @access protected
  791. * @since 3.0.000 (2008-03-27)
  792. */
  793. protected $n_ocg_view;
  794. /**
  795. * Array of transparency objects and parameters.
  796. * @access protected
  797. * @since 3.0.000 (2008-03-27)
  798. */
  799. protected $extgstates;
  800. /**
  801. * Set the default JPEG compression quality (1-100)
  802. * @access protected
  803. * @since 3.0.000 (2008-03-27)
  804. */
  805. protected $jpeg_quality;
  806. /**
  807. * Default cell height ratio.
  808. * @access protected
  809. * @since 3.0.014 (2008-05-23)
  810. */
  811. protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
  812. /**
  813. * PDF viewer preferences.
  814. * @access protected
  815. * @since 3.1.000 (2008-06-09)
  816. */
  817. protected $viewer_preferences;
  818. /**
  819. * A name object specifying how the document should be displayed when opened.
  820. * @access protected
  821. * @since 3.1.000 (2008-06-09)
  822. */
  823. protected $PageMode;
  824. /**
  825. * Array for storing gradient information.
  826. * @access protected
  827. * @since 3.1.000 (2008-06-09)
  828. */
  829. protected $gradients = array();
  830. /**
  831. * Array used to store positions inside the pages buffer.
  832. * keys are the page numbers
  833. * @access protected
  834. * @since 3.2.000 (2008-06-26)
  835. */
  836. protected $intmrk = array();
  837. /**
  838. * Array used to store footer positions of each page.
  839. * @access protected
  840. * @since 3.2.000 (2008-07-01)
  841. */
  842. protected $footerpos = array();
  843. /**
  844. * Array used to store footer lenght of each page.
  845. * @access protected
  846. * @since 4.0.014 (2008-07-29)
  847. */
  848. protected $footerlen = array();
  849. /**
  850. * True if a newline is created.
  851. * @access protected
  852. * @since 3.2.000 (2008-07-01)
  853. */
  854. protected $newline = true;
  855. /**
  856. * End position of the latest inserted line
  857. * @access protected
  858. * @since 3.2.000 (2008-07-01)
  859. */
  860. protected $endlinex = 0;
  861. /**
  862. * PDF string for last line width
  863. * @access protected
  864. * @since 4.0.006 (2008-07-16)
  865. */
  866. protected $linestyleWidth = '';
  867. /**
  868. * PDF string for last line width
  869. * @access protected
  870. * @since 4.0.006 (2008-07-16)
  871. */
  872. protected $linestyleCap = '0 J';
  873. /**
  874. * PDF string for last line width
  875. * @access protected
  876. * @since 4.0.006 (2008-07-16)
  877. */
  878. protected $linestyleJoin = '0 j';
  879. /**
  880. * PDF string for last line width
  881. * @access protected
  882. * @since 4.0.006 (2008-07-16)
  883. */
  884. protected $linestyleDash = '[] 0 d';
  885. /**
  886. * True if marked-content sequence is open
  887. * @access protected
  888. * @since 4.0.013 (2008-07-28)
  889. */
  890. protected $openMarkedContent = false;
  891. /**
  892. * Count the latest inserted vertical spaces on HTML
  893. * @access protected
  894. * @since 4.0.021 (2008-08-24)
  895. */
  896. protected $htmlvspace = 0;
  897. /**
  898. * Array of Spot colors
  899. * @access protected
  900. * @since 4.0.024 (2008-09-12)
  901. */
  902. protected $spot_colors = array();
  903. /**
  904. * Symbol used for HTML unordered list items
  905. * @access protected
  906. * @since 4.0.028 (2008-09-26)
  907. */
  908. protected $lisymbol = '';
  909. /**
  910. * String used to mark the beginning and end of EPS image blocks
  911. * @access protected
  912. * @since 4.1.000 (2008-10-18)
  913. */
  914. protected $epsmarker = 'x#!#EPS#!#x';
  915. /**
  916. * Array of transformation matrix
  917. * @access protected
  918. * @since 4.2.000 (2008-10-29)
  919. */
  920. protected $transfmatrix = array();
  921. /**
  922. * Booklet mode for double-sided pages
  923. * @access protected
  924. * @since 4.2.000 (2008-10-29)
  925. */
  926. protected $booklet = false;
  927. /**
  928. * Epsilon value used for float calculations
  929. * @access protected
  930. * @since 4.2.000 (2008-10-29)
  931. */
  932. protected $feps = 0.001;
  933. /**
  934. * Array used for custom vertical spaces for HTML tags
  935. * @access protected
  936. * @since 4.2.001 (2008-10-30)
  937. */
  938. protected $tagvspaces = array();
  939. /**
  940. * @var HTML PARSER: custom indent amount for lists.
  941. * Negative value means disabled.
  942. * @access protected
  943. * @since 4.2.007 (2008-11-12)
  944. */
  945. protected $customlistindent = -1;
  946. /**
  947. * @var if true keeps the border open for the cell sides that cross the page.
  948. * @access protected
  949. * @since 4.2.010 (2008-11-14)
  950. */
  951. protected $opencell = true;
  952. /**
  953. * @var array of files to embedd
  954. * @access protected
  955. * @since 4.4.000 (2008-12-07)
  956. */
  957. protected $embeddedfiles = array();
  958. /**
  959. * @var boolean true when inside html pre tag
  960. * @access protected
  961. * @since 4.4.001 (2008-12-08)
  962. */
  963. protected $premode = false;
  964. /**
  965. * Array used to store positions of graphics transformation blocks inside the page buffer.
  966. * keys are the page numbers
  967. * @access protected
  968. * @since 4.4.002 (2008-12-09)
  969. */
  970. protected $transfmrk = array();
  971. /**
  972. * Default color for html links
  973. * @access protected
  974. * @since 4.4.003 (2008-12-09)
  975. */
  976. protected $htmlLinkColorArray = array(0, 0, 255);
  977. /**
  978. * Default font style to add to html links
  979. * @access protected
  980. * @since 4.4.003 (2008-12-09)
  981. */
  982. protected $htmlLinkFontStyle = 'U';
  983. /**
  984. * Counts the number of pages.
  985. * @access protected
  986. * @since 4.5.000 (2008-12-31)
  987. */
  988. protected $numpages = 0;
  989. /**
  990. * Array containing page lenghts in bytes.
  991. * @access protected
  992. * @since 4.5.000 (2008-12-31)
  993. */
  994. protected $pagelen = array();
  995. /**
  996. * Counts the number of pages.
  997. * @access protected
  998. * @since 4.5.000 (2008-12-31)
  999. */
  1000. protected $numimages = 0;
  1001. /**
  1002. * Store the image keys.
  1003. * @access protected
  1004. * @since 4.5.000 (2008-12-31)
  1005. */
  1006. protected $imagekeys = array();
  1007. /**
  1008. * Lenght of the buffer in bytes.
  1009. * @access protected
  1010. * @since 4.5.000 (2008-12-31)
  1011. */
  1012. protected $bufferlen = 0;
  1013. /**
  1014. * If true enables disk caching.
  1015. * @access protected
  1016. * @since 4.5.000 (2008-12-31)
  1017. */
  1018. protected $diskcache = false;
  1019. /**
  1020. * Counts the number of fonts.
  1021. * @access protected
  1022. * @since 4.5.000 (2009-01-02)
  1023. */
  1024. protected $numfonts = 0;
  1025. /**
  1026. * Store the font keys.
  1027. * @access protected
  1028. * @since 4.5.000 (2009-01-02)
  1029. */
  1030. protected $fontkeys = array();
  1031. /**
  1032. * Store the fage status (true when opened, false when closed).
  1033. * @access protected
  1034. * @since 4.5.000 (2009-01-02)
  1035. */
  1036. protected $pageopen = array();
  1037. /**
  1038. * Default monospaced font
  1039. * @access protected
  1040. * @since 4.5.025 (2009-03-10)
  1041. */
  1042. protected $default_monospaced_font = 'courier';
  1043. /**
  1044. * Used to store a cloned copy of the current class object
  1045. * @access protected
  1046. * @since 4.5.029 (2009-03-19)
  1047. */
  1048. protected $objcopy;
  1049. /**
  1050. * Array used to store the lenghts of cache files
  1051. * @access protected
  1052. * @since 4.5.029 (2009-03-19)
  1053. */
  1054. protected $cache_file_lenght = array();
  1055. /**
  1056. * Table header content to be repeated on each new page
  1057. * @access protected
  1058. * @since 4.5.030 (2009-03-20)
  1059. */
  1060. protected $thead = '';
  1061. /**
  1062. * Distance between the top of page and end of table headers on a new page.
  1063. * @access protected
  1064. * @since 4.5.030 (2009-03-20)
  1065. */
  1066. protected $theadMargin = '';
  1067. /**
  1068. * Cache array for UTF8StringToArray() method.
  1069. * @access protected
  1070. * @since 4.5.037 (2009-04-07)
  1071. */
  1072. protected $cache_UTF8StringToArray = array();
  1073. /**
  1074. * Maximum size of cache array used for UTF8StringToArray() method.
  1075. * @access protected
  1076. * @since 4.5.037 (2009-04-07)
  1077. */
  1078. protected $cache_maxsize_UTF8StringToArray = 8;
  1079. /**
  1080. * Current size of cache array used for UTF8StringToArray() method.
  1081. * @access protected
  1082. * @since 4.5.037 (2009-04-07)
  1083. */
  1084. protected $cache_size_UTF8StringToArray = 0;
  1085. /**
  1086. * If true enables document signing
  1087. * @access protected
  1088. * @since 4.6.005 (2009-04-24)
  1089. */
  1090. protected $sign = false;
  1091. /**
  1092. * Signature data
  1093. * @access protected
  1094. * @since 4.6.005 (2009-04-24)
  1095. */
  1096. protected $signature_data = array();
  1097. /**
  1098. * Signature max lenght
  1099. * @access protected
  1100. * @since 4.6.005 (2009-04-24)
  1101. */
  1102. protected $signature_max_lenght = 5120;
  1103. /**
  1104. * Regular expression used to find blank characters used for word-wrapping.
  1105. * @access protected
  1106. * @since 4.6.006 (2009-04-28)
  1107. */
  1108. protected $re_spaces = '/[\s\p{Z}\p{Lo}]/';
  1109. //------------------------------------------------------------
  1110. // METHODS
  1111. //------------------------------------------------------------
  1112. /**
  1113. * This is the class constructor.
  1114. * It allows to set up the page format, the orientation and
  1115. * the measure unit used in all the methods (except for the font sizes).
  1116. * @since 1.0
  1117. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  1118. * @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.
  1119. * @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>
  1120. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  1121. * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
  1122. * @param String $encoding charset encoding; default is UTF-8
  1123. * @access public
  1124. */
  1125. public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false) {
  1126. /* Set internal character encoding to ASCII */
  1127. if (function_exists('mb_internal_encoding') AND mb_internal_encoding()) {
  1128. $this->internal_encoding = mb_internal_encoding();
  1129. mb_internal_encoding('ASCII');
  1130. }
  1131. // set disk caching
  1132. $this->diskcache = $diskcache ? true : false;
  1133. // set language direction
  1134. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  1135. $this->tmprtl = false;
  1136. //Some checks
  1137. $this->_dochecks();
  1138. //Initialization of properties
  1139. $this->isunicode = $unicode;
  1140. $this->page = 0;
  1141. $this->transfmrk[0] = array();
  1142. $this->pagedim = array();
  1143. $this->n = 2;
  1144. $this->buffer = '';
  1145. $this->pages = array();
  1146. $this->state = 0;
  1147. $this->fonts = array();
  1148. $this->FontFiles = array();
  1149. $this->diffs = array();
  1150. $this->images = array();
  1151. $this->links = array();
  1152. $this->gradients = array();
  1153. $this->InFooter = false;
  1154. $this->lasth = 0;
  1155. $this->FontFamily = 'helvetica';
  1156. $this->FontStyle = '';
  1157. $this->FontSizePt = 12;
  1158. $this->underline = false;
  1159. $this->linethrough = false;
  1160. $this->DrawColor = '0 G';
  1161. $this->FillColor = '0 g';
  1162. $this->TextColor = '0 g';
  1163. $this->ColorFlag = false;
  1164. // encryption values
  1165. $this->encrypted = false;
  1166. $this->last_rc4_key = '';
  1167. $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";
  1168. //Standard Unicode fonts
  1169. $this->CoreFonts = array(
  1170. 'courier'=>'Courier',
  1171. 'courierB'=>'Courier-Bold',
  1172. 'courierI'=>'Courier-Oblique',
  1173. 'courierBI'=>'Courier-BoldOblique',
  1174. 'helvetica'=>'Helvetica',
  1175. 'helveticaB'=>'Helvetica-Bold',
  1176. 'helveticaI'=>'Helvetica-Oblique',
  1177. 'helveticaBI'=>'Helvetica-BoldOblique',
  1178. 'times'=>'Times-Roman',
  1179. 'timesB'=>'Times-Bold',
  1180. 'timesI'=>'Times-Italic',
  1181. 'timesBI'=>'Times-BoldItalic',
  1182. 'symbol'=>'Symbol',
  1183. 'zapfdingbats'=>'ZapfDingbats'
  1184. );
  1185. //Set scale factor
  1186. $this->setPageUnit($unit);
  1187. // set page format and orientation
  1188. $this->setPageFormat($format, $orientation);
  1189. //Page margins (1 cm)
  1190. $margin = 28.35 / $this->k;
  1191. $this->SetMargins($margin, $margin);
  1192. //Interior cell margin
  1193. $this->cMargin = $margin / 10;
  1194. //Line width (0.2 mm)
  1195. $this->LineWidth = 0.57 / $this->k;
  1196. $this->linestyleWidth = sprintf('%.2F w', ($this->LineWidth * $this->k));
  1197. $this->linestyleCap = '0 J';
  1198. $this->linestyleJoin = '0 j';
  1199. $this->linestyleDash = '[] 0 d';
  1200. //Automatic page break
  1201. $this->SetAutoPageBreak(true, (2 * $margin));
  1202. //Full width display mode
  1203. $this->SetDisplayMode('fullwidth');
  1204. //Compression
  1205. $this->SetCompression(true);
  1206. //Set default PDF version number
  1207. $this->PDFVersion = '1.7';
  1208. $this->encoding = $encoding;
  1209. $this->HREF = array();
  1210. $this->getFontsList();
  1211. $this->fgcolor = array('R' => 0, 'G' => 0, 'B' => 0);
  1212. $this->bgcolor = array('R' => 255, 'G' => 255, 'B' => 255);
  1213. $this->extgstates = array();
  1214. // user's rights
  1215. $this->sign = false;
  1216. $this->ur = false;
  1217. $this->ur_document = '/FullSave';
  1218. $this->ur_annots = '/Create/Delete/Modify/Copy/Import/Export';
  1219. $this->ur_form = '/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate';
  1220. $this->ur_signature = '/Modify';
  1221. // set default JPEG quality
  1222. $this->jpeg_quality = 75;
  1223. // initialize some settings
  1224. $this->utf8Bidi(array(''), '');
  1225. // set default font
  1226. $this->SetFont($this->FontFamily, $this->FontStyle, $this->FontSizePt);
  1227. // check if PCRE Unicode support is enabled
  1228. if (@preg_match('/\pL/u', 'a') == 1) {
  1229. // PCRE unicode support is turned ON
  1230. // \p{Z} or \p{Separator}: any kind of Unicode whitespace or invisible separator.
  1231. // \p{Lo} or \p{Other_Letter}: a Unicode letter or ideograph that does not have lowercase and uppercase variants.
  1232. // \p{Lo} is needed because Chinese characters are packed next to each other without spaces in between.
  1233. $this->re_spaces = '/[\s\p{Z}\p{Lo}]/';
  1234. } else {
  1235. // PCRE unicode support is turned OFF
  1236. $this->re_spaces = '/[\s]/';
  1237. }
  1238. }
  1239. /**
  1240. * Default destructor.
  1241. * @access public
  1242. * @since 1.53.0.TC016
  1243. */
  1244. public function __destruct() {
  1245. // restore internal encoding
  1246. if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
  1247. mb_internal_encoding($this->internal_encoding);
  1248. }
  1249. // unset all class variables
  1250. $this->_destroy(true);
  1251. }
  1252. /**
  1253. * Set the units of measure for the document.
  1254. * @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.
  1255. * @access public
  1256. * @since 3.0.015 (2008-06-06)
  1257. */
  1258. public function setPageUnit($unit) {
  1259. //Set scale factor
  1260. switch (strtolower($unit)) {
  1261. // points
  1262. case 'px':
  1263. case 'pt': {
  1264. $this->k = 1;
  1265. break;
  1266. }
  1267. // millimeters
  1268. case 'mm': {
  1269. $this->k = $this->dpi / 25.4;
  1270. break;
  1271. }
  1272. // centimeters
  1273. case 'cm': {
  1274. $this->k = $this->dpi / 2.54;
  1275. break;
  1276. }
  1277. // inches
  1278. case 'in': {
  1279. $this->k = $this->dpi;
  1280. break;
  1281. }
  1282. // unsupported unit
  1283. default : {
  1284. $this->Error('Incorrect unit: '.$unit);
  1285. break;
  1286. }
  1287. }
  1288. if (isset($this->CurOrientation)) {
  1289. $this->setPageOrientation($this->CurOrientation);
  1290. }
  1291. }
  1292. /**
  1293. * Set the page format
  1294. * @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>
  1295. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1296. * @access public
  1297. * @since 3.0.015 (2008-06-06)
  1298. */
  1299. public function setPageFormat($format, $orientation='P') {
  1300. //Page format
  1301. if (is_string($format)) {
  1302. // Page formats (45 standard ISO paper formats and 4 american common formats).
  1303. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  1304. switch (strtoupper($format)) {
  1305. case '4A0': {$format = array(4767.87,6740.79); break;}
  1306. case '2A0': {$format = array(3370.39,4767.87); break;}
  1307. case 'A0': {$format = array(2383.94,3370.39); break;}
  1308. case 'A1': {$format = array(1683.78,2383.94); break;}
  1309. case 'A2': {$format = array(1190.55,1683.78); break;}
  1310. case 'A3': {$format = array(841.89,1190.55); break;}
  1311. case 'A4': default: {$format = array(595.28,841.89); break;}
  1312. case 'A5': {$format = array(419.53,595.28); break;}
  1313. case 'A6': {$format = array(297.64,419.53); break;}
  1314. case 'A7': {$format = array(209.76,297.64); break;}
  1315. case 'A8': {$format = array(147.40,209.76); break;}
  1316. case 'A9': {$format = array(104.88,147.40); break;}
  1317. case 'A10': {$format = array(73.70,104.88); break;}
  1318. case 'B0': {$format = array(2834.65,4008.19); break;}
  1319. case 'B1': {$format = array(2004.09,2834.65); break;}
  1320. case 'B2': {$format = array(1417.32,2004.09); break;}
  1321. case 'B3': {$format = array(1000.63,1417.32); break;}
  1322. case 'B4': {$format = array(708.66,1000.63); break;}
  1323. case 'B5': {$format = array(498.90,708.66); break;}
  1324. case 'B6': {$format = array(354.33,498.90); break;}
  1325. case 'B7': {$format = array(249.45,354.33); break;}
  1326. case 'B8': {$format = array(175.75,249.45); break;}
  1327. case 'B9': {$format = array(124.72,175.75); break;}
  1328. case 'B10': {$format = array(87.87,124.72); break;}
  1329. case 'C0': {$format = array(2599.37,3676.54); break;}
  1330. case 'C1': {$format = array(1836.85,2599.37); break;}
  1331. case 'C2': {$format = array(1298.27,1836.85); break;}
  1332. case 'C3': {$format = array(918.43,1298.27); break;}
  1333. case 'C4': {$format = array(649.13,918.43); break;}
  1334. case 'C5': {$format = array(459.21,649.13); break;}
  1335. case 'C6': {$format = array(323.15,459.21); break;}
  1336. case 'C7': {$format = array(229.61,323.15); break;}
  1337. case 'C8': {$format = array(161.57,229.61); break;}
  1338. case 'C9': {$format = array(113.39,161.57); break;}
  1339. case 'C10': {$format = array(79.37,113.39); break;}
  1340. case 'RA0': {$format = array(2437.80,3458.27); break;}
  1341. case 'RA1': {$format = array(1729.13,2437.80); break;}
  1342. case 'RA2': {$format = array(1218.90,1729.13); break;}
  1343. case 'RA3': {$format = array(864.57,1218.90); break;}
  1344. case 'RA4': {$format = array(609.45,864.57); break;}
  1345. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  1346. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  1347. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  1348. case 'SRA3': {$format = array(907.09,1275.59); break;}
  1349. case 'SRA4': {$format = array(637.80,907.09); break;}
  1350. case 'LETTER': {$format = array(612.00,792.00); break;}
  1351. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  1352. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  1353. case 'FOLIO': {$format = array(612.00,936.00); break;}
  1354. }
  1355. $this->fwPt = $format[0];
  1356. $this->fhPt = $format[1];
  1357. } else {
  1358. $this->fwPt = $format[0] * $this->k;
  1359. $this->fhPt = $format[1] * $this->k;
  1360. }
  1361. $this->setPageOrientation($orientation);
  1362. }
  1363. /**
  1364. * Set page orientation.
  1365. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or PORTRAIT (default)</li><li>L or LANDSCAPE</li></ul>
  1366. * @param boolean $autopagebreak Boolean indicating if auto-page-break mode should be on or off.
  1367. * @param float $bottommargin bottom margin of the page.
  1368. * @access public
  1369. * @since 3.0.015 (2008-06-06)
  1370. */
  1371. public function setPageOrientation($orientation, $autopagebreak='', $bottommargin='') {
  1372. $orientation = strtoupper($orientation);
  1373. if (($orientation == 'P') OR ($orientation == 'PORTRAIT')) {
  1374. $this->CurOrientation = 'P';
  1375. $this->wPt = $this->fwPt;
  1376. $this->hPt = $this->fhPt;
  1377. } elseif (($orientation == 'L') OR ($orientation == 'LANDSCAPE')) {
  1378. $this->CurOrientation = 'L';
  1379. $this->wPt = $this->fhPt;
  1380. $this->hPt = $this->fwPt;
  1381. } else {
  1382. $this->Error('Incorrect orientation: '.$orientation);
  1383. }
  1384. $this->w = $this->wPt / $this->k;
  1385. $this->h = $this->hPt / $this->k;
  1386. if ($this->empty_string($autopagebreak)) {
  1387. if (isset($this->AutoPageBreak)) {
  1388. $autopagebreak = $this->AutoPageBreak;
  1389. } else {
  1390. $autopagebreak = true;
  1391. }
  1392. }
  1393. if ($this->empty_string($bottommargin)) {
  1394. if (isset($this->bMargin)) {
  1395. $bottommargin = $this->bMargin;
  1396. } else {
  1397. // default value = 2 cm
  1398. $bottommargin = 2 * 28.35 / $this->k;
  1399. }
  1400. }
  1401. $this->SetAutoPageBreak($autopagebreak, $bottommargin);
  1402. // store page dimensions
  1403. $this->pagedim[$this->page] = array('w' => $this->wPt, 'h' => $this->hPt, 'wk' => $this->w, 'hk' => $this->h, 'tm' => $this->tMargin, 'bm' => $bottommargin, 'lm' => $this->lMargin, 'rm' => $this->rMargin, 'pb' => $autopagebreak, 'or' => $this->CurOrientation, 'olm' => $this->original_lMargin, 'orm' => $this->original_rMargin);
  1404. }
  1405. /**
  1406. * Enable or disable Right-To-Left language mode
  1407. * @param Boolean $enable if true enable Right-To-Left language mode.
  1408. * @access public
  1409. * @since 2.0.000 (2008-01-03)
  1410. */
  1411. public function setRTL($enable) {
  1412. $this->rtl = $enable ? true : false;
  1413. $this->tmprtl = false;
  1414. }
  1415. /**
  1416. * Return the RTL status
  1417. * @return boolean
  1418. * @access public
  1419. * @since 4.0.012 (2008-07-24)
  1420. */
  1421. public function getRTL() {
  1422. return $this->rtl;
  1423. }
  1424. /**
  1425. * Force temporary RTL language direction
  1426. * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  1427. * @access public
  1428. * @since 2.1.000 (2008-01-09)
  1429. */
  1430. public function setTempRTL($mode) {
  1431. switch ($mode) {
  1432. case false:
  1433. case 'L':
  1434. case 'R': {
  1435. $this->tmprtl = $mode;
  1436. }
  1437. }
  1438. }
  1439. /**
  1440. * Set the last cell height.
  1441. * @param float $h cell height.
  1442. * @author Nicola Asuni
  1443. * @access public
  1444. * @since 1.53.0.TC034
  1445. */
  1446. public function setLastH($h) {
  1447. $this->lasth = $h;
  1448. }
  1449. /**
  1450. * Get the last cell height.
  1451. * @return last cell height
  1452. * @access public
  1453. * @since 4.0.017 (2008-08-05)
  1454. */
  1455. public function getLastH() {
  1456. return $this->lasth;
  1457. }
  1458. /**
  1459. * Set the adjusting factor to convert pixels to user units.
  1460. * @param float $scale adjusting factor to convert pixels to user units.
  1461. * @author Nicola Asuni
  1462. * @access public
  1463. * @since 1.5.2
  1464. */
  1465. public function setImageScale($scale) {
  1466. $this->imgscale = $scale;
  1467. }
  1468. /**
  1469. * Returns the adjusting factor to convert pixels to user units.
  1470. * @return float adjusting factor to convert pixels to user units.
  1471. * @author Nicola Asuni
  1472. * @access public
  1473. * @since 1.5.2
  1474. */
  1475. public function getImageScale() {
  1476. return $this->imgscale;
  1477. }
  1478. /**
  1479. * Returns an array of page dimensions:
  1480. * <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>
  1481. * @param int $pagenum page number (empty = current page)
  1482. * @return array of page dimensions.
  1483. * @author Nicola Asuni
  1484. * @access public
  1485. * @since 4.5.027 (2009-03-16)
  1486. */
  1487. public function getPageDimensions($pagenum='') {
  1488. if (empty($pagenum)) {
  1489. $pagenum = $this->page;
  1490. }
  1491. return $this->pagedim[$pagenum];
  1492. }
  1493. /**
  1494. * Returns the page width in units.
  1495. * @param int $pagenum page number (empty = current page)
  1496. * @return int page width.
  1497. * @author Nicola Asuni
  1498. * @access public
  1499. * @since 1.5.2
  1500. * @see getPageDimensions()
  1501. */
  1502. public function getPageWidth($pagenum='') {
  1503. if (empty($pagenum)) {
  1504. return $this->w;
  1505. }
  1506. return $this->pagedim[$pagenum]['w'];
  1507. }
  1508. /**
  1509. * Returns the page height in units.
  1510. * @param int $pagenum page number (empty = current page)
  1511. * @return int page height.
  1512. * @author Nicola Asuni
  1513. * @access public
  1514. * @since 1.5.2
  1515. * @see getPageDimensions()
  1516. */
  1517. public function getPageHeight($pagenum='') {
  1518. if (empty($pagenum)) {
  1519. return $this->h;
  1520. }
  1521. return $this->pagedim[$pagenum]['h'];
  1522. }
  1523. /**
  1524. * Returns the page break margin.
  1525. * @param int $pagenum page number (empty = current page)
  1526. * @return int page break margin.
  1527. * @author Nicola Asuni
  1528. * @access public
  1529. * @since 1.5.2
  1530. * @see getPageDimensions()
  1531. */
  1532. public function getBreakMargin($pagenum='') {
  1533. if (empty($pagenum)) {
  1534. return $this->bMargin;
  1535. }
  1536. return $this->pagedim[$pagenum]['bm'];
  1537. }
  1538. /**
  1539. * Returns the scale factor (number of points in user unit).
  1540. * @return int scale factor.
  1541. * @author Nicola Asuni
  1542. * @access public
  1543. * @since 1.5.2
  1544. */
  1545. public function getScaleFactor() {
  1546. return $this->k;
  1547. }
  1548. /**
  1549. * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  1550. * @param float $left Left margin.
  1551. * @param float $top Top margin.
  1552. * @param float $right Right margin. Default value is the left one.
  1553. * @access public
  1554. * @since 1.0
  1555. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  1556. */
  1557. public function SetMargins($left, $top, $right=-1) {
  1558. //Set left, top and right margins
  1559. $this->lMargin = $left;
  1560. $this->tMargin = $top;
  1561. if …

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