example_054.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. //============================================================+
  3. // File name : example_054.php
  4. // Begin : 2009-09-07
  5. // Last Update : 2010-08-08
  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 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: XHTML Forms
  25. * @author Nicola Asuni
  26. * @since 2009-09-07
  27. */
  28. require_once('../config/lang/eng.php');
  29. require_once('../tcpdf.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
  54. $pdf->setLanguageArray($l);
  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', 'I');
  105. //============================================================+
  106. // END OF FILE
  107. //============================================================+