使用 .NET 将 EPS 文件合并为 PDF
您可以通过免费在线工具 EPS 合并器
Aspose.Page for .NET EPS 合并器允许使用 .NET 平台支持的任何语言(例如 C#、VB 和 J#)将封装的 PostScript (EPS) 文件合并为 PDF 文档。
执行 EPS 合并需要执行以下几个步骤:
- 创建一个
PsDocument实例,将第一个 EPS 文件的路径传递给其构造函数,该构造函数会加载要合并的 EPS 内容。 - 定义一个字符串数组,其中包含要合并的其他 EPS 文件的文件路径,例如
string[] epsFiles = { "second.eps", "third.eps" };。 - 实例化
PdfSaveOptions,将AdditionalFontsFolder设置为包含自定义字体的文件夹,并可选地设置SuppressError = true以收集非关键错误。 - 调用
document.AddPage(epsFiles);(或使用适当的合并方法),然后调用document.Save("merged.pdf", pdfSaveOptions);以生成单个 PDF。 - 当
SuppressError为 true 时,任何警告都会存储在document.Exceptions中;您可以在保存后迭代此集合以查看问题。
以下代码片段展示了如何在 C# 中将 EPS 文件合并为 PDF 文档:
1/ For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2// The path to the documents directory.
3string dataDir = RunExamples.GetDataDir_WorkingWithDocumentMerging();
4// Initialize PS document with the first EPS file
5PsDocument document = new PsDocument(dataDir + "input.eps");
6
7// Create an array of PostScript files that will be merged with the first one
8string[] filesForMerge = new string[] { dataDir + "input2.eps", dataDir + "input3.eps" };
9
10// If you want to convert Postscript file despite of minor errors set this flag
11bool suppressErrors = true;
12
13//Initialize options object with necessary parameters.
14PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
15// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
16options.AdditionalFontsFolders = new string[] { @"{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
22document.MergeToPdf(dataDir + "outputPDF_out.pdf", filesForMerge, options);
23
24//Review errors
25if (suppressErrors)
26{
27 foreach (Exception ex in options.Exceptions)
28 {
29 Console.WriteLine(ex.Message);
30 }
31}我们来看一下 PdfSaveOptions。使用此类,我们可以在将 EPS 合并为 PDF 时指定不同的转换参数。
- Size 指定结果文档的页面大小。
- AdditionalFontsFolder 指定字体的保存位置。默认情况下,始终包含系统字体文件夹。
- SuppressError 控制出现非关键错误时 EPS 合并的行为。如果值为 true,则可以在合并后在 Exceptions 字段中查看此类错误列表。默认值为 true。
- Debug 允许将调试信息输出到控制台。默认值为 false。