Zend_Pdf-Pages.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 24605 -->
  4. <sect1 id="zend.pdf.pages">
  5. <title>ページの操作</title>
  6. <sect2 id="zend.pdf.pages.creation">
  7. <title>ページの作成</title>
  8. <para>
  9. <acronym>PDF</acronym> ドキュメントのページは、<classname>Zend_Pdf</classname> の
  10. <classname>Zend_Pdf_Page</classname> クラスで表されます。
  11. </para>
  12. <para>
  13. <acronym>PDF</acronym> ページは既存の <acronym>PDF</acronym> から読み込むこともできますし、
  14. 新しく作成することもできます。
  15. </para>
  16. <para>
  17. 新しいページを取得するには、直接 <classname>Zend_Pdf_Page</classname>
  18. オブジェクトを作成するか、<methodname>Zend_Pdf::newPage()</methodname>
  19. メソッドをコールします。このメソッドは <classname>Zend_Pdf_Page</classname>
  20. オブジェクトを返します。<methodname>Zend_Pdf::newPage()</methodname>
  21. の場合は、すでにドキュメントにアタッチされているページを作成するという点が異なります。
  22. アタッチされたページは複製されない限り、他の <acronym>PDF</acronym> で使用できません。
  23. 詳しくは <link linkend="zend.pdf.pages.cloning">ページの複製</link> セクションをご覧ください。
  24. </para>
  25. <para>
  26. <methodname>Zend_Pdf::newPage()</methodname> メソッドおよび <classname>Zend_Pdf_Page</classname>
  27. のコンストラクタは、どちらも同じ形式のパラメータを受け取ります。
  28. ページサイズを ($x, $y) 形式のポイント数 (1/72 インチ)
  29. で表したものか、定義済みの定数のうちのいずれかになります。
  30. 以下の定数が定義されています。
  31. <itemizedlist>
  32. <listitem>
  33. <para>Zend_Pdf_Page::SIZE_A4</para>
  34. </listitem>
  35. <listitem>
  36. <para>Zend_Pdf_Page::SIZE_A4_LANDSCAPE</para>
  37. </listitem>
  38. <listitem>
  39. <para>Zend_Pdf_Page::SIZE_LETTER</para>
  40. </listitem>
  41. <listitem>
  42. <para>Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE</para>
  43. </listitem>
  44. </itemizedlist>
  45. </para>
  46. <para>
  47. ドキュメントのページは、<classname>Zend_Pdf</classname> クラスの public メンバである
  48. <varname>$pages</varname> に保存されます。これは <classname>Zend_Pdf_Page</classname>
  49. オブジェクトの配列です。これによってページの並び順も定義され、
  50. 一般的な配列と同じように操作できます。
  51. </para>
  52. <example id="zend.pdf.pages.example-1">
  53. <title>PDF ドキュメントのページの操作</title>
  54. <programlisting language="php"><![CDATA[
  55. ...
  56. // ページの並び順を反転します
  57. $pdf->pages = array_reverse($pdf->pages);
  58. ...
  59. // 新しいページを追加します
  60. $pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
  61. // 新しいページを追加します
  62. $pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
  63. // 指定したページを削除します
  64. unset($pdf->pages[$id]);
  65. ...
  66. ]]></programlisting>
  67. </example>
  68. </sect2>
  69. <sect2 id="zend.pdf.pages.cloning">
  70. <title>ページの複製</title>
  71. <para>
  72. 既存の <acronym>PDF</acronym> ページを繰り返すには、新しい <classname>Zend_Pdf_Page</classname>
  73. オブジェクトを作成する際に既存のページをパラメータとして指定します。
  74. </para>
  75. <example id="zend.pdf.pages.example-2">
  76. <title>既存のページを繰り返す</title>
  77. <programlisting language="php"><![CDATA[
  78. ...
  79. // テンプレートページを別の変数に格納します
  80. $template = $pdf->pages[$templatePageIndex];
  81. ...
  82. // 新しいページを追加します
  83. $page1 = new Zend_Pdf_Page($template);
  84. $page1->drawText('Some text...', $x, $y);
  85. $pdf->pages[] = $page1;
  86. ...
  87. // 別のページを追加します
  88. $page2 = new Zend_Pdf_Page($template);
  89. $page2->drawText('Another text...', $x, $y);
  90. $pdf->pages[] = $page2;
  91. ...
  92. // テンプレートページをドキュメントから削除します
  93. unset($pdf->pages[$templatePageIndex]);
  94. ...
  95. ]]></programlisting>
  96. </example>
  97. <para>
  98. これは、ひとつのテンプレートから複数のページを作成したい場合に便利です。
  99. </para>
  100. <caution>
  101. <para>
  102. 注意! 繰り返されたページは、テンプレートページと同じ
  103. <acronym>PDF</acronym> リソースを共有します。つまり、
  104. テンプレートページと同じドキュメントしか使用できません。
  105. ドキュメントを修正したら、新しいページとして保存できます。
  106. </para>
  107. </caution>
  108. <!-- TODO : to be translated -->
  109. <para>
  110. <code>clone</code> operator may be used to create page which is not attached to any document.
  111. It takes more time than duplicating page since it needs to copy all dependent objects
  112. (used fonts, images and other resources), but it allows to use pages from different source
  113. documents to create new one:
  114. </para>
  115. <example id="zend.pdf.pages.example-3">
  116. <title>既存のページを複製</title>
  117. <programlisting language="php"><![CDATA[
  118. $page1 = clone $pdf1->pages[$templatePageIndex1];
  119. $page2 = clone $pdf2->pages[$templatePageIndex2];
  120. $page1->drawText('Some text...', $x, $y);
  121. $page2->drawText('Another text...', $x, $y);
  122. ...
  123. $pdf = new Zend_Pdf();
  124. $pdf->pages[] = $page1;
  125. $pdf->pages[] = $page2;
  126. ]]></programlisting>
  127. </example>
  128. <!-- TODO : to be translated -->
  129. <para>
  130. If several template pages are planned to be used as templates then it could be more efficient
  131. to utilize <classname>Zend_Pdf_Resource_Extractor</classname> class which gives an ability
  132. to share resources between cloned pages - fonts, images, etc. (otherwise new resource copy
  133. will be created for each cloned page):
  134. </para>
  135. <example id="zend.pdf.pages.example-4">
  136. <title>Zend_Pdf_Resource_Extractor クラスを使用して既存のページを複製</title>
  137. <programlisting language="php"><![CDATA[
  138. $extractor = new Zend_Pdf_Resource_Extractor();
  139. ....
  140. $page1 = $extractor->clonePage($pdf->pages[$templatePageIndex1]);
  141. $page2 = $extractor->clonePage($pdf->pages[$templatePageIndex2]);
  142. $page1->drawText('Some text...', $x, $y);
  143. $page2->drawText('Another text...', $x, $y);
  144. ...
  145. $pdf = new Zend_Pdf();
  146. $pdf->pages[] = $page1;
  147. $pdf->pages[] = $page2;
  148. ]]></programlisting>
  149. </example>
  150. </sect2>
  151. </sect1>
  152. <!--
  153. vim:se ts=4 sw=4 et:
  154. -->