PostScript でのページ操作 | C++
Contents
[
Hide
Show
]PSドキュメントにページを追加する
Aspose.Page for C++ では、 PsDocument オブジェクトにページを追加する方法が2つあります。
以下のコードスニペットは、8つのステップで2ページのPSドキュメントを作成します。
- 出力されたPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptions オブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、2ページのPsDocumentを作成します。
- ドキュメントのデフォルトのページサイズ(A4縦向き)で1ページ目を開きます。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。
1 // The path to the documents directory.
2 System::String dataDir = RunExamples::GetDataDir_WorkingWithPages();
3
4 //Create output stream for PostScript document
5 {
6 System::SharedPtr<System::IO::Stream> outPsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"document1.ps", System::IO::FileMode::Create);
7 // Clearing resources under 'using' statement
8 System::Details::DisposeGuard<1> __dispose_guard_0({ outPsStream});
9 // ------------------------------------------
10
11 try
12 {
13 //Create save options with A4 size
14 System::SharedPtr<PsSaveOptions> options = System::MakeObject<PsSaveOptions>();
15
16 // Create new 2-paged PS Document
17 System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(outPsStream, options, 2);
18
19 //Add the first page
20 document->OpenPage();
21
22 //Add content
23
24 //Close the first page
25 document->ClosePage();
26
27 //Add the second page with different size
28 document->OpenPage(400.0f, 700.0f);
29
30 //Add content
31
32 //Close the second page
33 document->ClosePage();
34
35 //Save the document
36 document->Save();
37 }
38 catch(...)
39 {
40 __dispose_guard_0.SetCurrentException(std::current_exception());
41 }
42 }
以下のコードスニペットも2ページのPSドキュメントを作成しますが、手順は7つです。
- 出力先のPSファイル用の出力ストリームを作成します。
- デフォルトのオプションで PsSaveOptionsオブジェクトを作成します。
- 既に作成済みの出力ストリームと保存オプションを使用して、複数ページのPsDocumentを作成します。この場合、最初のページは既に開かれており、そのサイズはドキュメントのデフォルトのページサイズ(A4縦向き)です。
- ページを閉じます。
- 新しいサイズで2ページ目を開きます。
- ページを閉じます。
- ドキュメントを保存します。 このページ追加方法は、ドキュメントが1ページの場合、または1ページか2ページのどちらになるかわからない場合に便利です。
1 // The path to the documents directory.
2 System::String dataDir = RunExamples::GetDataDir_WorkingWithPages();
3
4 //Create output stream for PostScript document
5 {
6 System::SharedPtr<System::IO::Stream> outPsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"document2.ps", System::IO::FileMode::Create);
7 // Clearing resources under 'using' statement
8 System::Details::DisposeGuard<1> __dispose_guard_0({ outPsStream});
9 // ------------------------------------------
10
11 try
12 {
13 //Create save options with A4 size
14 System::SharedPtr<PsSaveOptions> options = System::MakeObject<PsSaveOptions>();
15
16 //Set variable that indicates if resulting PostScript document will be multipaged
17 bool multiPaged = true;
18
19 // Create new multipaged PS Document with one page opened
20 System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(outPsStream, options, multiPaged);
21
22 //Add content
23
24 //Close the first page
25 document->ClosePage();
26
27 //Add the second page with different size
28 document->OpenPage(500.0f, 300.0f);
29
30 //Add content
31
32 //Close the second page
33 document->ClosePage();
34
35 //Save the document
36 document->Save();
37 }
38 catch(...)
39 {
40 __dispose_guard_0.SetCurrentException(std::current_exception());
41 }
42 }
サンプルとデータ ファイルは GitHub からダウンロードできます。