PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/libraries/tcpdf/tcpdf.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 6997 lines | 3987 code | 482 blank | 2528 comment | 850 complexity | 8a8e84bc2bc3cf75eae666b1e0097305 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, MIT, BSD-3-Clause

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 : 2008-03-07
  6. // Author : Nicola Asuni
  7. // Version : 2.5.000_PHP4
  8. // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. //
  10. // Description : This is a PHP5 class for generating PDF files
  11. // on-the-fly without requiring external
  12. // extensions.
  13. //
  14. // NOTE:
  15. // This class was originally derived in 2002 from the Public
  16. // Domain FPDF class by Olivier Plathey (http://www.fpdf.org).
  17. //
  18. // Main features:
  19. // - supports all ISO page formats;
  20. // - supports UTF-8 Unicode and Right-To-Left languages;
  21. // - supports document encryption;
  22. // - includes methods to publish some xhtml code;
  23. // - includes graphic and transformation methods;
  24. // - includes bookmarks;
  25. // - includes Javascript and forms support;
  26. // - includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (http://www.mribti.com/barcode/) (require GD library: http://www.boutell.com/gd/)
  27. // - supports TrueTypeUnicode, TrueType, Type1 and encoding;
  28. // - supports custom page formats, margins and units of measure;
  29. // - includes methods for page header and footer management;
  30. // - supports automatic page break;
  31. // - supports automatic page numbering;
  32. // - supports automatic line break and text justification;
  33. // - supports JPEG, PNG anf GIF images;
  34. // - supports colors;
  35. // - supports links;
  36. // - support page compression (require zlib extension: http://www.gzip.org/zlib/);
  37. // - the source code is full documented in PhpDocumentor Style (http://www.phpdoc.org).
  38. //
  39. // -----------------------------------------------------------
  40. // THANKS TO:
  41. //
  42. // Olivier Plathey (http://www.fpdf.org) for original FPDF.
  43. // Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
  44. // Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
  45. // Warren Sherliker (wsherliker@gmail.com) for better image handling.
  46. // dullus for text Justification.
  47. // Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
  48. // Patrick Benny for text stretch suggestion on Cell().
  49. // Johannes G�ntert for JavaScript support.
  50. // Denis Van Nuffelen for Dynamic Form.
  51. // Jacek Czekaj for multibyte justification
  52. // Anthony Ferrara for the reintroduction of legacy image methods.
  53. // Anyone that has reported a bug or sent a suggestion.
  54. //============================================================+
  55. /**
  56. * This is a PHP5 class for generating PDF files on-the-fly without requiring external extensions.<br>
  57. * TCPDF project (http://tcpdf.sourceforge.net) has been originally derived from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  58. * <h3>TCPDF main features are:</h3>
  59. * <ul>
  60. * <li>supports all ISO page formats;</li>
  61. * <li>supports UTF-8 Unicode and Right-To-Left languages;</li>
  62. * <li>supports document encryption;</li>
  63. * <li>includes methods to publish some xhtml code, supporting the following elements: h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small;</li>
  64. * <li>includes a method to print various barcode formats using an improved version of "Generic Barcode Render Class" by Karim Mribti (<a href="http://www.mribti.com/barcode/" target="_blank" title="Generic Barcode Render Class by Karim Mribti">http://www.mribti.com/barcode/</a>) (require GD library: <a href="http://www.boutell.com/gd/" target="_blank" title="GD library">http://www.boutell.com/gd/</a>)</li>
  65. * <li>supports TrueTypeUnicode, TrueType, Type1 and encoding; </li>
  66. * <li>supports custom page formats, margins and units of measure;</li>
  67. * <li>includes methods for page header and footer management;</li>
  68. * <li>supports automatic page break;</li>
  69. * <li>supports automatic page numbering;</li>
  70. * <li>supports automatic line break and text justification;</li>
  71. * <li>supports JPEG, PNG anf GIF images;</li>
  72. * <li>supports colors;</li>
  73. * <li>supports links;</li>
  74. * <li>support page compression (require zlib extension: <a href="http://www.gzip.org/zlib/" target="_blank" title="zlib">http://www.gzip.org/zlib/</a>);</li>
  75. * <li>the source code is full documented in PhpDocumentor Style (<a href="http://www.phpdoc.org" target="_blank" title="phpDocumentor">http://www.phpdoc.org</a>).</li>
  76. * </ul>
  77. * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
  78. * @name TCPDF
  79. * @package com.tecnick.tcpdf
  80. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  81. * @author Nicola Asuni
  82. * @copyright 2004-2008 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
  83. * @link http://www.tcpdf.org
  84. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  85. * @version 2.5.000_PHP4
  86. */
  87. /**
  88. * include configuration file
  89. */
  90. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  91. if(!class_exists('TCPDF')) {
  92. /**
  93. * define default PDF document producer
  94. */
  95. define('PDF_PRODUCER','TCPDF 2.5.000_PHP4 (http://www.tcpdf.org)');
  96. /**
  97. * This is a PHP5 class for generating PDF files on-the-fly without requiring external extensions.<br>
  98. * TCPDF project (http://tcpdf.sourceforge.net) has been originally derived from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  99. * To add your own TTF fonts please read /fonts/README.TXT
  100. * @name TCPDF
  101. * @package com.tecnick.tcpdf
  102. * @version 2.5.000_PHP4
  103. * @author Nicola Asuni
  104. * @link http://www.tcpdf.org
  105. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  106. */
  107. class TCPDF {
  108. // Private or Protected properties
  109. /**
  110. * @var current page number
  111. * @access protected
  112. */
  113. var $page;
  114. /**
  115. * @var current object number
  116. * @access protected
  117. */
  118. var $n;
  119. /**
  120. * @var array of object offsets
  121. * @access protected
  122. */
  123. var $offsets;
  124. /**
  125. * @var buffer holding in-memory PDF
  126. * @access protected
  127. */
  128. var $buffer;
  129. /**
  130. * @var array containing pages
  131. * @access protected
  132. */
  133. var $pages;
  134. /**
  135. * @var current document state
  136. * @access protected
  137. */
  138. var $state;
  139. /**
  140. * @var compression flag
  141. * @access protected
  142. */
  143. var $compress;
  144. /**
  145. * @var default page orientation (P = Portrait, L = Landscape)
  146. * @access protected
  147. */
  148. var $DefOrientation;
  149. /**
  150. * @var current page orientation (P = Portrait, L = Landscape)
  151. * @access protected
  152. */
  153. var $CurOrientation;
  154. /**
  155. * @var array indicating page orientation changes
  156. * @access protected
  157. */
  158. var $OrientationChanges;
  159. /**
  160. * @var scale factor (number of points in user unit)
  161. * @access protected
  162. */
  163. var $k;
  164. /**
  165. * @var width of page format in points
  166. * @access protected
  167. */
  168. var $fwPt;
  169. /**
  170. * @var height of page format in points
  171. * @access protected
  172. */
  173. var $fhPt;
  174. /**
  175. * @var width of page format in user unit
  176. * @access protected
  177. */
  178. var $fw;
  179. /**
  180. * @var height of page format in user unit
  181. * @access protected
  182. */
  183. var $fh;
  184. /**
  185. * @var current width of page in points
  186. * @access protected
  187. */
  188. var $wPt;
  189. /**
  190. * @var current height of page in points
  191. * @access protected
  192. */
  193. var $hPt;
  194. /**
  195. * @var current width of page in user unit
  196. * @access protected
  197. */
  198. var $w;
  199. /**
  200. * @var current height of page in user unit
  201. * @access protected
  202. */
  203. var $h;
  204. /**
  205. * @var left margin
  206. * @access protected
  207. */
  208. var $lMargin;
  209. /**
  210. * @var top margin
  211. * @access protected
  212. */
  213. var $tMargin;
  214. /**
  215. * @var right margin
  216. * @access protected
  217. */
  218. var $rMargin;
  219. /**
  220. * @var page break margin
  221. * @access protected
  222. */
  223. var $bMargin;
  224. /**
  225. * @var cell internal padding
  226. * @access protected
  227. */
  228. var $cMargin;
  229. /**
  230. * @var current horizontal position in user unit for cell positioning
  231. * @access protected
  232. */
  233. var $x;
  234. /**
  235. * @var current vertical position in user unit for cell positioning
  236. * @access protected
  237. */
  238. var $y;
  239. /**
  240. * @var height of last cell printed
  241. * @access protected
  242. */
  243. var $lasth;
  244. /**
  245. * @var line width in user unit
  246. * @access protected
  247. */
  248. var $LineWidth;
  249. /**
  250. * @var array of standard font names
  251. * @access protected
  252. */
  253. var $CoreFonts;
  254. /**
  255. * @var array of used fonts
  256. * @access protected
  257. */
  258. var $fonts;
  259. /**
  260. * @var array of font files
  261. * @access protected
  262. */
  263. var $FontFiles;
  264. /**
  265. * @var array of encoding differences
  266. * @access protected
  267. */
  268. var $diffs;
  269. /**
  270. * @var array of used images
  271. * @access protected
  272. */
  273. var $images;
  274. /**
  275. * @var array of links in pages
  276. * @access protected
  277. */
  278. var $PageLinks;
  279. /**
  280. * @var array of internal links
  281. * @access protected
  282. */
  283. var $links;
  284. /**
  285. * @var current font family
  286. * @access protected
  287. */
  288. var $FontFamily;
  289. /**
  290. * @var current font style
  291. * @access protected
  292. */
  293. var $FontStyle;
  294. /**
  295. * @var underlining flag
  296. * @access protected
  297. */
  298. var $underline;
  299. /**
  300. * @var current font info
  301. * @access protected
  302. */
  303. var $CurrentFont;
  304. /**
  305. * @var current font size in points
  306. * @access protected
  307. */
  308. var $FontSizePt;
  309. /**
  310. * @var current font size in user unit
  311. * @access protected
  312. */
  313. var $FontSize;
  314. /**
  315. * @var commands for drawing color
  316. * @access protected
  317. */
  318. var $DrawColor;
  319. /**
  320. * @var commands for filling color
  321. * @access protected
  322. */
  323. var $FillColor;
  324. /**
  325. * @var commands for text color
  326. * @access protected
  327. */
  328. var $TextColor;
  329. /**
  330. * @var indicates whether fill and text colors are different
  331. * @access protected
  332. */
  333. var $ColorFlag;
  334. /**
  335. * @var word spacing
  336. * @access protected
  337. */
  338. var $ws;
  339. /**
  340. * @var automatic page breaking
  341. * @access protected
  342. */
  343. var $AutoPageBreak;
  344. /**
  345. * @var threshold used to trigger page breaks
  346. * @access protected
  347. */
  348. var $PageBreakTrigger;
  349. /**
  350. * @var flag set when processing footer
  351. * @access protected
  352. */
  353. var $InFooter;
  354. /**
  355. * @var zoom display mode
  356. * @access protected
  357. */
  358. var $ZoomMode;
  359. /**
  360. * @var layout display mode
  361. * @access protected
  362. */
  363. var $LayoutMode;
  364. /**
  365. * @var title
  366. * @access protected
  367. */
  368. var $title;
  369. /**
  370. * @var subject
  371. * @access protected
  372. */
  373. var $subject;
  374. /**
  375. * @var author
  376. * @access protected
  377. */
  378. var $author;
  379. /**
  380. * @var keywords
  381. * @access protected
  382. */
  383. var $keywords;
  384. /**
  385. * @var creator
  386. * @access protected
  387. */
  388. var $creator;
  389. /**
  390. * @var alias for total number of pages
  391. * @access protected
  392. */
  393. var $AliasNbPages;
  394. /**
  395. * @var right-bottom corner X coordinate of inserted image
  396. * @since 2002-07-31
  397. * @author Nicola Asuni
  398. * @access protected
  399. */
  400. var $img_rb_x;
  401. /**
  402. * @var right-bottom corner Y coordinate of inserted image
  403. * @since 2002-07-31
  404. * @author Nicola Asuni
  405. * @access protected
  406. */
  407. var $img_rb_y;
  408. /**
  409. * @var image scale factor
  410. * @since 2004-06-14
  411. * @author Nicola Asuni
  412. * @access protected
  413. */
  414. var $imgscale = 1;
  415. /**
  416. * @var boolean set to true when the input text is unicode (require unicode fonts)
  417. * @since 2005-01-02
  418. * @author Nicola Asuni
  419. * @access protected
  420. */
  421. var $isunicode = false;
  422. /**
  423. * @var PDF version
  424. * @since 1.5.3
  425. * @access protected
  426. */
  427. var $PDFVersion = "1.5";
  428. // ----------------------
  429. /**
  430. * @var Minimum distance between header and top page margin.
  431. * @access private
  432. */
  433. var $header_margin;
  434. /**
  435. * @var Minimum distance between footer and bottom page margin.
  436. * @access private
  437. */
  438. var $footer_margin;
  439. /**
  440. * @var original left margin value
  441. * @access private
  442. * @since 1.53.0.TC013
  443. */
  444. var $original_lMargin;
  445. /**
  446. * @var original right margin value
  447. * @access private
  448. * @since 1.53.0.TC013
  449. */
  450. var $original_rMargin;
  451. /**
  452. * @var Header font.
  453. * @access private
  454. */
  455. var $header_font;
  456. /**
  457. * @var Footer font.
  458. * @access private
  459. */
  460. var $footer_font;
  461. /**
  462. * @var Language templates.
  463. * @access private
  464. */
  465. var $l;
  466. /**
  467. * @var Barcode to print on page footer (only if set).
  468. * @access private
  469. */
  470. var $barcode = false;
  471. /**
  472. * @var If true prints header
  473. * @access private
  474. */
  475. var $print_header = true;
  476. /**
  477. * @var If true prints footer.
  478. * @access private
  479. */
  480. var $print_footer = true;
  481. /**
  482. * @var Header width (0 = full page width).
  483. * @access private
  484. */
  485. var $header_width = 0;
  486. /**
  487. * @var Header image logo.
  488. * @access private
  489. */
  490. var $header_logo = "";
  491. /**
  492. * @var Header image logo width in mm.
  493. * @access private
  494. */
  495. var $header_logo_width = 30;
  496. /**
  497. * @var String to print as title on document header.
  498. * @access private
  499. */
  500. var $header_title = "";
  501. /**
  502. * @var String to print on document header.
  503. * @access private
  504. */
  505. var $header_string = "";
  506. /**
  507. * @var Default number of columns for html table.
  508. * @access private
  509. */
  510. var $default_table_columns = 4;
  511. // variables for html parser
  512. /**
  513. * @var HTML PARSER: store current link.
  514. * @access private
  515. */
  516. var $HREF;
  517. /**
  518. * @var HTML PARSER: store font list.
  519. * @access private
  520. */
  521. var $fontList;
  522. /**
  523. * @var HTML PARSER: true when font attribute is set.
  524. * @access private
  525. */
  526. var $issetfont;
  527. /**
  528. * @var HTML PARSER: true when color attribute is set.
  529. * @access private
  530. */
  531. var $issetcolor;
  532. /**
  533. * @var HTML PARSER: true in case of ordered list (OL), false otherwise.
  534. * @access private
  535. */
  536. var $listordered = false;
  537. /**
  538. * @var HTML PARSER: count list items.
  539. * @access private
  540. */
  541. var $listcount = 0;
  542. /**
  543. * @var HTML PARSER: size of table border.
  544. * @access private
  545. */
  546. var $tableborder = 0;
  547. /**
  548. * @var HTML PARSER: true at the beginning of table.
  549. * @access private
  550. */
  551. var $tdbegin = false;
  552. /**
  553. * @var HTML PARSER: table width.
  554. * @access private
  555. */
  556. var $tdwidth = 0;
  557. /**
  558. * @var HTML PARSER: table height.
  559. * @access private
  560. */
  561. var $tdheight = 0;
  562. /**
  563. * @var HTML PARSER: table align.
  564. * @access private
  565. */
  566. var $tdalign = "L";
  567. /**
  568. * @var HTML PARSER: table background color.
  569. * @access private
  570. */
  571. var $tdbgcolor = false;
  572. /**
  573. * @var Store temporary font size in points.
  574. * @access private
  575. */
  576. var $tempfontsize = 10;
  577. /**
  578. * @var Bold font style status.
  579. * @access private
  580. */
  581. var $b;
  582. /**
  583. * @var Underlined font style status.
  584. * @access private
  585. */
  586. var $u;
  587. /**
  588. * @var Italic font style status.
  589. * @access private
  590. */
  591. var $i;
  592. /**
  593. * @var spacer for LI tags.
  594. * @access private
  595. */
  596. var $lispacer = "";
  597. /**
  598. * @var default encoding
  599. * @access private
  600. * @since 1.53.0.TC010
  601. */
  602. var $encoding = "UTF-8";
  603. /**
  604. * @var PHP internal encoding
  605. * @access private
  606. * @since 1.53.0.TC016
  607. */
  608. var $internal_encoding;
  609. /**
  610. * @var store previous fill color as RGB array
  611. * @access private
  612. * @since 1.53.0.TC017
  613. */
  614. var $prevFillColor = array(255,255,255);
  615. /**
  616. * @var store previous text color as RGB array
  617. * @access private
  618. * @since 1.53.0.TC017
  619. */
  620. var $prevTextColor = array(0,0,0);
  621. /**
  622. * @var store previous font family
  623. * @access private
  624. * @since 1.53.0.TC017
  625. */
  626. var $prevFontFamily;
  627. /**
  628. * @var store previous font style
  629. * @access private
  630. * @since 1.53.0.TC017
  631. */
  632. var $prevFontStyle;
  633. /**
  634. * @var indicates if the document language is Right-To-Left
  635. * @access private
  636. * @since 2.0.000
  637. */
  638. var $rtl = false;
  639. /**
  640. * @var used to force RTL or LTR string inversion
  641. * @access private
  642. * @since 2.0.000
  643. */
  644. var $tmprtl = false;
  645. // --- Variables used for document encryption:
  646. /**
  647. * Indicates whether document is protected
  648. * @access private
  649. * @since 2.0.000 (2008-01-02)
  650. */
  651. var $encrypted;
  652. /**
  653. * U entry in pdf document
  654. * @access private
  655. * @since 2.0.000 (2008-01-02)
  656. */
  657. var $Uvalue;
  658. /**
  659. * O entry in pdf document
  660. * @access private
  661. * @since 2.0.000 (2008-01-02)
  662. */
  663. var $Ovalue;
  664. /**
  665. * P entry in pdf document
  666. * @access private
  667. * @since 2.0.000 (2008-01-02)
  668. */
  669. var $Pvalue;
  670. /**
  671. * encryption object id
  672. * @access private
  673. * @since 2.0.000 (2008-01-02)
  674. */
  675. var $enc_obj_id;
  676. /**
  677. * last RC4 key encrypted (cached for optimisation)
  678. * @access private
  679. * @since 2.0.000 (2008-01-02)
  680. */
  681. var $last_rc4_key;
  682. /**
  683. * last RC4 computed key
  684. * @access private
  685. * @since 2.0.000 (2008-01-02)
  686. */
  687. var $last_rc4_key_c;
  688. // --- bookmark ---
  689. /**
  690. * Outlines for bookmark
  691. * @access private
  692. * @since 2.1.002 (2008-02-12)
  693. */
  694. var $outlines = array();
  695. /**
  696. * Outline root for bookmark
  697. * @access private
  698. * @since 2.1.002 (2008-02-12)
  699. */
  700. var $OutlineRoot;
  701. // --- javascript and form ---
  702. /**
  703. * javascript code
  704. * @access private
  705. * @since 2.1.002 (2008-02-12)
  706. */
  707. var $javascript = "";
  708. /**
  709. * javascript counter
  710. * @access private
  711. * @since 2.1.002 (2008-02-12)
  712. */
  713. var $n_js;
  714. //------------------------------------------------------------
  715. // Public methods
  716. //------------------------------------------------------------
  717. /**
  718. * This is the class constructor.
  719. * It allows to set up the page format, the orientation and
  720. * the measure unit used in all the methods (except for the font sizes).
  721. * @since 1.0
  722. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  723. * @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.
  724. * @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>
  725. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  726. * @param String $encoding charset encoding; default is UTF-8
  727. */
  728. function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") {
  729. /* Set internal character encoding to ASCII */
  730. if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) {
  731. $this->internal_encoding = mb_internal_encoding();
  732. mb_internal_encoding("ASCII");
  733. }
  734. // set language direction
  735. $this->rtl = $this->l['a_meta_dir']=='rtl' ? true : false;
  736. $this->tmprtl = false;
  737. //Some checks
  738. $this->_dochecks();
  739. //Initialization of properties
  740. $this->isunicode=$unicode;
  741. $this->page=0;
  742. $this->n=2;
  743. $this->buffer='';
  744. $this->pages=array();
  745. $this->OrientationChanges=array();
  746. $this->state=0;
  747. $this->fonts=array();
  748. $this->FontFiles=array();
  749. $this->diffs=array();
  750. $this->images=array();
  751. $this->links=array();
  752. $this->InFooter=false;
  753. $this->lasth=0;
  754. $this->FontFamily='';
  755. $this->FontStyle='';
  756. $this->FontSizePt=12;
  757. $this->underline=false;
  758. $this->DrawColor='0 G';
  759. $this->FillColor='0 g';
  760. $this->TextColor='0 g';
  761. $this->ColorFlag=false;
  762. $this->ws=0;
  763. // encryption values
  764. $this->encrypted=false;
  765. $this->last_rc4_key='';
  766. $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";
  767. //Standard Unicode fonts
  768. $this->CoreFonts=array(
  769. 'courier'=>'Courier',
  770. 'courierB'=>'Courier-Bold',
  771. 'courierI'=>'Courier-Oblique',
  772. 'courierBI'=>'Courier-BoldOblique',
  773. 'helvetica'=>'Helvetica',
  774. 'helveticaB'=>'Helvetica-Bold',
  775. 'helveticaI'=>'Helvetica-Oblique',
  776. 'helveticaBI'=>'Helvetica-BoldOblique',
  777. 'times'=>'Times-Roman',
  778. 'timesB'=>'Times-Bold',
  779. 'timesI'=>'Times-Italic',
  780. 'timesBI'=>'Times-BoldItalic',
  781. 'symbol'=>'Symbol',
  782. 'zapfdingbats'=>'ZapfDingbats'
  783. );
  784. //Scale factor
  785. switch (strtolower($unit)){
  786. case 'pt': {$this->k=1; break;}
  787. case 'mm': {$this->k=72/25.4; break;}
  788. case 'cm': {$this->k=72/2.54; break;}
  789. case 'in': {$this->k=72; break;}
  790. default : {$this->Error('Incorrect unit: '.$unit); break;}
  791. }
  792. //Page format
  793. if(is_string($format)) {
  794. // Page formats (45 standard ISO paper formats and 4 american common formats).
  795. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  796. switch (strtoupper($format)){
  797. case '4A0': {$format = array(4767.87,6740.79); break;}
  798. case '2A0': {$format = array(3370.39,4767.87); break;}
  799. case 'A0': {$format = array(2383.94,3370.39); break;}
  800. case 'A1': {$format = array(1683.78,2383.94); break;}
  801. case 'A2': {$format = array(1190.55,1683.78); break;}
  802. case 'A3': {$format = array(841.89,1190.55); break;}
  803. case 'A4': default: {$format = array(595.28,841.89); break;}
  804. case 'A5': {$format = array(419.53,595.28); break;}
  805. case 'A6': {$format = array(297.64,419.53); break;}
  806. case 'A7': {$format = array(209.76,297.64); break;}
  807. case 'A8': {$format = array(147.40,209.76); break;}
  808. case 'A9': {$format = array(104.88,147.40); break;}
  809. case 'A10': {$format = array(73.70,104.88); break;}
  810. case 'B0': {$format = array(2834.65,4008.19); break;}
  811. case 'B1': {$format = array(2004.09,2834.65); break;}
  812. case 'B2': {$format = array(1417.32,2004.09); break;}
  813. case 'B3': {$format = array(1000.63,1417.32); break;}
  814. case 'B4': {$format = array(708.66,1000.63); break;}
  815. case 'B5': {$format = array(498.90,708.66); break;}
  816. case 'B6': {$format = array(354.33,498.90); break;}
  817. case 'B7': {$format = array(249.45,354.33); break;}
  818. case 'B8': {$format = array(175.75,249.45); break;}
  819. case 'B9': {$format = array(124.72,175.75); break;}
  820. case 'B10': {$format = array(87.87,124.72); break;}
  821. case 'C0': {$format = array(2599.37,3676.54); break;}
  822. case 'C1': {$format = array(1836.85,2599.37); break;}
  823. case 'C2': {$format = array(1298.27,1836.85); break;}
  824. case 'C3': {$format = array(918.43,1298.27); break;}
  825. case 'C4': {$format = array(649.13,918.43); break;}
  826. case 'C5': {$format = array(459.21,649.13); break;}
  827. case 'C6': {$format = array(323.15,459.21); break;}
  828. case 'C7': {$format = array(229.61,323.15); break;}
  829. case 'C8': {$format = array(161.57,229.61); break;}
  830. case 'C9': {$format = array(113.39,161.57); break;}
  831. case 'C10': {$format = array(79.37,113.39); break;}
  832. case 'RA0': {$format = array(2437.80,3458.27); break;}
  833. case 'RA1': {$format = array(1729.13,2437.80); break;}
  834. case 'RA2': {$format = array(1218.90,1729.13); break;}
  835. case 'RA3': {$format = array(864.57,1218.90); break;}
  836. case 'RA4': {$format = array(609.45,864.57); break;}
  837. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  838. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  839. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  840. case 'SRA3': {$format = array(907.09,1275.59); break;}
  841. case 'SRA4': {$format = array(637.80,907.09); break;}
  842. case 'LETTER': {$format = array(612.00,792.00); break;}
  843. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  844. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  845. case 'FOLIO': {$format = array(612.00,936.00); break;}
  846. // default: {$this->Error('Unknown page format: '.$format); break;}
  847. }
  848. $this->fwPt=$format[0];
  849. $this->fhPt=$format[1];
  850. }
  851. else {
  852. $this->fwPt=$format[0]*$this->k;
  853. $this->fhPt=$format[1]*$this->k;
  854. }
  855. $this->fw=$this->fwPt/$this->k;
  856. $this->fh=$this->fhPt/$this->k;
  857. //Page orientation
  858. $orientation=strtolower($orientation);
  859. if($orientation=='p' or $orientation=='portrait') {
  860. $this->DefOrientation='P';
  861. $this->wPt=$this->fwPt;
  862. $this->hPt=$this->fhPt;
  863. }
  864. elseif($orientation=='l' or $orientation=='landscape') {
  865. $this->DefOrientation='L';
  866. $this->wPt=$this->fhPt;
  867. $this->hPt=$this->fwPt;
  868. }
  869. else {
  870. $this->Error('Incorrect orientation: '.$orientation);
  871. }
  872. $this->CurOrientation=$this->DefOrientation;
  873. $this->w=$this->wPt/$this->k;
  874. $this->h=$this->hPt/$this->k;
  875. //Page margins (1 cm)
  876. $margin=28.35/$this->k;
  877. $this->SetMargins($margin,$margin);
  878. //Interior cell margin (1 mm)
  879. $this->cMargin=$margin/10;
  880. //Line width (0.2 mm)
  881. $this->LineWidth=.567/$this->k;
  882. //Automatic page break
  883. $this->SetAutoPageBreak(true,2*$margin);
  884. //Full width display mode
  885. $this->SetDisplayMode('fullwidth');
  886. //Compression
  887. $this->SetCompression(true);
  888. //Set default PDF version number
  889. $this->PDFVersion = "1.5";
  890. $this->encoding = $encoding;
  891. $this->b = 0;
  892. $this->i = 0;
  893. $this->u = 0;
  894. $this->HREF = '';
  895. $this->fontlist = array("arial", "times", "courier", "helvetica", "symbol");
  896. $this->issetfont = false;
  897. $this->issetcolor = false;
  898. $this->tableborder = 0;
  899. $this->tdbegin = false;
  900. $this->tdwidth= 0;
  901. $this->tdheight = 0;
  902. if($this->rtl) {
  903. $this->tdalign = "R";
  904. } else {
  905. $this->tdalign = "L";
  906. }
  907. $this->tdbgcolor = false;
  908. $this->SetFillColor(200, 200, 200, true);
  909. $this->SetTextColor(0, 0, 0, true);
  910. }
  911. /**
  912. * Enable or disable Right-To-Left language mode
  913. * @param Boolean $enable if true enable Right-To-Left language mode.
  914. * @since 2.0.000 (2008-01-03)
  915. */
  916. function setRTL($enable) {
  917. $this->rtl = $enable ? true : false;
  918. $this->tmprtl = false;
  919. }
  920. /**
  921. * Force temporary RTL language direction
  922. * @param mixed $mode can be false, 'L' for LTR or 'R' for RTL
  923. * @since 2.1.000 (2008-01-09)
  924. */
  925. function setTempRTL($mode) {
  926. switch ($mode) {
  927. case false:
  928. case 'L':
  929. case 'R': {
  930. $this->tmprtl = $mode;
  931. }
  932. }
  933. }
  934. /**
  935. * Set the last cell height.
  936. * @param float $h cell height.
  937. * @author Nicola Asuni
  938. * @since 1.53.0.TC034
  939. */
  940. function setLastH($h) {
  941. $this->lasth=$h;
  942. }
  943. /**
  944. * Set the image scale.
  945. * @param float $scale image scale.
  946. * @author Nicola Asuni
  947. * @since 1.5.2
  948. */
  949. function setImageScale($scale) {
  950. $this->imgscale=$scale;
  951. }
  952. /**
  953. * Returns the image scale.
  954. * @return float image scale.
  955. * @author Nicola Asuni
  956. * @since 1.5.2
  957. */
  958. function getImageScale() {
  959. return $this->imgscale;
  960. }
  961. /**
  962. * Returns the page width in units.
  963. * @return int page width.
  964. * @author Nicola Asuni
  965. * @since 1.5.2
  966. */
  967. function getPageWidth() {
  968. return $this->w;
  969. }
  970. /**
  971. * Returns the page height in units.
  972. * @return int page height.
  973. * @author Nicola Asuni
  974. * @since 1.5.2
  975. */
  976. function getPageHeight() {
  977. return $this->h;
  978. }
  979. /**
  980. * Returns the page break margin.
  981. * @return int page break margin.
  982. * @author Nicola Asuni
  983. * @since 1.5.2
  984. */
  985. function getBreakMargin() {
  986. return $this->bMargin;
  987. }
  988. /**
  989. * Returns the scale factor (number of points in user unit).
  990. * @return int scale factor.
  991. * @author Nicola Asuni
  992. * @since 1.5.2
  993. */
  994. function getScaleFactor() {
  995. return $this->k;
  996. }
  997. /**
  998. * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  999. * @param float $left Left margin.
  1000. * @param float $top Top margin.
  1001. * @param float $right Right margin. Default value is the left one.
  1002. * @since 1.0
  1003. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  1004. */
  1005. function SetMargins($left, $top, $right=-1) {
  1006. //Set left, top and right margins
  1007. $this->lMargin=$left;
  1008. $this->tMargin=$top;
  1009. if($right==-1) {
  1010. $right=$left;
  1011. }
  1012. $this->rMargin=$right;
  1013. }
  1014. /**
  1015. * Defines the left margin. The method can be called before creating the first page. If the current abscissa gets out of page, it is brought back to the margin.
  1016. * @param float $margin The margin.
  1017. * @since 1.4
  1018. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1019. */
  1020. function SetLeftMargin($margin) {
  1021. //Set left margin
  1022. $this->lMargin=$margin;
  1023. if(($this->page > 0) AND ($this->x < $margin)) {
  1024. $this->x = $margin;
  1025. }
  1026. }
  1027. /**
  1028. * Defines the top margin. The method can be called before creating the first page.
  1029. * @param float $margin The margin.
  1030. * @since 1.5
  1031. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  1032. */
  1033. function SetTopMargin($margin) {
  1034. //Set top margin
  1035. $this->tMargin=$margin;
  1036. if(($this->page > 0) AND ($this->y < $margin)) {
  1037. $this->y = $margin;
  1038. }
  1039. }
  1040. /**
  1041. * Defines the right margin. The method can be called before creating the first page.
  1042. * @param float $margin The margin.
  1043. * @since 1.5
  1044. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1045. */
  1046. function SetRightMargin($margin) {
  1047. $this->rMargin=$margin;
  1048. if(($this->page > 0) AND ($this->x > ($this->w - $margin))) {
  1049. $this->x = $this->w - $margin;
  1050. }
  1051. }
  1052. /**
  1053. * Set the internal Cell padding.
  1054. * @param float $pad internal padding.
  1055. * @since 2.1.000 (2008-01-09)
  1056. * @see Cell(), SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  1057. */
  1058. function SetCellPadding($pad) {
  1059. $this->cMargin=$pad;
  1060. }
  1061. /**
  1062. * Enables or disables the automatic page breaking mode. When enabling, the second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.
  1063. * @param boolean $auto Boolean indicating if mode should be on or off.
  1064. * @param float $margin Distance from the bottom of the page.
  1065. * @since 1.0
  1066. * @see Cell(), MultiCell(), AcceptPageBreak()
  1067. */
  1068. function SetAutoPageBreak($auto, $margin=0) {
  1069. //Set auto page break mode and triggering margin
  1070. $this->AutoPageBreak = $auto;
  1071. $this->bMargin = $margin;
  1072. $this->PageBreakTrigger = $this->h - $margin;
  1073. }
  1074. /**
  1075. * Defines the way the document is to be displayed by the viewer. The zoom level can be set: pages can be displayed entirely on screen, occupy the full width of the window, use real size, be scaled by a specific zooming factor or use viewer default (configured in the Preferences menu of Acrobat). The page layout can be specified too: single at once, continuous display, two columns or viewer default. By default, documents use the full width mode with continuous display.
  1076. * @param mixed $zoom The zoom to use. It can be one of the following string values or a number indicating the zooming factor to use. <ul><li>fullpage: displays the entire page on screen </li><li>fullwidth: uses maximum width of window</li><li>real: uses real size (equivalent to 100% zoom)</li><li>default: uses viewer default mode</li></ul>
  1077. * @param string $layout The page layout. Possible values are:<ul><li>single: displays one page at once</li><li>continuous: displays pages continuously (default)</li><li>two: displays two pages on two columns</li><li>default: uses viewer default mode</li></ul>
  1078. * @since 1.2
  1079. */
  1080. function SetDisplayMode($zoom, $layout='continuous') {
  1081. //Set display mode in viewer
  1082. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
  1083. $this->ZoomMode=$zoom;
  1084. }
  1085. else {
  1086. $this->Error('Incorrect zoom display mode: '.$zoom);
  1087. }
  1088. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
  1089. $this->LayoutMode=$layout;
  1090. }
  1091. else {
  1092. $this->Error('Incorrect layout display mode: '.$layout);
  1093. }
  1094. }
  1095. /**
  1096. * Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default.
  1097. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  1098. * @param boolean $compress Boolean indicating if compression must be enabled.
  1099. * @since 1.4
  1100. */
  1101. function SetCompression($compress) {
  1102. //Set page compression
  1103. if(function_exists('gzcompress')) {
  1104. $this->compress=$compress;
  1105. }
  1106. else {
  1107. $this->compress=false;
  1108. }
  1109. }
  1110. /**
  1111. * Defines the title of the document.
  1112. * @param string $title The title.
  1113. * @since 1.2
  1114. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  1115. */
  1116. function SetTitle($title) {
  1117. //Title of document
  1118. $this->title=$title;
  1119. }
  1120. /**
  1121. * Defines the subject of the document.
  1122. * @param string $subject The subject.
  1123. * @since 1.2
  1124. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  1125. */
  1126. function SetSubject($subject) {
  1127. //Subject of document
  1128. $this->subject=$subject;
  1129. }
  1130. /**
  1131. * Defines the author of the document.
  1132. * @param string $author The name of the author.
  1133. * @since 1.2
  1134. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  1135. */
  1136. function SetAuthor($author) {
  1137. //Author of document
  1138. $this->author=$author;
  1139. }
  1140. /**
  1141. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  1142. * @param string $keywords The list of keywords.
  1143. * @since 1.2
  1144. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  1145. */
  1146. function SetKeywords($keywords) {
  1147. //Keywords of document
  1148. $this->keywords=$keywords;
  1149. }
  1150. /**
  1151. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  1152. * @param string $creator The name of the creator.
  1153. * @since 1.2
  1154. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  1155. */
  1156. function SetCreator($creator) {
  1157. //Creator of document
  1158. $this->creator=$creator;
  1159. }
  1160. /**
  1161. * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
  1162. * <b>Example:</b><br />
  1163. * <pre>
  1164. * class PDF extends TCPDF {
  1165. * function Footer() {
  1166. * //Go to 1.5 cm from bottom
  1167. * $this->SetY(-15);
  1168. * //Select Arial italic 8
  1169. * $this->SetFont('vera','I',8);
  1170. * //Print current and total page numbers
  1171. * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  1172. * }
  1173. * }
  1174. * $pdf=new PDF();
  1175. * $pdf->AliasNbPages();
  1176. * </pre>
  1177. * @param string $alias The alias. Default value: {nb}.
  1178. * @since 1.4
  1179. * @see PageNo(), Footer()
  1180. */
  1181. function AliasNbPages($alias='{nb}') {
  1182. //Define an alias for total number of pages
  1183. $this->AliasNbPages = $this->_escapetext($alias);
  1184. }
  1185. /**
  1186. * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
  1187. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  1188. * @param string $msg The error message
  1189. * @since 1.0
  1190. */
  1191. function Error($msg) {
  1192. //Fatal error
  1193. die('<strong>TCPDF error: </strong>'.$msg);
  1194. }
  1195. /**
  1196. * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
  1197. * Note: no page is created by this method
  1198. * @since 1.0
  1199. * @see AddPage(), Close()
  1200. */
  1201. function Open() {
  1202. //Begin document
  1203. $this->state=1;
  1204. }
  1205. /**
  1206. * Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document.
  1207. * @since 1.0
  1208. * @see Open(), Output()
  1209. */
  1210. function Close() {
  1211. //Terminate document
  1212. if($this->state==3) {
  1213. return;
  1214. }
  1215. if($this->page==0) {
  1216. $this->AddPage();
  1217. }
  1218. //Page footer
  1219. $this->InFooter=true;
  1220. $this->Footer();
  1221. $this->InFooter=false;
  1222. //Close page
  1223. $this->_endpage();
  1224. //Close document
  1225. $this->_enddoc();
  1226. }
  1227. /**
  1228. * Reset pointer to the last document page.
  1229. * @since 2.0.000 (2008-01-04)
  1230. * @see setPage(), getPage(), getNumPages()
  1231. */
  1232. function lastPage() {
  1233. $this->page = count($this->pages);
  1234. }
  1235. /**
  1236. * Move pointer to the apecified document page.
  1237. * @param int $pnum page number
  1238. * @since 2.1.000 (2008-01-07)
  1239. * @see getPage(), lastpage(), getNumPages()
  1240. */
  1241. function setPage($pnum) {
  1242. if(($pnum > 0) AND ($pnum <= count($this->pages))) {
  1243. $this->page = $pnum;
  1244. }
  1245. }
  1246. /**
  1247. * Get current document page number.
  1248. * @return int page number
  1249. * @since 2.1.000 (2008-01-07)
  1250. * @see setPage(), lastpage(), getNumPages()
  1251. */
  1252. function getPage() {
  1253. return $this->page;
  1254. }
  1255. /**
  1256. * Get the total number of insered pages.
  1257. * @return int number of pages
  1258. * @since 2.1.000 (2008-01-07)
  1259. * @see setPage(), getPage(), lastpage()
  1260. */
  1261. function getNumPages() {
  1262. return count($this->pages);
  1263. }
  1264. /**
  1265. * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header.
  1266. * The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width.
  1267. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  1268. * @param string $orientation Page orientation. Possible values are (case insensitive):<ul><li>P or Portrait</li><li>L or Landscape</li></ul> The default value is the one passed to the constructor.
  1269. * @since 1.0
  1270. * @see TCPDF(), Header(), Footer(), SetMargins()
  1271. */
  1272. function AddPage($orientation='') {
  1273. if (count($this->pages) > $this->page) {
  1274. // this page has been already added
  1275. $this->page++;
  1276. $this->y = $this->tMargin;
  1277. return;
  1278. }
  1279. //Start a new page
  1280. if($this->state==0) {
  1281. $this->Open();
  1282. }
  1283. $family=$this->FontFamily;
  1284. $style=$this->FontStyle.($this->underline ? 'U' : '');
  1285. $size=$this->FontSizePt;
  1286. $lw=$this->LineWidth;
  1287. $dc=$this->DrawColor;
  1288. $fc=$this->FillColor;
  1289. $tc=$this->TextColor;
  1290. $cf=$this->ColorFlag;
  1291. if($this->page>0) {
  1292. //Page footer
  1293. $this->InFooter=true;
  1294. $this->Footer();
  1295. $this->InFooter=false;
  1296. //Close page
  1297. $this->_endpage();
  1298. }
  1299. //Start new page
  1300. $this->_beginpage($orientation);
  1301. //Set line cap style to square
  1302. $this->_out('2 J');
  1303. //Set line width
  1304. $this->LineWidth=$lw;
  1305. $this->_out(sprintf('%.2f w',$lw*$this->k));
  1306. //Set font
  1307. if($family) {
  1308. $this->SetFont($family,$style,$size);
  1309. }
  1310. //Set colors
  1311. $this->DrawColor=$dc;
  1312. if($dc!='0 G') {
  1313. $this->_out($dc);
  1314. }
  1315. $this->FillColor=$fc;
  1316. if($fc!='0 g') {
  1317. $this->_out($fc);
  1318. }
  1319. $this->TextColor=$tc;
  1320. $this->ColorFlag=$cf;
  1321. //Page header
  1322. $this->Header();
  1323. //Restore line width
  1324. if($this->LineWidth!=$lw) {
  1325. $this->LineWidth=$lw;
  1326. $this->_out(sprintf('%.2f w',$lw*$this->k));
  1327. }
  1328. //Restore font
  1329. if($family) {
  1330. $this->SetFont($family,$style,$size);
  1331. }
  1332. //Restore colors
  1333. if($this->DrawColor!=$dc) {
  1334. $this->DrawColor=$dc;
  1335. $this->_out($dc);
  1336. }
  1337. if($this->FillColor!=$fc) {
  1338. $this->FillColor=$fc;
  1339. $this->_out($fc);
  1340. }
  1341. $this->TextColor=$tc;
  1342. $this->ColorFlag=$cf;
  1343. }
  1344. /**
  1345. * Set header data.
  1346. * @param string $ln header image logo
  1347. * @param string $lw header image logo width in mm
  1348. * @param string $ht string to print as title on document header
  1349. * @param string $hs string to print on document header
  1350. */
  1351. function setHeaderData($ln="", $lw=0, $ht="", $hs="") {
  1352. $this->header_logo = $ln;
  1353. $this->header_logo_width = $lw;
  1354. $this->header_title = $ht;
  1355. $this->header_string = $hs;
  1356. }
  1357. /**
  1358. * Set header margin.
  1359. * (minimum distance between header and top page margin)
  1360. * @param int $hm distance in millimeters
  1361. */
  1362. function setHeaderMargin($hm=10) {
  1363. $this->header_margin = $hm;
  1364. }
  1365. /**
  1366. * Set footer margin.
  1367. * (minimum distance between footer and bottom page margin)
  1368. * @param int $fm distance in millimeters
  1369. */
  1370. function setFooterMargin($fm=10) {
  1371. $this->footer_margin = $fm;
  1372. }
  1373. /**
  1374. * Set a flag to print page header.
  1375. * @param boolean $val set to true to print the page header (default), false otherwise.
  1376. */
  1377. function setPrintHeader($val=true) {
  1378. $this->print_header = $val;
  1379. }
  1380. /**
  1381. * Set a flag to print page footer.
  1382. * @param boolean $value set to true to print the page footer (default), false otherwise.
  1383. */
  1384. function setPrintFooter($val=true) {
  1385. $this->print_footer = $val;
  1386. }
  1387. /**
  1388. * This method is used to render the page header.
  1389. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1390. */
  1391. function Header() {
  1392. if ($this->print_header) {
  1393. if (!isset($this->original_lMargin)) {
  1394. $this->original_lMargin = $this->lMargin;
  1395. }
  1396. if (!isset($this->original_rMargin)) {
  1397. $this->original_rMargin = $this->rMargin;
  1398. }
  1399. // reset original header margins
  1400. $this->rMargin = $this->original_rMargin;
  1401. $this->lMargin = $this->original_lMargin;
  1402. // save current font values
  1403. $font_family = $this->FontFamily;
  1404. $font_style = $this->FontStyle;
  1405. $font_size = $this->FontSizePt;
  1406. //set current position
  1407. if ($this->rtl) {
  1408. $this->SetXY($this->original_rMargin, $this->header_margin);
  1409. } else {
  1410. $this->SetXY($this->original_lMargin, $this->header_margin);
  1411. }
  1412. if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) {
  1413. $this->Image(K_PATH_IMAGES.$this->header_logo, $this->GetX(), $this->header_margin, $this->header_logo_width);
  1414. } else {
  1415. $this->img_rb_x = $this->GetX();
  1416. $this->img_rb_y = $this->GetY();
  1417. }
  1418. $cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2);
  1419. // set starting margin for text data cell
  1420. if ($this->rtl) {
  1421. $header_x = $this->original_rMargin + ($this->header_logo_width * 1.1);
  1422. } else {
  1423. $header_x = $this->original_lMargin + ($this->header_logo_width * 1.1);
  1424. }
  1425. // header title
  1426. $this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1);
  1427. $this->SetX($header_x);
  1428. $this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, '');
  1429. // header string
  1430. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  1431. $this->SetX($header_x);
  1432. $this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, '', 0, 1, 0, 0, true, 0);
  1433. // print an ending header line
  1434. //set style for cell border
  1435. $prevlinewidth = $this->GetLineWidth();
  1436. $line_width = 0.3;
  1437. $this->SetLineWidth($line_width);
  1438. $this->SetDrawColor(0, 0, 0);
  1439. $this->SetY(1 + max($this->img_rb_y, $this->GetY()));
  1440. if ($this->rtl) {
  1441. $this->SetX($this->original_rMargin);
  1442. } else {
  1443. $this->SetX($this->original_lMargin);
  1444. }
  1445. $this->Cell(0, 0, '', 'T', 0, 'C');
  1446. $this->SetLineWidth($prevlinewidth);
  1447. //restore position
  1448. if ($this->rtl) {
  1449. $this->SetXY($this->original_rMargin, $this->tMargin);
  1450. } else {
  1451. $this->SetXY($this->original_lMargin, $this->tMargin);
  1452. }
  1453. // restore font values
  1454. $this->SetFont($font_family, $font_style, $font_size);
  1455. }
  1456. }
  1457. /**
  1458. * This method is used to render the page footer.
  1459. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1460. */
  1461. function Footer() {
  1462. if ($this->print_footer) {
  1463. if (!isset($this->original_lMargin)) {
  1464. $this->original_lMargin = $this->lMargin;
  1465. }
  1466. if (!isset($this->original_rMargin)) {
  1467. $this->original_rMargin = $this->rMargin;
  1468. }
  1469. // reset original header margins
  1470. $this->rMargin = $this->original_rMargin;
  1471. $this->lMargin = $this->original_lMargin;
  1472. // save current font values
  1473. $font_family = $this->FontFamily;
  1474. $font_style = $this->FontStyle;
  1475. $font_size = $this->FontSizePt;
  1476. //set font
  1477. $this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]);
  1478. //set style for cell border
  1479. $prevlinewidth = $this->GetLineWidth();
  1480. $line_width = 0.3;
  1481. $this->SetLineWidth($line_width);
  1482. $this->SetDrawColor(0, 0, 0);
  1483. $footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height
  1484. //get footer y position
  1485. $footer_y = $this->h - $this->footer_margin - $footer_height;
  1486. //set current position
  1487. if ($this->rtl) {
  1488. $this->SetXY($this->original_rMargin, $footer_y);
  1489. } else {
  1490. $this->SetXY($this->original_lMargin, $footer_y);
  1491. }
  1492. //print document barcode
  1493. if ($this->barcode) {
  1494. $this->Ln();
  1495. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)/3); //max width
  1496. $this->writeBarcode($this->GetX(), $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode);
  1497. }
  1498. $pagenumtxt = $this->l['w_page']." ".$this->PageNo().' / {nb}';
  1499. $this->SetY($footer_y);
  1500. //Print page number
  1501. if ($this->rtl) {
  1502. $this->SetX($this->original_rMargin);
  1503. $this->Cell(0, $footer_height, $pagenumtxt, 'T', 0, 'L');
  1504. } else {
  1505. $this->SetX($this->original_lMargin);
  1506. $this->Cell(0, $footer_height, $pagenumtxt, 'T', 0, 'R');
  1507. }
  1508. // restore line width
  1509. $this->SetLineWidth($prevlinewidth);
  1510. // restore font values
  1511. $this->SetFont($font_family, $font_style, $font_size);
  1512. }
  1513. }
  1514. /**
  1515. * Returns the current page number.
  1516. * @return int page number
  1517. * @since 1.0
  1518. * @see AliasNbPages()
  1519. */
  1520. function PageNo() {
  1521. //Get current page number
  1522. return $this->page;
  1523. }
  1524. /**
  1525. * Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  1526. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1527. * @param int $g Green component (between 0 and 255)
  1528. * @param int $b Blue component (between 0 and 255)
  1529. * @since 1.3
  1530. * @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  1531. */
  1532. function SetDrawColor($r, $g=-1, $b=-1) {
  1533. //Set color for all stroking operations
  1534. if(($r==0 and $g==0 and $b==0) or $g==-1) {
  1535. $this->DrawColor=sprintf('%.3f G',$r/255);
  1536. }
  1537. else {
  1538. $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
  1539. }
  1540. if($this->page>0) {
  1541. $this->_out($this->DrawColor);
  1542. }
  1543. }
  1544. /**
  1545. * Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  1546. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1547. * @param int $g Green component (between 0 and 255)
  1548. * @param int $b Blue component (between 0 and 255)
  1549. * @param boolean $storeprev if true stores the RGB array on $prevFillColor variable.
  1550. * @since 1.3
  1551. * @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  1552. */
  1553. function SetFillColor($r, $g=-1, $b=-1, $storeprev=false) {
  1554. //Set color for all filling operations
  1555. if(($r==0 and $g==0 and $b==0) or $g==-1) {
  1556. $this->FillColor=sprintf('%.3f g',$r/255);
  1557. }
  1558. else {
  1559. $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  1560. }
  1561. $this->ColorFlag=($this->FillColor!=$this->TextColor);
  1562. if($this->page>0) {
  1563. $this->_out($this->FillColor);
  1564. }
  1565. if ($storeprev) {
  1566. // store color as previous value
  1567. $this->prevFillColor = array($r, $g, $b);
  1568. }
  1569. }
  1570. /**
  1571. * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
  1572. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1573. * @param int $g Green component (between 0 and 255)
  1574. * @param int $b Blue component (between 0 and 255)
  1575. * @param boolean $storeprev if true stores the RGB array on $prevTextColor variable.
  1576. * @since 1.3
  1577. * @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  1578. */
  1579. function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) {
  1580. //Set color for text
  1581. if(($r==0 and $g==0 and $b==0) or $g==-1) {
  1582. $this->TextColor=sprintf('%.3f g',$r/255);
  1583. }
  1584. else {
  1585. $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  1586. }
  1587. $this->ColorFlag=($this->FillColor!=$this->TextColor);
  1588. if ($storeprev) {
  1589. // store color as previous value
  1590. $this->prevTextColor = array($r, $g, $b);
  1591. }
  1592. }
  1593. /**
  1594. * Returns the length of a string in user unit. A font must be selected.<br>
  1595. * @param string $s The string whose length is to be computed
  1596. * @return int string length
  1597. * @author Nicola Asuni
  1598. * @since 1.2
  1599. */
  1600. function GetStringWidth($s) {
  1601. return $this->GetArrStringWidth($this->utf8Bidi($this->UTF8StringToArray($s), $this->tmprtl));
  1602. }
  1603. /**
  1604. * Returns the string length of an array of chars in user unit. A font must be selected.<br>
  1605. * @param string $arr The ar…

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