PostScript でのドキュメント操作 | .NET

Contents
[ Hide Show ]

PSドキュメントの作成

Aspose.Page for .NETには、 PsDocumentクラスを作成するための2つのコンストラクターが用意されています。次のコードスニペットは、1ページのPSドキュメントを作成します。

 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    //If you want to assign page size other than A4, set page size in options
 7    options.PageSize = PageConstants.GetSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT);
 8    //If you want to assign page margins other than empty, set page margins in options
 9    options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_ZERO);
10    //If you plan to use fonts that are located in non system folders, set additional fonts folders in options
11    options.AdditionalFontsFolders = new string[] { dir };
12
13    //Set variable that indicates if resulting PostScript document will be multipaged
14    bool multiPaged = false;
15
16    // Create new multipaged PS Document with one page opened
17    PsDocument document = new PsDocument(outPsStream, options, multiPaged);
18
19    //Close current page
20    document.ClosePage();
21    //Save the document
22    document.Save();
23}

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}

PSドキュメントの操作については、 Java を参照してください。

適切なPostScriptドキュメントを作成するためのオプションをカプセル化した PsSaveOptions クラスを見てみましょう。

1options.PageSize = PageConstants.GetSize(PageConstants.SIZE_International, PageConstants.ORIENTATION_PORTRAIT);

デフォルトのページサイズは「A4」で、印刷方向は「縦」です。

1options.Margins = PageConstants.GetMargins(PageConstants.MARGINS_SMALL); // 20 points for each margin

デフォルトの余白は「ゼロ」(0, 0, 0, 0)です。

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」で、背景なしを意味します。

1options.EmbedFontsAs = FontsConstants.EMBED_FONTS_TYPE3

Linux、macOS、その他のWindows以外のオペレーティングシステムでは、 Aspose.Page.Drawing NuGetパッケージをご利用いただけます。このパッケージは、System.Drawingシステムライブラリではなく、Aspose.Drawingバックエンドを使用します。

そのため、System.Drawing名前空間ではなく、Aspose.Page.Drawing名前空間をインポートしてください。上記のコードスニペットでは、System.Drawing.Colorではなく、Aspose.Page.Drawing.Colorが使用されます。GitHubのコード例には、必要な置換がすべて含まれています。

デフォルト値は「TrueType」です。

サンプルとデータ ファイルは GitHub からダウンロードできます。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.