PageRenderTime 74ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/__docs/phpdoc/en/reference/pdf/examples.xml

https://github.com/andregoiano/hack-hhvm-docs
XML | 121 lines | 100 code | 20 blank | 1 comment | 0 complexity | a65f7e457753f5c3785e3a56533ffa57 MD5 | raw file
Possible License(s): CC-BY-3.0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- $Revision: 297028 $ -->
  3. <chapter xml:id="pdf.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
  4. &reftitle.examples;
  5. <section xml:id="pdf.examples-basic">
  6. <title>Basic Usage Examples</title>
  7. <para>
  8. Most of the functions are fairly easy to use. The most difficult part
  9. is probably creating your first PDF document. The following
  10. example should help to get you started. It is developed for PHP 4 and
  11. creates the file <filename>hello.pdf</filename> with one page.
  12. It defines some document info field contents, loads the Helvetica-Bold
  13. font and outputs the text "Hello world! (says PHP)".
  14. </para>
  15. <para>
  16. <example>
  17. <title>Hello World example from PDFlib distribution for PHP 4</title>
  18. <programlisting role="php">
  19. <![CDATA[
  20. <?php
  21. $p = PDF_new();
  22. /* open new PDF file; insert a file name to create the PDF on disk */
  23. if (PDF_begin_document($p, "", "") == 0) {
  24. die("Error: " . PDF_get_errmsg($p));
  25. }
  26. PDF_set_info($p, "Creator", "hello.php");
  27. PDF_set_info($p, "Author", "Rainer Schaaf");
  28. PDF_set_info($p, "Title", "Hello world (PHP)!");
  29. PDF_begin_page_ext($p, 595, 842, "");
  30. $font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");
  31. PDF_setfont($p, $font, 24.0);
  32. PDF_set_text_pos($p, 50, 700);
  33. PDF_show($p, "Hello world!");
  34. PDF_continue_text($p, "(says PHP)");
  35. PDF_end_page_ext($p, "");
  36. PDF_end_document($p, "");
  37. $buf = PDF_get_buffer($p);
  38. $len = strlen($buf);
  39. header("Content-type: application/pdf");
  40. header("Content-Length: $len");
  41. header("Content-Disposition: inline; filename=hello.pdf");
  42. print $buf;
  43. PDF_delete($p);
  44. ?>
  45. ]]>
  46. </programlisting>
  47. </example>
  48. </para>
  49. <para>
  50. The following example comes with the PDFlib distribution for PHP 5.
  51. It uses the new exception handling and object encapsulation features
  52. available in PHP 5. It creates the file <filename>hello.pdf</filename>
  53. with one page. It defines some document info field contents, loads the
  54. Helvetica-Bold font and outputs the text "Hello world! (says PHP)".
  55. </para>
  56. <para>
  57. <example>
  58. <title>Hello World example from PDFlib distribution for PHP 5</title>
  59. <programlisting role="php">
  60. <![CDATA[
  61. <?php
  62. try {
  63. $p = new PDFlib();
  64. /* open new PDF file; insert a file name to create the PDF on disk */
  65. if ($p->begin_document("", "") == 0) {
  66. die("Error: " . $p->get_errmsg());
  67. }
  68. $p->set_info("Creator", "hello.php");
  69. $p->set_info("Author", "Rainer Schaaf");
  70. $p->set_info("Title", "Hello world (PHP)!");
  71. $p->begin_page_ext(595, 842, "");
  72. $font = $p->load_font("Helvetica-Bold", "winansi", "");
  73. $p->setfont($font, 24.0);
  74. $p->set_text_pos(50, 700);
  75. $p->show("Hello world!");
  76. $p->continue_text("(says PHP)");
  77. $p->end_page_ext("");
  78. $p->end_document("");
  79. $buf = $p->get_buffer();
  80. $len = strlen($buf);
  81. header("Content-type: application/pdf");
  82. header("Content-Length: $len");
  83. header("Content-Disposition: inline; filename=hello.pdf");
  84. print $buf;
  85. }
  86. catch (PDFlibException $e) {
  87. die("PDFlib exception occurred in hello sample:\n" .
  88. "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
  89. $e->get_errmsg() . "\n");
  90. }
  91. catch (Exception $e) {
  92. die($e);
  93. }
  94. $p = 0;
  95. ?>
  96. ]]>
  97. </programlisting>
  98. </example>
  99. </para>
  100. </section>
  101. </chapter>