example_010.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. //============================================================+
  3. // File name : example_010.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2010-08-11
  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. // disable existing columns
  44. $this->setEqualColumns();
  45. // add a new page
  46. $this->AddPage();
  47. // reset margins
  48. $this->selectColumn();
  49. // print chapter title
  50. $this->ChapterTitle($num, $title);
  51. // set columns
  52. $this->setEqualColumns(3, 57);
  53. // print chapter body
  54. $this->ChapterBody($file, $mode);
  55. }
  56. /**
  57. * Set chapter title
  58. * @param $num (int) chapter number
  59. * @param $title (string) chapter title
  60. * @public
  61. */
  62. public function ChapterTitle($num, $title) {
  63. $this->SetFont('helvetica', '', 14);
  64. $this->SetFillColor(200, 220, 255);
  65. $this->Cell(180, 6, 'Chapter '.$num.' : '.$title, 0, 1, '', 1);
  66. $this->Ln(4);
  67. }
  68. /**
  69. * Print chapter body
  70. * @param $file (string) name of the file containing the chapter body
  71. * @param $mode (boolean) if true the chapter body is in HTML, otherwise in simple text.
  72. * @public
  73. */
  74. public function ChapterBody($file, $mode=false) {
  75. $this->selectColumn();
  76. // get esternal file content
  77. $content = file_get_contents($file, false);
  78. // set font
  79. $this->SetFont('times', '', 9);
  80. $this->SetTextColor(50, 50, 50);
  81. // print content
  82. if ($mode) {
  83. // ------ HTML MODE ------
  84. $this->writeHTML($content, true, false, true, false, 'J');
  85. } else {
  86. // ------ TEXT MODE ------
  87. $this->Write(0, $content, '', 0, 'J', true, 0, false, true, 0);
  88. }
  89. $this->Ln();
  90. }
  91. } // end of extended class
  92. // ---------------------------------------------------------
  93. // EXAMPLE
  94. // ---------------------------------------------------------
  95. // create new PDF document
  96. $pdf = new MC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  97. // set document information
  98. $pdf->SetCreator(PDF_CREATOR);
  99. $pdf->SetAuthor('Nicola Asuni');
  100. $pdf->SetTitle('TCPDF Example 010');
  101. $pdf->SetSubject('TCPDF Tutorial');
  102. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  103. // set default header data
  104. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 010', PDF_HEADER_STRING);
  105. // set header and footer fonts
  106. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  107. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  108. // set default monospaced font
  109. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  110. //set margins
  111. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  112. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  113. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  114. //set auto page breaks
  115. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  116. //set image scale factor
  117. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  118. //set some language-dependent strings
  119. $pdf->setLanguageArray($l);
  120. // ---------------------------------------------------------
  121. // print TEXT
  122. $pdf->PrintChapter(1, 'LOREM IPSUM [TEXT]', '../cache/chapter_demo_1.txt', false);
  123. // print HTML
  124. $pdf->PrintChapter(2, 'LOREM IPSUM [HTML]', '../cache/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. //============================================================+