example_010.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. //============================================================+
  3. // File name : example_010.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 010 for TCPDF class
  8. // Text on multiple columns
  9. //
  10. // Author: Nicola Asuni
  11. //
  12. // (c) Copyright:
  13. // Nicola Asuni
  14. // Tecnick.com LTD
  15. // www.tecnick.com
  16. // info@tecnick.com
  17. //============================================================+
  18. /**
  19. * Creates an example PDF TEST document using TCPDF
  20. * @package com.tecnick.tcpdf
  21. * @abstract TCPDF - Example: Text on multiple columns
  22. * @author Nicola Asuni
  23. * @since 2008-03-04
  24. * @group column
  25. * @group pdf
  26. */
  27. // Include the main TCPDF library (search for installation path).
  28. require_once('tcpdf_include.php');
  29. /**
  30. * Extend TCPDF to work with multiple columns
  31. */
  32. class MC_TCPDF extends TCPDF {
  33. /**
  34. * Print chapter
  35. * @param int $num chapter number
  36. * @param string $title chapter title
  37. * @param string $file name of the file containing the chapter body
  38. * @param boolean $mode if true the chapter body is in HTML, otherwise in simple text.
  39. * @public
  40. */
  41. public function PrintChapter($num, $title, $file, $mode=false) {
  42. // add a new page
  43. $this->AddPage();
  44. // disable existing columns
  45. $this->resetColumns();
  46. // print chapter title
  47. $this->ChapterTitle($num, $title);
  48. // set columns
  49. $this->setEqualColumns(3, 57);
  50. // print chapter body
  51. $this->ChapterBody($file, $mode);
  52. }
  53. /**
  54. * Set chapter title
  55. * @param int $num chapter number
  56. * @param string $title chapter title
  57. * @public
  58. */
  59. public function ChapterTitle($num, $title) {
  60. $this->setFont('helvetica', '', 14);
  61. $this->setFillColor(200, 220, 255);
  62. $this->Cell(180, 6, 'Chapter '.$num.' : '.$title, 0, 1, '', 1);
  63. $this->Ln(4);
  64. }
  65. /**
  66. * Print chapter body
  67. * @param string $file name of the file containing the chapter body
  68. * @param boolean $mode if true the chapter body is in HTML, otherwise in simple text.
  69. * @public
  70. */
  71. public function ChapterBody($file, $mode=false) {
  72. $this->selectColumn();
  73. // get esternal file content
  74. $content = file_get_contents($file, false);
  75. // set font
  76. $this->setFont('times', '', 9);
  77. $this->setTextColor(50, 50, 50);
  78. // print content
  79. if ($mode) {
  80. // ------ HTML MODE ------
  81. $this->writeHTML($content, true, false, true, false, 'J');
  82. } else {
  83. // ------ TEXT MODE ------
  84. $this->Write(0, $content, '', 0, 'J', true, 0, false, true, 0);
  85. }
  86. $this->Ln();
  87. }
  88. } // end of extended class
  89. // ---------------------------------------------------------
  90. // EXAMPLE
  91. // ---------------------------------------------------------
  92. // create new PDF document
  93. $pdf = new MC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  94. // set document information
  95. $pdf->setCreator(PDF_CREATOR);
  96. $pdf->setAuthor('Nicola Asuni');
  97. $pdf->setTitle('TCPDF Example 010');
  98. $pdf->setSubject('TCPDF Tutorial');
  99. $pdf->setKeywords('TCPDF, PDF, example, test, guide');
  100. // set default header data
  101. $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 010', PDF_HEADER_STRING);
  102. // set header and footer fonts
  103. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  104. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  105. // set default monospaced font
  106. $pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  107. // set margins
  108. $pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  109. $pdf->setHeaderMargin(PDF_MARGIN_HEADER);
  110. $pdf->setFooterMargin(PDF_MARGIN_FOOTER);
  111. // set auto page breaks
  112. $pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  113. // set image scale factor
  114. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  115. // set some language-dependent strings (optional)
  116. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  117. require_once(dirname(__FILE__).'/lang/eng.php');
  118. $pdf->setLanguageArray($l);
  119. }
  120. // ---------------------------------------------------------
  121. // print TEXT
  122. $pdf->PrintChapter(1, 'LOREM IPSUM [TEXT]', 'data/chapter_demo_1.txt', false);
  123. // print HTML
  124. $pdf->PrintChapter(2, 'LOREM IPSUM [HTML]', 'data/chapter_demo_2.txt', true);
  125. // ---------------------------------------------------------
  126. //Close and output PDF document
  127. $pdf->Output('example_010.pdf', 'I');
  128. //============================================================+
  129. // END OF FILE
  130. //============================================================+