PSファイル内のページ操作 | Java

PSドキュメントにページを追加する

Aspose.Page for Javaでは、 PsDocumentオブジェクトにページを追加する方法が2つあります。
以下のコードスニペットは、8つのステップで2ページのPSドキュメントを作成します。

  1. 出力されたPSファイル用の出力ストリームを作成します。
  2. デフォルトのオプションで PsSaveOptionsオブジェクトを作成します。
  3. 既に作成済みの出力ストリームと保存オプションを使用して、2ページのPsDocumentを作成します。
  4. ドキュメントのデフォルトのページサイズ(A4縦向き)で1ページ目を開きます。
  5. ページを閉じます。
  6. 新しいサイズで2ページ目を開きます。
  7. ページを閉じます。
  8. ドキュメントを保存します。
 1//Create an output stream for PostScript document
 2FileOutputStream outPsStream = new FileOutputStream(dataDir + "AddPages1_outPS.ps");
 3//Create a save options with A4 size
 4PsSaveOptions options = new PsSaveOptions();
 5
 6// Create new 2-paged PS Document
 7PsDocument document = new PsDocument(outPsStream, options, 2);
 8
 9//Add the first page with the document's page size
10document.openPage(null);
11
12//Add content
13
14//Close the first page
15document.closePage();
16
17//Add the second page with the different size
18document.openPage(400, 700);
19
20//Add content
21
22//Close current page
23document.closePage();
24//Save the document
25document.save();

.NET での PS ドキュメントのページの操作を参照してください。

以下のコードスニペットも2ページのPSドキュメントを作成しますが、手順は7つです。

  1. 出力先のPSファイル用の出力ストリームを作成します。
  2. デフォルトのオプションで PsSaveOptionsオブジェクトを作成します。
  3. 既に作成済みの出力ストリームと保存オプションを使用して、複数ページのPsDocumentを作成します。この場合、最初のページは既に開かれており、そのサイズはドキュメントのデフォルトのページサイズ(A4縦向き)です。
  4. ページを閉じます。
  5. 新しいサイズで2ページ目を開きます。
  6. ページを閉じます。
  7. ドキュメントを保存します。 このページ追加方法は、ドキュメントが1ページの場合、または1ページか2ページのどちらになるかわからない場合に便利です。
 1//Create output stream for PostScript document
 2FileOutputStream outPsStream = new FileOutputStream(dataDir + "AddPages2_outPS.ps");
 3//Create save options with A4 size
 4PsSaveOptions options = new PsSaveOptions();
 5
 6//Set variable that indicates if resulting PostScript document will be multipaged
 7boolean multiPaged = true;
 8
 9// Create new multipaged PS Document with one page opened
10PsDocument document = new PsDocument(outPsStream, options, multiPaged);
11
12//Add content
13
14//Close the first page
15document.closePage();
16
17//Add the second page with the different size
18document.openPage(500, 300);
19
20//Add content
21
22//Close current page
23document.closePage();
24//Save the document
25document.save();

サンプルとデータファイルは以下からダウンロードできます。 GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.