PSファイル内のページ操作 | Java
Contents
[
Hide
Show
]PSドキュメントにページを追加する
Aspose.Page for Javaでは、
PsDocumentオブジェクトにページを追加する方法が2つあります。
以下のコードスニペットは、8つのステップで2ページのPSドキュメントを作成します。
- 出力されたPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptionsオブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、2ページのPsDocumentを作成します。
- ドキュメントのデフォルトのページサイズ(A4縦向き)で1ページ目を開きます。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。
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つです。
- 出力先のPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptionsオブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、複数ページのPsDocumentを作成します。この場合、最初のページは既に開かれており、そのサイズはドキュメントのデフォルトのページサイズ(A4縦向き)です。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。 このページ追加方法は、ドキュメントが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.