example_051.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. * @group background
  25. * @group page
  26. * @group pdf
  27. */
  28. // Include the main TCPDF library (search for installation path).
  29. require_once('tcpdf_include.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, null, 0, 210, 297, '', '', '', false, 300, 'C', 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 (optional)
  72. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  73. require_once(dirname(__FILE__).'/lang/eng.php');
  74. $pdf->setLanguageArray($l);
  75. }
  76. // ---------------------------------------------------------
  77. // set font
  78. $pdf->setFont('times', '', 48);
  79. // add a page
  80. $pdf->AddPage();
  81. // Print a text
  82. $html = '<span style="background-color:yellow;color:blue;">&nbsp;PAGE 1&nbsp;</span>
  83. <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>';
  84. $pdf->writeHTML($html, true, false, true, false, '');
  85. // add a page
  86. $pdf->AddPage();
  87. // Print a text
  88. $html = '<span style="background-color:yellow;color:blue;">&nbsp;PAGE 2&nbsp;</span>';
  89. $pdf->writeHTML($html, true, false, true, false, '');
  90. // --- example with background set on page ---
  91. // remove default header
  92. $pdf->setPrintHeader(false);
  93. // add a page
  94. $pdf->AddPage();
  95. // -- set new background ---
  96. // get the current page break margin
  97. $bMargin = $pdf->getBreakMargin();
  98. // get current auto-page-break mode
  99. $auto_page_break = $pdf->getAutoPageBreak();
  100. // disable auto-page-break
  101. $pdf->setAutoPageBreak(false, 0);
  102. // set bacground image
  103. $img_file = K_PATH_IMAGES.'image_demo.jpg';
  104. $pdf->Image($img_file, null, 0, 210, 297, '', '', '', false, 300, 'C', false, false, 0);
  105. // restore auto-page-break status
  106. $pdf->setAutoPageBreak($auto_page_break, $bMargin);
  107. // set the starting point for the page content
  108. $pdf->setPageMark();
  109. // Print a text
  110. $html = '<span style="color:white;text-align:center;font-weight:bold;font-size:80pt;">PAGE 3</span>';
  111. $pdf->writeHTML($html, true, false, true, false, '');
  112. // ---------------------------------------------------------
  113. //Close and output PDF document
  114. $pdf->Output('example_051.pdf', 'I');
  115. //============================================================+
  116. // END OF FILE
  117. //============================================================+