Zend_Pdf-Pages.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.pdf.pages">
  4. <title>Working with Pages</title>
  5. <sect2 id="zend.pdf.pages.creation">
  6. <title>Page Creation</title>
  7. <para>
  8. The pages in a <acronym>PDF</acronym> document are represented as
  9. <classname>Zend_Pdf_Page</classname> instances in <classname>Zend_Pdf</classname>.
  10. </para>
  11. <para>
  12. <acronym>PDF</acronym> pages either are loaded from an existing <acronym>PDF</acronym>
  13. or created using the <classname>Zend_Pdf</classname> <acronym>API</acronym>.
  14. </para>
  15. <para>
  16. New pages can be created by instantiating new <classname>Zend_Pdf_Page</classname>
  17. objects directly or by calling the <methodname>Zend_Pdf::newPage()</methodname> method,
  18. which returns a <classname>Zend_Pdf_Page</classname> object.
  19. <methodname>Zend_Pdf::newPage()</methodname> creates a page that is already attached to
  20. a document. Unattached pages can't be used with multiple <acronym>PDF</acronym>
  21. documents, but they are somewhat more performant.
  22. <footnote>
  23. <para>
  24. It's a limitation of current Zend Framework version. It will be eliminated in
  25. future versions. But unattached pages will always give better (more optimal)
  26. result for sharing pages between documents.
  27. </para>
  28. </footnote>
  29. </para>
  30. <para>
  31. The <methodname>Zend_Pdf::newPage()</methodname> method and the
  32. <classname>Zend_Pdf_Page</classname> constructor take the same parameters specifying
  33. page size. They can take either the size of page ($x, $y) in points (1/72 inch) or a
  34. predefined constant representing a page type:
  35. <itemizedlist>
  36. <listitem><para>Zend_Pdf_Page::SIZE_A4</para></listitem>
  37. <listitem><para>Zend_Pdf_Page::SIZE_A4_LANDSCAPE</para></listitem>
  38. <listitem><para>Zend_Pdf_Page::SIZE_LETTER</para></listitem>
  39. <listitem><para>Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE</para></listitem>
  40. </itemizedlist>
  41. </para>
  42. <para>
  43. Document pages are stored in the <varname>$pages</varname> public attribute of the
  44. <classname>Zend_Pdf</classname> class. The attribute holds an array of
  45. <classname>Zend_Pdf_Page</classname> objects and completely defines the instances and
  46. order of pages. This array can be manipulated like any other <acronym>PHP</acronym>
  47. array:
  48. </para>
  49. <example id="zend.pdf.pages.example-1">
  50. <title>PDF document pages management</title>
  51. <programlisting language="php"><![CDATA[
  52. ...
  53. // Reverse page order
  54. $pdf->pages = array_reverse($pdf->pages);
  55. ...
  56. // Add new page
  57. $pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
  58. // Add new page
  59. $pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  60. // Remove specified page.
  61. unset($pdf->pages[$id]);
  62. ...
  63. ]]></programlisting>
  64. </example>
  65. </sect2>
  66. <sect2 id="zend.pdf.pages.cloning">
  67. <title>Page cloning</title>
  68. <para>
  69. Existing <acronym>PDF</acronym> page can be cloned by creating new
  70. <classname>Zend_Pdf_Page</classname> object with existing page as a parameter:
  71. </para>
  72. <example id="zend.pdf.pages.example-2">
  73. <title>Cloning existing page</title>
  74. <programlisting language="php"><![CDATA[
  75. ...
  76. // Store template page in a separate variable
  77. $template = $pdf->pages[$templatePageIndex];
  78. ...
  79. // Add new page
  80. $page1 = new Zend_Pdf_Page($template);
  81. $pdf->pages[] = $page1;
  82. ...
  83. // Add another page
  84. $page2 = new Zend_Pdf_Page($template);
  85. $pdf->pages[] = $page2;
  86. ...
  87. // Remove source template page from the documents.
  88. unset($pdf->pages[$templatePageIndex]);
  89. ...
  90. ]]></programlisting>
  91. </example>
  92. <para>
  93. It's useful if you need several pages to be created using one template.
  94. </para>
  95. <caution>
  96. <para>
  97. Important! Cloned page shares some <acronym>PDF</acronym> resources with a template
  98. page, so it can be used only within the same document as a template page. Modified
  99. document can be saved as new one.
  100. </para>
  101. </caution>
  102. </sect2>
  103. </sect1>
  104. <!--
  105. vim:se ts=4 sw=4 et:
  106. -->