PostScript でのドキュメント操作 | C++
PSドキュメントの作成
Aspose.Page for C++ には、 PsDocument クラスを作成するための2つのコンストラクターが用意されています。次のコードスニペットは、1ページのPSドキュメントを作成します。
1 // The path to the documents directory.
2 System::String dir = RunExamples::GetDataDir_WorkingWithDocument();
3
4 //Create output stream for PostScript document
5 {
6 System::SharedPtr<System::IO::Stream> outPsStream = System::MakeObject<System::IO::FileStream>(dir + u"document.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
14 System::SharedPtr<PsSaveOptions> options = System::MakeObject<PsSaveOptions>();
15 //If you want to aassign page size other than A4, set page size in options
16 options->set_PageSize(PageConstants::GetSize(PageConstants::SIZE_A4(), PageConstants::ORIENTATION_PORTRAIT()));
17 //If you want to aassign page margins other empty, set page margins in options
18 options->set_Margins(PageConstants::GetMargins(PageConstants::MARGINS_ZERO()));
19 //If you plan to use fonts that located in non system folders, set additional fonts folders in options
20 options->set_AdditionalFontsFolders(System::MakeArray<System::String>({dir}));
21
22 //Set variable that indicates if resulting PostScript document will be multipaged
23 bool multiPaged = false;
24
25 // Create new multipaged PS Document with one page opened
26 System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(outPsStream, options, multiPaged);
27
28 //Close current page
29 document->ClosePage();
30 //Save the document
31 document->Save();
32 }
33 catch(...)
34 {
35 __dispose_guard_0.SetCurrentException(std::current_exception());
36 }
37 }
PSドキュメントを複数ページに分割する場合は、multiPaged 変数を true に設定してください。
別のコンストラクタを使用すると、定義したページ数を持つ PsDocument オブジェクトを作成できます。
1//Create output stream for PostScript document
2using (Stream outPsStream = new FileStream(dir + "document.ps", FileMode.Create))
3{
4 //Create save options
5 PsSaveOptions options = new PsSaveOptions();
6
7 // Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by AddPage() method.
8 PsDocument document = new PsDocument(outPsStream, options, 2);
9
10 //Adding pages and it's content
11
12 //Save the document
13 document.Save();
14}
15 // The path to the documents directory.
16 System::String dir = RunExamples::GetDataDir_WorkingWithDocument();
17
18 //Create output stream for PostScript document
19 {
20 System::SharedPtr<System::IO::Stream> outPsStream = System::MakeObject<System::IO::FileStream>(dir + u"document.ps", System::IO::FileMode::Create);
21 // Clearing resources under 'using' statement
22 System::Details::DisposeGuard<1> __dispose_guard_0({ outPsStream});
23 // ------------------------------------------
24
25 try
26 {
27 //Create save options
28 System::SharedPtr<PsSaveOptions> options = System::MakeObject<PsSaveOptions>();
29
30 // Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by AddPage() method.
31 System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(outPsStream, options, 2);
32
33 //Adding pages and it's content
34
35 //Save the document
36 document->Save();
37 }
38 catch(...)
39 {
40 __dispose_guard_0.SetCurrentException(std::current_exception());
41 }
42 }
PSドキュメントの操作については、 Java を参照してください。
適切なPostScriptドキュメントを作成するためのオプションをカプセル化した PsSaveOptions クラスを見てみましょう。
SaveFormat はドキュメントの出力形式を指定します。PSまたはEPSを指定できます。Aspose.Pageライブラリでは、これら2つの形式の違いはPostScriptコメントとファイル拡張子にのみ反映されます。 また、EPSファイルの仕様に従い、EPSファイルは1ページである必要があります。デフォルトではPS形式が使用されます。
PageSize はPSドキュメントのページサイズを指定します。ただし、必要に応じてページごとに異なるページサイズを割り当てることができます。ページ サイズは、次の例のように PageConstants クラスから取得できます。
1 options->set_PageSize(PageConstants::GetSize(PageConstants::SIZE_International(), PageConstants::ORIENTATION_PORTRAIT()));
Tデフォルトのページサイズは「A4」で、印刷方向は「縦」です。
- Margins は、ページ境界とページコンテンツの左、上、右、下の端の間の余白を指定します。これは PageConstants クラスから取得できます。
1 options->set_Margins(PageConstants::GetMargins(PageConstants::MARGINS_SMALL())); // 20 points for each margin
デフォルトの余白は「ゼロ」(0, 0, 0, 0)です。
- BackGroundColor はページの背景色を指定します。以下の値を指定できます。
1 options->set_BackgroundColor(Color::FromArgb(211, 8, 48));
または:
1 options->set_BackgroundColor(System::Drawing::Color::get_Yellow());
デフォルト値は「null」で、背景なしを意味します。
EmbedFonts は、PsDocument をファイルに保存する際の動作を制御します。「false」の場合、使用されているフォントは PS ファイルに書き込まれません。この場合、PostScript インタープリターは、ターゲットホストのシステムフォルダーに使用されているフォントが見つからないとエラーをスローします。
EmbedFontsAs は、フォントを PS ファイルに埋め込む方法を制御します。現時点では、TrueType と Type3 フォント形式の 2 つの方法が機能します。値は、 FontConstants クラスを使用して、次のように設定できます。
1 options->set_EmbedFontsAs(FontsConstants::EMBED_FONTS_TYPE3);
デフォルト値は「TrueType」です。
JpegQualityLevel は、生成されるPSドキュメント内の画像の圧縮率/品質レベルを指定します。品質が高いほど圧縮率は低くなり、低いほど圧縮率は低くなります。最低品質は0、最高品質は100です。デフォルトは75です。
AdditionalFontsFolder は、フォントの検索場所を指定します。システムフォントフォルダは常にデフォルトで含まれます。
Debug は、デバッグ情報をコンソールに出力します。デフォルト値はfalseです。
サンプルとデータ ファイルは GitHub からダウンロードできます。