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.

118 lines
3.4 KiB

  1. <?php
  2. //============================================================+
  3. // File name : example_003.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 003 for TCPDF class
  8. // Custom Header and Footer
  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: Custom Header and Footer
  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. // Extend the TCPDF class to create custom Header and Footer
  28. class MYPDF extends TCPDF {
  29. //Page header
  30. public function Header() {
  31. // Logo
  32. $image_file = K_PATH_IMAGES.'logo_example.jpg';
  33. $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
  34. // Set font
  35. $this->SetFont('helvetica', 'B', 20);
  36. // Title
  37. $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
  38. }
  39. // Page footer
  40. public function Footer() {
  41. // Position at 15 mm from bottom
  42. $this->SetY(-15);
  43. // Set font
  44. $this->SetFont('helvetica', 'I', 8);
  45. // Page number
  46. $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
  47. }
  48. }
  49. // create new PDF document
  50. $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  51. // set document information
  52. $pdf->SetCreator(PDF_CREATOR);
  53. $pdf->SetAuthor('Nicola Asuni');
  54. $pdf->SetTitle('TCPDF Example 003');
  55. $pdf->SetSubject('TCPDF Tutorial');
  56. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  57. // set default header data
  58. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
  59. // set header and footer fonts
  60. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  61. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  62. // set default monospaced font
  63. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  64. // set margins
  65. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  66. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  67. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  68. // set auto page breaks
  69. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  70. // set image scale factor
  71. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  72. // set some language-dependent strings (optional)
  73. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  74. require_once(dirname(__FILE__).'/lang/eng.php');
  75. $pdf->setLanguageArray($l);
  76. }
  77. // ---------------------------------------------------------
  78. // set font
  79. $pdf->SetFont('times', 'BI', 12);
  80. // add a page
  81. $pdf->AddPage();
  82. // set some text to print
  83. $txt = <<<EOD
  84. TCPDF Example 003
  85. Custom page header and footer are defined by extending the TCPDF class and overriding the Header() and Footer() methods.
  86. EOD;
  87. // print a block of text using Write()
  88. $pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
  89. // ---------------------------------------------------------
  90. //Close and output PDF document
  91. $pdf->Output('example_003.pdf', 'I');
  92. //============================================================+
  93. // END OF FILE
  94. //============================================================+