使用 C++ 将 PostScript 文件合并为 PDF

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

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

Aspose.Page for C++ PS 合并器允许在 Windows 和 Linux 系统上将 PostScript (PS) 文件合并为 PDF 文档。
执行 PS 到 PDF 合并需要执行以下几个步骤:

  1. 从第一个 PostScript 文件创建 PsDocument 实例。
  2. 创建一个将与第一个 PostScript 文件合并的 PS 文件数组。
  3. 使用 PdfSaveOptions 指定 AdditionalFontsFolderSuppressError 布尔值。
  4. 使用 MergeToPdf 将 PS 文件与创建的文档合并,并使用 PDF 保存选项将其保存为 PDF。
  5. 如果 SuppressErrors 值为 true(默认情况下),则可以查看将 PostScript 文件合并为 PDF 文档时引发的错误,并将其保存在 Exceptions 列表中。


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

 1    // The path to the documents directory.
 2    System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentMerging();
 3    
 4    // Initialize PS document with the first PostScript file
 5    System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.ps");
 6    
 7    // Create an array of PostScript files that will be merged with the first one
 8    System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir + u"input2.ps", dataDir + u"input3.ps"});
 9    
10    // If you want to convert Postscript file despite of minor errors set this flag
11    bool suppressErrors = true;
12    
13    //Initialize options object with necessary parameters.
14    System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
15    // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
16    options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"}));
17    
18    // Default page size is 595x842 and it is not mandatory to set it in SaveOptions
19    // But if you need to specify the page size following line
20    //PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Aspose.Page.Drawing.Size(595, 842));
21    
22    document->MergeToPdf(dataDir + u"outputPDF_out.pdf", filesForMerge, options);
23    
24    //Review errors
25    if (suppressErrors)
26    {
27        for (auto&& ex : System::IterateOver(options->get_Exceptions()))
28        {
29            System::Console::WriteLine(ex->get_Message());
30        }
31    }

请参阅 .NetJava 中的 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.

OSZAR »