example_051.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. //============================================================+
  3. // File name : example_051.php
  4. // Begin : 2009-04-16
  5. // Last Update : 2013-05-14
  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 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: Full page background
  22. * @author Nicola Asuni
  23. * @since 2009-04-16
  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. // get the current page break margin
  32. $bMargin = $this->getBreakMargin();
  33. // get current auto-page-break mode
  34. $auto_page_break = $this->AutoPageBreak;
  35. // disable auto-page-break
  36. $this->SetAutoPageBreak(false, 0);
  37. // set bacground image
  38. $img_file = K_PATH_IMAGES.'image_demo.jpg';
  39. $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
  40. // restore auto-page-break status
  41. $this->SetAutoPageBreak($auto_page_break, $bMargin);
  42. // set the starting point for the page content
  43. $this->setPageMark();
  44. }
  45. }
  46. // create new PDF document
  47. $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  48. // set document information
  49. $pdf->SetCreator(PDF_CREATOR);
  50. $pdf->SetAuthor('Nicola Asuni');
  51. $pdf->SetTitle('TCPDF Example 051');
  52. $pdf->SetSubject('TCPDF Tutorial');
  53. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  54. // set header and footer fonts
  55. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  56. // set default monospaced font
  57. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  58. // set margins
  59. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  60. $pdf->SetHeaderMargin(0);
  61. $pdf->SetFooterMargin(0);
  62. // remove default footer
  63. $pdf->setPrintFooter(false);
  64. // set auto page breaks
  65. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  66. // set image scale factor
  67. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  68. // set some language-dependent strings (optional)
  69. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  70. require_once(dirname(__FILE__).'/lang/eng.php');
  71. $pdf->setLanguageArray($l);
  72. }
  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. //============================================================+