Zend_Pdf-Pages.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <classname>Zend_Pdf_Page</classname> instances in <classname>Zend_Pdf</classname>.
  9. </para>
  10. <para>
  11. <acronym>PDF</acronym> pages either are loaded from an existing <acronym>PDF</acronym> or created using the <classname>Zend_Pdf</classname> <acronym>API</acronym>.
  12. </para>
  13. <para>
  14. New pages can be created by instantiating new <classname>Zend_Pdf_Page</classname> objects directly or by calling
  15. the <methodname>Zend_Pdf::newPage()</methodname> method, which returns a <classname>Zend_Pdf_Page</classname> object.
  16. <methodname>Zend_Pdf::newPage()</methodname> creates a page that is already attached to
  17. a document. Unattached pages can't be used with multiple <acronym>PDF</acronym> documents,
  18. but they are somewhat more performant.
  19. <footnote>
  20. <para>
  21. It's a limitation of current Zend Framework version. It will be eliminated in future versions.
  22. But unattached pages will always give better (more optimal) result for sharing pages between documents.
  23. </para>
  24. </footnote>
  25. </para>
  26. <para>
  27. The <methodname>Zend_Pdf::newPage()</methodname> method and the <classname>Zend_Pdf_Page</classname> constructor take the same
  28. parameters specifying page size. They can take either the size of page ($x, $y) in points (1/72 inch)
  29. or a predefined constant representing a page type:
  30. <itemizedlist>
  31. <listitem>
  32. <para>Zend_Pdf_Page::SIZE_A4</para>
  33. </listitem>
  34. <listitem>
  35. <para>Zend_Pdf_Page::SIZE_A4_LANDSCAPE</para>
  36. </listitem>
  37. <listitem>
  38. <para>Zend_Pdf_Page::SIZE_LETTER</para>
  39. </listitem>
  40. <listitem>
  41. <para>Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE</para>
  42. </listitem>
  43. </itemizedlist>
  44. </para>
  45. <para>
  46. Document pages are stored in the <varname>$pages</varname> public attribute of the <classname>Zend_Pdf</classname> class.
  47. The attribute holds an array of <classname>Zend_Pdf_Page</classname> objects and completely defines the instances and order of pages.
  48. This array can be manipulated like any other <acronym>PHP</acronym> array:
  49. </para>
  50. <example id="zend.pdf.pages.example-1">
  51. <title>PDF document pages management</title>
  52. <programlisting language="php"><![CDATA[
  53. ...
  54. // Reverse page order
  55. $pdf->pages = array_reverse($pdf->pages);
  56. ...
  57. // Add new page
  58. $pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
  59. // Add new page
  60. $pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  61. // Remove specified page.
  62. unset($pdf->pages[$id]);
  63. ...
  64. ]]></programlisting>
  65. </example>
  66. </sect2>
  67. <sect2 id="zend.pdf.pages.cloning">
  68. <title>Page cloning</title>
  69. <para>
  70. Existing <acronym>PDF</acronym> page can be cloned by creating new <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 page, so it can be used only within the same document
  98. as a template page. Modified document can be saved as new one.
  99. </para>
  100. </caution>
  101. </sect2>
  102. </sect1>
  103. <!--
  104. vim:se ts=4 sw=4 et:
  105. -->