PageRenderTime 409ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 2ms

/include/tcpdf/tcpdf.php

https://github.com/mikmagic/sugarcrm_dev
PHP | 13689 lines | 8693 code | 529 blank | 4467 comment | 2017 complexity | 5910187df5ca596767e5a384279c3f0b MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, AGPL-3.0

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

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

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