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// Add page to PS document.
 2
 3String outputFileName = "document1_out.ps";
 4
 5//Create save options with A4 size
 6PsSaveOptions options = new PsSaveOptions();
 7options.setDebug(true);
 8
 9// Create new 2-paged PS Document
10PsDocument document = new PsDocument(getOutputDir() + outputFileName, options, 2);
11
12//Add the first page
13document.openPage(null);
14
15//Add content
16
17//Close the first page
18document.closePage();
19
20//Add the second page with different size
21document.openPage(400, 700);
22
23//Add content
24
25//Close the second page
26document.closePage();
27
28//Save the document
29document.save();
Example-AddPagePS1.java hosted with ❤ by GitHub

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

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

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

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.