在 PostScript 中处理文档 | .NET

Contents
[ Hide Show ]

创建 PS 文档

Aspose.Page for .NET 提供了两个构造函数来创建 PsDocument 类。以下代码片段用于创建一个单页 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}

请参阅在 Java 中处理 PS 文档。

让我们看一下 PsSaveOptions 类,它封装了有助于创建正确 PostScript 文档的可用选项。

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 包。它使用 Aspose.Drawing 后端,而不是 System.Drawing 系统库。

因此,请导入 Aspose.Page.Drawing 命名空间,而不是 System.Drawing 命名空间。在上述代码片段中,将使用 Aspose.Page.Drawing.Color 代替 System.Drawing.Color。我们在 GitHub 上的代码示例包含所有必要的替换。

默认值为“null”,表示无背景。

1options.EmbedFontsAs = FontsConstants.EMBED_FONTS_TYPE3

默认值为“TrueType”。

您可以从 GitHub 下载示例和数据文件。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.