You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.3 KiB

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