example_010.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. //============================================================+
  3. // File name : example_010.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2011-04-26
  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 s.r.l.
  15. // Via Della Pace, 11
  16. // 09044 Quartucciu (CA)
  17. // ITALY
  18. // www.tecnick.com
  19. // info@tecnick.com
  20. //============================================================+
  21. /**
  22. * Creates an example PDF TEST document using TCPDF
  23. * @package com.tecnick.tcpdf
  24. * @abstract TCPDF - Example: Text on multiple columns
  25. * @author Nicola Asuni
  26. * @since 2008-03-04
  27. */
  28. require_once('../config/lang/eng.php');
  29. require_once('../tcpdf.php');
  30. /**
  31. * Extend TCPDF to work with multiple columns
  32. */
  33. class MC_TCPDF extends TCPDF {
  34. /**
  35. * Print chapter
  36. * @param $num (int) chapter number
  37. * @param $title (string) chapter title
  38. * @param $file (string) name of the file containing the chapter body
  39. * @param $mode (boolean) if true the chapter body is in HTML, otherwise in simple text.
  40. * @public
  41. */
  42. public function PrintChapter($num, $title, $file, $mode=false) {
  43. // add a new page
  44. $this->AddPage();
  45. // disable existing columns
  46. $this->resetColumns();
  47. // print chapter title
  48. $this->ChapterTitle($num, $title);
  49. // set columns
  50. $this->setEqualColumns(3, 57);
  51. // print chapter body
  52. $this->ChapterBody($file, $mode);
  53. }
  54. /**
  55. * Set chapter title
  56. * @param $num (int) chapter number
  57. * @param $title (string) chapter title
  58. * @public
  59. */
  60. public function ChapterTitle($num, $title) {
  61. $this->SetFont('helvetica', '', 14);
  62. $this->SetFillColor(200, 220, 255);
  63. $this->Cell(180, 6, 'Chapter '.$num.' : '.$title, 0, 1, '', 1);
  64. $this->Ln(4);
  65. }
  66. /**
  67. * Print chapter body
  68. * @param $file (string) name of the file containing the chapter body
  69. * @param $mode (boolean) if true the chapter body is in HTML, otherwise in simple text.
  70. * @public
  71. */
  72. public function ChapterBody($file, $mode=false) {
  73. $this->selectColumn();
  74. // get esternal file content
  75. $content = file_get_contents($file, false);
  76. // set font
  77. $this->SetFont('times', '', 9);
  78. $this->SetTextColor(50, 50, 50);
  79. // print content
  80. if ($mode) {
  81. // ------ HTML MODE ------
  82. $this->writeHTML($content, true, false, true, false, 'J');
  83. } else {
  84. // ------ TEXT MODE ------
  85. $this->Write(0, $content, '', 0, 'J', true, 0, false, true, 0);
  86. }
  87. $this->Ln();
  88. }
  89. } // end of extended class
  90. // ---------------------------------------------------------
  91. // EXAMPLE
  92. // ---------------------------------------------------------
  93. // create new PDF document
  94. $pdf = new MC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  95. // set document information
  96. $pdf->SetCreator(PDF_CREATOR);
  97. $pdf->SetAuthor('Nicola Asuni');
  98. $pdf->SetTitle('TCPDF Example 010');
  99. $pdf->SetSubject('TCPDF Tutorial');
  100. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  101. // set default header data
  102. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 010', PDF_HEADER_STRING);
  103. // set header and footer fonts
  104. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  105. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  106. // set default monospaced font
  107. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  108. //set margins
  109. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  110. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  111. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  112. //set auto page breaks
  113. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  114. //set image scale factor
  115. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  116. //set some language-dependent strings
  117. $pdf->setLanguageArray($l);
  118. // ---------------------------------------------------------
  119. // print TEXT
  120. $pdf->PrintChapter(1, 'LOREM IPSUM [TEXT]', '../cache/chapter_demo_1.txt', false);
  121. // print HTML
  122. $pdf->PrintChapter(2, 'LOREM IPSUM [HTML]', '../cache/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. //============================================================+