example_003.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. //============================================================+
  3. // File name : example_003.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2010-08-08
  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 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: Custom Header and Footer
  25. * @author Nicola Asuni
  26. * @since 2008-03-04
  27. */
  28. require_once('../config/lang/eng.php');
  29. require_once('../tcpdf.php');
  30. // Extend the TCPDF class to create custom Header and Footer
  31. class MYPDF extends TCPDF {
  32. //Page header
  33. public function Header() {
  34. // Logo
  35. $image_file = K_PATH_IMAGES.'logo_example.jpg';
  36. $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
  37. // Set font
  38. $this->SetFont('helvetica', 'B', 20);
  39. // Title
  40. $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
  41. }
  42. // Page footer
  43. public function Footer() {
  44. // Position at 15 mm from bottom
  45. $this->SetY(-15);
  46. // Set font
  47. $this->SetFont('helvetica', 'I', 8);
  48. // Page number
  49. $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
  50. }
  51. }
  52. // create new PDF document
  53. $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  54. // set document information
  55. $pdf->SetCreator(PDF_CREATOR);
  56. $pdf->SetAuthor('Nicola Asuni');
  57. $pdf->SetTitle('TCPDF Example 003');
  58. $pdf->SetSubject('TCPDF Tutorial');
  59. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  60. // set default header data
  61. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
  62. // set header and footer fonts
  63. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  64. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  65. // set default monospaced font
  66. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  67. //set margins
  68. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  69. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  70. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  71. //set auto page breaks
  72. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  73. //set image scale factor
  74. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  75. //set some language-dependent strings
  76. $pdf->setLanguageArray($l);
  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($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
  89. // ---------------------------------------------------------
  90. //Close and output PDF document
  91. $pdf->Output('example_003.pdf', 'I');
  92. //============================================================+
  93. // END OF FILE
  94. //============================================================+