在 PS 文件中处理文档 | Java

Contents
[ Hide Show ]

创建 PS 文档

Aspose.Page for Java 提供了两个构造函数来创建 PsDocument 类。以下代码片段用于创建一个单页 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.setPageSize(PageConstants.getSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT));
 9//If you want to aassign page margins other empty, set page margins in options
10options.setMargins(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.setAdditionalFontsFolders(new String[] { getDataDir() });
13
14//Set variable that indicates if resulting PostScript document will be multipaged
15boolean multiPaged = false;
16
17// Create new multipaged PS Document with one page opened
18PsDocument document = new PsDocument(getOutputDir() + 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.setPageSize(PageConstants.getSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT));
 9//If you want to aassign page margins other empty, set page margins in options
10options.setMargins(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.setAdditionalFontsFolders(new String[] { getDataDir() });
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(getOutputDir() + outputFileName, options, 2);
16
17//Add the first page
18document.openPage(null);
19//Close current page
20document.closePage();
21//Save the document
22document.save();

请参阅在 .NET 中使用 PS 文档。

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

1options.setPageSize(PageConstants.getSize(PageConstants.SIZE_International, PageConstants.ORIENTATION_PORTRAIT));

默认页面尺寸为“纵向”方向的“A4”。

1options.setMargins(PageConstants.getMargins(PageConstants.MARGINS_SMALL)); // 20 points for each margin

默认边距为“零”(0, 0, 0, 0)。

1options.setBackgroundColor(new Color(211, 8, 48));

或:

1options.setBackgroundColor(Color.YELLOW);

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

1options.setEmbedFontsAs(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.