| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <!-- EN-Revision: 24605 -->
- <sect1 id="zend.pdf.pages">
- <title>ページの操作</title>
- <sect2 id="zend.pdf.pages.creation">
- <title>ページの作成</title>
- <para>
- <acronym>PDF</acronym> ドキュメントのページは、<classname>Zend_Pdf</classname> の
- <classname>Zend_Pdf_Page</classname> クラスで表されます。
- </para>
- <para>
- <acronym>PDF</acronym> ページは既存の <acronym>PDF</acronym> から読み込むこともできますし、
- 新しく作成することもできます。
- </para>
- <para>
- 新しいページを取得するには、直接 <classname>Zend_Pdf_Page</classname>
- オブジェクトを作成するか、<methodname>Zend_Pdf::newPage()</methodname>
- メソッドをコールします。このメソッドは <classname>Zend_Pdf_Page</classname>
- オブジェクトを返します。<methodname>Zend_Pdf::newPage()</methodname>
- の場合は、すでにドキュメントにアタッチされているページを作成するという点が異なります。
- アタッチされたページは複製されない限り、他の <acronym>PDF</acronym> で使用できません。
- 詳しくは <link linkend="zend.pdf.pages.cloning">ページの複製</link> セクションをご覧ください。
- </para>
- <para>
- <methodname>Zend_Pdf::newPage()</methodname> メソッドおよび <classname>Zend_Pdf_Page</classname>
- のコンストラクタは、どちらも同じ形式のパラメータを受け取ります。
- ページサイズを ($x, $y) 形式のポイント数 (1/72 インチ)
- で表したものか、定義済みの定数のうちのいずれかになります。
- 以下の定数が定義されています。
- <itemizedlist>
- <listitem>
- <para>Zend_Pdf_Page::SIZE_A4</para>
- </listitem>
- <listitem>
- <para>Zend_Pdf_Page::SIZE_A4_LANDSCAPE</para>
- </listitem>
- <listitem>
- <para>Zend_Pdf_Page::SIZE_LETTER</para>
- </listitem>
- <listitem>
- <para>Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE</para>
- </listitem>
- </itemizedlist>
- </para>
- <para>
- ドキュメントのページは、<classname>Zend_Pdf</classname> クラスの public メンバである
- <varname>$pages</varname> に保存されます。これは <classname>Zend_Pdf_Page</classname>
- オブジェクトの配列です。これによってページの並び順も定義され、
- 一般的な配列と同じように操作できます。
- </para>
- <example id="zend.pdf.pages.example-1">
- <title>PDF ドキュメントのページの操作</title>
- <programlisting language="php"><![CDATA[
- ...
- // ページの並び順を反転します
- $pdf->pages = array_reverse($pdf->pages);
- ...
- // 新しいページを追加します
- $pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
- // 新しいページを追加します
- $pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
- // 指定したページを削除します
- unset($pdf->pages[$id]);
- ...
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.pdf.pages.cloning">
- <title>ページの複製</title>
- <para>
- 既存の <acronym>PDF</acronym> ページを繰り返すには、新しい <classname>Zend_Pdf_Page</classname>
- オブジェクトを作成する際に既存のページをパラメータとして指定します。
- </para>
- <example id="zend.pdf.pages.example-2">
- <title>既存のページを繰り返す</title>
- <programlisting language="php"><![CDATA[
- ...
- // テンプレートページを別の変数に格納します
- $template = $pdf->pages[$templatePageIndex];
- ...
- // 新しいページを追加します
- $page1 = new Zend_Pdf_Page($template);
- $page1->drawText('Some text...', $x, $y);
- $pdf->pages[] = $page1;
- ...
- // 別のページを追加します
- $page2 = new Zend_Pdf_Page($template);
- $page2->drawText('Another text...', $x, $y);
- $pdf->pages[] = $page2;
- ...
- // テンプレートページをドキュメントから削除します
- unset($pdf->pages[$templatePageIndex]);
- ...
- ]]></programlisting>
- </example>
- <para>
- これは、ひとつのテンプレートから複数のページを作成したい場合に便利です。
- </para>
- <caution>
- <para>
- 注意! 繰り返されたページは、テンプレートページと同じ
- <acronym>PDF</acronym> リソースを共有します。つまり、
- テンプレートページと同じドキュメントしか使用できません。
- ドキュメントを修正したら、新しいページとして保存できます。
- </para>
- </caution>
- <!-- TODO : to be translated -->
- <para>
- <code>clone</code> operator may be used to create page which is not attached to any document.
- It takes more time than duplicating page since it needs to copy all dependent objects
- (used fonts, images and other resources), but it allows to use pages from different source
- documents to create new one:
- </para>
- <example id="zend.pdf.pages.example-3">
- <title>既存のページを複製</title>
- <programlisting language="php"><![CDATA[
- $page1 = clone $pdf1->pages[$templatePageIndex1];
- $page2 = clone $pdf2->pages[$templatePageIndex2];
- $page1->drawText('Some text...', $x, $y);
- $page2->drawText('Another text...', $x, $y);
- ...
- $pdf = new Zend_Pdf();
- $pdf->pages[] = $page1;
- $pdf->pages[] = $page2;
- ]]></programlisting>
- </example>
- <!-- TODO : to be translated -->
- <para>
- If several template pages are planned to be used as templates then it could be more efficient
- to utilize <classname>Zend_Pdf_Resource_Extractor</classname> class which gives an ability
- to share resources between cloned pages - fonts, images, etc. (otherwise new resource copy
- will be created for each cloned page):
- </para>
- <example id="zend.pdf.pages.example-4">
- <title>Zend_Pdf_Resource_Extractor クラスを使用して既存のページを複製</title>
- <programlisting language="php"><![CDATA[
- $extractor = new Zend_Pdf_Resource_Extractor();
- ....
- $page1 = $extractor->clonePage($pdf->pages[$templatePageIndex1]);
- $page2 = $extractor->clonePage($pdf->pages[$templatePageIndex2]);
- $page1->drawText('Some text...', $x, $y);
- $page2->drawText('Another text...', $x, $y);
- ...
- $pdf = new Zend_Pdf();
- $pdf->pages[] = $page1;
- $pdf->pages[] = $page2;
- ]]></programlisting>
- </example>
- </sect2>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|