PostScript でのページ操作 | .NET
Contents
[
Hide
Show
]PSドキュメントにページを追加する
Aspose.Page for .NETでは、 PsDocument オブジェクトにページを追加する方法が2つあります。
以下のコードスニペットは、8つのステップで2ページのPSドキュメントを作成します。
- 出力されたPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptions オブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、2ページのPsDocumentを作成します。
- ドキュメントのデフォルトのページサイズ(A4縦向き)で1ページ目を開きます。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。
1//Create output stream for PostScript document
2using (Stream outPsStream = new FileStream(dataDir + "document1.ps", FileMode.Create))
3{
4 //Create save options with A4 size
5 PsSaveOptions options = new PsSaveOptions();
6
7 // Create new 2-paged PS Document
8 PsDocument document = new PsDocument(outPsStream, options, 2);
9
10 //Add the first page
11 document.OpenPage();
12
13 //Add content
14
15 //Close the first page
16 document.ClosePage();
17
18 //Add the second page with different size
19 document.OpenPage(400, 700);
20
21 //Add content
22
23 //Close the second page
24 document.ClosePage();
25
26 //Save the document
27 document.Save();
28}
PSドキュメントのページ操作については、 Java を参照してください。
以下のコードスニペットも2ページのPSドキュメントを作成しますが、7つのステップが必要です。
- 生成されたPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptionsオブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、複数ページのPsDocumentを作成します。この場合、最初のページは既に開かれており、そのサイズはドキュメントのデフォルトのページサイズ(A4縦向き)です。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。 この方法でページを追加する方法は、ドキュメントが 1 ページの場合、または 1 ページか 2 ページのドキュメントかどうか不明な場合に便利です。
1//Create an output stream for PostScript document
2using (Stream outPsStream = new FileStream(dataDir + "document2.ps", FileMode.Create))
3{
4 //Create save options with A4 size
5 PsSaveOptions options = new PsSaveOptions();
6
7 //Set variable that indicates if resulting PostScript document will be multipaged
8 bool multiPaged = true;
9
10 // Create new multipaged PS Document with one page opened
11 PsDocument document = new PsDocument(outPsStream, options, multiPaged);
12
13 //Add content
14
15 //Close the first page
16 document.ClosePage();
17
18 //Add the second page with different size
19 document.OpenPage(500, 300);
20
21 //Add content
22
23 //Close the second page
24 document.ClosePage();
25
26 //Save the document
27 document.Save();
28}
サンプルとデータ ファイルは GitHub からダウンロードできます。