example_054.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. //============================================================+
  3. // File name : example_054.php
  4. // Begin : 2009-09-07
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 054 for TCPDF class
  8. // XHTML Forms
  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: XHTML Forms
  22. * @author Nicola Asuni
  23. * @since 2009-09-07
  24. * @group html
  25. * @group form
  26. * @group pdf
  27. */
  28. // Include the main TCPDF library (search for installation path).
  29. require_once('tcpdf_include.php');
  30. // create new PDF document
  31. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  32. // set document information
  33. $pdf->setCreator(PDF_CREATOR);
  34. $pdf->setAuthor('Nicola Asuni');
  35. $pdf->setTitle('TCPDF Example 054');
  36. $pdf->setSubject('TCPDF Tutorial');
  37. $pdf->setKeywords('TCPDF, PDF, example, test, guide');
  38. // set default header data
  39. $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 054', PDF_HEADER_STRING);
  40. // set header and footer fonts
  41. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  42. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  43. // set default monospaced font
  44. $pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  45. // set margins
  46. $pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  47. $pdf->setHeaderMargin(PDF_MARGIN_HEADER);
  48. $pdf->setFooterMargin(PDF_MARGIN_FOOTER);
  49. // set auto page breaks
  50. $pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  51. // set image scale factor
  52. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  53. // set some language-dependent strings (optional)
  54. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  55. require_once(dirname(__FILE__).'/lang/eng.php');
  56. $pdf->setLanguageArray($l);
  57. }
  58. // ---------------------------------------------------------
  59. // IMPORTANT: disable font subsetting to allow users editing the document
  60. $pdf->setFontSubsetting(false);
  61. // set font. 'helvetica' MUST be used to avoid a PHP notice from PHP 7.4+
  62. $pdf->setFont('helvetica', '', 10, '', false);
  63. // add a page
  64. $pdf->AddPage();
  65. // create some HTML content
  66. $html = <<<EOD
  67. <h1>XHTML Form Example</h1>
  68. <form method="post" action="http://localhost/printvars.php" enctype="multipart/form-data">
  69. <label for="name">name:</label> <input type="text" name="name" value="" size="20" maxlength="30" /><br />
  70. <label for="password">password:</label> <input type="password" name="password" value="" size="20" maxlength="30" /><br /><br />
  71. <label for="infile">file:</label> <input type="file" name="userfile" size="20" /><br /><br />
  72. <input type="checkbox" name="agree" value="1" checked="checked" /> <label for="agree">I agree </label><br /><br />
  73. <input type="radio" name="radioquestion" id="rqa" value="1" /> <label for="rqa">one</label><br />
  74. <input type="radio" name="radioquestion" id="rqb" value="2" checked="checked"/> <label for="rqb">two</label><br />
  75. <input type="radio" name="radioquestion" id="rqc" value="3" /> <label for="rqc">three</label><br /><br />
  76. <label for="selection">select:</label>
  77. <select name="selection" size="0">
  78. <option value="0">zero</option>
  79. <option value="1">one</option>
  80. <option value="2">two</option>
  81. <option value="3">three</option>
  82. </select><br /><br />
  83. <label for="selection">select:</label>
  84. <select name="multiselection" size="2" multiple="multiple">
  85. <option value="0">zero</option>
  86. <option value="1">one</option>
  87. <option value="2">two</option>
  88. <option value="3">three</option>
  89. </select><br /><br /><br />
  90. <label for="text">text area:</label><br />
  91. <textarea cols="40" rows="3" name="text">line one
  92. line two</textarea><br />
  93. <br /><br /><br />
  94. <input type="reset" name="reset" value="Reset" />
  95. <input type="submit" name="submit" value="Submit" />
  96. <input type="button" name="print" value="Print" onclick="print()" />
  97. <input type="hidden" name="hiddenfield" value="OK" />
  98. <br />
  99. </form>
  100. EOD;
  101. // output the HTML content
  102. $pdf->writeHTML($html, true, 0, true, 0);
  103. // reset pointer to the last page
  104. $pdf->lastPage();
  105. // ---------------------------------------------------------
  106. //Close and output PDF document
  107. $pdf->Output('example_054.pdf', 'D');
  108. //============================================================+
  109. // END OF FILE
  110. //============================================================+