使用 Python 将 EPS 文件合并为 PDF

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

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

Aspose.Page for Python via .NET EPS Merger 可以在任何运行 Python 虚拟机的操作系统上将封装的 PostScript (EPS) 文件合并为 PDF 文档。

要执行 EPS 到 PDF 的合并,需要执行以下几个步骤:

  1. 为第一个输入 EPS 文件初始化输入流。
  2. 为输出 PDF 文档初始化输出流。
  3. 创建一个要与第一个 EPS 文件合并的 EPS 文件数组。
  4. 从先前创建的输入流创建 PsDocument 实例。
  5. 使用 PdfSaveOptions 指定 AdditionalFontsFolderSuppressError 布尔值。
  6. 从之前创建的输出流创建 PdfDevice 实例。
  7. 将 EPS 文件与创建的文档合并,并使用指定的 PDF 保存选项将其保存为 PDF。


以下代码片段演示了如何使用 Python 将 EPS 文件合并为 PDF 文档:

 1# For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Python
 2
 3# The path to the documents directory.
 4data_dir = Util.get_data_dir_working_with_document_merging()
 5# Initialize a PDF output stream
 6pdf_stream = open(data_dir + "outputPDF_out.pdf", "wb")
 7# Initialize the first PostScript file input stream
 8ps_stream = open(data_dir + "input.eps", "rb",)
 9document = PsDocument(ps_stream)
10
11# Create an array of PostScript files that will be merged with the first one
12files_for_merge = [ data_dir + "input2.eps", data_dir + "input3.eps" ]
13
14# If you want to convert the Postscript file despite of minor errors set this flag
15suppress_errors = True
16
17# Initialize options object with the necessary parameters.
18options = PdfSaveOptions(suppress_errors)
19# If you want to add a special folder where fonts are stored. Default fonts folder in OS is always included.
20options.additional_fonts_folders = [ """{FONT_FOLDER}""" ]
21
22# Default page size is 595x842 and it is not mandatory to set it in PdfDevice
23device = PdfDevice(pdf_stream)
24# But if you need to specify size and image format use following line
25#Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new aspose.pydrawing.Size(595, 842));
26
27try:
28    document.merge(files_for_merge, device, options)
29finally:
30    ps_stream.close()
31    pdf_stream.close()

请参阅 .NETJavaC++ 中的 EPS 合并。

我们来看一下 PdfSaveOptions,它允许我们在将 EPS 文件合并为 PDF 时设置各种转换参数。

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

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.