example_051.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. //============================================================+
  3. // File name : example_051.php
  4. // Begin : 2009-04-16
  5. // Last Update : 2011-06-01
  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. // get the current page break margin
  35. $bMargin = $this->getBreakMargin();
  36. // get current auto-page-break mode
  37. $auto_page_break = $this->AutoPageBreak;
  38. // disable auto-page-break
  39. $this->SetAutoPageBreak(false, 0);
  40. // set bacground image
  41. $img_file = K_PATH_IMAGES.'image_demo.jpg';
  42. $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
  43. // restore auto-page-break status
  44. $this->SetAutoPageBreak($auto_page_break, $bMargin);
  45. // set the starting point for the page content
  46. $this->setPageMark();
  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 051');
  55. $pdf->SetSubject('TCPDF Tutorial');
  56. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  57. // set header and footer fonts
  58. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  59. // set default monospaced font
  60. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  61. //set margins
  62. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  63. $pdf->SetHeaderMargin(0);
  64. $pdf->SetFooterMargin(0);
  65. // remove default footer
  66. $pdf->setPrintFooter(false);
  67. //set auto page breaks
  68. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  69. //set image scale factor
  70. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  71. //set some language-dependent strings
  72. $pdf->setLanguageArray($l);
  73. // ---------------------------------------------------------
  74. // set font
  75. $pdf->SetFont('times', '', 48);
  76. // add a page
  77. $pdf->AddPage();
  78. // Print a text
  79. $html = '<span style="background-color:yellow;color:blue;">&nbsp;PAGE 1&nbsp;</span>
  80. <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>';
  81. $pdf->writeHTML($html, true, false, true, false, '');
  82. // add a page
  83. $pdf->AddPage();
  84. // Print a text
  85. $html = '<span style="background-color:yellow;color:blue;">&nbsp;PAGE 2&nbsp;</span>';
  86. $pdf->writeHTML($html, true, false, true, false, '');
  87. // --- example with background set on page ---
  88. // remove default header
  89. $pdf->setPrintHeader(false);
  90. // add a page
  91. $pdf->AddPage();
  92. // -- set new background ---
  93. // get the current page break margin
  94. $bMargin = $pdf->getBreakMargin();
  95. // get current auto-page-break mode
  96. $auto_page_break = $pdf->getAutoPageBreak();
  97. // disable auto-page-break
  98. $pdf->SetAutoPageBreak(false, 0);
  99. // set bacground image
  100. $img_file = K_PATH_IMAGES.'image_demo.jpg';
  101. $pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
  102. // restore auto-page-break status
  103. $pdf->SetAutoPageBreak($auto_page_break, $bMargin);
  104. // set the starting point for the page content
  105. $pdf->setPageMark();
  106. // Print a text
  107. $html = '<span style="color:white;text-align:center;font-weight:bold;font-size:80pt;">PAGE 3</span>';
  108. $pdf->writeHTML($html, true, false, true, false, '');
  109. // ---------------------------------------------------------
  110. //Close and output PDF document
  111. $pdf->Output('example_051.pdf', 'I');
  112. //============================================================+
  113. // END OF FILE
  114. //============================================================+