PostScript でのページ操作 | .NET
Contents
[
Hide
Show
]PSドキュメントにページを追加する
Aspose.Page for .NETでは、 PsDocument オブジェクトにページを追加する方法が2つあります。
以下のコードスニペットは、8つのステップで2ページのPSドキュメントを作成します。
- 出力されたPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptions オブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、2ページのPsDocumentを作成します。
- ドキュメントのデフォルトのページサイズ(A4縦向き)で1ページ目を開きます。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。
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.Debug = true;
8
9// Create new 2-paged PS Document
10PsDocument document = new PsDocument(OutputDir + outputFileName, options, 2);
11
12//Add the first page
13document.OpenPage();
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();PSドキュメントのページ操作については、 Java を参照してください。
以下のコードスニペットも2ページのPSドキュメントを作成しますが、7つのステップが必要です。
- 生成されたPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptionsオブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、複数ページのPsDocumentを作成します。この場合、最初のページは既に開かれており、そのサイズはドキュメントのデフォルトのページサイズ(A4縦向き)です。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。
この方法でページを追加する方法は、ドキュメントが 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 9bool multiPaged = true; 10 11// Create new multipaged PS Document with one page opened 12PsDocument document = new PsDocument(OutputDir + 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();
サンプルとデータ ファイルは GitHub からダウンロードできます。