Merge PostScript files to PDF using Python
You can check the quality of Aspose.Page PS Merger and view the results via free online PostScipt Merger
Take the next easy steps to combine several PS files into a single PDF via Python:
- Initialize an input stream for the first input PS file.
- Initialize an output stream for output PDF document.
- Create an array of PS files that will be merged with the first one.
- Create an instance of PsDocument from the previously created input stream.
- Use PdfSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
- Create an instance of PdfDevice from created earlier output stream.
- Merge PostScript files with created document and save it as PDF with PDF save options.
The following code snippet shows how to merge PS files to PDF document in Python:
1# For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Python
2
3from aspose.page.eps import *
4from aspose.page.eps.device import *
5from util import Util
6###############################################
7###### Class and Method declaration here ######
8###############################################
9
10# The path to the documents directory.
11data_dir = Util.get_data_dir_working_with_document_merging()
12# Initialize PDF output stream
13pdf_stream = open(data_dir + "outputPDF_out.pdf", "wb")
14# Initialize the first PostScript file input stream
15ps_stream = open(data_dir + "input.ps", "rb",)
16document = PsDocument(ps_stream)
17
18# Create an array of PostScript files that will be merged with the first one
19files_for_merge = [ data_dir + "input2.ps", data_dir + "input3.ps" ]
20
21# If you want to convert Postscript file despite of minor errors set this flag
22suppress_errors = True
23
24#Initialize options object with necessary parameters.
25options = PdfSaveOptions(suppress_errors)
26# If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
27options.additional_fonts_folders = [ """{FONT_FOLDER}""" ]
28
29# Default page size is 595x842 and it is not mandatory to set it in PdfDevice
30device = PdfDevice(pdf_stream)
31# But if you need to specify size and image format use following line
32#Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new aspose.pydrawing.Size(595, 842));
33
34try:
35 document.merge(files_for_merge, device, options)
36finally:
37 ps_stream.close()
38 pdf_stream.close()
Let’s consider
PdfSaveOptions. Using this class we can assign different conversion parameters while merging PS files to PDF.
- AdditionalFontsFolder specifies locations where the converter can find additional fonts. By default, system fonts folders are always included.
- SuppressError controls the behavior of the EPS to PDF merger when non-critical errors occur. If set to true, it allows the merging process to continue, and a list of such errors can be viewed in the Exceptions field after merging. The default value is true.
- Debug allows the output of debug information to the console. By default, it is set to false.