PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/tcpdf/tcpdf.php

https://bitbucket.org/ceu/moodle_demo
PHP | 4137 lines | 2321 code | 305 blank | 1511 comment | 373 complexity | 4e978c04afa0fd8cfe9fc5ed9a91e829 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1

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 : 2006-08-05
  6. // Author : Nicola Asuni
  7. // Version : 1.53.0.TC023_PHP4
  8. // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9. //
  10. // Description : This is a PHP4 class for generating PDF files
  11. // on-the-fly without requiring external
  12. // extensions.
  13. //
  14. // IMPORTANT:
  15. // This class is an extension and improvement of the public Domain
  16. // FPDF class by Olivier Plathey (http://www.fpdf.org).
  17. //
  18. // Main changes by Nicola Asuni:
  19. // PHP4 porting;
  20. // UTF-8 Unicode support;
  21. // code refactoring;
  22. // source code clean up;
  23. // code style and formatting;
  24. // source code documentation using phpDocumentor (www.phpdoc.org);
  25. // All ISO page formats were included;
  26. // image scale factor;
  27. // includes methods to parse and printsome 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;
  28. // 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/);
  29. // defines standard Header() and Footer() methods.
  30. //============================================================+
  31. /**
  32. * include configuration file
  33. */
  34. require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  35. /**
  36. * TCPDF Class.
  37. * @package com.tecnick.tcpdf
  38. */
  39. /**
  40. * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
  41. * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  42. * <h3>TCPDF main changes from FPDF are:</h3><ul>
  43. * <li>PHP4 porting</li>
  44. * <li>UTF-8 Unicode support</li>
  45. * <li>source code clean up</li>
  46. * <li>code style and formatting</li>
  47. * <li>source code documentation using phpDocumentor (www.phpdoc.org)</li>
  48. * <li>All ISO page formats were included</li>
  49. * <li>image scale factor</li>
  50. * <li>includes methods to parse and printsome 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>
  51. * <li>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/)</li>
  52. * <li>defines standard Header() and Footer() methods.</li>
  53. * </ul>
  54. * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
  55. * @name TCPDF
  56. * @package com.tecnick.tcpdf
  57. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  58. * @author Nicola Asuni
  59. * @copyright 2004-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com
  60. * @link http://tcpdf.sourceforge.net
  61. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  62. @version 1.53.0.TC023_PHP4
  63. */
  64. if(!class_exists('TCPDF')) {
  65. /**
  66. * define default PDF document producer
  67. */
  68. define('PDF_PRODUCER','TCPDF 1.53.0.TC023_PHP4 (http://tcpdf.sourceforge.net)');
  69. /**
  70. * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
  71. * This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  72. * This version contains some changes: [porting to PHP4, support for UTF-8 Unicode, code style and formatting, php documentation (www.phpdoc.org), ISO page formats, minor improvements, image scale factor]<br>
  73. * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  74. * To add your own TTF fonts please read /fonts/README.TXT
  75. * @name TCPDF
  76. * @package com.tecnick.tcpdf
  77. * @version 1.53.0.TC023
  78. * @author Nicola Asuni
  79. * @link http://tcpdf.sourceforge.net
  80. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  81. */
  82. class TCPDF {
  83. //var properties
  84. /**
  85. * @var current page number
  86. * @access protected
  87. */
  88. var $page;
  89. /**
  90. * @var current object number
  91. * @access protected
  92. */
  93. var $n;
  94. /**
  95. * @var array of object offsets
  96. * @access protected
  97. */
  98. var $offsets;
  99. /**
  100. * @var buffer holding in-memory PDF
  101. * @access protected
  102. */
  103. var $buffer;
  104. /**
  105. * @var array containing pages
  106. * @access protected
  107. */
  108. var $pages;
  109. /**
  110. * @var current document state
  111. * @access protected
  112. */
  113. var $state;
  114. /**
  115. * @var compression flag
  116. * @access protected
  117. */
  118. var $compress;
  119. /**
  120. * @var default orientation
  121. * @access protected
  122. */
  123. var $DefOrientation;
  124. /**
  125. * @var current orientation
  126. * @access protected
  127. */
  128. var $CurOrientation;
  129. /**
  130. * @var array indicating orientation changes
  131. * @access protected
  132. */
  133. var $OrientationChanges;
  134. /**
  135. * @var scale factor (number of points in user unit)
  136. * @access protected
  137. */
  138. var $k;
  139. /**
  140. * @var width of page format in points
  141. * @access protected
  142. */
  143. var $fwPt;
  144. /**
  145. * @var height of page format in points
  146. * @access protected
  147. */
  148. var $fhPt;
  149. /**
  150. * @var width of page format in user unit
  151. * @access protected
  152. */
  153. var $fw;
  154. /**
  155. * @var height of page format in user unit
  156. * @access protected
  157. */
  158. var $fh;
  159. /**
  160. * @var current width of page in points
  161. * @access protected
  162. */
  163. var $wPt;
  164. /**
  165. * @var current height of page in points
  166. * @access protected
  167. */
  168. var $hPt;
  169. /**
  170. * @var current width of page in user unit
  171. * @access protected
  172. */
  173. var $w;
  174. /**
  175. * @var current height of page in user unit
  176. * @access protected
  177. */
  178. var $h;
  179. /**
  180. * @var left margin
  181. * @access protected
  182. */
  183. var $lMargin;
  184. /**
  185. * @var top margin
  186. * @access protected
  187. */
  188. var $tMargin;
  189. /**
  190. * @var right margin
  191. * @access protected
  192. */
  193. var $rMargin;
  194. /**
  195. * @var page break margin
  196. * @access protected
  197. */
  198. var $bMargin;
  199. /**
  200. * @var cell margin
  201. * @access protected
  202. */
  203. var $cMargin;
  204. /**
  205. * @var current horizontal position in user unit for cell positioning
  206. * @access protected
  207. */
  208. var $x;
  209. /**
  210. * @var current vertical position in user unit for cell positioning
  211. * @access protected
  212. */
  213. var $y;
  214. /**
  215. * @var height of last cell printed
  216. * @access protected
  217. */
  218. var $lasth;
  219. /**
  220. * @var line width in user unit
  221. * @access protected
  222. */
  223. var $LineWidth;
  224. /**
  225. * @var array of standard font names
  226. * @access protected
  227. */
  228. var $CoreFonts;
  229. /**
  230. * @var array of used fonts
  231. * @access protected
  232. */
  233. var $fonts;
  234. /**
  235. * @var array of font files
  236. * @access protected
  237. */
  238. var $FontFiles;
  239. /**
  240. * @var array of encoding differences
  241. * @access protected
  242. */
  243. var $diffs;
  244. /**
  245. * @var array of used images
  246. * @access protected
  247. */
  248. var $images;
  249. /**
  250. * @var array of links in pages
  251. * @access protected
  252. */
  253. var $PageLinks;
  254. /**
  255. * @var array of internal links
  256. * @access protected
  257. */
  258. var $links;
  259. /**
  260. * @var current font family
  261. * @access protected
  262. */
  263. var $FontFamily;
  264. /**
  265. * @var current font style
  266. * @access protected
  267. */
  268. var $FontStyle;
  269. /**
  270. * @var underlining flag
  271. * @access protected
  272. */
  273. var $underline;
  274. /**
  275. * @var current font info
  276. * @access protected
  277. */
  278. var $CurrentFont;
  279. /**
  280. * @var current font size in points
  281. * @access protected
  282. */
  283. var $FontSizePt;
  284. /**
  285. * @var current font size in user unit
  286. * @access protected
  287. */
  288. var $FontSize;
  289. /**
  290. * @var commands for drawing color
  291. * @access protected
  292. */
  293. var $DrawColor;
  294. /**
  295. * @var commands for filling color
  296. * @access protected
  297. */
  298. var $FillColor;
  299. /**
  300. * @var commands for text color
  301. * @access protected
  302. */
  303. var $TextColor;
  304. /**
  305. * @var indicates whether fill and text colors are different
  306. * @access protected
  307. */
  308. var $ColorFlag;
  309. /**
  310. * @var word spacing
  311. * @access protected
  312. */
  313. var $ws;
  314. /**
  315. * @var automatic page breaking
  316. * @access protected
  317. */
  318. var $AutoPageBreak;
  319. /**
  320. * @var threshold used to trigger page breaks
  321. * @access protected
  322. */
  323. var $PageBreakTrigger;
  324. /**
  325. * @var flag set when processing footer
  326. * @access protected
  327. */
  328. var $InFooter;
  329. /**
  330. * @var zoom display mode
  331. * @access protected
  332. */
  333. var $ZoomMode;
  334. /**
  335. * @var layout display mode
  336. * @access protected
  337. */
  338. var $LayoutMode;
  339. /**
  340. * @var title
  341. * @access protected
  342. */
  343. var $title;
  344. /**
  345. * @var subject
  346. * @access protected
  347. */
  348. var $subject;
  349. /**
  350. * @var author
  351. * @access protected
  352. */
  353. var $author;
  354. /**
  355. * @var keywords
  356. * @access protected
  357. */
  358. var $keywords;
  359. /**
  360. * @var creator
  361. * @access protected
  362. */
  363. var $creator;
  364. /**
  365. * @var alias for total number of pages
  366. * @access protected
  367. */
  368. var $AliasNbPages;
  369. /**
  370. * @var right-bottom corner X coordinate of inserted image
  371. * @since 2002-07-31
  372. * @author Nicola Asuni
  373. * @access protected
  374. */
  375. var $img_rb_x;
  376. /**
  377. * @var right-bottom corner Y coordinate of inserted image
  378. * @since 2002-07-31
  379. * @author Nicola Asuni
  380. * @access protected
  381. */
  382. var $img_rb_y;
  383. /**
  384. * @var image scale factor
  385. * @since 2004-06-14
  386. * @author Nicola Asuni
  387. * @access protected
  388. */
  389. var $imgscale = 1;
  390. /**
  391. * @var boolean set to true when the input text is unicode (require unicode fonts)
  392. * @since 2005-01-02
  393. * @author Nicola Asuni
  394. * @access protected
  395. */
  396. var $isunicode = false;
  397. /**
  398. * @var PDF version
  399. * @since 1.5.3
  400. * @access protected
  401. */
  402. var $PDFVersion = "1.3";
  403. // ----------------------
  404. /**
  405. * @var Minimum distance between header and top page margin.
  406. * @access private
  407. */
  408. var $header_margin;
  409. /**
  410. * @var Minimum distance between footer and bottom page margin.
  411. * @access private
  412. */
  413. var $footer_margin;
  414. /**
  415. * @var original left margin value
  416. * @access private
  417. * @since 1.53.0.TC013
  418. */
  419. var $original_lMargin;
  420. /**
  421. * @var original right margin value
  422. * @access private
  423. * @since 1.53.0.TC013
  424. */
  425. var $original_rMargin;
  426. /**
  427. * @var Header font.
  428. * @access private
  429. */
  430. var $header_font;
  431. /**
  432. * @var Footer font.
  433. * @access private
  434. */
  435. var $footer_font;
  436. /**
  437. * @var Language templates.
  438. * @access private
  439. */
  440. var $l;
  441. /**
  442. * @var Barcode to print on page footer (only if set).
  443. * @access private
  444. */
  445. var $barcode = false;
  446. /**
  447. * @var If true prints header
  448. * @access private
  449. */
  450. var $print_header = true;
  451. /**
  452. * @var If true prints footer.
  453. * @access private
  454. */
  455. var $print_footer = true;
  456. /**
  457. * @var Header width (0 = full page width).
  458. * @access private
  459. */
  460. var $header_width = 0;
  461. /**
  462. * @var Header image logo.
  463. * @access private
  464. */
  465. var $header_logo = "";
  466. /**
  467. * @var Header image logo width in mm.
  468. * @access private
  469. */
  470. var $header_logo_width = 30;
  471. /**
  472. * @var String to print as title on document header.
  473. * @access private
  474. */
  475. var $header_title = "";
  476. /**
  477. * @var String to print on document header.
  478. * @access private
  479. */
  480. var $header_string = "";
  481. /**
  482. * @var Default number of columns for html table.
  483. * @access private
  484. */
  485. var $default_table_columns = 4;
  486. // variables for html parser
  487. /**
  488. * @var HTML PARSER: store current link.
  489. * @access private
  490. */
  491. var $HREF;
  492. /**
  493. * @var HTML PARSER: store font list.
  494. * @access private
  495. */
  496. var $fontList;
  497. /**
  498. * @var HTML PARSER: true when font attribute is set.
  499. * @access private
  500. */
  501. var $issetfont;
  502. /**
  503. * @var HTML PARSER: true when color attribute is set.
  504. * @access private
  505. */
  506. var $issetcolor;
  507. /**
  508. * @var HTML PARSER: true in case of ordered list (OL), false otherwise.
  509. * @access private
  510. */
  511. var $listordered = false;
  512. /**
  513. * @var HTML PARSER: count list items.
  514. * @access private
  515. */
  516. var $listcount = 0;
  517. /**
  518. * @var HTML PARSER: size of table border.
  519. * @access private
  520. */
  521. var $tableborder = 0;
  522. /**
  523. * @var HTML PARSER: true at the beginning of table.
  524. * @access private
  525. */
  526. var $tdbegin = false;
  527. /**
  528. * @var HTML PARSER: table width.
  529. * @access private
  530. */
  531. var $tdwidth = 0;
  532. /**
  533. * @var HTML PARSER: table height.
  534. * @access private
  535. */
  536. var $tdheight = 0;
  537. /**
  538. * @var HTML PARSER: table align.
  539. * @access private
  540. */
  541. var $tdalign = "L";
  542. /**
  543. * @var HTML PARSER: table background color.
  544. * @access private
  545. */
  546. var $tdbgcolor = false;
  547. /**
  548. * @var Store temporary font size in points.
  549. * @access private
  550. */
  551. var $tempfontsize = 10;
  552. /**
  553. * @var Bold font style status.
  554. * @access private
  555. */
  556. var $b;
  557. /**
  558. * @var Underlined font style status.
  559. * @access private
  560. */
  561. var $u;
  562. /**
  563. * @var Italic font style status.
  564. * @access private
  565. */
  566. var $i;
  567. /**
  568. * @var spacer for LI tags.
  569. * @access private
  570. */
  571. var $lispacer = "";
  572. /**
  573. * @var default encoding
  574. * @access private
  575. * @since 1.53.0.TC010
  576. */
  577. var $encoding = "UTF-8";
  578. /**
  579. * @var PHP internal encoding
  580. * @access private
  581. * @since 1.53.0.TC016
  582. */
  583. var $internal_encoding;
  584. /**
  585. * @var store previous fill color as RGB array
  586. * @access private
  587. * @since 1.53.0.TC017
  588. */
  589. var $prevFillColor = array(255,255,255);
  590. /**
  591. * @var store previous text color as RGB array
  592. * @access private
  593. * @since 1.53.0.TC017
  594. */
  595. var $prevTextColor = array(0,0,0);
  596. /**
  597. * @var store previous font family
  598. * @access private
  599. * @since 1.53.0.TC017
  600. */
  601. var $prevFontFamily;
  602. /**
  603. * @var store previous font style
  604. * @access private
  605. * @since 1.53.0.TC017
  606. */
  607. var $prevFontStyle;
  608. //------------------------------------------------------------
  609. // var methods
  610. //------------------------------------------------------------
  611. /**
  612. * This is the class constructor.
  613. * It allows to set up the page format, the orientation and
  614. * the measure unit used in all the methods (except for the font sizes).
  615. * @since 1.0
  616. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  617. * @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.
  618. * @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>
  619. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  620. * @param String $encoding charset encoding; default is UTF-8
  621. */
  622. function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") {
  623. /* Set internal character encoding to ASCII */
  624. if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) {
  625. $this->internal_encoding = mb_internal_encoding();
  626. mb_internal_encoding("ASCII");
  627. }
  628. //Some checks
  629. $this->_dochecks();
  630. //Initialization of properties
  631. $this->isunicode=$unicode;
  632. $this->page=0;
  633. $this->n=2;
  634. $this->buffer='';
  635. $this->pages=array();
  636. $this->OrientationChanges=array();
  637. $this->state=0;
  638. $this->fonts=array();
  639. $this->FontFiles=array();
  640. $this->diffs=array();
  641. $this->images=array();
  642. $this->links=array();
  643. $this->InFooter=false;
  644. $this->lasth=0;
  645. $this->FontFamily='';
  646. $this->FontStyle='';
  647. $this->FontSizePt=12;
  648. $this->underline=false;
  649. $this->DrawColor='0 G';
  650. $this->FillColor='0 g';
  651. $this->TextColor='0 g';
  652. $this->ColorFlag=false;
  653. $this->ws=0;
  654. //Standard Unicode fonts
  655. $this->CoreFonts=array(
  656. 'courier'=>'Courier',
  657. 'courierB'=>'Courier-Bold',
  658. 'courierI'=>'Courier-Oblique',
  659. 'courierBI'=>'Courier-BoldOblique',
  660. 'helvetica'=>'Helvetica',
  661. 'helveticaB'=>'Helvetica-Bold',
  662. 'helveticaI'=>'Helvetica-Oblique',
  663. 'helveticaBI'=>'Helvetica-BoldOblique',
  664. 'times'=>'Times-Roman',
  665. 'timesB'=>'Times-Bold',
  666. 'timesI'=>'Times-Italic',
  667. 'timesBI'=>'Times-BoldItalic',
  668. 'symbol'=>'Symbol',
  669. 'zapfdingbats'=>'ZapfDingbats'
  670. );
  671. //Scale factor
  672. // 2003-06-11 - Nicola Asuni : changed if/else with switch statement
  673. switch (strtolower($unit)){
  674. case 'pt': {$this->k=1; break;}
  675. case 'mm': {$this->k=72/25.4; break;}
  676. case 'cm': {$this->k=72/2.54; break;}
  677. case 'in': {$this->k=72; break;}
  678. default : {$this->Error('Incorrect unit: '.$unit); break;}
  679. }
  680. //Page format
  681. if(is_string($format)) {
  682. // 2002-07-24 - Nicola Asuni (info@tecnick.com)
  683. // Added new page formats (45 standard ISO paper formats and 4 american common formats).
  684. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  685. switch (strtoupper($format)){
  686. case '4A0': {$format = array(4767.87,6740.79); break;}
  687. case '2A0': {$format = array(3370.39,4767.87); break;}
  688. case 'A0': {$format = array(2383.94,3370.39); break;}
  689. case 'A1': {$format = array(1683.78,2383.94); break;}
  690. case 'A2': {$format = array(1190.55,1683.78); break;}
  691. case 'A3': {$format = array(841.89,1190.55); break;}
  692. case 'A4': default: {$format = array(595.28,841.89); break;}
  693. case 'A5': {$format = array(419.53,595.28); break;}
  694. case 'A6': {$format = array(297.64,419.53); break;}
  695. case 'A7': {$format = array(209.76,297.64); break;}
  696. case 'A8': {$format = array(147.40,209.76); break;}
  697. case 'A9': {$format = array(104.88,147.40); break;}
  698. case 'A10': {$format = array(73.70,104.88); break;}
  699. case 'B0': {$format = array(2834.65,4008.19); break;}
  700. case 'B1': {$format = array(2004.09,2834.65); break;}
  701. case 'B2': {$format = array(1417.32,2004.09); break;}
  702. case 'B3': {$format = array(1000.63,1417.32); break;}
  703. case 'B4': {$format = array(708.66,1000.63); break;}
  704. case 'B5': {$format = array(498.90,708.66); break;}
  705. case 'B6': {$format = array(354.33,498.90); break;}
  706. case 'B7': {$format = array(249.45,354.33); break;}
  707. case 'B8': {$format = array(175.75,249.45); break;}
  708. case 'B9': {$format = array(124.72,175.75); break;}
  709. case 'B10': {$format = array(87.87,124.72); break;}
  710. case 'C0': {$format = array(2599.37,3676.54); break;}
  711. case 'C1': {$format = array(1836.85,2599.37); break;}
  712. case 'C2': {$format = array(1298.27,1836.85); break;}
  713. case 'C3': {$format = array(918.43,1298.27); break;}
  714. case 'C4': {$format = array(649.13,918.43); break;}
  715. case 'C5': {$format = array(459.21,649.13); break;}
  716. case 'C6': {$format = array(323.15,459.21); break;}
  717. case 'C7': {$format = array(229.61,323.15); break;}
  718. case 'C8': {$format = array(161.57,229.61); break;}
  719. case 'C9': {$format = array(113.39,161.57); break;}
  720. case 'C10': {$format = array(79.37,113.39); break;}
  721. case 'RA0': {$format = array(2437.80,3458.27); break;}
  722. case 'RA1': {$format = array(1729.13,2437.80); break;}
  723. case 'RA2': {$format = array(1218.90,1729.13); break;}
  724. case 'RA3': {$format = array(864.57,1218.90); break;}
  725. case 'RA4': {$format = array(609.45,864.57); break;}
  726. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  727. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  728. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  729. case 'SRA3': {$format = array(907.09,1275.59); break;}
  730. case 'SRA4': {$format = array(637.80,907.09); break;}
  731. case 'LETTER': {$format = array(612.00,792.00); break;}
  732. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  733. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  734. case 'FOLIO': {$format = array(612.00,936.00); break;}
  735. // default: {$this->Error('Unknown page format: '.$format); break;}
  736. // END CHANGES Nicola Asuni
  737. }
  738. $this->fwPt=$format[0];
  739. $this->fhPt=$format[1];
  740. }
  741. else {
  742. $this->fwPt=$format[0]*$this->k;
  743. $this->fhPt=$format[1]*$this->k;
  744. }
  745. $this->fw=$this->fwPt/$this->k;
  746. $this->fh=$this->fhPt/$this->k;
  747. //Page orientation
  748. $orientation=strtolower($orientation);
  749. if($orientation=='p' or $orientation=='portrait') {
  750. $this->DefOrientation='P';
  751. $this->wPt=$this->fwPt;
  752. $this->hPt=$this->fhPt;
  753. }
  754. elseif($orientation=='l' or $orientation=='landscape') {
  755. $this->DefOrientation='L';
  756. $this->wPt=$this->fhPt;
  757. $this->hPt=$this->fwPt;
  758. }
  759. else {
  760. $this->Error('Incorrect orientation: '.$orientation);
  761. }
  762. $this->CurOrientation=$this->DefOrientation;
  763. $this->w=$this->wPt/$this->k;
  764. $this->h=$this->hPt/$this->k;
  765. //Page margins (1 cm)
  766. $margin=28.35/$this->k;
  767. $this->SetMargins($margin,$margin);
  768. //Interior cell margin (1 mm)
  769. $this->cMargin=$margin/10;
  770. //Line width (0.2 mm)
  771. $this->LineWidth=.567/$this->k;
  772. //Automatic page break
  773. $this->SetAutoPageBreak(true,2*$margin);
  774. //Full width display mode
  775. $this->SetDisplayMode('fullwidth');
  776. //Compression
  777. $this->SetCompression(true);
  778. //Set default PDF version number
  779. $this->PDFVersion = "1.3";
  780. $this->encoding = $encoding;
  781. $this->b = 0;
  782. $this->i = 0;
  783. $this->u = 0;
  784. $this->HREF = '';
  785. $this->fontlist = array("arial", "times", "courier", "helvetica", "symbol");
  786. $this->issetfont = false;
  787. $this->issetcolor = false;
  788. $this->tableborder = 0;
  789. $this->tdbegin = false;
  790. $this->tdwidth= 0;
  791. $this->tdheight = 0;
  792. $this->tdalign = "L";
  793. $this->tdbgcolor = false;
  794. $this->SetFillColor(200, 200, 200, true);
  795. $this->SetTextColor(0, 0, 0, true);
  796. }
  797. /**
  798. * Set the image scale.
  799. * @param float $scale image scale.
  800. * @author Nicola Asuni
  801. * @since 1.5.2
  802. */
  803. function setImageScale($scale) {
  804. $this->imgscale=$scale;
  805. }
  806. /**
  807. * Returns the image scale.
  808. * @return float image scale.
  809. * @author Nicola Asuni
  810. * @since 1.5.2
  811. */
  812. function getImageScale() {
  813. return $this->imgscale;
  814. }
  815. /**
  816. * Returns the page width in units.
  817. * @return int page width.
  818. * @author Nicola Asuni
  819. * @since 1.5.2
  820. */
  821. function getPageWidth() {
  822. return $this->w;
  823. }
  824. /**
  825. * Returns the page height in units.
  826. * @return int page height.
  827. * @author Nicola Asuni
  828. * @since 1.5.2
  829. */
  830. function getPageHeight() {
  831. return $this->fh;
  832. }
  833. /**
  834. * Returns the page break margin.
  835. * @return int page break margin.
  836. * @author Nicola Asuni
  837. * @since 1.5.2
  838. */
  839. function getBreakMargin() {
  840. return $this->bMargin;
  841. }
  842. /**
  843. * Returns the scale factor (number of points in user unit).
  844. * @return int scale factor.
  845. * @author Nicola Asuni
  846. * @since 1.5.2
  847. */
  848. function getScaleFactor() {
  849. return $this->k;
  850. }
  851. /**
  852. * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  853. * @param float $left Left margin.
  854. * @param float $top Top margin.
  855. * @param float $right Right margin. Default value is the left one.
  856. * @since 1.0
  857. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  858. */
  859. function SetMargins($left, $top, $right=-1) {
  860. //Set left, top and right margins
  861. $this->lMargin=$left;
  862. $this->tMargin=$top;
  863. if($right==-1) {
  864. $right=$left;
  865. }
  866. $this->rMargin=$right;
  867. }
  868. /**
  869. * 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.
  870. * @param float $margin The margin.
  871. * @since 1.4
  872. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  873. */
  874. function SetLeftMargin($margin) {
  875. //Set left margin
  876. $this->lMargin=$margin;
  877. if(($this->page>0) and ($this->x<$margin)) {
  878. $this->x=$margin;
  879. }
  880. }
  881. /**
  882. * Defines the top margin. The method can be called before creating the first page.
  883. * @param float $margin The margin.
  884. * @since 1.5
  885. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  886. */
  887. function SetTopMargin($margin) {
  888. //Set top margin
  889. $this->tMargin=$margin;
  890. }
  891. /**
  892. * Defines the right margin. The method can be called before creating the first page.
  893. * @param float $margin The margin.
  894. * @since 1.5
  895. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  896. */
  897. function SetRightMargin($margin) {
  898. //Set right margin
  899. $this->rMargin=$margin;
  900. }
  901. /**
  902. * 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.
  903. * @param boolean $auto Boolean indicating if mode should be on or off.
  904. * @param float $margin Distance from the bottom of the page.
  905. * @since 1.0
  906. * @see Cell(), MultiCell(), AcceptPageBreak()
  907. */
  908. function SetAutoPageBreak($auto, $margin=0) {
  909. //Set auto page break mode and triggering margin
  910. $this->AutoPageBreak=$auto;
  911. $this->bMargin=$margin;
  912. $this->PageBreakTrigger=$this->h-$margin;
  913. }
  914. /**
  915. * 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.
  916. * @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>
  917. * @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>
  918. * @since 1.2
  919. */
  920. function SetDisplayMode($zoom, $layout='continuous') {
  921. //Set display mode in viewer
  922. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
  923. $this->ZoomMode=$zoom;
  924. }
  925. else {
  926. $this->Error('Incorrect zoom display mode: '.$zoom);
  927. }
  928. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
  929. $this->LayoutMode=$layout;
  930. }
  931. else {
  932. $this->Error('Incorrect layout display mode: '.$layout);
  933. }
  934. }
  935. /**
  936. * 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.
  937. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  938. * @param boolean $compress Boolean indicating if compression must be enabled.
  939. * @since 1.4
  940. */
  941. function SetCompression($compress) {
  942. //Set page compression
  943. if(function_exists('gzcompress')) {
  944. $this->compress=$compress;
  945. }
  946. else {
  947. $this->compress=false;
  948. }
  949. }
  950. /**
  951. * Defines the title of the document.
  952. * @param string $title The title.
  953. * @since 1.2
  954. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  955. */
  956. function SetTitle($title) {
  957. //Title of document
  958. $this->title=$title;
  959. }
  960. /**
  961. * Defines the subject of the document.
  962. * @param string $subject The subject.
  963. * @since 1.2
  964. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  965. */
  966. function SetSubject($subject) {
  967. //Subject of document
  968. $this->subject=$subject;
  969. }
  970. /**
  971. * Defines the author of the document.
  972. * @param string $author The name of the author.
  973. * @since 1.2
  974. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  975. */
  976. function SetAuthor($author) {
  977. //Author of document
  978. $this->author=$author;
  979. }
  980. /**
  981. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  982. * @param string $keywords The list of keywords.
  983. * @since 1.2
  984. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  985. */
  986. function SetKeywords($keywords) {
  987. //Keywords of document
  988. $this->keywords=$keywords;
  989. }
  990. /**
  991. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  992. * @param string $creator The name of the creator.
  993. * @since 1.2
  994. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  995. */
  996. function SetCreator($creator) {
  997. //Creator of document
  998. $this->creator=$creator;
  999. }
  1000. /**
  1001. * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
  1002. * <b>Example:</b><br />
  1003. * <pre>
  1004. * class PDF extends TCPDF {
  1005. * function Footer() {
  1006. * //Go to 1.5 cm from bottom
  1007. * $this->SetY(-15);
  1008. * //Select Arial italic 8
  1009. * $this->SetFont('Arial','I',8);
  1010. * //Print current and total page numbers
  1011. * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  1012. * }
  1013. * }
  1014. * $pdf=new PDF();
  1015. * $pdf->AliasNbPages();
  1016. * </pre>
  1017. * @param string $alias The alias. Default value: {nb}.
  1018. * @since 1.4
  1019. * @see PageNo(), Footer()
  1020. */
  1021. function AliasNbPages($alias='{nb}') {
  1022. //Define an alias for total number of pages
  1023. $this->AliasNbPages = $this->_escapetext($alias);
  1024. }
  1025. /**
  1026. * 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.
  1027. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  1028. * @param string $msg The error message
  1029. * @since 1.0
  1030. */
  1031. function Error($msg) {
  1032. //Fatal error
  1033. die('<strong>TCPDF error: </strong>'.$msg);
  1034. }
  1035. /**
  1036. * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
  1037. * Note: no page is created by this method
  1038. * @since 1.0
  1039. * @see AddPage(), Close()
  1040. */
  1041. function Open() {
  1042. //Begin document
  1043. $this->state=1;
  1044. }
  1045. /**
  1046. * 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.
  1047. * @since 1.0
  1048. * @see Open(), Output()
  1049. */
  1050. function Close() {
  1051. //Terminate document
  1052. if($this->state==3) {
  1053. return;
  1054. }
  1055. if($this->page==0) {
  1056. $this->AddPage();
  1057. }
  1058. //Page footer
  1059. $this->InFooter=true;
  1060. $this->Footer();
  1061. $this->InFooter=false;
  1062. //Close page
  1063. $this->_endpage();
  1064. //Close document
  1065. $this->_enddoc();
  1066. }
  1067. /**
  1068. * 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.
  1069. * 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.
  1070. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  1071. * @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.
  1072. * @since 1.0
  1073. * @see TCPDF(), Header(), Footer(), SetMargins()
  1074. */
  1075. function AddPage($orientation='') {
  1076. //Start a new page
  1077. if($this->state==0) {
  1078. $this->Open();
  1079. }
  1080. $family=$this->FontFamily;
  1081. $style=$this->FontStyle.($this->underline ? 'U' : '');
  1082. $size=$this->FontSizePt;
  1083. $lw=$this->LineWidth;
  1084. $dc=$this->DrawColor;
  1085. $fc=$this->FillColor;
  1086. $tc=$this->TextColor;
  1087. $cf=$this->ColorFlag;
  1088. if($this->page>0) {
  1089. //Page footer
  1090. $this->InFooter=true;
  1091. $this->Footer();
  1092. $this->InFooter=false;
  1093. //Close page
  1094. $this->_endpage();
  1095. }
  1096. //Start new page
  1097. $this->_beginpage($orientation);
  1098. //Set line cap style to square
  1099. $this->_out('2 J');
  1100. //Set line width
  1101. $this->LineWidth=$lw;
  1102. $this->_out(sprintf('%.2f w',$lw*$this->k));
  1103. //Set font
  1104. if($family) {
  1105. $this->SetFont($family,$style,$size);
  1106. }
  1107. //Set colors
  1108. $this->DrawColor=$dc;
  1109. if($dc!='0 G') {
  1110. $this->_out($dc);
  1111. }
  1112. $this->FillColor=$fc;
  1113. if($fc!='0 g') {
  1114. $this->_out($fc);
  1115. }
  1116. $this->TextColor=$tc;
  1117. $this->ColorFlag=$cf;
  1118. //Page header
  1119. $this->Header();
  1120. //Restore line width
  1121. if($this->LineWidth!=$lw) {
  1122. $this->LineWidth=$lw;
  1123. $this->_out(sprintf('%.2f w',$lw*$this->k));
  1124. }
  1125. //Restore font
  1126. if($family) {
  1127. $this->SetFont($family,$style,$size);
  1128. }
  1129. //Restore colors
  1130. if($this->DrawColor!=$dc) {
  1131. $this->DrawColor=$dc;
  1132. $this->_out($dc);
  1133. }
  1134. if($this->FillColor!=$fc) {
  1135. $this->FillColor=$fc;
  1136. $this->_out($fc);
  1137. }
  1138. $this->TextColor=$tc;
  1139. $this->ColorFlag=$cf;
  1140. }
  1141. /**
  1142. * Set header data.
  1143. * @param string $ln header image logo
  1144. * @param string $lw header image logo width in mm
  1145. * @param string $ht string to print as title on document header
  1146. * @param string $hs string to print on document header
  1147. */
  1148. function setHeaderData($ln="", $lw=0, $ht="", $hs="") {
  1149. $this->header_logo = $ln;
  1150. $this->header_logo_width = $lw;
  1151. $this->header_title = $ht;
  1152. $this->header_string = $hs;
  1153. }
  1154. /**
  1155. * Set header margin.
  1156. * (minimum distance between header and top page margin)
  1157. * @param int $hm distance in millimeters
  1158. */
  1159. function setHeaderMargin($hm=10) {
  1160. $this->header_margin = $hm;
  1161. }
  1162. /**
  1163. * Set footer margin.
  1164. * (minimum distance between footer and bottom page margin)
  1165. * @param int $fm distance in millimeters
  1166. */
  1167. function setFooterMargin($fm=10) {
  1168. $this->footer_margin = $fm;
  1169. }
  1170. /**
  1171. * This method is used to render the page header.
  1172. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1173. */
  1174. function Header() {
  1175. if ($this->print_header) {
  1176. if (!isset($this->original_lMargin)) {
  1177. $this->original_lMargin = $this->lMargin;
  1178. }
  1179. if (!isset($this->original_rMargin)) {
  1180. $this->original_rMargin = $this->rMargin;
  1181. }
  1182. //set current position
  1183. $this->SetXY($this->original_lMargin, $this->header_margin);
  1184. if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) {
  1185. $this->Image(K_PATH_IMAGES.$this->header_logo, $this->original_lMargin, $this->header_margin, $this->header_logo_width);
  1186. }
  1187. else {
  1188. $this->img_rb_y = $this->GetY();
  1189. }
  1190. $cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2);
  1191. $header_x = $this->original_lMargin + ($this->header_logo_width * 1.05); //set left margin for text data cell
  1192. // header title
  1193. $this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1);
  1194. $this->SetX($header_x);
  1195. $this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, 'L');
  1196. // header string
  1197. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  1198. $this->SetX($header_x);
  1199. $this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, 'L', 0);
  1200. // print an ending header line
  1201. if (empty($this->header_width)) {
  1202. //set style for cell border
  1203. $this->SetLineWidth(0.3);
  1204. $this->SetDrawColor(0, 0, 0);
  1205. $this->SetY(1 + max($this->img_rb_y, $this->GetY()));
  1206. $this->SetX($this->original_lMargin);
  1207. $this->Cell(0, 0, '', 'T', 0, 'C');
  1208. }
  1209. //restore position
  1210. $this->SetXY($this->original_lMargin, $this->tMargin);
  1211. }
  1212. }
  1213. /**
  1214. * This method is used to render the page footer.
  1215. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1216. */
  1217. function Footer() {
  1218. if ($this->print_footer) {
  1219. if (!isset($this->original_lMargin)) {
  1220. $this->original_lMargin = $this->lMargin;
  1221. }
  1222. if (!isset($this->original_rMargin)) {
  1223. $this->original_rMargin = $this->rMargin;
  1224. }
  1225. //set font
  1226. $this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]);
  1227. //set style for cell border
  1228. $line_width = 0.3;
  1229. $this->SetLineWidth($line_width);
  1230. $this->SetDrawColor(0, 0, 0);
  1231. $footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height
  1232. //get footer y position
  1233. $footer_y = $this->h - $this->footer_margin - $footer_height;
  1234. //set current position
  1235. $this->SetXY($this->original_lMargin, $footer_y);
  1236. //print document barcode
  1237. if ($this->barcode) {
  1238. $this->Ln();
  1239. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)); //max width
  1240. $this->writeBarcode($this->original_lMargin, $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode);
  1241. }
  1242. $this->SetXY($this->original_lMargin, $footer_y);
  1243. //Print page number
  1244. $this->Cell(0, $footer_height, $this->l['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R');
  1245. }
  1246. }
  1247. /**
  1248. * Returns the current page number.
  1249. * @return int page number
  1250. * @since 1.0
  1251. * @see AliasNbPages()
  1252. */
  1253. function PageNo() {
  1254. //Get current page number
  1255. return $this->page;
  1256. }
  1257. /**
  1258. * 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.
  1259. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1260. *…

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