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

/phpmyadmin/libraries/tcpdf/tcpdf.php

https://bitbucket.org/astawiarski/openemr
PHP | 4138 lines | 2321 code | 305 blank | 1512 comment | 373 complexity | 0df8deb95a8500375d794023287dd673 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, MPL-2.0

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

  1. <?php
  2. //============================================================+
  3. // File name : tcpdf.php
  4. // Begin : 2002-08-03
  5. // Last Update : 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 documeā€¦

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