PageRenderTime 68ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/phpmyadmin/libraries/tcpdf/tcpdf.php

https://bitbucket.org/DenizYldrm/openemr
PHP | 4138 lines | 2321 code | 305 blank | 1512 comment | 373 complexity | 0df8deb95a8500375d794023287dd673 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MPL-2.0, LGPL-2.1
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Begin : 2002-08-03
  5. // Last Update : 2006-10-27
  6. // Author : Nicola Asuni
  7. // Version : 1.53.0.TC026_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. // Disabled in phpMyAdmin
  35. //require_once(dirname(__FILE__).'/config/tcpdf_config.php');
  36. /**
  37. * TCPDF Class.
  38. * @package com.tecnick.tcpdf
  39. */
  40. /**
  41. * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
  42. * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  43. * <h3>TCPDF main changes from FPDF are:</h3><ul>
  44. * <li>PHP4 porting</li>
  45. * <li>UTF-8 Unicode support</li>
  46. * <li>source code clean up</li>
  47. * <li>code style and formatting</li>
  48. * <li>source code documentation using phpDocumentor (www.phpdoc.org)</li>
  49. * <li>All ISO page formats were included</li>
  50. * <li>image scale factor</li>
  51. * <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>
  52. * <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>
  53. * <li>defines standard Header() and Footer() methods.</li>
  54. * </ul>
  55. * Tools to encode your unicode fonts are on fonts/ttf2ufm directory.</p>
  56. * @name TCPDF
  57. * @package com.tecnick.tcpdf
  58. * @abstract Class for generating PDF files on-the-fly without requiring external extensions.
  59. * @author Nicola Asuni
  60. * @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
  61. * @link http://tcpdf.sourceforge.net
  62. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  63. @version 1.53.0.TC026_PHP4
  64. */
  65. if(!class_exists('TCPDF')) {
  66. /**
  67. * define default PDF document producer
  68. */
  69. define('PDF_PRODUCER','TCPDF 1.53.0.TC026_PHP4 (http://tcpdf.sourceforge.net)');
  70. /**
  71. * This is a PHP4 class for generating PDF files on-the-fly without requiring external extensions.<br>
  72. * This class is an extension and improvement of the FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  73. * 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>
  74. * TCPDF project (http://tcpdf.sourceforge.net) is based on the public Domain FPDF class by Olivier Plathey (http://www.fpdf.org).<br>
  75. * To add your own TTF fonts please read /fonts/README.TXT
  76. * @name TCPDF
  77. * @package com.tecnick.tcpdf
  78. * @version 1.53.0.TC026_PHP4
  79. * @author Nicola Asuni
  80. * @link http://tcpdf.sourceforge.net
  81. * @license http://www.gnu.org/copyleft/lesser.html LGPL
  82. */
  83. class TCPDF {
  84. //var properties
  85. /**
  86. * @var current page number
  87. * @access protected
  88. */
  89. var $page;
  90. /**
  91. * @var current object number
  92. * @access protected
  93. */
  94. var $n;
  95. /**
  96. * @var array of object offsets
  97. * @access protected
  98. */
  99. var $offsets;
  100. /**
  101. * @var buffer holding in-memory PDF
  102. * @access protected
  103. */
  104. var $buffer;
  105. /**
  106. * @var array containing pages
  107. * @access protected
  108. */
  109. var $pages;
  110. /**
  111. * @var current document state
  112. * @access protected
  113. */
  114. var $state;
  115. /**
  116. * @var compression flag
  117. * @access protected
  118. */
  119. var $compress;
  120. /**
  121. * @var default orientation
  122. * @access protected
  123. */
  124. var $DefOrientation;
  125. /**
  126. * @var current orientation
  127. * @access protected
  128. */
  129. var $CurOrientation;
  130. /**
  131. * @var array indicating orientation changes
  132. * @access protected
  133. */
  134. var $OrientationChanges;
  135. /**
  136. * @var scale factor (number of points in user unit)
  137. * @access protected
  138. */
  139. var $k;
  140. /**
  141. * @var width of page format in points
  142. * @access protected
  143. */
  144. var $fwPt;
  145. /**
  146. * @var height of page format in points
  147. * @access protected
  148. */
  149. var $fhPt;
  150. /**
  151. * @var width of page format in user unit
  152. * @access protected
  153. */
  154. var $fw;
  155. /**
  156. * @var height of page format in user unit
  157. * @access protected
  158. */
  159. var $fh;
  160. /**
  161. * @var current width of page in points
  162. * @access protected
  163. */
  164. var $wPt;
  165. /**
  166. * @var current height of page in points
  167. * @access protected
  168. */
  169. var $hPt;
  170. /**
  171. * @var current width of page in user unit
  172. * @access protected
  173. */
  174. var $w;
  175. /**
  176. * @var current height of page in user unit
  177. * @access protected
  178. */
  179. var $h;
  180. /**
  181. * @var left margin
  182. * @access protected
  183. */
  184. var $lMargin;
  185. /**
  186. * @var top margin
  187. * @access protected
  188. */
  189. var $tMargin;
  190. /**
  191. * @var right margin
  192. * @access protected
  193. */
  194. var $rMargin;
  195. /**
  196. * @var page break margin
  197. * @access protected
  198. */
  199. var $bMargin;
  200. /**
  201. * @var cell margin
  202. * @access protected
  203. */
  204. var $cMargin;
  205. /**
  206. * @var current horizontal position in user unit for cell positioning
  207. * @access protected
  208. */
  209. var $x;
  210. /**
  211. * @var current vertical position in user unit for cell positioning
  212. * @access protected
  213. */
  214. var $y;
  215. /**
  216. * @var height of last cell printed
  217. * @access protected
  218. */
  219. var $lasth;
  220. /**
  221. * @var line width in user unit
  222. * @access protected
  223. */
  224. var $LineWidth;
  225. /**
  226. * @var array of standard font names
  227. * @access protected
  228. */
  229. var $CoreFonts;
  230. /**
  231. * @var array of used fonts
  232. * @access protected
  233. */
  234. var $fonts;
  235. /**
  236. * @var array of font files
  237. * @access protected
  238. */
  239. var $FontFiles;
  240. /**
  241. * @var array of encoding differences
  242. * @access protected
  243. */
  244. var $diffs;
  245. /**
  246. * @var array of used images
  247. * @access protected
  248. */
  249. var $images;
  250. /**
  251. * @var array of links in pages
  252. * @access protected
  253. */
  254. var $PageLinks;
  255. /**
  256. * @var array of internal links
  257. * @access protected
  258. */
  259. var $links;
  260. /**
  261. * @var current font family
  262. * @access protected
  263. */
  264. var $FontFamily;
  265. /**
  266. * @var current font style
  267. * @access protected
  268. */
  269. var $FontStyle;
  270. /**
  271. * @var underlining flag
  272. * @access protected
  273. */
  274. var $underline;
  275. /**
  276. * @var current font info
  277. * @access protected
  278. */
  279. var $CurrentFont;
  280. /**
  281. * @var current font size in points
  282. * @access protected
  283. */
  284. var $FontSizePt;
  285. /**
  286. * @var current font size in user unit
  287. * @access protected
  288. */
  289. var $FontSize;
  290. /**
  291. * @var commands for drawing color
  292. * @access protected
  293. */
  294. var $DrawColor;
  295. /**
  296. * @var commands for filling color
  297. * @access protected
  298. */
  299. var $FillColor;
  300. /**
  301. * @var commands for text color
  302. * @access protected
  303. */
  304. var $TextColor;
  305. /**
  306. * @var indicates whether fill and text colors are different
  307. * @access protected
  308. */
  309. var $ColorFlag;
  310. /**
  311. * @var word spacing
  312. * @access protected
  313. */
  314. var $ws;
  315. /**
  316. * @var automatic page breaking
  317. * @access protected
  318. */
  319. var $AutoPageBreak;
  320. /**
  321. * @var threshold used to trigger page breaks
  322. * @access protected
  323. */
  324. var $PageBreakTrigger;
  325. /**
  326. * @var flag set when processing footer
  327. * @access protected
  328. */
  329. var $InFooter;
  330. /**
  331. * @var zoom display mode
  332. * @access protected
  333. */
  334. var $ZoomMode;
  335. /**
  336. * @var layout display mode
  337. * @access protected
  338. */
  339. var $LayoutMode;
  340. /**
  341. * @var title
  342. * @access protected
  343. */
  344. var $title;
  345. /**
  346. * @var subject
  347. * @access protected
  348. */
  349. var $subject;
  350. /**
  351. * @var author
  352. * @access protected
  353. */
  354. var $author;
  355. /**
  356. * @var keywords
  357. * @access protected
  358. */
  359. var $keywords;
  360. /**
  361. * @var creator
  362. * @access protected
  363. */
  364. var $creator;
  365. /**
  366. * @var alias for total number of pages
  367. * @access protected
  368. */
  369. var $AliasNbPages;
  370. /**
  371. * @var right-bottom corner X coordinate of inserted image
  372. * @since 2002-07-31
  373. * @author Nicola Asuni
  374. * @access protected
  375. */
  376. var $img_rb_x;
  377. /**
  378. * @var right-bottom corner Y coordinate of inserted image
  379. * @since 2002-07-31
  380. * @author Nicola Asuni
  381. * @access protected
  382. */
  383. var $img_rb_y;
  384. /**
  385. * @var image scale factor
  386. * @since 2004-06-14
  387. * @author Nicola Asuni
  388. * @access protected
  389. */
  390. var $imgscale = 1;
  391. /**
  392. * @var boolean set to true when the input text is unicode (require unicode fonts)
  393. * @since 2005-01-02
  394. * @author Nicola Asuni
  395. * @access protected
  396. */
  397. var $isunicode = false;
  398. /**
  399. * @var PDF version
  400. * @since 1.5.3
  401. * @access protected
  402. */
  403. var $PDFVersion = "1.3";
  404. // ----------------------
  405. /**
  406. * @var Minimum distance between header and top page margin.
  407. * @access private
  408. */
  409. var $header_margin;
  410. /**
  411. * @var Minimum distance between footer and bottom page margin.
  412. * @access private
  413. */
  414. var $footer_margin;
  415. /**
  416. * @var original left margin value
  417. * @access private
  418. * @since 1.53.0.TC013
  419. */
  420. var $original_lMargin;
  421. /**
  422. * @var original right margin value
  423. * @access private
  424. * @since 1.53.0.TC013
  425. */
  426. var $original_rMargin;
  427. /**
  428. * @var Header font.
  429. * @access private
  430. */
  431. var $header_font;
  432. /**
  433. * @var Footer font.
  434. * @access private
  435. */
  436. var $footer_font;
  437. /**
  438. * @var Language templates.
  439. * @access private
  440. */
  441. var $l;
  442. /**
  443. * @var Barcode to print on page footer (only if set).
  444. * @access private
  445. */
  446. var $barcode = false;
  447. /**
  448. * @var If true prints header
  449. * @access private
  450. */
  451. var $print_header = true;
  452. /**
  453. * @var If true prints footer.
  454. * @access private
  455. */
  456. var $print_footer = true;
  457. /**
  458. * @var Header width (0 = full page width).
  459. * @access private
  460. */
  461. var $header_width = 0;
  462. /**
  463. * @var Header image logo.
  464. * @access private
  465. */
  466. var $header_logo = "";
  467. /**
  468. * @var Header image logo width in mm.
  469. * @access private
  470. */
  471. var $header_logo_width = 30;
  472. /**
  473. * @var String to print as title on document header.
  474. * @access private
  475. */
  476. var $header_title = "";
  477. /**
  478. * @var String to print on document header.
  479. * @access private
  480. */
  481. var $header_string = "";
  482. /**
  483. * @var Default number of columns for html table.
  484. * @access private
  485. */
  486. var $default_table_columns = 4;
  487. // variables for html parser
  488. /**
  489. * @var HTML PARSER: store current link.
  490. * @access private
  491. */
  492. var $HREF;
  493. /**
  494. * @var HTML PARSER: store font list.
  495. * @access private
  496. */
  497. var $fontList;
  498. /**
  499. * @var HTML PARSER: true when font attribute is set.
  500. * @access private
  501. */
  502. var $issetfont;
  503. /**
  504. * @var HTML PARSER: true when color attribute is set.
  505. * @access private
  506. */
  507. var $issetcolor;
  508. /**
  509. * @var HTML PARSER: true in case of ordered list (OL), false otherwise.
  510. * @access private
  511. */
  512. var $listordered = false;
  513. /**
  514. * @var HTML PARSER: count list items.
  515. * @access private
  516. */
  517. var $listcount = 0;
  518. /**
  519. * @var HTML PARSER: size of table border.
  520. * @access private
  521. */
  522. var $tableborder = 0;
  523. /**
  524. * @var HTML PARSER: true at the beginning of table.
  525. * @access private
  526. */
  527. var $tdbegin = false;
  528. /**
  529. * @var HTML PARSER: table width.
  530. * @access private
  531. */
  532. var $tdwidth = 0;
  533. /**
  534. * @var HTML PARSER: table height.
  535. * @access private
  536. */
  537. var $tdheight = 0;
  538. /**
  539. * @var HTML PARSER: table align.
  540. * @access private
  541. */
  542. var $tdalign = "L";
  543. /**
  544. * @var HTML PARSER: table background color.
  545. * @access private
  546. */
  547. var $tdbgcolor = false;
  548. /**
  549. * @var Store temporary font size in points.
  550. * @access private
  551. */
  552. var $tempfontsize = 10;
  553. /**
  554. * @var Bold font style status.
  555. * @access private
  556. */
  557. var $b;
  558. /**
  559. * @var Underlined font style status.
  560. * @access private
  561. */
  562. var $u;
  563. /**
  564. * @var Italic font style status.
  565. * @access private
  566. */
  567. var $i;
  568. /**
  569. * @var spacer for LI tags.
  570. * @access private
  571. */
  572. var $lispacer = "";
  573. /**
  574. * @var default encoding
  575. * @access private
  576. * @since 1.53.0.TC010
  577. */
  578. var $encoding = "UTF-8";
  579. /**
  580. * @var PHP internal encoding
  581. * @access private
  582. * @since 1.53.0.TC016
  583. */
  584. var $internal_encoding;
  585. /**
  586. * @var store previous fill color as RGB array
  587. * @access private
  588. * @since 1.53.0.TC017
  589. */
  590. var $prevFillColor = array(255,255,255);
  591. /**
  592. * @var store previous text color as RGB array
  593. * @access private
  594. * @since 1.53.0.TC017
  595. */
  596. var $prevTextColor = array(0,0,0);
  597. /**
  598. * @var store previous font family
  599. * @access private
  600. * @since 1.53.0.TC017
  601. */
  602. var $prevFontFamily;
  603. /**
  604. * @var store previous font style
  605. * @access private
  606. * @since 1.53.0.TC017
  607. */
  608. var $prevFontStyle;
  609. //------------------------------------------------------------
  610. // var methods
  611. //------------------------------------------------------------
  612. /**
  613. * This is the class constructor.
  614. * It allows to set up the page format, the orientation and
  615. * the measure unit used in all the methods (except for the font sizes).
  616. * @since 1.0
  617. * @param string $orientation page orientation. Possible values are (case insensitive):<ul><li>P or Portrait (default)</li><li>L or Landscape</li></ul>
  618. * @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.
  619. * @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>
  620. * @param boolean $unicode TRUE means that the input text is unicode (default = true)
  621. * @param String $encoding charset encoding; default is UTF-8
  622. */
  623. function TCPDF($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding="UTF-8") {
  624. /* Set internal character encoding to ASCII */
  625. if (function_exists("mb_internal_encoding") AND mb_internal_encoding()) {
  626. $this->internal_encoding = mb_internal_encoding();
  627. mb_internal_encoding("ASCII");
  628. }
  629. //Some checks
  630. $this->_dochecks();
  631. //Initialization of properties
  632. $this->isunicode=$unicode;
  633. $this->page=0;
  634. $this->n=2;
  635. $this->buffer='';
  636. $this->pages=array();
  637. $this->OrientationChanges=array();
  638. $this->state=0;
  639. $this->fonts=array();
  640. $this->FontFiles=array();
  641. $this->diffs=array();
  642. $this->images=array();
  643. $this->links=array();
  644. $this->InFooter=false;
  645. $this->lasth=0;
  646. $this->FontFamily='';
  647. $this->FontStyle='';
  648. $this->FontSizePt=12;
  649. $this->underline=false;
  650. $this->DrawColor='0 G';
  651. $this->FillColor='0 g';
  652. $this->TextColor='0 g';
  653. $this->ColorFlag=false;
  654. $this->ws=0;
  655. //Standard Unicode fonts
  656. $this->CoreFonts=array(
  657. 'courier'=>'Courier',
  658. 'courierB'=>'Courier-Bold',
  659. 'courierI'=>'Courier-Oblique',
  660. 'courierBI'=>'Courier-BoldOblique',
  661. 'helvetica'=>'Helvetica',
  662. 'helveticaB'=>'Helvetica-Bold',
  663. 'helveticaI'=>'Helvetica-Oblique',
  664. 'helveticaBI'=>'Helvetica-BoldOblique',
  665. 'times'=>'Times-Roman',
  666. 'timesB'=>'Times-Bold',
  667. 'timesI'=>'Times-Italic',
  668. 'timesBI'=>'Times-BoldItalic',
  669. 'symbol'=>'Symbol',
  670. 'zapfdingbats'=>'ZapfDingbats'
  671. );
  672. //Scale factor
  673. // 2003-06-11 - Nicola Asuni : changed if/else with switch statement
  674. switch (strtolower($unit)){
  675. case 'pt': {$this->k=1; break;}
  676. case 'mm': {$this->k=72/25.4; break;}
  677. case 'cm': {$this->k=72/2.54; break;}
  678. case 'in': {$this->k=72; break;}
  679. default : {$this->Error('Incorrect unit: '.$unit); break;}
  680. }
  681. //Page format
  682. if(is_string($format)) {
  683. // 2002-07-24 - Nicola Asuni (info@tecnick.com)
  684. // Added new page formats (45 standard ISO paper formats and 4 american common formats).
  685. // Paper cordinates are calculated in this way: (inches * 72) where (1 inch = 2.54 cm)
  686. switch (strtoupper($format)){
  687. case '4A0': {$format = array(4767.87,6740.79); break;}
  688. case '2A0': {$format = array(3370.39,4767.87); break;}
  689. case 'A0': {$format = array(2383.94,3370.39); break;}
  690. case 'A1': {$format = array(1683.78,2383.94); break;}
  691. case 'A2': {$format = array(1190.55,1683.78); break;}
  692. case 'A3': {$format = array(841.89,1190.55); break;}
  693. case 'A4': default: {$format = array(595.28,841.89); break;}
  694. case 'A5': {$format = array(419.53,595.28); break;}
  695. case 'A6': {$format = array(297.64,419.53); break;}
  696. case 'A7': {$format = array(209.76,297.64); break;}
  697. case 'A8': {$format = array(147.40,209.76); break;}
  698. case 'A9': {$format = array(104.88,147.40); break;}
  699. case 'A10': {$format = array(73.70,104.88); break;}
  700. case 'B0': {$format = array(2834.65,4008.19); break;}
  701. case 'B1': {$format = array(2004.09,2834.65); break;}
  702. case 'B2': {$format = array(1417.32,2004.09); break;}
  703. case 'B3': {$format = array(1000.63,1417.32); break;}
  704. case 'B4': {$format = array(708.66,1000.63); break;}
  705. case 'B5': {$format = array(498.90,708.66); break;}
  706. case 'B6': {$format = array(354.33,498.90); break;}
  707. case 'B7': {$format = array(249.45,354.33); break;}
  708. case 'B8': {$format = array(175.75,249.45); break;}
  709. case 'B9': {$format = array(124.72,175.75); break;}
  710. case 'B10': {$format = array(87.87,124.72); break;}
  711. case 'C0': {$format = array(2599.37,3676.54); break;}
  712. case 'C1': {$format = array(1836.85,2599.37); break;}
  713. case 'C2': {$format = array(1298.27,1836.85); break;}
  714. case 'C3': {$format = array(918.43,1298.27); break;}
  715. case 'C4': {$format = array(649.13,918.43); break;}
  716. case 'C5': {$format = array(459.21,649.13); break;}
  717. case 'C6': {$format = array(323.15,459.21); break;}
  718. case 'C7': {$format = array(229.61,323.15); break;}
  719. case 'C8': {$format = array(161.57,229.61); break;}
  720. case 'C9': {$format = array(113.39,161.57); break;}
  721. case 'C10': {$format = array(79.37,113.39); break;}
  722. case 'RA0': {$format = array(2437.80,3458.27); break;}
  723. case 'RA1': {$format = array(1729.13,2437.80); break;}
  724. case 'RA2': {$format = array(1218.90,1729.13); break;}
  725. case 'RA3': {$format = array(864.57,1218.90); break;}
  726. case 'RA4': {$format = array(609.45,864.57); break;}
  727. case 'SRA0': {$format = array(2551.18,3628.35); break;}
  728. case 'SRA1': {$format = array(1814.17,2551.18); break;}
  729. case 'SRA2': {$format = array(1275.59,1814.17); break;}
  730. case 'SRA3': {$format = array(907.09,1275.59); break;}
  731. case 'SRA4': {$format = array(637.80,907.09); break;}
  732. case 'LETTER': {$format = array(612.00,792.00); break;}
  733. case 'LEGAL': {$format = array(612.00,1008.00); break;}
  734. case 'EXECUTIVE': {$format = array(521.86,756.00); break;}
  735. case 'FOLIO': {$format = array(612.00,936.00); break;}
  736. // default: {$this->Error('Unknown page format: '.$format); break;}
  737. // END CHANGES Nicola Asuni
  738. }
  739. $this->fwPt=$format[0];
  740. $this->fhPt=$format[1];
  741. }
  742. else {
  743. $this->fwPt=$format[0]*$this->k;
  744. $this->fhPt=$format[1]*$this->k;
  745. }
  746. $this->fw=$this->fwPt/$this->k;
  747. $this->fh=$this->fhPt/$this->k;
  748. //Page orientation
  749. $orientation=strtolower($orientation);
  750. if($orientation=='p' or $orientation=='portrait') {
  751. $this->DefOrientation='P';
  752. $this->wPt=$this->fwPt;
  753. $this->hPt=$this->fhPt;
  754. }
  755. elseif($orientation=='l' or $orientation=='landscape') {
  756. $this->DefOrientation='L';
  757. $this->wPt=$this->fhPt;
  758. $this->hPt=$this->fwPt;
  759. }
  760. else {
  761. $this->Error('Incorrect orientation: '.$orientation);
  762. }
  763. $this->CurOrientation=$this->DefOrientation;
  764. $this->w=$this->wPt/$this->k;
  765. $this->h=$this->hPt/$this->k;
  766. //Page margins (1 cm)
  767. $margin=28.35/$this->k;
  768. $this->SetMargins($margin,$margin);
  769. //Interior cell margin (1 mm)
  770. $this->cMargin=$margin/10;
  771. //Line width (0.2 mm)
  772. $this->LineWidth=.567/$this->k;
  773. //Automatic page break
  774. $this->SetAutoPageBreak(true,2*$margin);
  775. //Full width display mode
  776. $this->SetDisplayMode('fullwidth');
  777. //Compression
  778. $this->SetCompression(true);
  779. //Set default PDF version number
  780. $this->PDFVersion = "1.3";
  781. $this->encoding = $encoding;
  782. $this->b = 0;
  783. $this->i = 0;
  784. $this->u = 0;
  785. $this->HREF = '';
  786. $this->fontlist = array("arial", "times", "courier", "helvetica", "symbol");
  787. $this->issetfont = false;
  788. $this->issetcolor = false;
  789. $this->tableborder = 0;
  790. $this->tdbegin = false;
  791. $this->tdwidth= 0;
  792. $this->tdheight = 0;
  793. $this->tdalign = "L";
  794. $this->tdbgcolor = false;
  795. $this->SetFillColor(200, 200, 200, true);
  796. $this->SetTextColor(0, 0, 0, true);
  797. }
  798. /**
  799. * Set the image scale.
  800. * @param float $scale image scale.
  801. * @author Nicola Asuni
  802. * @since 1.5.2
  803. */
  804. function setImageScale($scale) {
  805. $this->imgscale=$scale;
  806. }
  807. /**
  808. * Returns the image scale.
  809. * @return float image scale.
  810. * @author Nicola Asuni
  811. * @since 1.5.2
  812. */
  813. function getImageScale() {
  814. return $this->imgscale;
  815. }
  816. /**
  817. * Returns the page width in units.
  818. * @return int page width.
  819. * @author Nicola Asuni
  820. * @since 1.5.2
  821. */
  822. function getPageWidth() {
  823. return $this->w;
  824. }
  825. /**
  826. * Returns the page height in units.
  827. * @return int page height.
  828. * @author Nicola Asuni
  829. * @since 1.5.2
  830. */
  831. function getPageHeight() {
  832. return $this->h;
  833. }
  834. /**
  835. * Returns the page break margin.
  836. * @return int page break margin.
  837. * @author Nicola Asuni
  838. * @since 1.5.2
  839. */
  840. function getBreakMargin() {
  841. return $this->bMargin;
  842. }
  843. /**
  844. * Returns the scale factor (number of points in user unit).
  845. * @return int scale factor.
  846. * @author Nicola Asuni
  847. * @since 1.5.2
  848. */
  849. function getScaleFactor() {
  850. return $this->k;
  851. }
  852. /**
  853. * Defines the left, top and right margins. By default, they equal 1 cm. Call this method to change them.
  854. * @param float $left Left margin.
  855. * @param float $top Top margin.
  856. * @param float $right Right margin. Default value is the left one.
  857. * @since 1.0
  858. * @see SetLeftMargin(), SetTopMargin(), SetRightMargin(), SetAutoPageBreak()
  859. */
  860. function SetMargins($left, $top, $right=-1) {
  861. //Set left, top and right margins
  862. $this->lMargin=$left;
  863. $this->tMargin=$top;
  864. if($right==-1) {
  865. $right=$left;
  866. }
  867. $this->rMargin=$right;
  868. }
  869. /**
  870. * 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.
  871. * @param float $margin The margin.
  872. * @since 1.4
  873. * @see SetTopMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  874. */
  875. function SetLeftMargin($margin) {
  876. //Set left margin
  877. $this->lMargin=$margin;
  878. if(($this->page>0) and ($this->x<$margin)) {
  879. $this->x=$margin;
  880. }
  881. }
  882. /**
  883. * Defines the top margin. The method can be called before creating the first page.
  884. * @param float $margin The margin.
  885. * @since 1.5
  886. * @see SetLeftMargin(), SetRightMargin(), SetAutoPageBreak(), SetMargins()
  887. */
  888. function SetTopMargin($margin) {
  889. //Set top margin
  890. $this->tMargin=$margin;
  891. }
  892. /**
  893. * Defines the right margin. The method can be called before creating the first page.
  894. * @param float $margin The margin.
  895. * @since 1.5
  896. * @see SetLeftMargin(), SetTopMargin(), SetAutoPageBreak(), SetMargins()
  897. */
  898. function SetRightMargin($margin) {
  899. //Set right margin
  900. $this->rMargin=$margin;
  901. }
  902. /**
  903. * 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.
  904. * @param boolean $auto Boolean indicating if mode should be on or off.
  905. * @param float $margin Distance from the bottom of the page.
  906. * @since 1.0
  907. * @see Cell(), MultiCell(), AcceptPageBreak()
  908. */
  909. function SetAutoPageBreak($auto, $margin=0) {
  910. //Set auto page break mode and triggering margin
  911. $this->AutoPageBreak=$auto;
  912. $this->bMargin=$margin;
  913. $this->PageBreakTrigger=$this->h-$margin;
  914. }
  915. /**
  916. * 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.
  917. * @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>
  918. * @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>
  919. * @since 1.2
  920. */
  921. function SetDisplayMode($zoom, $layout='continuous') {
  922. //Set display mode in viewer
  923. if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) {
  924. $this->ZoomMode=$zoom;
  925. }
  926. else {
  927. $this->Error('Incorrect zoom display mode: '.$zoom);
  928. }
  929. if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') {
  930. $this->LayoutMode=$layout;
  931. }
  932. else {
  933. $this->Error('Incorrect layout display mode: '.$layout);
  934. }
  935. }
  936. /**
  937. * 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.
  938. * Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
  939. * @param boolean $compress Boolean indicating if compression must be enabled.
  940. * @since 1.4
  941. */
  942. function SetCompression($compress) {
  943. //Set page compression
  944. if(function_exists('gzcompress')) {
  945. $this->compress=$compress;
  946. }
  947. else {
  948. $this->compress=false;
  949. }
  950. }
  951. /**
  952. * Defines the title of the document.
  953. * @param string $title The title.
  954. * @since 1.2
  955. * @see SetAuthor(), SetCreator(), SetKeywords(), SetSubject()
  956. */
  957. function SetTitle($title) {
  958. //Title of document
  959. $this->title=$title;
  960. }
  961. /**
  962. * Defines the subject of the document.
  963. * @param string $subject The subject.
  964. * @since 1.2
  965. * @see SetAuthor(), SetCreator(), SetKeywords(), SetTitle()
  966. */
  967. function SetSubject($subject) {
  968. //Subject of document
  969. $this->subject=$subject;
  970. }
  971. /**
  972. * Defines the author of the document.
  973. * @param string $author The name of the author.
  974. * @since 1.2
  975. * @see SetCreator(), SetKeywords(), SetSubject(), SetTitle()
  976. */
  977. function SetAuthor($author) {
  978. //Author of document
  979. $this->author=$author;
  980. }
  981. /**
  982. * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
  983. * @param string $keywords The list of keywords.
  984. * @since 1.2
  985. * @see SetAuthor(), SetCreator(), SetSubject(), SetTitle()
  986. */
  987. function SetKeywords($keywords) {
  988. //Keywords of document
  989. $this->keywords=$keywords;
  990. }
  991. /**
  992. * Defines the creator of the document. This is typically the name of the application that generates the PDF.
  993. * @param string $creator The name of the creator.
  994. * @since 1.2
  995. * @see SetAuthor(), SetKeywords(), SetSubject(), SetTitle()
  996. */
  997. function SetCreator($creator) {
  998. //Creator of document
  999. $this->creator=$creator;
  1000. }
  1001. /**
  1002. * Defines an alias for the total number of pages. It will be substituted as the document is closed.<br />
  1003. * <b>Example:</b><br />
  1004. * <pre>
  1005. * class PDF extends TCPDF {
  1006. * function Footer() {
  1007. * //Go to 1.5 cm from bottom
  1008. * $this->SetY(-15);
  1009. * //Select Arial italic 8
  1010. * $this->SetFont('Arial','I',8);
  1011. * //Print current and total page numbers
  1012. * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  1013. * }
  1014. * }
  1015. * $pdf=new PDF();
  1016. * $pdf->AliasNbPages();
  1017. * </pre>
  1018. * @param string $alias The alias. Default value: {nb}.
  1019. * @since 1.4
  1020. * @see PageNo(), Footer()
  1021. */
  1022. function AliasNbPages($alias='{nb}') {
  1023. //Define an alias for total number of pages
  1024. $this->AliasNbPages = $this->_escapetext($alias);
  1025. }
  1026. /**
  1027. * 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.
  1028. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
  1029. * @param string $msg The error message
  1030. * @since 1.0
  1031. */
  1032. function Error($msg) {
  1033. //Fatal error
  1034. die('<strong>TCPDF error: </strong>'.$msg);
  1035. }
  1036. /**
  1037. * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically.
  1038. * Note: no page is created by this method
  1039. * @since 1.0
  1040. * @see AddPage(), Close()
  1041. */
  1042. function Open() {
  1043. //Begin document
  1044. $this->state=1;
  1045. }
  1046. /**
  1047. * 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.
  1048. * @since 1.0
  1049. * @see Open(), Output()
  1050. */
  1051. function Close() {
  1052. //Terminate document
  1053. if($this->state==3) {
  1054. return;
  1055. }
  1056. if($this->page==0) {
  1057. $this->AddPage();
  1058. }
  1059. //Page footer
  1060. $this->InFooter=true;
  1061. $this->Footer();
  1062. $this->InFooter=false;
  1063. //Close page
  1064. $this->_endpage();
  1065. //Close document
  1066. $this->_enddoc();
  1067. }
  1068. /**
  1069. * 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.
  1070. * 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.
  1071. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards.
  1072. * @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.
  1073. * @since 1.0
  1074. * @see TCPDF(), Header(), Footer(), SetMargins()
  1075. */
  1076. function AddPage($orientation='') {
  1077. //Start a new page
  1078. if($this->state==0) {
  1079. $this->Open();
  1080. }
  1081. $family=$this->FontFamily;
  1082. $style=$this->FontStyle.($this->underline ? 'U' : '');
  1083. $size=$this->FontSizePt;
  1084. $lw=$this->LineWidth;
  1085. $dc=$this->DrawColor;
  1086. $fc=$this->FillColor;
  1087. $tc=$this->TextColor;
  1088. $cf=$this->ColorFlag;
  1089. if($this->page>0) {
  1090. //Page footer
  1091. $this->InFooter=true;
  1092. $this->Footer();
  1093. $this->InFooter=false;
  1094. //Close page
  1095. $this->_endpage();
  1096. }
  1097. //Start new page
  1098. $this->_beginpage($orientation);
  1099. //Set line cap style to square
  1100. $this->_out('2 J');
  1101. //Set line width
  1102. $this->LineWidth=$lw;
  1103. $this->_out(sprintf('%.2f w',$lw*$this->k));
  1104. //Set font
  1105. if($family) {
  1106. $this->SetFont($family,$style,$size);
  1107. }
  1108. //Set colors
  1109. $this->DrawColor=$dc;
  1110. if($dc!='0 G') {
  1111. $this->_out($dc);
  1112. }
  1113. $this->FillColor=$fc;
  1114. if($fc!='0 g') {
  1115. $this->_out($fc);
  1116. }
  1117. $this->TextColor=$tc;
  1118. $this->ColorFlag=$cf;
  1119. //Page header
  1120. $this->Header();
  1121. //Restore line width
  1122. if($this->LineWidth!=$lw) {
  1123. $this->LineWidth=$lw;
  1124. $this->_out(sprintf('%.2f w',$lw*$this->k));
  1125. }
  1126. //Restore font
  1127. if($family) {
  1128. $this->SetFont($family,$style,$size);
  1129. }
  1130. //Restore colors
  1131. if($this->DrawColor!=$dc) {
  1132. $this->DrawColor=$dc;
  1133. $this->_out($dc);
  1134. }
  1135. if($this->FillColor!=$fc) {
  1136. $this->FillColor=$fc;
  1137. $this->_out($fc);
  1138. }
  1139. $this->TextColor=$tc;
  1140. $this->ColorFlag=$cf;
  1141. }
  1142. /**
  1143. * Set header data.
  1144. * @param string $ln header image logo
  1145. * @param string $lw header image logo width in mm
  1146. * @param string $ht string to print as title on document header
  1147. * @param string $hs string to print on document header
  1148. */
  1149. function setHeaderData($ln="", $lw=0, $ht="", $hs="") {
  1150. $this->header_logo = $ln;
  1151. $this->header_logo_width = $lw;
  1152. $this->header_title = $ht;
  1153. $this->header_string = $hs;
  1154. }
  1155. /**
  1156. * Set header margin.
  1157. * (minimum distance between header and top page margin)
  1158. * @param int $hm distance in millimeters
  1159. */
  1160. function setHeaderMargin($hm=10) {
  1161. $this->header_margin = $hm;
  1162. }
  1163. /**
  1164. * Set footer margin.
  1165. * (minimum distance between footer and bottom page margin)
  1166. * @param int $fm distance in millimeters
  1167. */
  1168. function setFooterMargin($fm=10) {
  1169. $this->footer_margin = $fm;
  1170. }
  1171. /**
  1172. * This method is used to render the page header.
  1173. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1174. */
  1175. function Header() {
  1176. if ($this->print_header) {
  1177. if (!isset($this->original_lMargin)) {
  1178. $this->original_lMargin = $this->lMargin;
  1179. }
  1180. if (!isset($this->original_rMargin)) {
  1181. $this->original_rMargin = $this->rMargin;
  1182. }
  1183. //set current position
  1184. $this->SetXY($this->original_lMargin, $this->header_margin);
  1185. if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) {
  1186. $this->Image(K_PATH_IMAGES.$this->header_logo, $this->original_lMargin, $this->header_margin, $this->header_logo_width);
  1187. }
  1188. else {
  1189. $this->img_rb_y = $this->GetY();
  1190. }
  1191. $cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2);
  1192. $header_x = $this->original_lMargin + ($this->header_logo_width * 1.05); //set left margin for text data cell
  1193. // header title
  1194. $this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1);
  1195. $this->SetX($header_x);
  1196. $this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, 'L');
  1197. // header string
  1198. $this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);
  1199. $this->SetX($header_x);
  1200. $this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, 'L', 0);
  1201. // print an ending header line
  1202. if (empty($this->header_width)) {
  1203. //set style for cell border
  1204. $this->SetLineWidth(0.3);
  1205. $this->SetDrawColor(0, 0, 0);
  1206. $this->SetY(1 + max($this->img_rb_y, $this->GetY()));
  1207. $this->SetX($this->original_lMargin);
  1208. $this->Cell(0, 0, '', 'T', 0, 'C');
  1209. }
  1210. //restore position
  1211. $this->SetXY($this->original_lMargin, $this->tMargin);
  1212. }
  1213. }
  1214. /**
  1215. * This method is used to render the page footer.
  1216. * It is automatically called by AddPage() and could be overwritten in your own inherited class.
  1217. */
  1218. function Footer() {
  1219. if ($this->print_footer) {
  1220. if (!isset($this->original_lMargin)) {
  1221. $this->original_lMargin = $this->lMargin;
  1222. }
  1223. if (!isset($this->original_rMargin)) {
  1224. $this->original_rMargin = $this->rMargin;
  1225. }
  1226. //set font
  1227. $this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]);
  1228. //set style for cell border
  1229. $line_width = 0.3;
  1230. $this->SetLineWidth($line_width);
  1231. $this->SetDrawColor(0, 0, 0);
  1232. $footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height
  1233. //get footer y position
  1234. $footer_y = $this->h - $this->footer_margin - $footer_height;
  1235. //set current position
  1236. $this->SetXY($this->original_lMargin, $footer_y);
  1237. //print document barcode
  1238. if ($this->barcode) {
  1239. $this->Ln();
  1240. $barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)); //max width
  1241. $this->writeBarcode($this->original_lMargin, $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode);
  1242. }
  1243. $this->SetXY($this->original_lMargin, $footer_y);
  1244. //Print page number
  1245. $this->Cell(0, $footer_height, $this->l['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R');
  1246. }
  1247. }
  1248. /**
  1249. * Returns the current page number.
  1250. * @return int page number
  1251. * @since 1.0
  1252. * @see AliasNbPages()
  1253. */
  1254. function PageNo() {
  1255. //Get current page number
  1256. return $this->page;
  1257. }
  1258. /**
  1259. * 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.
  1260. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1261. * @param int $g Green component (between 0 and 255)
  1262. * @param int $b Blue component (between 0 and 255)
  1263. * @since 1.3
  1264. * @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()
  1265. */
  1266. function SetDrawColor($r, $g=-1, $b=-1) {
  1267. //Set color for all stroking operations
  1268. if(($r==0 and $g==0 and $b==0) or $g==-1) {
  1269. $this->DrawColor=sprintf('%.3f G',$r/255);
  1270. }
  1271. else {
  1272. $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255);
  1273. }
  1274. if($this->page>0) {
  1275. $this->_out($this->DrawColor);
  1276. }
  1277. }
  1278. /**
  1279. * 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.
  1280. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1281. * @param int $g Green component (between 0 and 255)
  1282. * @param int $b Blue component (between 0 and 255)
  1283. * @param boolean $storeprev if true stores the RGB array on $prevFillColor variable.
  1284. * @since 1.3
  1285. * @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()
  1286. */
  1287. function SetFillColor($r, $g=-1, $b=-1, $storeprev=false) {
  1288. //Set color for all filling operations
  1289. if(($r==0 and $g==0 and $b==0) or $g==-1) {
  1290. $this->FillColor=sprintf('%.3f g',$r/255);
  1291. }
  1292. else {
  1293. $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  1294. }
  1295. $this->ColorFlag=($this->FillColor!=$this->TextColor);
  1296. if($this->page>0) {
  1297. $this->_out($this->FillColor);
  1298. }
  1299. if ($storeprev) {
  1300. // store color as previous value
  1301. $this->prevFillColor = array($r, $g, $b);
  1302. }
  1303. }
  1304. /**
  1305. * 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.
  1306. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255
  1307. * @param int $g Green component (between 0 and 255)
  1308. * @param int $b Blue component (between 0 and 255)
  1309. * @param boolean $storeprev if true stores the RGB array on $prevTextColor variable.
  1310. * @since 1.3
  1311. * @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()
  1312. */
  1313. function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) {
  1314. //Set color for text
  1315. if(($r==0 and $g==0 and $b==0) or $g==-1) {
  1316. $this->TextColor=sprintf('%.3f g',$r/255);
  1317. }
  1318. else {
  1319. $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255);
  1320. }
  1321. $this->ColorFlag=($this->FillColor!=$this->TextColor);
  1322. if ($storeprev) {
  1323. // store color as previous value
  1324. $this->prevTextColor = array($r, $g, $b);
  1325. }
  1326. }
  1327. /**
  1328. * Returns the length of a string in user unit. A font must be selected.<br>
  1329. * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]
  1330. * @param string $s The string whose length is to be computed
  1331. * @return int
  1332. * @since 1.2
  1333. */
  1334. function GetStringWidth($s) {
  1335. //Get width of a string in the current font
  1336. $s = (string)$s;
  1337. $cw = &$this->CurrentFont['cw'];
  1338. $w = 0;
  1339. if($this->isunicode) {
  1340. $unicode = $this->UTF8StringToArray($s);
  1341. foreach($unicode as $char) {
  1342. if (isset($cw[$char])) {
  1343. $w+=$cw[$char];
  1344. } elseif(isset($cw[ord($char)])) {
  1345. $w+=$cw[ord($char)];
  1346. } elseif(isset($cw[chr($char)])) {
  1347. $w+=$cw[chr($char)];
  1348. } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) {
  1349. $w += $this->CurrentFont['desc']['MissingWidth']; // set default size
  1350. } else {
  1351. $w += 500;
  1352. }
  1353. }
  1354. } else {
  1355. $l = strlen($s);
  1356. for($i=0; $i<$l; $i++) {
  1357. if (isset($cw[$s{$i}])) {
  1358. $w += $cw[$s{$i}];
  1359. } else if (isset($cw[ord($s{$i})])) {
  1360. $w += $cw[ord($s{$i})];
  1361. }
  1362. }
  1363. }
  1364. return ($w * $this->FontSize / 1000);
  1365. }
  1366. /**
  1367. * Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
  1368. * @param float $width The width.
  1369. * @since 1.0
  1370. * @see Line(), Rect(), Cell(), MultiCell()
  1371. */
  1372. function SetLineWidth($width) {
  1373. //Set line width
  1374. $this->LineWidth=$width;
  1375. if($this->page>0) {
  1376. $this->_out(sprintf('%.2f w',$width*$this->k));
  1377. }
  1378. }
  1379. /**
  1380. * Draws a line between two points.
  1381. * @param float $x1 Abscissa of first point
  1382. * @param float $y1 Ordinate of first point
  1383. * @param float $x2 Abscissa of second point
  1384. * @param float $y2 Ordinate of second point
  1385. * @since 1.0
  1386. * @see SetLineWidth(), SetDrawColor()
  1387. */
  1388. function Line($x1, $y1, $x2, $y2) {
  1389. //Draw a line
  1390. $this->_out(sprintf('%.2f %.2f m %.2f %.2f l S', $x1*$this->k, ($this->h-$y1)*$this->k, $x2*$this->k, ($this->h-$y2)*$this->k));
  1391. }
  1392. /**
  1393. * Outputs a rectangle. It can be drawn (border only), filled (with no border) or both.
  1394. * @param float $x Abscissa of upper-left corner
  1395. * @param float $y Ordinate of upper-left corner
  1396. * @param float $w Width
  1397. * @param float $h Height
  1398. * @param string $style Style of rendering. Possible values are:<ul><li>D or empty string: draw (default)</li><li>F: fill</li><li>DF or FD: draw and fill</li></ul>
  1399. * @since 1.0
  1400. * @see SetLineWidth(), SetDrawColor(), SetFillColor()
  1401. */
  1402. function Rect($x, $y, $w, $h, $style='') {
  1403. //Draw a rectangle
  1404. if($style=='F') {
  1405. $op='f';
  1406. }
  1407. elseif($style=='FD' or $style=='DF') {
  1408. $op='B';
  1409. }
  1410. else {
  1411. $op='S';
  1412. }
  1413. $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
  1414. }
  1415. /**
  1416. * Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by FPDF_FONTPATH if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
  1417. * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02].
  1418. * <b>Example</b>:<br />
  1419. * <pre>
  1420. * $pdf->AddFont('Comic','I');
  1421. * // is equivalent to:
  1422. * $pdf->AddFont('Comic','I','comici.php');
  1423. * </pre>
  1424. * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
  1425. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
  1426. * @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space.
  1427. * @since 1.5
  1428. * @see SetFont()
  1429. */
  1430. function AddFont($family, $style='', $file='') {
  1431. if(empty($family)) {
  1432. return;
  1433. }
  1434. //Add a TrueType or Type1 font
  1435. $family = strtolower($family);
  1436. if((!$this->isunicode) AND ($family == 'arial')) {
  1437. $family = 'helvetica';
  1438. }
  1439. $style=strtoupper($style);
  1440. $style=str_replace('U','',$style);
  1441. if($style == 'IB') {
  1442. $style = 'BI';
  1443. }
  1444. $fontkey = $family.$style;
  1445. // check if the font has been already added
  1446. if(isset($this->fonts[$fontkey])) {
  1447. return;
  1448. }
  1449. if($file=='') {
  1450. $file = str_replace(' ', '', $family).strtolower($style).'.php';
  1451. }
  1452. if(!file_exists($this->_getfontpath().$file)) {
  1453. // try to load the basic file without styles
  1454. $file = str_replace(' ', '', $family).'.php';
  1455. }
  1456. include($this->_getfontpath().$file);
  1457. if(!isset($name) AND !isset($fpdf_charwidths)) {
  1458. $this->Error('Could not include font definition file');
  1459. }
  1460. $i = count($this->fonts)+1;
  1461. if($this->isunicode) {
  1462. $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);
  1463. $fpdf_charwidths[$fontkey] = $cw;
  1464. } else {
  1465. $this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);
  1466. }
  1467. if(isset($diff) AND (!empty($diff))) {
  1468. //Search existing encodings
  1469. $d=0;
  1470. $nb=count($this->diffs);
  1471. for($i=1;$i<=$nb;$i++) {
  1472. if($this->diffs[$i]==$diff) {
  1473. $d=$i;
  1474. break;
  1475. }
  1476. }
  1477. if($d==0) {
  1478. $d=$nb+1;
  1479. $this->diffs[$d]=$diff;
  1480. }
  1481. $this->fonts[$fontkey]['diff']=$d;
  1482. }
  1483. if(!empty($file)) {
  1484. if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) {
  1485. $this->FontFiles[$file]=array('length1'=>$originalsize);
  1486. }
  1487. else {
  1488. $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
  1489. }
  1490. }
  1491. }
  1492. /**
  1493. * Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid.
  1494. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
  1495. * The method can be called before the first page is created and the font is retained from page to page.
  1496. If you just wish to change the current font size, it is simpler to call SetFontSize().
  1497. * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the FPDF_FONTPATH constant</li></ul><br />
  1498. * Example for the last case (note the trailing slash):<br />
  1499. * <pre>
  1500. * define('FPDF_FONTPATH','/home/www/font/');
  1501. * require('tcpdf.php');
  1502. *
  1503. * //Times regular 12
  1504. * $pdf->SetFont('Times');
  1505. * //Arial bold 14
  1506. * $pdf->SetFont('Arial','B',14);
  1507. * //Removes bold
  1508. * $pdf->SetFont('');
  1509. * //Times bold, italic and underlined 14
  1510. * $pdf->SetFont('Times','BIU');
  1511. * </pre><br />
  1512. * If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated.
  1513. * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained.
  1514. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li></ul>or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats
  1515. * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
  1516. * @since 1.0
  1517. * @see AddFont(), SetFontSize(), Cell(), MultiCell(), Write()
  1518. */
  1519. function SetFont($family, $style='', $size=0) {
  1520. // save previous values
  1521. $this->prevFontFamily = $this->FontFamily;
  1522. $this->prevFontStyle = $this->FontStyle;
  1523. //Select a font; size given in points
  1524. global $fpdf_charwidths;
  1525. $family=strtolower($family);
  1526. if($family=='') {
  1527. $family=$this->FontFamily;
  1528. }
  1529. if((!$this->isunicode) AND ($family == 'arial')) {
  1530. $family = 'helvetica';
  1531. }
  1532. elseif(($family=="symbol") OR ($family=="zapfdingbats")) {
  1533. $style='';
  1534. }
  1535. $style=strtoupper($style);
  1536. if(strpos($style,'U')!==false) {
  1537. $this->underline=true;
  1538. $style=str_replace('U','',$style);
  1539. }
  1540. else {
  1541. $this->underline=false;
  1542. }
  1543. if($style=='IB') {
  1544. $style='BI';
  1545. }
  1546. if($size==0) {
  1547. $size=$this->FontSizePt;
  1548. }
  1549. // try to add font (if not already added)
  1550. if($this->isunicode) {
  1551. $this->AddFont($family, $style);
  1552. }
  1553. //Test if font is already selected
  1554. if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size)) {
  1555. return;
  1556. }
  1557. $fontkey = $family.$style;
  1558. //if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) {
  1559. // $style='';
  1560. //}
  1561. //Test if used for the first time
  1562. if(!isset($this->fonts[$fontkey])) {
  1563. //Check if one of the standard fonts
  1564. if(isset($this->CoreFonts[$fontkey])) {
  1565. if(!isset($fpdf_charwidths[$fontkey])) {
  1566. //Load metric file
  1567. $file = $family;
  1568. if(($family!='symbol') AND ($family!='zapfdingbats')) {
  1569. $file .= strtolower($style);
  1570. }
  1571. if(!file_exists($this->_getfontpath().$file.'.php')) {
  1572. // try to load the basic file without styles
  1573. $file = $family;
  1574. $fontkey = $family;
  1575. }
  1576. include($this->_getfontpath().$file.'.php');
  1577. if (($this->isunicode AND !isset($ctg)) OR ((!$this->isunicode) AND (!isset($fpdf_charwidths[$fontkey]))) ) {
  1578. $this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php");
  1579. }
  1580. }
  1581. $i = count($this->fonts) + 1;
  1582. if($this->isunicode) {
  1583. $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);
  1584. $fpdf_charwidths[$fontkey] = $cw;
  1585. } else {
  1586. $this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);
  1587. }
  1588. }
  1589. else {
  1590. $this->Error('Undefined font: '.$family.' '.$style);
  1591. }
  1592. }
  1593. //Select it
  1594. $this->FontFamily = $family;
  1595. $this->FontStyle = $style;
  1596. $this->FontSizePt = $size;
  1597. $this->FontSize = $size / $this->k;
  1598. $this->CurrentFont = &$this->fonts[$fontkey];
  1599. if($this->page>0) {
  1600. $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  1601. }
  1602. }
  1603. /**
  1604. * Defines the size of the current font.
  1605. * @param float $size The size (in points)
  1606. * @since 1.0
  1607. * @see SetFont()
  1608. */
  1609. function SetFontSize($size) {
  1610. //Set font size in points
  1611. if($this->FontSizePt==$size) {
  1612. return;
  1613. }
  1614. $this->FontSizePt = $size;
  1615. $this->FontSize = $size / $this->k;
  1616. if($this->page > 0) {
  1617. $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
  1618. }
  1619. }
  1620. /**
  1621. * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />
  1622. * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().
  1623. * @since 1.5
  1624. * @see Cell(), Write(), Image(), Link(), SetLink()
  1625. */
  1626. function AddLink() {
  1627. //Create a new internal link
  1628. $n=count($this->links)+1;
  1629. $this->links[$n]=array(0,0);
  1630. return $n;
  1631. }
  1632. /**
  1633. * Defines the page and position a link points to
  1634. * @param int $link The link identifier returned by AddLink()
  1635. * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)
  1636. * @param int $page Number of target page; -1 indicates the current page. This is the default value
  1637. * @since 1.5
  1638. * @see AddLink()
  1639. */
  1640. function SetLink($link, $y=0, $page=-1) {
  1641. //Set destination of internal link
  1642. if($y==-1) {
  1643. $y=$this->y;
  1644. }
  1645. if($page==-1) {
  1646. $page=$this->page;
  1647. }
  1648. $this->links[$link]=array($page,$y);
  1649. }
  1650. /**
  1651. * Puts a link on a rectangular area of the page. Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.
  1652. * @param float $x Abscissa of the upper-left corner of the rectangle
  1653. * @param float $y Ordinate of the upper-left corner of the rectangle
  1654. * @param float $w Width of the rectangle
  1655. * @param float $h Height of the rectangle
  1656. * @param mixed $link URL or identifier returned by AddLink()
  1657. * @since 1.5
  1658. * @see AddLink(), Cell(), Write(), Image()
  1659. */
  1660. function Link($x, $y, $w, $h, $link) {
  1661. //Put a link on the page
  1662. $this->PageLinks[$this->page][] = array($x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h*$this->k, $link);
  1663. }
  1664. /**
  1665. * Prints a character string. The origin is on the left of the first charcter, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text.
  1666. * @param float $x Abscissa of the origin
  1667. * @param float $y Ordinate of the origin
  1668. * @param string $txt String to print
  1669. * @since 1.0
  1670. * @see SetFont(), SetTextColor(), Cell(), MultiCell(), Write()
  1671. */
  1672. function Text($x, $y, $txt) {
  1673. //Output a string
  1674. $s=sprintf('BT %.2f %.2f Td (%s) Tj ET', $x * $this->k, ($this->h-$y) * $this->k, $this->_escapetext($txt));
  1675. if($this->underline AND ($txt!='')) {
  1676. $s .= ' '.$this->_dounderline($x,$y,$txt);
  1677. }
  1678. if($this->ColorFlag) {
  1679. $s='q '.$this->TextColor.' '.$s.' Q';
  1680. }
  1681. $this->_out($s);
  1682. }
  1683. /**
  1684. * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />
  1685. * This method is called automatically and should not be called directly by the application.<br />
  1686. * <b>Example:</b><br />
  1687. * The method is overriden in an inherited class in order to obtain a 3 column layout:<br />
  1688. * <pre>
  1689. * class PDF extends TCPDF {
  1690. * var $col=0;
  1691. *
  1692. * function SetCol($col) {
  1693. * //Move position to a column
  1694. * $this->col=$col;
  1695. * $x=10+$col*65;
  1696. * $this->SetLeftMargin($x);
  1697. * $this->SetX($x);
  1698. * }
  1699. *
  1700. * function AcceptPageBreak() {
  1701. * if($this->col<2) {
  1702. * //Go to next column
  1703. * $this->SetCol($this->col+1);
  1704. * $this->SetY(10);
  1705. * return false;
  1706. * }
  1707. * else {
  1708. * //Go back to first column and issue page break
  1709. * $this->SetCol(0);
  1710. * return true;
  1711. * }
  1712. * }
  1713. * }
  1714. *
  1715. * $pdf=new PDF();
  1716. * $pdf->Open();
  1717. * $pdf->AddPage();
  1718. * $pdf->SetFont('Arial','',12);
  1719. * for($i=1;$i<=300;$i++) {
  1720. * $pdf->Cell(0,5,"Line $i",0,1);
  1721. * }
  1722. * $pdf->Output();
  1723. * </pre>
  1724. * @return boolean
  1725. * @since 1.4
  1726. * @see SetAutoPageBreak()
  1727. */
  1728. function AcceptPageBreak() {
  1729. //Accept automatic page break or not
  1730. return $this->AutoPageBreak;
  1731. }
  1732. /**
  1733. * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />
  1734. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  1735. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  1736. * @param float $h Cell height. Default value: 0.
  1737. * @param string $txt String to print. Default value: empty string.
  1738. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  1739. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  1740. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  1741. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li></ul>
  1742. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  1743. * @param mixed $link URL or identifier returned by AddLink().
  1744. * @since 1.0
  1745. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()
  1746. */
  1747. function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='') {
  1748. //Output a cell
  1749. $k=$this->k;
  1750. if(($this->y + $h) > $this->PageBreakTrigger AND empty($this->InFooter) AND $this->AcceptPageBreak()) {
  1751. //Automatic page break
  1752. $x = $this->x;
  1753. $ws = $this->ws;
  1754. if($ws > 0) {
  1755. $this->ws = 0;
  1756. $this->_out('0 Tw');
  1757. }
  1758. $this->AddPage($this->CurOrientation);
  1759. $this->x = $x;
  1760. if($ws > 0) {
  1761. $this->ws = $ws;
  1762. $this->_out(sprintf('%.3f Tw',$ws * $k));
  1763. }
  1764. }
  1765. if($w == 0) {
  1766. $w = $this->w - $this->rMargin - $this->x;
  1767. }
  1768. $s = '';
  1769. if(($fill == 1) OR ($border == 1)) {
  1770. if($fill == 1) {
  1771. $op = ($border == 1) ? 'B' : 'f';
  1772. }
  1773. else {
  1774. $op = 'S';
  1775. }
  1776. $s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op);
  1777. }
  1778. if(is_string($border)) {
  1779. $x=$this->x;
  1780. $y=$this->y;
  1781. if(strpos($border,'L')!==false) {
  1782. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
  1783. }
  1784. if(strpos($border,'T')!==false) {
  1785. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
  1786. }
  1787. if(strpos($border,'R')!==false) {
  1788. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
  1789. }
  1790. if(strpos($border,'B')!==false) {
  1791. $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
  1792. }
  1793. }
  1794. if($txt != '') {
  1795. $width = $this->GetStringWidth($txt);
  1796. if($align == 'R') {
  1797. $dx = $w - $this->cMargin - $width;
  1798. }
  1799. elseif($align=='C') {
  1800. $dx = ($w - $width)/2;
  1801. }
  1802. else {
  1803. $dx = $this->cMargin;
  1804. }
  1805. if($this->ColorFlag) {
  1806. $s .= 'q '.$this->TextColor.' ';
  1807. }
  1808. $txt2 = $this->_escapetext($txt);
  1809. $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + 0.5 * $h + 0.3 * $this->FontSize)) * $k, $txt2);
  1810. if($this->underline) {
  1811. $s.=' '.$this->_dounderline($this->x + $dx, $this->y + 0.5 * $h + 0.3 * $this->FontSize, $txt);
  1812. }
  1813. if($this->ColorFlag) {
  1814. $s.=' Q';
  1815. }
  1816. if($link) {
  1817. $this->Link($this->x + $dx, $this->y + 0.5 * $h - 0.5 * $this->FontSize, $width, $this->FontSize, $link);
  1818. }
  1819. }
  1820. if($s) {
  1821. $this->_out($s);
  1822. }
  1823. $this->lasth = $h;
  1824. if($ln>0) {
  1825. //Go to next line
  1826. $this->y += $h;
  1827. if($ln == 1) {
  1828. $this->x = $this->lMargin;
  1829. }
  1830. }
  1831. else {
  1832. $this->x += $w;
  1833. }
  1834. }
  1835. /**
  1836. * This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />
  1837. * Text can be aligned, centered or justified. The cell block can be framed and the background painted.
  1838. * @param float $w Width of cells. If 0, they extend up to the right margin of the page.
  1839. * @param float $h Height of cells.
  1840. * @param string $txt String to print
  1841. * @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  1842. * @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value)</li></ul>
  1843. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  1844. * @since 1.3
  1845. * @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
  1846. */
  1847. function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0) {
  1848. //Output text with automatic or explicit line breaks
  1849. $cw = &$this->CurrentFont['cw'];
  1850. if($w == 0) {
  1851. $w = $this->w - $this->rMargin - $this->x;
  1852. }
  1853. $wmax = ($w - 2 * $this->cMargin);
  1854. $s = str_replace("\r", '', $txt); // remove carriage returns
  1855. $nb = strlen($s);
  1856. $b=0;
  1857. if($border) {
  1858. if($border==1) {
  1859. $border='LTRB';
  1860. $b='LRT';
  1861. $b2='LR';
  1862. }
  1863. else {
  1864. $b2='';
  1865. if(strpos($border,'L')!==false) {
  1866. $b2.='L';
  1867. }
  1868. if(strpos($border,'R')!==false) {
  1869. $b2.='R';
  1870. }
  1871. $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2;
  1872. }
  1873. }
  1874. $sep=-1;
  1875. $i=0;
  1876. $j=0;
  1877. $l=0;
  1878. $ns=0;
  1879. $nl=1;
  1880. while($i<$nb) {
  1881. //Get next character
  1882. $c = $s{$i};
  1883. if(preg_match("/[\n]/u", $c)) {
  1884. //Explicit line break
  1885. if($this->ws > 0) {
  1886. $this->ws = 0;
  1887. $this->_out('0 Tw');
  1888. }
  1889. $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
  1890. $i++;
  1891. $sep=-1;
  1892. $j=$i;
  1893. $l=0;
  1894. $ns=0;
  1895. $nl++;
  1896. if($border and $nl==2) {
  1897. $b = $b2;
  1898. }
  1899. continue;
  1900. }
  1901. if(preg_match("/[ ]/u", $c)) {
  1902. $sep = $i;
  1903. $ls = $l;
  1904. $ns++;
  1905. }
  1906. $l = $this->GetStringWidth(substr($s, $j, $i-$j));
  1907. if($l > $wmax) {
  1908. //Automatic line break
  1909. if($sep == -1) {
  1910. if($i == $j) {
  1911. $i++;
  1912. }
  1913. if($this->ws > 0) {
  1914. $this->ws = 0;
  1915. $this->_out('0 Tw');
  1916. }
  1917. $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
  1918. }
  1919. else {
  1920. if($align=='J') {
  1921. $this->ws = ($ns>1) ? ($wmax-$ls)/($ns-1) : 0;
  1922. $this->_out(sprintf('%.3f Tw', $this->ws * $this->k));
  1923. }
  1924. $this->Cell($w, $h, substr($s, $j, $sep-$j), $b, 2, $align, $fill);
  1925. $i = $sep + 1;
  1926. }
  1927. $sep=-1;
  1928. $j=$i;
  1929. $l=0;
  1930. $ns=0;
  1931. $nl++;
  1932. if($border AND ($nl==2)) {
  1933. $b=$b2;
  1934. }
  1935. }
  1936. else {
  1937. $i++;
  1938. }
  1939. }
  1940. //Last chunk
  1941. if($this->ws>0) {
  1942. $this->ws=0;
  1943. $this->_out('0 Tw');
  1944. }
  1945. if($border and is_int(strpos($border,'B'))) {
  1946. $b.='B';
  1947. }
  1948. $this->Cell($w, $h, substr($s, $j, $i-$j), $b, 2, $align, $fill);
  1949. $this->x=$this->lMargin;
  1950. }
  1951. /**
  1952. * This method prints text from the current position. When the right margin is reached (or the \n character is met) a line break occurs and text continues from the left margin. Upon method exit, the current position is left just at the end of the text. It is possible to put a link on the text.<br />
  1953. * <b>Example:</b><br />
  1954. * <pre>
  1955. * //Begin with regular font
  1956. * $pdf->SetFont('Arial','',14);
  1957. * $pdf->Write(5,'Visit ');
  1958. * //Then put a blue underlined link
  1959. * $pdf->SetTextColor(0,0,255);
  1960. * $pdf->SetFont('','U');
  1961. * $pdf->Write(5,'www.tecnick.com','http://www.tecnick.com');
  1962. * </pre>
  1963. * @param float $h Line height
  1964. * @param string $txt String to print
  1965. * @param mixed $link URL or identifier returned by AddLink()
  1966. * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  1967. * @since 1.5
  1968. * @see SetFont(), SetTextColor(), AddLink(), MultiCell(), SetAutoPageBreak()
  1969. */
  1970. function Write($h, $txt, $link='', $fill=0) {
  1971. //Output text in flowing mode
  1972. $cw = &$this->CurrentFont['cw'];
  1973. $w = $this->w - $this->rMargin - $this->x;
  1974. $wmax = ($w - 2 * $this->cMargin);
  1975. $s = str_replace("\r", '', $txt);
  1976. $nb = strlen($s);
  1977. // handle single space character
  1978. if(($nb==1) AND preg_match("/[ ]/u", $s)) {
  1979. $this->x += $this->GetStringWidth($s);
  1980. return;
  1981. }
  1982. $sep=-1;
  1983. $i=0;
  1984. $j=0;
  1985. $l=0;
  1986. $nl=1;
  1987. while($i<$nb) {
  1988. //Get next character
  1989. $c=$s{$i};
  1990. if(preg_match("/[\n]/u", $c)) {
  1991. //Explicit line break
  1992. $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link);
  1993. $i++;
  1994. $sep = -1;
  1995. $j = $i;
  1996. $l = 0;
  1997. if($nl == 1) {
  1998. $this->x = $this->lMargin;
  1999. $w = $this->w - $this->rMargin - $this->x;
  2000. $wmax = ($w - 2 * $this->cMargin);
  2001. }
  2002. $nl++;
  2003. continue;
  2004. }
  2005. if(preg_match("/[ ]/u", $c)) {
  2006. $sep= $i;
  2007. }
  2008. $l = $this->GetStringWidth(substr($s, $j, $i-$j));
  2009. if($l > $wmax) {
  2010. //Automatic line break (word wrapping)
  2011. if($sep == -1) {
  2012. if($this->x > $this->lMargin) {
  2013. //Move to next line
  2014. $this->x = $this->lMargin;
  2015. $this->y += $h;
  2016. $w=$this->w - $this->rMargin - $this->x;
  2017. $wmax=($w - 2 * $this->cMargin);
  2018. $i++;
  2019. $nl++;
  2020. continue;
  2021. }
  2022. if($i==$j) {
  2023. $i++;
  2024. }
  2025. $this->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, '', $fill, $link);
  2026. }
  2027. else {
  2028. $this->Cell($w, $h, substr($s, $j, $sep-$j), 0, 2, '', $fill, $link);
  2029. $i=$sep+1;
  2030. }
  2031. $sep = -1;
  2032. $j = $i;
  2033. $l = 0;
  2034. if($nl==1) {
  2035. $this->x = $this->lMargin;
  2036. $w = $this->w - $this->rMargin - $this->x;
  2037. $wmax = ($w - 2 * $this->cMargin);
  2038. }
  2039. $nl++;
  2040. }
  2041. else {
  2042. $i++;
  2043. }
  2044. }
  2045. //Last chunk
  2046. if($i!=$j) {
  2047. $this->Cell($this->GetStringWidth(substr($s, $j)), $h, substr($s, $j), 0, 0, '', $fill, $link);
  2048. }
  2049. }
  2050. /**
  2051. * Puts an image in the page. The upper-left corner must be given. The dimensions can be specified in different ways:<ul><li>explicit width and height (expressed in user unit)</li><li>one explicit dimension, the other being calculated automatically in order to keep the original proportions</li><li>no explicit dimension, in which case the image is put at 72 dpi</li></ul>
  2052. * Supported formats are JPEG and PNG.
  2053. * For JPEG, all flavors are allowed:<ul><li>gray scales</li><li>true colors (24 bits)</li><li>CMYK (32 bits)</li></ul>
  2054. * For PNG, are allowed:<ul><li>gray scales on at most 8 bits (256 levels)</li><li>indexed colors</li><li>true colors (24 bits)</li></ul>
  2055. * but are not supported:<ul><li>Interlacing</li><li>Alpha channel</li></ul>
  2056. * If a transparent color is defined, it will be taken into account (but will be only interpreted by Acrobat 4 and above).<br />
  2057. * The format can be specified explicitly or inferred from the file extension.<br />
  2058. * It is possible to put a link on the image.<br />
  2059. * Remark: if an image is used several times, only one copy will be embedded in the file.<br />
  2060. * @param string $file Name of the file containing the image.
  2061. * @param float $x Abscissa of the upper-left corner.
  2062. * @param float $y Ordinate of the upper-left corner.
  2063. * @param float $w Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  2064. * @param float $h Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  2065. * @param string $type Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.
  2066. * @param mixed $link URL or identifier returned by AddLink().
  2067. * @since 1.1
  2068. * @see AddLink()
  2069. */
  2070. function Image($file, $x, $y, $w=0, $h=0, $type='', $link='') {
  2071. //Put an image on the page
  2072. if(!isset($this->images[$file])) {
  2073. //First use of image, get info
  2074. if($type == '') {
  2075. $pos = strrpos($file,'.');
  2076. if(empty($pos)) {
  2077. $this->Error('Image file has no extension and no type was specified: '.$file);
  2078. }
  2079. $type = substr($file, $pos+1);
  2080. }
  2081. $type = strtolower($type);
  2082. $mqr = get_magic_quotes_runtime();
  2083. set_magic_quotes_runtime(0);
  2084. if($type == 'jpg' or $type == 'jpeg') {
  2085. $info=$this->_parsejpg($file);
  2086. }
  2087. elseif($type == 'png') {
  2088. $info=$this->_parsepng($file);
  2089. }
  2090. else {
  2091. //Allow for additional formats
  2092. $mtd='_parse'.$type;
  2093. if(!method_exists($this,$mtd)) {
  2094. $this->Error('Unsupported image type: '.$type);
  2095. }
  2096. $info=$this->$mtd($file);
  2097. }
  2098. set_magic_quotes_runtime($mqr);
  2099. $info['i']=count($this->images)+1;
  2100. $this->images[$file]=$info;
  2101. }
  2102. else {
  2103. $info=$this->images[$file];
  2104. }
  2105. //Automatic width and height calculation if needed
  2106. if(($w == 0) and ($h == 0)) {
  2107. //Put image at 72 dpi
  2108. // 2004-06-14 :: Nicola Asuni, scale factor where added
  2109. $w = $info['w'] / ($this->imgscale * $this->k);
  2110. $h = $info['h'] / ($this->imgscale * $this->k);
  2111. }
  2112. if($w == 0) {
  2113. $w = $h * $info['w'] / $info['h'];
  2114. }
  2115. if($h == 0) {
  2116. $h = $w * $info['h'] / $info['w'];
  2117. }
  2118. $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q', $w*$this->k, $h*$this->k, $x*$this->k, ($this->h-($y+$h))*$this->k, $info['i']));
  2119. if($link) {
  2120. $this->Link($x, $y, $w, $h, $link);
  2121. }
  2122. //2002-07-31 - Nicola Asuni
  2123. // set right-bottom corner coordinates
  2124. $this->img_rb_x = $x + $w;
  2125. $this->img_rb_y = $y + $h;
  2126. }
  2127. /**
  2128. * Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.
  2129. * @param float $h The height of the break. By default, the value equals the height of the last printed cell.
  2130. * @since 1.0
  2131. * @see Cell()
  2132. */
  2133. function Ln($h='') {
  2134. //Line feed; default value is last cell height
  2135. $this->x=$this->lMargin;
  2136. if(is_string($h)) {
  2137. $this->y+=$this->lasth;
  2138. }
  2139. else {
  2140. $this->y+=$h;
  2141. }
  2142. }
  2143. /**
  2144. * Returns the abscissa of the current position.
  2145. * @return float
  2146. * @since 1.2
  2147. * @see SetX(), GetY(), SetY()
  2148. */
  2149. function GetX() {
  2150. //Get x position
  2151. return $this->x;
  2152. }
  2153. /**
  2154. * Defines the abscissa of the current position. If the passed value is negative, it is relative to the right of the page.
  2155. * @param float $x The value of the abscissa.
  2156. * @since 1.2
  2157. * @see GetX(), GetY(), SetY(), SetXY()
  2158. */
  2159. function SetX($x) {
  2160. //Set x position
  2161. if($x>=0) {
  2162. $this->x=$x;
  2163. }
  2164. else {
  2165. $this->x=$this->w+$x;
  2166. }
  2167. }
  2168. /**
  2169. * Returns the ordinate of the current position.
  2170. * @return float
  2171. * @since 1.0
  2172. * @see SetY(), GetX(), SetX()
  2173. */
  2174. function GetY() {
  2175. //Get y position
  2176. return $this->y;
  2177. }
  2178. /**
  2179. * Moves the current abscissa back to the left margin and sets the ordinate. If the passed value is negative, it is relative to the bottom of the page.
  2180. * @param float $y The value of the ordinate.
  2181. * @since 1.0
  2182. * @see GetX(), GetY(), SetY(), SetXY()
  2183. */
  2184. function SetY($y) {
  2185. //Set y position and reset x
  2186. $this->x=$this->lMargin;
  2187. if($y>=0) {
  2188. $this->y=$y;
  2189. }
  2190. else {
  2191. $this->y=$this->h+$y;
  2192. }
  2193. }
  2194. /**
  2195. * Defines the abscissa and ordinate of the current position. If the passed values are negative, they are relative respectively to the right and bottom of the page.
  2196. * @param float $x The value of the abscissa
  2197. * @param float $y The value of the ordinate
  2198. * @since 1.2
  2199. * @see SetX(), SetY()
  2200. */
  2201. function SetXY($x, $y) {
  2202. //Set x and y positions
  2203. $this->SetY($y);
  2204. $this->SetX($x);
  2205. }
  2206. /**
  2207. * Send the document to a given destination: string, local file or browser. In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br />
  2208. * The method first calls Close() if necessary to terminate the document.
  2209. * @param string $name The name of the file. If not given, the document will be sent to the browser (destination I) with the name doc.pdf.
  2210. * @param string $dest Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser. The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local file with the name given by name.</li><li>S: return the document as a string. name is ignored.</li></ul>If the parameter is not specified but a name is given, destination is F. If no parameter is specified at all, destination is I.<br />Note: for compatibility with previous versions, a boolean value is also accepted (false for F and true for D).
  2211. * @since 1.0
  2212. * @see Close()
  2213. */
  2214. function Output($name='',$dest='') {
  2215. //Output PDF to some destination
  2216. //Finish document if necessary
  2217. if($this->state < 3) {
  2218. $this->Close();
  2219. }
  2220. //Normalize parameters
  2221. if(is_bool($dest)) {
  2222. $dest=$dest ? 'D' : 'F';
  2223. }
  2224. $dest=strtoupper($dest);
  2225. if($dest=='') {
  2226. if($name=='') {
  2227. $name='doc.pdf';
  2228. $dest='I';
  2229. } else {
  2230. $dest='F';
  2231. }
  2232. }
  2233. switch($dest) {
  2234. case 'I': {
  2235. //Send to standard output
  2236. if(ob_get_contents()) {
  2237. $this->Error('Some data has already been output, can\'t send PDF file');
  2238. }
  2239. if(php_sapi_name()!='cli') {
  2240. //We send to a browser
  2241. header('Content-Type: application/pdf');
  2242. if(headers_sent()) {
  2243. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  2244. }
  2245. header('Content-Length: '.strlen($this->buffer));
  2246. header('Content-disposition: inline; filename="'.$name.'"');
  2247. }
  2248. echo $this->buffer;
  2249. break;
  2250. }
  2251. case 'D': {
  2252. //Download file
  2253. if(ob_get_contents()) {
  2254. $this->Error('Some data has already been output, can\'t send PDF file');
  2255. }
  2256. if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) {
  2257. header('Content-Type: application/force-download');
  2258. } else {
  2259. header('Content-Type: application/octet-stream');
  2260. }
  2261. if(headers_sent()) {
  2262. $this->Error('Some data has already been output to browser, can\'t send PDF file');
  2263. }
  2264. header('Content-Length: '.strlen($this->buffer));
  2265. header('Content-disposition: attachment; filename="'.$name.'"');
  2266. echo $this->buffer;
  2267. break;
  2268. }
  2269. case 'F': {
  2270. //Save to local file
  2271. $f=fopen($name,'wb');
  2272. if(!$f) {
  2273. $this->Error('Unable to create output file: '.$name);
  2274. }
  2275. fwrite($f,$this->buffer,strlen($this->buffer));
  2276. fclose($f);
  2277. break;
  2278. }
  2279. case 'S': {
  2280. //Return as a string
  2281. return $this->buffer;
  2282. }
  2283. default: {
  2284. $this->Error('Incorrect output destination: '.$dest);
  2285. }
  2286. }
  2287. return '';
  2288. }
  2289. // var methods
  2290. /**
  2291. * Check for locale-related bug
  2292. * @access protected
  2293. */
  2294. function _dochecks() {
  2295. //Check for locale-related bug
  2296. if(1.1==1) {
  2297. $this->Error('Don\'t alter the locale before including class file');
  2298. }
  2299. //Check for decimal separator
  2300. if(sprintf('%.1f',1.0)!='1.0') {
  2301. setlocale(LC_NUMERIC,'C');
  2302. }
  2303. }
  2304. /**
  2305. * Return fonts path
  2306. * @access protected
  2307. */
  2308. function _getfontpath() {
  2309. if(!defined('FPDF_FONTPATH') AND is_dir(dirname(__FILE__).'/font')) {
  2310. define('FPDF_FONTPATH', dirname(__FILE__).'/font/');
  2311. }
  2312. return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : '';
  2313. }
  2314. /**
  2315. * Start document
  2316. * @access protected
  2317. */
  2318. function _begindoc() {
  2319. //Start document
  2320. $this->state=1;
  2321. $this->_out('%PDF-1.3');
  2322. }
  2323. /**
  2324. * _putpages
  2325. * @access protected
  2326. */
  2327. function _putpages() {
  2328. $nb = $this->page;
  2329. if(!empty($this->AliasNbPages)) {
  2330. $nbstr = $this->UTF8ToUTF16BE($nb, false);
  2331. //Replace number of pages
  2332. for($n=1;$n<=$nb;$n++) {
  2333. $this->pages[$n]=str_replace($this->AliasNbPages, $nbstr, $this->pages[$n]);
  2334. }
  2335. }
  2336. if($this->DefOrientation=='P') {
  2337. $wPt=$this->fwPt;
  2338. $hPt=$this->fhPt;
  2339. }
  2340. else {
  2341. $wPt=$this->fhPt;
  2342. $hPt=$this->fwPt;
  2343. }
  2344. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  2345. for($n=1;$n<=$nb;$n++) {
  2346. //Page
  2347. $this->_newobj();
  2348. $this->_out('<</Type /Page');
  2349. $this->_out('/Parent 1 0 R');
  2350. if(isset($this->OrientationChanges[$n])) {
  2351. $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt));
  2352. }
  2353. $this->_out('/Resources 2 0 R');
  2354. if(isset($this->PageLinks[$n])) {
  2355. //Links
  2356. $annots='/Annots [';
  2357. foreach($this->PageLinks[$n] as $pl) {
  2358. $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
  2359. $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
  2360. if(is_string($pl[4])) {
  2361. $annots.='/A <</S /URI /URI ('.$this->_escape($pl[4]).')>>>>';
  2362. }
  2363. else {
  2364. $l=$this->links[$pl[4]];
  2365. $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt;
  2366. $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k);
  2367. }
  2368. }
  2369. $this->_out($annots.']');
  2370. }
  2371. $this->_out('/Contents '.($this->n+1).' 0 R>>');
  2372. $this->_out('endobj');
  2373. //Page content
  2374. $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
  2375. $this->_newobj();
  2376. $this->_out('<<'.$filter.'/Length '.strlen($p).'>>');
  2377. $this->_putstream($p);
  2378. $this->_out('endobj');
  2379. }
  2380. //Pages root
  2381. $this->offsets[1]=strlen($this->buffer);
  2382. $this->_out('1 0 obj');
  2383. $this->_out('<</Type /Pages');
  2384. $kids='/Kids [';
  2385. for($i=0;$i<$nb;$i++) {
  2386. $kids.=(3+2*$i).' 0 R ';
  2387. }
  2388. $this->_out($kids.']');
  2389. $this->_out('/Count '.$nb);
  2390. $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt));
  2391. $this->_out('>>');
  2392. $this->_out('endobj');
  2393. }
  2394. /**
  2395. * Adds fonts
  2396. * _putfonts
  2397. * @access protected
  2398. */
  2399. function _putfonts() {
  2400. $nf=$this->n;
  2401. foreach($this->diffs as $diff) {
  2402. //Encodings
  2403. $this->_newobj();
  2404. $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
  2405. $this->_out('endobj');
  2406. }
  2407. $mqr=get_magic_quotes_runtime();
  2408. set_magic_quotes_runtime(0);
  2409. foreach($this->FontFiles as $file=>$info) {
  2410. //Font file embedding
  2411. $this->_newobj();
  2412. $this->FontFiles[$file]['n']=$this->n;
  2413. $font='';
  2414. $f=fopen($this->_getfontpath().$file,'rb',1);
  2415. if(!$f) {
  2416. $this->Error('Font file not found');
  2417. }
  2418. while(!feof($f)) {
  2419. $font .= fread($f, 8192);
  2420. }
  2421. fclose($f);
  2422. $compressed=(substr($file,-2)=='.z');
  2423. if(!$compressed && isset($info['length2'])) {
  2424. $header=(ord($font{0})==128);
  2425. if($header) {
  2426. //Strip first binary header
  2427. $font=substr($font,6);
  2428. }
  2429. if($header && ord($font{$info['length1']})==128) {
  2430. //Strip second binary header
  2431. $font=substr($font,0,$info['length1']).substr($font,$info['length1']+6);
  2432. }
  2433. }
  2434. $this->_out('<</Length '.strlen($font));
  2435. if($compressed) {
  2436. $this->_out('/Filter /FlateDecode');
  2437. }
  2438. $this->_out('/Length1 '.$info['length1']);
  2439. if(isset($info['length2'])) {
  2440. $this->_out('/Length2 '.$info['length2'].' /Length3 0');
  2441. }
  2442. $this->_out('>>');
  2443. $this->_putstream($font);
  2444. $this->_out('endobj');
  2445. }
  2446. set_magic_quotes_runtime($mqr);
  2447. foreach($this->fonts as $k=>$font) {
  2448. //Font objects
  2449. $this->fonts[$k]['n']=$this->n+1;
  2450. $type=$font['type'];
  2451. $name=$font['name'];
  2452. if($type=='core') {
  2453. //Standard font
  2454. $this->_newobj();
  2455. $this->_out('<</Type /Font');
  2456. $this->_out('/BaseFont /'.$name);
  2457. $this->_out('/Subtype /Type1');
  2458. if($name!='Symbol' && $name!='ZapfDingbats') {
  2459. $this->_out('/Encoding /WinAnsiEncoding');
  2460. }
  2461. $this->_out('>>');
  2462. $this->_out('endobj');
  2463. } elseif($type=='Type1' || $type=='TrueType') {
  2464. //Additional Type1 or TrueType font
  2465. $this->_newobj();
  2466. $this->_out('<</Type /Font');
  2467. $this->_out('/BaseFont /'.$name);
  2468. $this->_out('/Subtype /'.$type);
  2469. $this->_out('/FirstChar 32 /LastChar 255');
  2470. $this->_out('/Widths '.($this->n+1).' 0 R');
  2471. $this->_out('/FontDescriptor '.($this->n+2).' 0 R');
  2472. if($font['enc']) {
  2473. if(isset($font['diff'])) {
  2474. $this->_out('/Encoding '.($nf+$font['diff']).' 0 R');
  2475. } else {
  2476. $this->_out('/Encoding /WinAnsiEncoding');
  2477. }
  2478. }
  2479. $this->_out('>>');
  2480. $this->_out('endobj');
  2481. //Widths
  2482. $this->_newobj();
  2483. $cw=&$font['cw'];
  2484. $s='[';
  2485. for($i=32;$i<=255;$i++) {
  2486. $s.=$cw[chr($i)].' ';
  2487. }
  2488. $this->_out($s.']');
  2489. $this->_out('endobj');
  2490. //Descriptor
  2491. $this->_newobj();
  2492. $s='<</Type /FontDescriptor /FontName /'.$name;
  2493. foreach($font['desc'] as $k=>$v) {
  2494. $s.=' /'.$k.' '.$v;
  2495. }
  2496. $file = $font['file'];
  2497. if($file) {
  2498. $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
  2499. }
  2500. $this->_out($s.'>>');
  2501. $this->_out('endobj');
  2502. } else {
  2503. //Allow for additional types
  2504. $mtd='_put'.strtolower($type);
  2505. if(!method_exists($this, $mtd)) {
  2506. $this->Error('Unsupported font type: '.$type);
  2507. }
  2508. $this->$mtd($font);
  2509. }
  2510. }
  2511. }
  2512. /**
  2513. * _putimages
  2514. * @access protected
  2515. */
  2516. function _putimages() {
  2517. $filter=($this->compress) ? '/Filter /FlateDecode ' : '';
  2518. reset($this->images);
  2519. while(list($file,$info)=each($this->images)) {
  2520. $this->_newobj();
  2521. $this->images[$file]['n']=$this->n;
  2522. $this->_out('<</Type /XObject');
  2523. $this->_out('/Subtype /Image');
  2524. $this->_out('/Width '.$info['w']);
  2525. $this->_out('/Height '.$info['h']);
  2526. if($info['cs']=='Indexed') {
  2527. $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]');
  2528. }
  2529. else {
  2530. $this->_out('/ColorSpace /'.$info['cs']);
  2531. if($info['cs']=='DeviceCMYK') {
  2532. $this->_out('/Decode [1 0 1 0 1 0 1 0]');
  2533. }
  2534. }
  2535. $this->_out('/BitsPerComponent '.$info['bpc']);
  2536. if(isset($info['f'])) {
  2537. $this->_out('/Filter /'.$info['f']);
  2538. }
  2539. if(isset($info['parms'])) {
  2540. $this->_out($info['parms']);
  2541. }
  2542. if(isset($info['trns']) and is_array($info['trns'])) {
  2543. $trns='';
  2544. for($i=0;$i<count($info['trns']);$i++) {
  2545. $trns.=$info['trns'][$i].' '.$info['trns'][$i].' ';
  2546. }
  2547. $this->_out('/Mask ['.$trns.']');
  2548. }
  2549. $this->_out('/Length '.strlen($info['data']).'>>');
  2550. $this->_putstream($info['data']);
  2551. unset($this->images[$file]['data']);
  2552. $this->_out('endobj');
  2553. //Palette
  2554. if($info['cs']=='Indexed') {
  2555. $this->_newobj();
  2556. $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal'];
  2557. $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>');
  2558. $this->_putstream($pal);
  2559. $this->_out('endobj');
  2560. }
  2561. }
  2562. }
  2563. /**
  2564. * _putxobjectdict
  2565. * @access protected
  2566. */
  2567. function _putxobjectdict() {
  2568. foreach($this->images as $image) {
  2569. $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R');
  2570. }
  2571. }
  2572. /**
  2573. * _putresourcedict
  2574. * @access protected
  2575. */
  2576. function _putresourcedict(){
  2577. $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
  2578. $this->_out('/Font <<');
  2579. foreach($this->fonts as $font) {
  2580. $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R');
  2581. }
  2582. $this->_out('>>');
  2583. $this->_out('/XObject <<');
  2584. $this->_putxobjectdict();
  2585. $this->_out('>>');
  2586. }
  2587. /**
  2588. * _putresources
  2589. * @access protected
  2590. */
  2591. function _putresources() {
  2592. $this->_putfonts();
  2593. $this->_putimages();
  2594. //Resource dictionary
  2595. $this->offsets[2]=strlen($this->buffer);
  2596. $this->_out('2 0 obj');
  2597. $this->_out('<<');
  2598. $this->_putresourcedict();
  2599. $this->_out('>>');
  2600. $this->_out('endobj');
  2601. }
  2602. /**
  2603. * _putinfo
  2604. * @access protected
  2605. */
  2606. function _putinfo() {
  2607. $this->_out('/Producer '.$this->_textstring(PDF_PRODUCER));
  2608. if(!empty($this->title)) {
  2609. $this->_out('/Title '.$this->_textstring($this->title));
  2610. }
  2611. if(!empty($this->subject)) {
  2612. $this->_out('/Subject '.$this->_textstring($this->subject));
  2613. }
  2614. if(!empty($this->author)) {
  2615. $this->_out('/Author '.$this->_textstring($this->author));
  2616. }
  2617. if(!empty($this->keywords)) {
  2618. $this->_out('/Keywords '.$this->_textstring($this->keywords));
  2619. }
  2620. if(!empty($this->creator)) {
  2621. $this->_out('/Creator '.$this->_textstring($this->creator));
  2622. }
  2623. $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis')));
  2624. }
  2625. /**
  2626. * _putcatalog
  2627. * @access protected
  2628. */
  2629. function _putcatalog() {
  2630. $this->_out('/Type /Catalog');
  2631. $this->_out('/Pages 1 0 R');
  2632. if($this->ZoomMode=='fullpage') {
  2633. $this->_out('/OpenAction [3 0 R /Fit]');
  2634. }
  2635. elseif($this->ZoomMode=='fullwidth') {
  2636. $this->_out('/OpenAction [3 0 R /FitH null]');
  2637. }
  2638. elseif($this->ZoomMode=='real') {
  2639. $this->_out('/OpenAction [3 0 R /XYZ null null 1]');
  2640. }
  2641. elseif(!is_string($this->ZoomMode)) {
  2642. $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']');
  2643. }
  2644. if($this->LayoutMode=='single') {
  2645. $this->_out('/PageLayout /SinglePage');
  2646. }
  2647. elseif($this->LayoutMode=='continuous') {
  2648. $this->_out('/PageLayout /OneColumn');
  2649. }
  2650. elseif($this->LayoutMode=='two') {
  2651. $this->_out('/PageLayout /TwoColumnLeft');
  2652. }
  2653. }
  2654. /**
  2655. * _puttrailer
  2656. * @access protected
  2657. */
  2658. function _puttrailer() {
  2659. $this->_out('/Size '.($this->n+1));
  2660. $this->_out('/Root '.$this->n.' 0 R');
  2661. $this->_out('/Info '.($this->n-1).' 0 R');
  2662. }
  2663. /**
  2664. * _putheader
  2665. * @access protected
  2666. */
  2667. function _putheader() {
  2668. $this->_out('%PDF-'.$this->PDFVersion);
  2669. }
  2670. /**
  2671. * _enddoc
  2672. * @access protected
  2673. */
  2674. function _enddoc() {
  2675. $this->_putheader();
  2676. $this->_putpages();
  2677. $this->_putresources();
  2678. //Info
  2679. $this->_newobj();
  2680. $this->_out('<<');
  2681. $this->_putinfo();
  2682. $this->_out('>>');
  2683. $this->_out('endobj');
  2684. //Catalog
  2685. $this->_newobj();
  2686. $this->_out('<<');
  2687. $this->_putcatalog();
  2688. $this->_out('>>');
  2689. $this->_out('endobj');
  2690. //Cross-ref
  2691. $o=strlen($this->buffer);
  2692. $this->_out('xref');
  2693. $this->_out('0 '.($this->n+1));
  2694. $this->_out('0000000000 65535 f ');
  2695. for($i=1;$i<=$this->n;$i++) {
  2696. $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i]));
  2697. }
  2698. //Trailer
  2699. $this->_out('trailer');
  2700. $this->_out('<<');
  2701. $this->_puttrailer();
  2702. $this->_out('>>');
  2703. $this->_out('startxref');
  2704. $this->_out($o);
  2705. $this->_out('%%EOF');
  2706. $this->state=3;
  2707. }
  2708. /**
  2709. * _beginpage
  2710. * @access protected
  2711. */
  2712. function _beginpage($orientation) {
  2713. $this->page++;
  2714. $this->pages[$this->page]='';
  2715. $this->state=2;
  2716. $this->x=$this->lMargin;
  2717. $this->y=$this->tMargin;
  2718. $this->FontFamily='';
  2719. //Page orientation
  2720. if(empty($orientation)) {
  2721. $orientation=$this->DefOrientation;
  2722. }
  2723. else {
  2724. $orientation=strtoupper($orientation{0});
  2725. if($orientation!=$this->DefOrientation) {
  2726. $this->OrientationChanges[$this->page]=true;
  2727. }
  2728. }
  2729. if($orientation!=$this->CurOrientation) {
  2730. //Change orientation
  2731. if($orientation=='P') {
  2732. $this->wPt=$this->fwPt;
  2733. $this->hPt=$this->fhPt;
  2734. $this->w=$this->fw;
  2735. $this->h=$this->fh;
  2736. }
  2737. else {
  2738. $this->wPt=$this->fhPt;
  2739. $this->hPt=$this->fwPt;
  2740. $this->w=$this->fh;
  2741. $this->h=$this->fw;
  2742. }
  2743. $this->PageBreakTrigger=$this->h-$this->bMargin;
  2744. $this->CurOrientation=$orientation;
  2745. }
  2746. }
  2747. /**
  2748. * End of page contents
  2749. * @access protected
  2750. */
  2751. function _endpage() {
  2752. $this->state=1;
  2753. }
  2754. /**
  2755. * Begin a new object
  2756. * @access protected
  2757. */
  2758. function _newobj() {
  2759. $this->n++;
  2760. $this->offsets[$this->n]=strlen($this->buffer);
  2761. $this->_out($this->n.' 0 obj');
  2762. }
  2763. /**
  2764. * Underline text
  2765. * @access protected
  2766. */
  2767. function _dounderline($x,$y,$txt) {
  2768. $up = $this->CurrentFont['up'];
  2769. $ut = $this->CurrentFont['ut'];
  2770. $w = $this->GetStringWidth($txt) + $this->ws * substr_count($txt,' ');
  2771. return sprintf('%.2f %.2f %.2f %.2f re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, -$ut / 1000 * $this->FontSizePt);
  2772. }
  2773. /**
  2774. * Extract info from a JPEG file
  2775. * @access protected
  2776. */
  2777. function _parsejpg($file) {
  2778. $a=GetImageSize($file);
  2779. if(empty($a)) {
  2780. $this->Error('Missing or incorrect image file: '.$file);
  2781. }
  2782. if($a[2]!=2) {
  2783. $this->Error('Not a JPEG file: '.$file);
  2784. }
  2785. if(!isset($a['channels']) or $a['channels']==3) {
  2786. $colspace='DeviceRGB';
  2787. }
  2788. elseif($a['channels']==4) {
  2789. $colspace='DeviceCMYK';
  2790. }
  2791. else {
  2792. $colspace='DeviceGray';
  2793. }
  2794. $bpc=isset($a['bits']) ? $a['bits'] : 8;
  2795. //Read whole file
  2796. $f=fopen($file,'rb');
  2797. $data='';
  2798. while(!feof($f)) {
  2799. $data.=fread($f,4096);
  2800. }
  2801. fclose($f);
  2802. return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
  2803. }
  2804. /**
  2805. * Extract info from a PNG file
  2806. * @access protected
  2807. */
  2808. function _parsepng($file) {
  2809. $f=fopen($file,'rb');
  2810. if(empty($f)) {
  2811. $this->Error('Can\'t open image file: '.$file);
  2812. }
  2813. //Check signature
  2814. if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
  2815. $this->Error('Not a PNG file: '.$file);
  2816. }
  2817. //Read header chunk
  2818. fread($f,4);
  2819. if(fread($f,4)!='IHDR') {
  2820. $this->Error('Incorrect PNG file: '.$file);
  2821. }
  2822. $w=$this->_freadint($f);
  2823. $h=$this->_freadint($f);
  2824. $bpc=ord(fread($f,1));
  2825. if($bpc>8) {
  2826. $this->Error('16-bit depth not supported: '.$file);
  2827. }
  2828. $ct=ord(fread($f,1));
  2829. if($ct==0) {
  2830. $colspace='DeviceGray';
  2831. }
  2832. elseif($ct==2) {
  2833. $colspace='DeviceRGB';
  2834. }
  2835. elseif($ct==3) {
  2836. $colspace='Indexed';
  2837. }
  2838. else {
  2839. $this->Error('Alpha channel not supported: '.$file);
  2840. }
  2841. if(ord(fread($f,1))!=0) {
  2842. $this->Error('Unknown compression method: '.$file);
  2843. }
  2844. if(ord(fread($f,1))!=0) {
  2845. $this->Error('Unknown filter method: '.$file);
  2846. }
  2847. if(ord(fread($f,1))!=0) {
  2848. $this->Error('Interlacing not supported: '.$file);
  2849. }
  2850. fread($f,4);
  2851. $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
  2852. //Scan chunks looking for palette, transparency and image data
  2853. $pal='';
  2854. $trns='';
  2855. $data='';
  2856. do {
  2857. $n=$this->_freadint($f);
  2858. $type=fread($f,4);
  2859. if($type=='PLTE') {
  2860. //Read palette
  2861. $pal=fread($f,$n);
  2862. fread($f,4);
  2863. }
  2864. elseif($type=='tRNS') {
  2865. //Read transparency info
  2866. $t=fread($f,$n);
  2867. if($ct==0) {
  2868. $trns=array(ord(substr($t,1,1)));
  2869. }
  2870. elseif($ct==2) {
  2871. $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
  2872. }
  2873. else {
  2874. $pos=strpos($t,chr(0));
  2875. if($pos!==false) {
  2876. $trns=array($pos);
  2877. }
  2878. }
  2879. fread($f,4);
  2880. }
  2881. elseif($type=='IDAT') {
  2882. //Read image data block
  2883. $data.=fread($f,$n);
  2884. fread($f,4);
  2885. }
  2886. elseif($type=='IEND') {
  2887. break;
  2888. }
  2889. else {
  2890. fread($f,$n+4);
  2891. }
  2892. }
  2893. while($n);
  2894. if($colspace=='Indexed' and empty($pal)) {
  2895. $this->Error('Missing palette in '.$file);
  2896. }
  2897. fclose($f);
  2898. return array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'parms'=>$parms, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data);
  2899. }
  2900. /**
  2901. * Read a 4-byte integer from file
  2902. * @access protected
  2903. */
  2904. function _freadint($f) {
  2905. //Read a 4-byte integer from file
  2906. $a=unpack('Ni',fread($f,4));
  2907. return $a['i'];
  2908. }
  2909. /**
  2910. * Format a text string
  2911. * @access protected
  2912. */
  2913. function _textstring($s) {
  2914. if($this->isunicode) {
  2915. //Convert string to UTF-16BE
  2916. $s = $this->UTF8ToUTF16BE($s, true);
  2917. }
  2918. return '('. $this->_escape($s).')';
  2919. }
  2920. /**
  2921. * Format a text string
  2922. * @access protected
  2923. */
  2924. function _escapetext($s) {
  2925. if($this->isunicode) {
  2926. //Convert string to UTF-16BE
  2927. $s = $this->UTF8ToUTF16BE($s, false);
  2928. }
  2929. return $this->_escape($s);
  2930. }
  2931. /**
  2932. * Add \ before \, ( and )
  2933. * @access protected
  2934. */
  2935. function _escape($s) {
  2936. // the chr(13) substitution fixes the Bugs item #1421290.
  2937. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  2938. }
  2939. /**
  2940. *
  2941. * @access protected
  2942. */
  2943. function _putstream($s) {
  2944. $this->_out('stream');
  2945. $this->_out($s);
  2946. $this->_out('endstream');
  2947. }
  2948. /**
  2949. * Add a line to the document
  2950. * @access protected
  2951. */
  2952. function _out($s) {
  2953. if($this->state==2) {
  2954. $this->pages[$this->page] .= $s."\n";
  2955. }
  2956. else {
  2957. $this->buffer .= $s."\n";
  2958. }
  2959. }
  2960. /**
  2961. * Adds unicode fonts.<br>
  2962. * Based on PDF Reference 1.3 (section 5)
  2963. * @access protected
  2964. * @author Nicola Asuni
  2965. * @since 1.52.0.TC005 (2005-01-05)
  2966. */
  2967. function _puttruetypeunicode($font) {
  2968. // Type0 Font
  2969. // A composite font—a font composed of other fonts, organized hierarchically
  2970. $this->_newobj();
  2971. $this->_out('<</Type /Font');
  2972. $this->_out('/Subtype /Type0');
  2973. $this->_out('/BaseFont /'.$font['name'].'');
  2974. $this->_out('/Encoding /Identity-H'); //The horizontal identity mapping for 2-byte CIDs; may be used with CIDFonts using any Registry, Ordering, and Supplement values.
  2975. $this->_out('/DescendantFonts ['.($this->n + 1).' 0 R]');
  2976. $this->_out('>>');
  2977. $this->_out('endobj');
  2978. // CIDFontType2
  2979. // A CIDFont whose glyph descriptions are based on TrueType font technology
  2980. $this->_newobj();
  2981. $this->_out('<</Type /Font');
  2982. $this->_out('/Subtype /CIDFontType2');
  2983. $this->_out('/BaseFont /'.$font['name'].'');
  2984. $this->_out('/CIDSystemInfo '.($this->n + 1).' 0 R');
  2985. $this->_out('/FontDescriptor '.($this->n + 2).' 0 R');
  2986. if (isset($font['desc']['MissingWidth'])){
  2987. $this->_out('/DW '.$font['desc']['MissingWidth'].''); // The default width for glyphs in the CIDFont MissingWidth
  2988. }
  2989. $w = "";
  2990. foreach ($font['cw'] as $cid => $width) {
  2991. $w .= ''.$cid.' ['.$width.'] '; // define a specific width for each individual CID
  2992. }
  2993. $this->_out('/W ['.$w.']'); // A description of the widths for the glyphs in the CIDFont
  2994. $this->_out('/CIDToGIDMap '.($this->n + 3).' 0 R');
  2995. $this->_out('>>');
  2996. $this->_out('endobj');
  2997. // CIDSystemInfo dictionary
  2998. // A dictionary containing entries that define the character collection of the CIDFont.
  2999. $this->_newobj();
  3000. $this->_out('<</Registry (Adobe)'); // A string identifying an issuer of character collections
  3001. $this->_out('/Ordering (UCS)'); // A string that uniquely names a character collection issued by a specific registry
  3002. $this->_out('/Supplement 0'); // The supplement number of the character collection.
  3003. $this->_out('>>');
  3004. $this->_out('endobj');
  3005. // Font descriptor
  3006. // A font descriptor describing the CIDFont’s default metrics other than its glyph widths
  3007. $this->_newobj();
  3008. $this->_out('<</Type /FontDescriptor');
  3009. $this->_out('/FontName /'.$font['name']);
  3010. foreach ($font['desc'] as $key => $value) {
  3011. $this->_out('/'.$key.' '.$value);
  3012. }
  3013. if ($font['file']) {
  3014. // A stream containing a TrueType font program
  3015. $this->_out('/FontFile2 '.$this->FontFiles[$font['file']]['n'].' 0 R');
  3016. }
  3017. $this->_out('>>');
  3018. $this->_out('endobj');
  3019. // Embed CIDToGIDMap
  3020. // A specification of the mapping from CIDs to glyph indices
  3021. $this->_newobj();
  3022. $ctgfile = $this->_getfontpath().$font['ctg'];
  3023. if(!file_exists($ctgfile)) {
  3024. $this->Error('Font file not found: '.$ctgfile);
  3025. }
  3026. $size = filesize($ctgfile);
  3027. $this->_out('<</Length '.$size.'');
  3028. if(substr($ctgfile, -2) == '.z') { // check file extension
  3029. /* Decompresses data encoded using the public-domain
  3030. zlib/deflate compression method, reproducing the
  3031. original text or binary data */
  3032. $this->_out('/Filter /FlateDecode');
  3033. }
  3034. $this->_out('>>');
  3035. $this->_putstream(file_get_contents($ctgfile));
  3036. $this->_out('endobj');
  3037. }
  3038. /**
  3039. * Converts UTF-8 strings to codepoints array.<br>
  3040. * Invalid byte sequences will be replaced with 0xFFFD (replacement character)<br>
  3041. * Based on: http://www.faqs.org/rfcs/rfc3629.html
  3042. * <pre>
  3043. * Char. number range | UTF-8 octet sequence
  3044. * (hexadecimal) | (binary)
  3045. * --------------------+-----------------------------------------------
  3046. * 0000 0000-0000 007F | 0xxxxxxx
  3047. * 0000 0080-0000 07FF | 110xxxxx 10xxxxxx
  3048. * 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
  3049. * 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  3050. * ---------------------------------------------------------------------
  3051. *
  3052. * ABFN notation:
  3053. * ---------------------------------------------------------------------
  3054. * UTF8-octets = *( UTF8-char )
  3055. * UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
  3056. * UTF8-1 = %x00-7F
  3057. * UTF8-2 = %xC2-DF UTF8-tail
  3058. *
  3059. * UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
  3060. * %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
  3061. * UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
  3062. * %xF4 %x80-8F 2( UTF8-tail )
  3063. * UTF8-tail = %x80-BF
  3064. * ---------------------------------------------------------------------
  3065. * </pre>
  3066. * @param string $str string to process.
  3067. * @return array containing codepoints (UTF-8 characters values)
  3068. * @access protected
  3069. * @author Nicola Asuni
  3070. * @since 1.53.0.TC005 (2005-01-05)
  3071. */
  3072. function UTF8StringToArray($str) {
  3073. if(!$this->isunicode) {
  3074. return $str; // string is not in unicode
  3075. }
  3076. $unicode = array(); // array containing unicode values
  3077. $bytes = array(); // array containing single character byte sequences
  3078. $numbytes = 1; // number of octetc needed to represent the UTF-8 character
  3079. $str .= ""; // force $str to be a string
  3080. $length = strlen($str);
  3081. for($i = 0; $i < $length; $i++) {
  3082. $char = ord($str{$i}); // get one string character at time
  3083. if(count($bytes) == 0) { // get starting octect
  3084. if ($char <= 0x7F) {
  3085. $unicode[] = $char; // use the character "as is" because is ASCII
  3086. $numbytes = 1;
  3087. } elseif (($char >> 0x05) == 0x06) { // 2 bytes character (0x06 = 110 BIN)
  3088. $bytes[] = ($char - 0xC0) << 0x06;
  3089. $numbytes = 2;
  3090. } elseif (($char >> 0x04) == 0x0E) { // 3 bytes character (0x0E = 1110 BIN)
  3091. $bytes[] = ($char - 0xE0) << 0x0C;
  3092. $numbytes = 3;
  3093. } elseif (($char >> 0x03) == 0x1E) { // 4 bytes character (0x1E = 11110 BIN)
  3094. $bytes[] = ($char - 0xF0) << 0x12;
  3095. $numbytes = 4;
  3096. } else {
  3097. // use replacement character for other invalid sequences
  3098. $unicode[] = 0xFFFD;
  3099. $bytes = array();
  3100. $numbytes = 1;
  3101. }
  3102. } elseif (($char >> 0x06) == 0x02) { // bytes 2, 3 and 4 must start with 0x02 = 10 BIN
  3103. $bytes[] = $char - 0x80;
  3104. if (count($bytes) == $numbytes) {
  3105. // compose UTF-8 bytes to a single unicode value
  3106. $char = $bytes[0];
  3107. for($j = 1; $j < $numbytes; $j++) {
  3108. $char += ($bytes[$j] << (($numbytes - $j - 1) * 0x06));
  3109. }
  3110. if ((($char >= 0xD800) AND ($char <= 0xDFFF)) OR ($char >= 0x10FFFF)) {
  3111. /* The definition of UTF-8 prohibits encoding character numbers between
  3112. U+D800 and U+DFFF, which are reserved for use with the UTF-16
  3113. encoding form (as surrogate pairs) and do not directly represent
  3114. characters. */
  3115. $unicode[] = 0xFFFD; // use replacement character
  3116. }
  3117. else {
  3118. $unicode[] = $char; // add char to array
  3119. }
  3120. // reset data for next char
  3121. $bytes = array();
  3122. $numbytes = 1;
  3123. }
  3124. } else {
  3125. // use replacement character for other invalid sequences
  3126. $unicode[] = 0xFFFD;
  3127. $bytes = array();
  3128. $numbytes = 1;
  3129. }
  3130. }
  3131. return $unicode;
  3132. }
  3133. /**
  3134. * Converts UTF-8 strings to UTF16-BE.<br>
  3135. * Based on: http://www.faqs.org/rfcs/rfc2781.html
  3136. * <pre>
  3137. * Encoding UTF-16:
  3138. *
  3139. * Encoding of a single character from an ISO 10646 character value to
  3140. * UTF-16 proceeds as follows. Let U be the character number, no greater
  3141. * than 0x10FFFF.
  3142. *
  3143. * 1) If U < 0x10000, encode U as a 16-bit unsigned integer and
  3144. * terminate.
  3145. *
  3146. * 2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
  3147. * U' must be less than or equal to 0xFFFFF. That is, U' can be
  3148. * represented in 20 bits.
  3149. *
  3150. * 3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
  3151. * 0xDC00, respectively. These integers each have 10 bits free to
  3152. * encode the character value, for a total of 20 bits.
  3153. *
  3154. * 4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
  3155. * bits of W1 and the 10 low-order bits of U' to the 10 low-order
  3156. * bits of W2. Terminate.
  3157. *
  3158. * Graphically, steps 2 through 4 look like:
  3159. * U' = yyyyyyyyyyxxxxxxxxxx
  3160. * W1 = 110110yyyyyyyyyy
  3161. * W2 = 110111xxxxxxxxxx
  3162. * </pre>
  3163. * @param string $str string to process.
  3164. * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
  3165. * @return string
  3166. * @access protected
  3167. * @author Nicola Asuni
  3168. * @since 1.53.0.TC005 (2005-01-05)
  3169. * @uses UTF8StringToArray
  3170. */
  3171. function UTF8ToUTF16BE($str, $setbom=true) {
  3172. if(!$this->isunicode) {
  3173. return $str; // string is not in unicode
  3174. }
  3175. $outstr = ""; // string to be returned
  3176. $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
  3177. $numitems = count($unicode);
  3178. if ($setbom) {
  3179. $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
  3180. }
  3181. foreach($unicode as $char) {
  3182. if($char == 0xFFFD) {
  3183. $outstr .= "\xFF\xFD"; // replacement character
  3184. } elseif ($char < 0x10000) {
  3185. $outstr .= chr($char >> 0x08);
  3186. $outstr .= chr($char & 0xFF);
  3187. } else {
  3188. $char -= 0x10000;
  3189. $w1 = 0xD800 | ($char >> 0x10);
  3190. $w2 = 0xDC00 | ($char & 0x3FF);
  3191. $outstr .= chr($w1 >> 0x08);
  3192. $outstr .= chr($w1 & 0xFF);
  3193. $outstr .= chr($w2 >> 0x08);
  3194. $outstr .= chr($w2 & 0xFF);
  3195. }
  3196. }
  3197. return $outstr;
  3198. }
  3199. // ====================================================
  3200. /**
  3201. * Set header font.
  3202. * @param array $font font
  3203. * @since 1.1
  3204. */
  3205. function setHeaderFont($font) {
  3206. $this->header_font = $font;
  3207. }
  3208. /**
  3209. * Set footer font.
  3210. * @param array $font font
  3211. * @since 1.1
  3212. */
  3213. function setFooterFont($font) {
  3214. $this->footer_font = $font;
  3215. }
  3216. /**
  3217. * Set language array.
  3218. * @param array $language
  3219. * @since 1.1
  3220. */
  3221. function setLanguageArray($language) {
  3222. $this->l = $language;
  3223. }
  3224. /**
  3225. * Set document barcode.
  3226. * @param string $bc barcode
  3227. */
  3228. function setBarcode($bc="") {
  3229. $this->barcode = $bc;
  3230. }
  3231. /**
  3232. * Print Barcode.
  3233. * @param int $x x position in user units
  3234. * @param int $y y position in user units
  3235. * @param int $w width in user units
  3236. * @param int $h height position in user units
  3237. * @param string $type type of barcode (I25, C128A, C128B, C128C, C39)
  3238. * @param string $style barcode style
  3239. * @param string $font font for text
  3240. * @param int $xres x resolution
  3241. * @param string $code code to print
  3242. */
  3243. function writeBarcode($x, $y, $w, $h, $type, $style, $font, $xres, $code) {
  3244. require_once(dirname(__FILE__)."/barcode/barcode.php");
  3245. require_once(dirname(__FILE__)."/barcode/i25object.php");
  3246. require_once(dirname(__FILE__)."/barcode/c39object.php");
  3247. require_once(dirname(__FILE__)."/barcode/c128aobject.php");
  3248. require_once(dirname(__FILE__)."/barcode/c128bobject.php");
  3249. require_once(dirname(__FILE__)."/barcode/c128cobject.php");
  3250. if (empty($code)) {
  3251. return;
  3252. }
  3253. if (empty($style)) {
  3254. $style = BCS_ALIGN_LEFT;
  3255. $style |= BCS_IMAGE_PNG;
  3256. $style |= BCS_TRANSPARENT;
  3257. //$style |= BCS_BORDER;
  3258. //$style |= BCS_DRAW_TEXT;
  3259. //$style |= BCS_STRETCH_TEXT;
  3260. //$style |= BCS_REVERSE_COLOR;
  3261. }
  3262. if (empty($font)) {$font = BCD_DEFAULT_FONT;}
  3263. if (empty($xres)) {$xres = BCD_DEFAULT_XRES;}
  3264. $scale_factor = 1.5 * $xres * $this->k;
  3265. $bc_w = round($w * $scale_factor); //width in points
  3266. $bc_h = round($h * $scale_factor); //height in points
  3267. switch (strtoupper($type)) {
  3268. case "I25": {
  3269. $obj = new I25Object($bc_w, $bc_h, $style, $code);
  3270. break;
  3271. }
  3272. case "C128A": {
  3273. $obj = new C128AObject($bc_w, $bc_h, $style, $code);
  3274. break;
  3275. }
  3276. default:
  3277. case "C128B": {
  3278. $obj = new C128BObject($bc_w, $bc_h, $style, $code);
  3279. break;
  3280. }
  3281. case "C128C": {
  3282. $obj = new C128CObject($bc_w, $bc_h, $style, $code);
  3283. break;
  3284. }
  3285. case "C39": {
  3286. $obj = new C39Object($bc_w, $bc_h, $style, $code);
  3287. break;
  3288. }
  3289. }
  3290. $obj->SetFont($font);
  3291. $obj->DrawObject($xres);
  3292. //use a temporary file....
  3293. $tmpName = tempnam(K_PATH_CACHE,'img');
  3294. imagepng($obj->getImage(), $tmpName);
  3295. $this->Image($tmpName, $x, $y, $w, $h, 'png');
  3296. $obj->DestroyObject();
  3297. unset($obj);
  3298. unlink($tmpName);
  3299. }
  3300. /**
  3301. * Returns the PDF data.
  3302. */
  3303. function getPDFData() {
  3304. if($this->state < 3) {
  3305. $this->Close();
  3306. }
  3307. return $this->buffer;
  3308. }
  3309. // --- HTML PARSER FUNCTIONS ---
  3310. /**
  3311. * Allows to preserve some HTML formatting.<br />
  3312. * Supports: 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
  3313. * @param string $html text to display
  3314. * @param boolean $ln if true add a new line after text (default = true)
  3315. * @param int $fill Indicates if the background must be painted (1) or transparent (0). Default value: 0.
  3316. */
  3317. function writeHTML($html, $ln=true, $fill=0) {
  3318. // store some variables
  3319. $html=strip_tags($html,"<h1><h2><h3><h4><h5><h6><b><u><i><a><img><p><br><br/><strong><em><font><blockquote><li><ul><ol><hr><td><th><tr><table><sup><sub><small>"); //remove all unsupported tags
  3320. //replace carriage returns, newlines and tabs
  3321. $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
  3322. $html = strtr($html, $repTable);
  3323. $pattern = '/(<[^>]+>)/Uu';
  3324. $a = preg_split($pattern, $html, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); //explodes the string
  3325. if (empty($this->lasth)) {
  3326. //set row height
  3327. $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  3328. }
  3329. foreach($a as $key=>$element) {
  3330. if (!preg_match($pattern, $element)) {
  3331. //Text
  3332. if($this->HREF) {
  3333. $this->addHtmlLink($this->HREF, $element, $fill);
  3334. }
  3335. elseif($this->tdbegin) {
  3336. if((strlen(trim($element)) > 0) AND ($element != "&nbsp;")) {
  3337. $this->Cell($this->tdwidth, $this->tdheight, $this->unhtmlentities($element), $this->tableborder, '', $this->tdalign, $this->tdbgcolor);
  3338. }
  3339. elseif($element == "&nbsp;") {
  3340. $this->Cell($this->tdwidth, $this->tdheight, '', $this->tableborder, '', $this->tdalign, $this->tdbgcolor);
  3341. }
  3342. }
  3343. else {
  3344. $this->Write($this->lasth, stripslashes($this->unhtmlentities($element)), '', $fill);
  3345. }
  3346. }
  3347. else {
  3348. $element = substr($element, 1, -1);
  3349. //Tag
  3350. if($element{0}=='/') {
  3351. $this->closedHTMLTagHandler(strtolower(substr($element, 1)));
  3352. }
  3353. else {
  3354. //Extract attributes
  3355. // get tag name
  3356. preg_match('/([a-zA-Z0-9]*)/', $element, $tag);
  3357. $tag = strtolower($tag[0]);
  3358. // get attributes
  3359. preg_match_all('/([^=\s]*)=["\']?([^"\']*)["\']?/', $element, $attr_array, PREG_PATTERN_ORDER);
  3360. $attr = array(); // reset attribute array
  3361. while(list($id,$name)=each($attr_array[1])) {
  3362. $attr[strtolower($name)] = $attr_array[2][$id];
  3363. }
  3364. $this->openHTMLTagHandler($tag, $attr, $fill);
  3365. }
  3366. }
  3367. }
  3368. if ($ln) {
  3369. $this->Ln($this->lasth);
  3370. }
  3371. }
  3372. /**
  3373. * Prints a cell (rectangular area) with optional borders, background color and html text string. The upper-left corner of the cell corresponds to the current position. After the call, the current position moves to the right or to the next line.<br />
  3374. * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.
  3375. * @param float $w Cell width. If 0, the cell extends up to the right margin.
  3376. * @param float $h Cell minimum height. The cell extends automatically if needed.
  3377. * @param float $x upper-left corner X coordinate
  3378. * @param float $y upper-left corner Y coordinate
  3379. * @param string $html html text to print. Default value: empty string.
  3380. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  3381. * @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
  3382. Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
  3383. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3384. * @see Cell()
  3385. */
  3386. function writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0) {
  3387. if (empty($this->lasth)) {
  3388. //set row height
  3389. $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  3390. }
  3391. if (empty($x)) {
  3392. $x = $this->GetX();
  3393. }
  3394. if (empty($y)) {
  3395. $y = $this->GetY();
  3396. }
  3397. // get current page number
  3398. $pagenum = $this->page;
  3399. $this->SetX($x);
  3400. $this->SetY($y);
  3401. if(empty($w)) {
  3402. $w = $this->fw - $x - $this->rMargin;
  3403. }
  3404. // store original margin values
  3405. $lMargin = $this->lMargin;
  3406. $rMargin = $this->rMargin;
  3407. // set new margin values
  3408. $this->SetLeftMargin($x);
  3409. $this->SetRightMargin($this->fw - $x - $w);
  3410. // calculate remaining vertical space on page
  3411. $restspace = $this->getPageHeight() - $this->GetY() - $this->getBreakMargin();
  3412. $this->writeHTML($html, true, $fill); // write html text
  3413. $currentY = $this->GetY();
  3414. // check if a new page has been created
  3415. if ($this->page > $pagenum) {
  3416. // design a cell around the text on first page
  3417. $currentpage = $this->page;
  3418. $this->page = $pagenum;
  3419. $this->SetY($this->getPageHeight() - $restspace - $this->getBreakMargin());
  3420. $h = $restspace - 1;
  3421. $this->Cell($w, $h, "", $border, $ln, 'L', 0);
  3422. // design a cell around the text on last page
  3423. $this->page = $currentpage;
  3424. $h = $currentY - $this->tMargin;
  3425. $this->SetY($this->tMargin); // put cursor at the beginning of text
  3426. $this->Cell($w, $h, "", $border, $ln, 'L', 0);
  3427. } else {
  3428. $h = max($h, ($currentY - $y));
  3429. $this->SetY($y); // put cursor at the beginning of text
  3430. // design a cell around the text
  3431. $this->Cell($w, $h, "", $border, $ln, 'L', 0);
  3432. }
  3433. // restore original margin values
  3434. $this->SetLeftMargin($lMargin);
  3435. $this->SetRightMargin($rMargin);
  3436. if ($ln) {
  3437. $this->Ln(0);
  3438. }
  3439. }
  3440. /**
  3441. * Process opening tags.
  3442. * @param string $tag tag name (in uppercase)
  3443. * @param string $attr tag attribute (in uppercase)
  3444. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3445. * @access private
  3446. */
  3447. function openHTMLTagHandler($tag, $attr, $fill=0) {
  3448. //Opening tag
  3449. switch($tag) {
  3450. case 'table': {
  3451. if ((isset($attr['border'])) AND ($attr['border'] != '')) {
  3452. $this->tableborder = $attr['border'];
  3453. }
  3454. else {
  3455. $this->tableborder = 0;
  3456. }
  3457. break;
  3458. }
  3459. case 'tr': {
  3460. break;
  3461. }
  3462. case 'td':
  3463. case 'th': {
  3464. if ((isset($attr['width'])) AND ($attr['width'] != '')) {
  3465. $this->tdwidth = ($attr['width']/4);
  3466. }
  3467. else {
  3468. $this->tdwidth = (($this->w - $this->lMargin - $this->rMargin) / $this->default_table_columns);
  3469. }
  3470. if ((isset($attr['height'])) AND ($attr['height'] != '')) {
  3471. $this->tdheight=($attr['height'] / $this->k);
  3472. }
  3473. else {
  3474. $this->tdheight = $this->lasth;
  3475. }
  3476. if ((isset($attr['align'])) AND ($attr['align'] != '')) {
  3477. switch ($attr['align']) {
  3478. case 'center': {
  3479. $this->tdalign = "C";
  3480. break;
  3481. }
  3482. case 'right': {
  3483. $this->tdalign = "R";
  3484. break;
  3485. }
  3486. default:
  3487. case 'left': {
  3488. $this->tdalign = "L";
  3489. break;
  3490. }
  3491. }
  3492. }
  3493. if ((isset($attr['bgcolor'])) AND ($attr['bgcolor'] != '')) {
  3494. $coul = $this->convertColorHexToDec($attr['bgcolor']);
  3495. $this->SetFillColor($coul['R'], $coul['G'], $coul['B']);
  3496. $this->tdbgcolor=true;
  3497. }
  3498. $this->tdbegin=true;
  3499. break;
  3500. }
  3501. case 'hr': {
  3502. $this->Ln();
  3503. if ((isset($attr['width'])) AND ($attr['width'] != '')) {
  3504. $hrWidth = $attr['width'];
  3505. }
  3506. else {
  3507. $hrWidth = $this->w - $this->lMargin - $this->rMargin;
  3508. }
  3509. $x = $this->GetX();
  3510. $y = $this->GetY();
  3511. $this->SetLineWidth(0.2);
  3512. $this->Line($x, $y, $x + $hrWidth, $y);
  3513. $this->SetLineWidth(0.2);
  3514. $this->Ln();
  3515. break;
  3516. }
  3517. case 'strong': {
  3518. $this->setStyle('b', true);
  3519. break;
  3520. }
  3521. case 'em': {
  3522. $this->setStyle('i', true);
  3523. break;
  3524. }
  3525. case 'b':
  3526. case 'i':
  3527. case 'u': {
  3528. $this->setStyle($tag, true);
  3529. break;
  3530. }
  3531. case 'a': {
  3532. $this->HREF = $attr['href'];
  3533. break;
  3534. }
  3535. case 'img': {
  3536. if(isset($attr['src'])) {
  3537. // replace relative path with real server path
  3538. $attr['src'] = str_replace(K_PATH_URL_CACHE, K_PATH_CACHE, $attr['src']);
  3539. if(!isset($attr['width'])) {
  3540. $attr['width'] = 0;
  3541. }
  3542. if(!isset($attr['height'])) {
  3543. $attr['height'] = 0;
  3544. }
  3545. $this->Image($attr['src'], $this->GetX(),$this->GetY(), $this->pixelsToMillimeters($attr['width']), $this->pixelsToMillimeters($attr['height']));
  3546. //$this->SetX($this->img_rb_x);
  3547. $this->SetY($this->img_rb_y);
  3548. }
  3549. break;
  3550. }
  3551. case 'ul': {
  3552. $this->listordered = false;
  3553. $this->listcount = 0;
  3554. break;
  3555. }
  3556. case 'ol': {
  3557. $this->listordered = true;
  3558. $this->listcount = 0;
  3559. break;
  3560. }
  3561. case 'li': {
  3562. $this->Ln();
  3563. if ($this->listordered) {
  3564. $this->lispacer = " ".(++$this->listcount).". ";
  3565. }
  3566. else {
  3567. //unordered list simbol
  3568. $this->lispacer = " - ";
  3569. }
  3570. $this->Write($this->lasth, $this->lispacer, '', $fill);
  3571. break;
  3572. }
  3573. case 'blockquote':
  3574. case 'br': {
  3575. $this->Ln();
  3576. if(strlen($this->lispacer) > 0) {
  3577. $this->x += $this->GetStringWidth($this->lispacer);
  3578. }
  3579. break;
  3580. }
  3581. case 'p': {
  3582. $this->Ln();
  3583. $this->Ln();
  3584. break;
  3585. }
  3586. case 'sup': {
  3587. $currentFontSize = $this->FontSize;
  3588. $this->tempfontsize = $this->FontSizePt;
  3589. $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
  3590. $this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
  3591. break;
  3592. }
  3593. case 'sub': {
  3594. $currentFontSize = $this->FontSize;
  3595. $this->tempfontsize = $this->FontSizePt;
  3596. $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
  3597. $this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
  3598. break;
  3599. }
  3600. case 'small': {
  3601. $currentFontSize = $this->FontSize;
  3602. $this->tempfontsize = $this->FontSizePt;
  3603. $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
  3604. $this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)/3));
  3605. break;
  3606. }
  3607. case 'font': {
  3608. if (isset($attr['color']) AND $attr['color']!='') {
  3609. $coul = $this->convertColorHexToDec($attr['color']);
  3610. $this->SetTextColor($coul['R'],$coul['G'],$coul['B']);
  3611. $this->issetcolor=true;
  3612. }
  3613. if (isset($attr['face']) and in_array(strtolower($attr['face']), $this->fontlist)) {
  3614. $this->SetFont(strtolower($attr['FACE']));
  3615. $this->issetfont=true;
  3616. }
  3617. if (isset($attr['size'])) {
  3618. $headsize = intval($attr['size']);
  3619. } else {
  3620. $headsize = 0;
  3621. }
  3622. $currentFontSize = $this->FontSize;
  3623. $this->tempfontsize = $this->FontSizePt;
  3624. $this->SetFontSize($this->FontSizePt + $headsize);
  3625. $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  3626. break;
  3627. }
  3628. case 'h1':
  3629. case 'h2':
  3630. case 'h3':
  3631. case 'h4':
  3632. case 'h5':
  3633. case 'h6': {
  3634. $headsize = (4 - substr($tag, 1)) * 2;
  3635. $currentFontSize = $this->FontSize;
  3636. $this->tempfontsize = $this->FontSizePt;
  3637. $this->SetFontSize($this->FontSizePt + $headsize);
  3638. $this->setStyle('b', true);
  3639. $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  3640. break;
  3641. }
  3642. }
  3643. }
  3644. /**
  3645. * Process closing tags.
  3646. * @param string $tag tag name (in uppercase)
  3647. * @access private
  3648. */
  3649. function closedHTMLTagHandler($tag) {
  3650. //Closing tag
  3651. switch($tag) {
  3652. case 'td':
  3653. case 'th': {
  3654. $this->tdbegin = false;
  3655. $this->tdwidth = 0;
  3656. $this->tdheight = 0;
  3657. $this->tdalign = "L";
  3658. $this->tdbgcolor = false;
  3659. $this->SetFillColor($this->prevFillColor[0], $this->prevFillColor[1], $this->prevFillColor[2]);
  3660. break;
  3661. }
  3662. case 'tr': {
  3663. $this->Ln();
  3664. break;
  3665. }
  3666. case 'table': {
  3667. $this->tableborder=0;
  3668. break;
  3669. }
  3670. case 'strong': {
  3671. $this->setStyle('b', false);
  3672. break;
  3673. }
  3674. case 'em': {
  3675. $this->setStyle('i', false);
  3676. break;
  3677. }
  3678. case 'b':
  3679. case 'i':
  3680. case 'u': {
  3681. $this->setStyle($tag, false);
  3682. break;
  3683. }
  3684. case 'a': {
  3685. $this->HREF = '';
  3686. break;
  3687. }
  3688. case 'sup': {
  3689. $currentFontSize = $this->FontSize;
  3690. $this->SetFontSize($this->tempfontsize);
  3691. $this->tempfontsize = $this->FontSizePt;
  3692. $this->SetXY($this->GetX(), $this->GetY() - (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
  3693. break;
  3694. }
  3695. case 'sub': {
  3696. $currentFontSize = $this->FontSize;
  3697. $this->SetFontSize($this->tempfontsize);
  3698. $this->tempfontsize = $this->FontSizePt;
  3699. $this->SetXY($this->GetX(), $this->GetY() + (($currentFontSize - $this->FontSize)*(K_SMALL_RATIO)));
  3700. break;
  3701. }
  3702. case 'small': {
  3703. $currentFontSize = $this->FontSize;
  3704. $this->SetFontSize($this->tempfontsize);
  3705. $this->tempfontsize = $this->FontSizePt;
  3706. $this->SetXY($this->GetX(), $this->GetY() - (($this->FontSize - $currentFontSize)/3));
  3707. break;
  3708. }
  3709. case 'font': {
  3710. if ($this->issetcolor == true) {
  3711. $this->SetTextColor($this->prevTextColor[0], $this->prevTextColor[1], $this->prevTextColor[2]);
  3712. }
  3713. if ($this->issetfont) {
  3714. $this->FontFamily = $this->prevFontFamily;
  3715. $this->FontStyle = $this->prevFontStyle;
  3716. $this->SetFont($this->FontFamily);
  3717. $this->issetfont = false;
  3718. }
  3719. $currentFontSize = $this->FontSize;
  3720. $this->SetFontSize($this->tempfontsize);
  3721. $this->tempfontsize = $this->FontSizePt;
  3722. //$this->TextColor = $this->prevTextColor;
  3723. $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  3724. break;
  3725. }
  3726. case 'ul': {
  3727. $this->Ln();
  3728. break;
  3729. }
  3730. case 'ol': {
  3731. $this->Ln();
  3732. break;
  3733. }
  3734. case 'li': {
  3735. $this->lispacer = "";
  3736. break;
  3737. }
  3738. case 'h1':
  3739. case 'h2':
  3740. case 'h3':
  3741. case 'h4':
  3742. case 'h5':
  3743. case 'h6': {
  3744. $currentFontSize = $this->FontSize;
  3745. $this->SetFontSize($this->tempfontsize);
  3746. $this->tempfontsize = $this->FontSizePt;
  3747. $this->setStyle('b', false);
  3748. $this->Ln();
  3749. $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
  3750. break;
  3751. }
  3752. default : {
  3753. break;
  3754. }
  3755. }
  3756. }
  3757. /**
  3758. * Sets font style.
  3759. * @param string $tag tag name (in lowercase)
  3760. * @param boolean $enable
  3761. * @access private
  3762. */
  3763. function setStyle($tag, $enable) {
  3764. //Modify style and select corresponding font
  3765. $this->$tag += ($enable ? 1 : -1);
  3766. $style='';
  3767. foreach(array('b', 'i', 'u') as $s) {
  3768. if($this->$s > 0) {
  3769. $style .= $s;
  3770. }
  3771. }
  3772. $this->SetFont('', $style);
  3773. }
  3774. /**
  3775. * Output anchor link.
  3776. * @param string $url link URL
  3777. * @param string $name link name
  3778. * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  3779. * @access public
  3780. */
  3781. function addHtmlLink($url, $name, $fill=0) {
  3782. //Put a hyperlink
  3783. $this->SetTextColor(0, 0, 255);
  3784. $this->setStyle('u', true);
  3785. $this->Write($this->lasth, $name, $url, $fill);
  3786. $this->setStyle('u', false);
  3787. $this->SetTextColor(0);
  3788. }
  3789. /**
  3790. * Returns an associative array (keys: R,G,B) from
  3791. * a hex html code (e.g. #3FE5AA).
  3792. * @param string $color hexadecimal html color [#rrggbb]
  3793. * @return array
  3794. * @access private
  3795. */
  3796. function convertColorHexToDec($color = "#000000"){
  3797. $tbl_color = array();
  3798. $tbl_color['R'] = hexdec(substr($color, 1, 2));
  3799. $tbl_color['G'] = hexdec(substr($color, 3, 2));
  3800. $tbl_color['B'] = hexdec(substr($color, 5, 2));
  3801. return $tbl_color;
  3802. }
  3803. /**
  3804. * Converts pixels to millimeters in 72 dpi.
  3805. * @param int $px pixels
  3806. * @return float millimeters
  3807. * @access private
  3808. */
  3809. function pixelsToMillimeters($px){
  3810. return $px * 25.4 / 72;
  3811. }
  3812. /**
  3813. * Reverse function for htmlentities.
  3814. * Convert entities in UTF-8.
  3815. *
  3816. * @param $text_to_convert Text to convert.
  3817. * @return string converted
  3818. */
  3819. function unhtmlentities($text_to_convert) {
  3820. require_once(dirname(__FILE__).'/html_entity_decode_php4.php');
  3821. return html_entity_decode_php4($text_to_convert);
  3822. }
  3823. } // END OF CLASS
  3824. //Handle special IE contype request
  3825. if(isset($_SERVER['HTTP_USER_AGENT']) AND ($_SERVER['HTTP_USER_AGENT']=='contype')) {
  3826. header('Content-Type: application/pdf');
  3827. exit;
  3828. }
  3829. }
  3830. //============================================================+
  3831. // END OF FILE
  3832. //============================================================+
  3833. ?>