You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.3 KiB

  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. */
  25. // Include the main TCPDF library (search for installation path).
  26. require_once('tcpdf_include.php');
  27. /**
  28. * Extend TCPDF to work with multiple columns
  29. */
  30. class MC_TCPDF extends TCPDF {
  31. /**
  32. * Print chapter
  33. * @param $num (int) chapter number
  34. * @param $title (string) chapter title
  35. * @param $file (string) name of the file containing the chapter body
  36. * @param $mode (boolean) if true the chapter body is in HTML, otherwise in simple text.
  37. * @public
  38. */
  39. public function PrintChapter($num, $title, $file, $mode=false) {
  40. // add a new page
  41. $this->AddPage();
  42. // disable existing columns
  43. $this->resetColumns();
  44. // print chapter title
  45. $this->ChapterTitle($num, $title);
  46. // set columns
  47. $this->setEqualColumns(3, 57);
  48. // print chapter body
  49. $this->ChapterBody($file, $mode);
  50. }
  51. /**
  52. * Set chapter title
  53. * @param $num (int) chapter number
  54. * @param $title (string) chapter title
  55. * @public
  56. */
  57. public function ChapterTitle($num, $title) {
  58. $this->SetFont('helvetica', '', 14);
  59. $this->SetFillColor(200, 220, 255);
  60. $this->Cell(180, 6, 'Chapter '.$num.' : '.$title, 0, 1, '', 1);
  61. $this->Ln(4);
  62. }
  63. /**
  64. * Print chapter body
  65. * @param $file (string) name of the file containing the chapter body
  66. * @param $mode (boolean) if true the chapter body is in HTML, otherwise in simple text.
  67. * @public
  68. */
  69. public function ChapterBody($file, $mode=false) {
  70. $this->selectColumn();
  71. // get esternal file content
  72. $content = file_get_contents($file, false);
  73. // set font
  74. $this->SetFont('times', '', 9);
  75. $this->SetTextColor(50, 50, 50);
  76. // print content
  77. if ($mode) {
  78. // ------ HTML MODE ------
  79. $this->writeHTML($content, true, false, true, false, 'J');
  80. } else {
  81. // ------ TEXT MODE ------
  82. $this->Write(0, $content, '', 0, 'J', true, 0, false, true, 0);
  83. }
  84. $this->Ln();
  85. }
  86. } // end of extended class
  87. // ---------------------------------------------------------
  88. // EXAMPLE
  89. // ---------------------------------------------------------
  90. // create new PDF document
  91. $pdf = new MC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  92. // set document information
  93. $pdf->SetCreator(PDF_CREATOR);
  94. $pdf->SetAuthor('Nicola Asuni');
  95. $pdf->SetTitle('TCPDF Example 010');
  96. $pdf->SetSubject('TCPDF Tutorial');
  97. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  98. // set default header data
  99. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 010', PDF_HEADER_STRING);
  100. // set header and footer fonts
  101. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  102. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  103. // set default monospaced font
  104. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  105. // set margins
  106. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  107. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  108. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  109. // set auto page breaks
  110. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  111. // set image scale factor
  112. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  113. // set some language-dependent strings (optional)
  114. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  115. require_once(dirname(__FILE__).'/lang/eng.php');
  116. $pdf->setLanguageArray($l);
  117. }
  118. // ---------------------------------------------------------
  119. // print TEXT
  120. $pdf->PrintChapter(1, 'LOREM IPSUM [TEXT]', 'data/chapter_demo_1.txt', false);
  121. // print HTML
  122. $pdf->PrintChapter(2, 'LOREM IPSUM [HTML]', 'data/chapter_demo_2.txt', true);
  123. // ---------------------------------------------------------
  124. //Close and output PDF document
  125. $pdf->Output('example_010.pdf', 'I');
  126. //============================================================+
  127. // END OF FILE
  128. //============================================================+