PostScript でのドキュメント操作 | .NET
PSドキュメントの作成
Aspose.Page for .NETには、 PsDocumentクラスを作成するための2つのコンストラクターが用意されています。次のコードスニペットは、1ページのPSドキュメントを作成します。
 1// Create new multipaged PS document from scratch.
 2
 3string outputFileName = "document_out.ps";
 4
 5//Create save options
 6PsSaveOptions options = new PsSaveOptions();
 7//If you want to aassign page size other than A4, set page size in options
 8options.PageSize = PageConstants.GetSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT);
 9//If you want to aassign page margins other empty, set page margins in options
10options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_ZERO);
11//If you plan to use fonts that located in non system folders, set additional fonts folders in options
12options.AdditionalFontsFolders = new string[] { DataDir };
13
14//Set variable that indicates if resulting PostScript document will be multipaged
15bool multiPaged = false;
16
17// Create new multipaged PS Document with one page opened
18PsDocument document = new PsDocument(OutputDir + outputFileName, options, multiPaged);
19
20//Close current page
21document.ClosePage();
22//Save the document
23document.Save();PSドキュメントを複数ページに分割する場合は、multiPaged 変数を true に設定してください。
別のコンストラクタを使用すると、定義したページ数を持つ PsDocument オブジェクトを作成できます。
 1// Create new PS document with defined number of pages.
 2
 3string outputFileName = "document_out.ps";
 4
 5//Create save options
 6PsSaveOptions options = new PsSaveOptions();
 7//If you want to aassign page size other than A4, set page size in options
 8options.PageSize = PageConstants.GetSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT);
 9//If you want to aassign page margins other empty, set page margins in options
10options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_ZERO);
11//If you plan to use fonts that located in non system folders, set additional fonts folders in options
12options.AdditionalFontsFolders = new string[] { DataDir };
13
14// Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by OpenPage() method.
15PsDocument document = new PsDocument(OutputDir + outputFileName, options, 2);
16
17//Add the first page
18document.OpenPage();
19//Close current page
20document.ClosePage();
21//Save the document
22document.Save();PSドキュメントの操作については、 Java を参照してください。
適切なPostScriptドキュメントを作成するためのオプションをカプセル化した PsSaveOptions クラスを見てみましょう。
- SaveFormat はドキュメントの出力形式を指定します。PSまたはEPSを指定できます。Aspose.Pageライブラリでは、これら2つの形式の違いはPostScriptコメントとファイル拡張子にのみ反映されます。 また、EPSファイルの仕様に従い、EPSファイルは1ページである必要があります。デフォルトではPS形式が使用されます。 
- PageSize はPSドキュメントのページサイズを指定します。ただし、必要に応じてページごとに異なるページサイズを割り当てることができます。ページ サイズは、次の例のように PageConstants クラスから取得できます。 
1options.PageSize = PageConstants.GetSize(PageConstants.SIZE_International, PageConstants.ORIENTATION_PORTRAIT);デフォルトのページサイズは「A4」で、印刷方向は「縦」です。
- Margins は、ページ境界とページコンテンツの左、上、右、下の端の間の空白領域を指定します。これは PageConstants クラスから取得できます。
1options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_SMALL); // 20 points for each marginデフォルトの余白は「ゼロ」(0, 0, 0, 0)です。
- BackGroundColor はページの背景色を指定します。以下の値を指定できます。
1options.BackgroundColor = Color.FromArgb(211, 8, 48);または:
1options.BackgroundColor = Color.Yellow;Linux、macOS、その他のWindows以外のオペレーティングシステムでは、 Aspose.Page.Drawing NuGetパッケージをご利用いただけます。このパッケージは、System.Drawingシステムライブラリではなく、Aspose.Drawingバックエンドを使用します。
そのため、System.Drawing名前空間ではなく、Aspose.Page.Drawing名前空間をインポートしてください。上記のコードスニペットでは、System.Drawing.Colorではなく、Aspose.Page.Drawing.Colorが使用されます。GitHubのコード例には、必要な置換がすべて含まれています。
デフォルト値は「null」で、背景なしを意味します。
- EmbedFonts は、PsDocumentをファイルに保存する際の動作を制御します。「false」の場合、使用されているフォントはPSファイルに書き込まれません。この場合、ターゲットホストのシステムフォルダーに使用されているフォントが見つからない場合、PostScriptインタープリターはエラーをスローします。 
- EmbedFontsAs は、PSファイルへのフォントの埋め込み方法を制御します。現時点では、TrueTypeとType3フォント形式の2つの方法が利用可能です。値は、 FontConstants クラスを使用して、次のように設定できます。 
1options.EmbedFontsAs = FontsConstants.EMBED_FONTS_TYPE3Linux、macOS、その他のWindows以外のオペレーティングシステムでは、 Aspose.Page.Drawing NuGetパッケージをご利用いただけます。このパッケージは、System.Drawingシステムライブラリではなく、Aspose.Drawingバックエンドを使用します。
そのため、System.Drawing名前空間ではなく、Aspose.Page.Drawing名前空間をインポートしてください。上記のコードスニペットでは、System.Drawing.Colorではなく、Aspose.Page.Drawing.Colorが使用されます。GitHubのコード例には、必要な置換がすべて含まれています。
デフォルト値は「TrueType」です。
- JpegQualityLevel は、生成されるPSドキュメントにおける画像の圧縮/品質レベルを指定します。品質を高く設定するほど圧縮率は低くなり、逆に品質を低く設定するほど圧縮率は低くなります。最小品質は 0、最大品質は 100 です。デフォルトは 75 です。 
- AdditionalFontsFolder は、フォントを見つける場所を指定します。システム フォント フォルダーはデフォルトで常に含まれます。 
- デバッグ では、デバッグ情報をコンソールに出力できます。デフォルト値は false です。 
サンプルとデータ ファイルは GitHub からダウンロードできます。
