example_051.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. //============================================================+
  3. // File name : example_051.php
  4. // Begin : 2009-04-16
  5. // Last Update : 2010-08-08
  6. //
  7. // Description : Example 051 for TCPDF class
  8. // Full page background
  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: Full page background
  25. * @author Nicola Asuni
  26. * @since 2009-04-16
  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. // full background image
  35. // store current auto-page-break status
  36. $bMargin = $this->getBreakMargin();
  37. $auto_page_break = $this->AutoPageBreak;
  38. $this->SetAutoPageBreak(false, 0);
  39. $img_file = K_PATH_IMAGES.'image_demo.jpg';
  40. $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
  41. // restore auto-page-break status
  42. $this->SetAutoPageBreak($auto_page_break, $bMargin);
  43. }
  44. }
  45. // create new PDF document
  46. $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  47. // set document information
  48. $pdf->SetCreator(PDF_CREATOR);
  49. $pdf->SetAuthor('Nicola Asuni');
  50. $pdf->SetTitle('TCPDF Example 051');
  51. $pdf->SetSubject('TCPDF Tutorial');
  52. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  53. // set header and footer fonts
  54. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  55. // set default monospaced font
  56. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  57. //set margins
  58. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  59. $pdf->SetHeaderMargin(0);
  60. $pdf->SetFooterMargin(0);
  61. // remove default footer
  62. $pdf->setPrintFooter(false);
  63. //set auto page breaks
  64. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  65. //set image scale factor
  66. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  67. //set some language-dependent strings
  68. $pdf->setLanguageArray($l);
  69. // ---------------------------------------------------------
  70. // set font
  71. $pdf->SetFont('times', '', 48);
  72. // add a page
  73. $pdf->AddPage();
  74. // Print a text
  75. $html = '<span style="background-color:yellow;color:blue;">&nbsp;PAGE 1&nbsp;</span>
  76. <p stroke="0.2" fill="true" strokecolor="yellow" color="blue" style="font-family:helvetica;font-weight:bold;font-size:26pt;">You can set a full page background.</p>';
  77. $pdf->writeHTML($html, true, false, true, false, '');
  78. // add a page
  79. $pdf->AddPage();
  80. // Print a text
  81. $html = '<span style="background-color:yellow;color:blue;">&nbsp;PAGE 2&nbsp;</span>';
  82. $pdf->writeHTML($html, true, false, true, false, '');
  83. // ---------------------------------------------------------
  84. //Close and output PDF document
  85. $pdf->Output('example_051.pdf', 'I');
  86. //============================================================+
  87. // END OF FILE
  88. //============================================================+