Zend_Pdf-Pages.xml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <sect1 id="zend.pdf.pages">
  2. <title> 文档页面 </title>
  3. <sect2 id="zend.pdf.pages.creation">
  4. <title> 页面生成 </title>
  5. <para>
  6. PDF 文档页面摘要由 <code>Zend_Pdf_Page</code> 类来描绘。
  7. </para>
  8. <para>
  9. PDF 页面或者从 PDF 加载,或者生成新的。
  10. </para>
  11. <para>
  12. 新页面可以通过创建 <code>Zend_Pdf_Page</code> 对象或调用 <code>Zend_Pdf::newPage()</code> 方法来获得,它返回 <code>Zend_Pdf_Page</code> 对象。<code>Zend_Pdf::newPage()</code> 方法生成已经附加到文档的页面,和未附加的页面不同的是它不能和若干个 PDF 文档一起用,但是性能会稍好一些。
  13. <footnote>
  14. <para>
  15. Zend_Pdf 模块的 V1.0 有点限制,会在将来的版本中改善。但未附加的页面总是为在文档间共享提供更好(更多的优化)的结果。
  16. </para>
  17. </footnote>.
  18. 选择那种方式是你的自由。
  19. </para>
  20. <para>
  21. <code>Zend_Pdf::newPage()</code> 方法和 <code>Zend_Pdf_Page</code> 构造器带有相同的指定页面尺寸的参数。它或者是以点(1/72 英寸)来计算的页面的尺寸($x,$y),或者以预先定义的常数来计算,常数就是页面类型:
  22. <itemizedlist>
  23. <listitem>
  24. <para>Zend_Pdf_Page::SIZE_A4</para>
  25. </listitem>
  26. <listitem>
  27. <para>Zend_Pdf_Page::SIZE_A4_LANDSCAPE</para>
  28. </listitem>
  29. <listitem>
  30. <para>Zend_Pdf_Page::SIZE_LETTER</para>
  31. </listitem>
  32. <listitem>
  33. <para>Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE</para>
  34. </listitem>
  35. </itemizedlist>
  36. </para>
  37. <para>
  38. 文档存储在 <code>Zend_Pdf</code> 类的 public 成员 <code>$pages</code> 里,它是 <code>Zend_Pdf_Page</code> 对象的一个数组。它完整地定义了设置和文档页面的顺序并可以以普通的数组来处理:
  39. </para>
  40. <example id="zend.pdf.pages.example-1">
  41. <title>PDF 文档页面管理 </title>
  42. <programlisting role="php"><![CDATA[<?php
  43. ...
  44. // Reverse page order
  45. $pdf->pages = array_reverse($pdf->pages);
  46. ...
  47. // Add new page
  48. $pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
  49. // Add new page
  50. $pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  51. // Remove specified page.
  52. unset($pdf->pages[$id]);
  53. ...]]>
  54. </programlisting>
  55. </example>
  56. </sect2>
  57. <sect2 id="zend.pdf.pages.cloning">
  58. <title> 页面克隆 </title>
  59. <para>
  60. 通过用页面为参数创建 <code>Zend_Pdf_Page</code> 对象 PDF 页面可以被克隆:
  61. </para>
  62. <example id="zend.pdf.pages.example-2">
  63. <title>Cloning existing page.</title>
  64. <programlisting role="php"><![CDATA[<?php
  65. ...
  66. // Store template page in a separate variable
  67. $template = $pdf->pages[$templatePageIndex];
  68. ...
  69. // Add new page
  70. $page1 = new Zend_Pdf_Page($template);
  71. $pdf->pages[] = $page1;
  72. ...
  73. // Add another page
  74. $page2 = new Zend_Pdf_Page($template);
  75. $pdf->pages[] = $page2;
  76. ...
  77. // Remove source template page from the documents.
  78. unset($pdf->pages[$templatePageIndex]);
  79. ...]]>
  80. </programlisting>
  81. </example>
  82. <para>
  83. 如果你需要用同一个模板生成若干页面,这很有用。
  84. </para>
  85. <caution>
  86. <para>
  87. 重要!克隆页面用模板页面来共享一些 PDF 资源,它只可以用于使用模板页的同一个文档内。修改后的文档可当作新文件来保存。
  88. </para>
  89. </caution>
  90. </sect2>
  91. </sect1>
  92. <!--
  93. vim:se ts=4 sw=4 et:
  94. -->