使用 .NET 将 PostScript 文件合并为 PDF

您可以通过免费在线工具 PostScipt Merger

检查 Aspose.Page PS Merger 的质量并查看结果。

Aspose.Page for .NET PS Merger 允许使用 .NET 平台支持的任何语言(例如 C#、VB 和 J#)将 PostScript (PS) 文件合并为 PDF 文档。
执行 PS 合并需要执行以下几个步骤:

  1. 使用主 PS 文件初始化 PsDocument,例如 var document = new PsDocument("first.ps");
  2. 定义一个字符串数组,其中包含要合并的附加 PS 文件的路径,例如:
1string[] additionalPs = { "second.ps", "third.ps" };
  1. 创建 PdfSaveOptions 实例,可选地设置 AdditionalFontsFolder 并启用 SuppressError = true 以捕获非关键警告。
  2. 将每个附加 PS 文件添加到文档中(例如 foreach (var file in additionalPs) document.AddPage(file);),然后保存合并后的 PDF:
1document.Save("merged.pdf", pdfSaveOptions);
  1. SuppressError 为 true 时,所有警告都会存储在 document.Exceptions 中;保存后,您可以迭代此集合来查看问题。


以下代码片段展示了如何在 C# 中将 PS 文件合并为 PDF 文档:

 1// Merge several PS files to one PDF document.
 2
 3// Initialize PS document with the first PostScript file
 4PsDocument document = new PsDocument(DataDir + "input.ps");
 5
 6// Create an array of PostScript files that will be merged with the first one
 7string[] filesForMerge = new string[] { DataDir + "input2.ps", DataDir + "input3.ps" };
 8
 9// If you want to convert Postscript file despite of minor errors set this flag
10bool suppressErrors = true;
11
12//Initialize options object with necessary parameters.
13PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
14// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
15options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" };
16
17// Default page size is 595x842 and it is not mandatory to set it in SaveOptions
18// But if you need to specify the page size following line
19//PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Aspose.Page.Drawing.Size(595, 842));
20
21document.MergeToPdf(OutputDir + "outputPDF_out.pdf", filesForMerge, options);
22
23//Review errors
24if (suppressErrors)
25{
26    foreach (Exception ex in options.Exceptions)
27    {
28        Console.WriteLine(ex.Message);
29    }
30}
Example-MergePStoPDF.cs hosted with ❤ by GitHub

请参阅 JavaC++ 中的 PS 合并。

我们来看一下 PdfSaveOptions。使用此类,我们可以在将 PS 文件合并为 PDF 时指定不同的转换参数。

在我们的 PS Merger 上在线评估 PS 合并。

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.