Convert PS, EPS, and XPS
Unlock unparalleled convenience and efficiency as you convert your PostScript (PS), Encapsulated PostScript (EPS), XML Paper Specification (XPS), and Open XML Paper Specification (OXPS) files into popular image formats such as JPEG, PNG, TIFF, and more with Aspose.Page API Solution for Python
Introducing our cutting-edge API for Python, the ultimate solution for effortlessly converting PS, EPS, XPS, and OXPS files to a variety of image formats and PDFs. With our powerful converter, you can seamlessly transform your documents into high-quality images or PDFs, all with just a few lines of code.
For PS and EPS formats, the API supports PostScript operators ranging from Levels 1 to 3, along with most EPS header comments. It seamlessly transforms PostScript documents, ensuring maximum compliance with only a few exceptions, such as font cases, where the API handles fonts like Times New Roman.
Furthermore, for XPS file transformations, the API enables you to add or remove pages, manipulate canvases, paths, and glyph elements, create vector graphics shapes and text strings, convert XPS outline items, and more.
Our Python API solution facilitates the programmatic conversion of files in PDL formats such as PS, EPS, and XPS. However, you may also find it beneficial to explore and experiment with cross-platform development using these native APIs. With comprehensive documentation and support, getting started is a breeze, even for developers new to file conversion tasks. Don’t let file formats stand in the way of your productivity. Elevate your document management capabilities today with our API for Python converter.
PostScript to PDF Conversion via Python.
To convert PostScript PS and Encapsulated PostScript EPS files to PDF via Python API you need to take the next steps:
- Initialize an input stream for input PS file.
- Initialize an output stream for the output PDF document.
- Create an instance of PsDocument from the created input stream.
- Use PdfSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
- Create an instance of PdfDevice from created earlier output stream.
- Save PostScript document as PDF with PDF save options.
Let’s consider PdfSaveOptions. Using this class we can assign different conversion parameters while converting PS to PDF.
- AdditionalFontsFolder specifies locations where to find fonts. System font folders are always included by default.
- SuppressError controls the behavior of the PS to PDF converter when non-critical errors appear. If the value is true then it is possible to view a list of such errors after conversion in the Exceptions field. The default value is true.
- Debug allows the output of debug information to the console. The default value is false.
Python Code to convert PS EPS to PDF
# The following lines must be uncommented and place at the beginning of Python source file
# from aspose.page.eps import *
# from aspose.page.eps.device import *
# The path to the documents directory.
data_dir = Util.get_data_dir_working_with_document_conversion()
# Initialize PsDocument with the input PostScript file.
document = PsDocument(data_dir + "inputForImage.ps")
# If you want to convert Postscript file despite of minor errors set this flag
suppress_errors = True
#Initialize options object with necessary parameters.
options = PdfSaveOptions(suppress_errors)
# If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.additional_fonts_folders = [ """{FONT_FOLDER}""" ]
# Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
# But if you need to specify sizeuse following line
# PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Aspose.Page.Drawing.Size(595x842));
# or
# saveOptions.Size = new Aspose.Page.Drawing.Size(595, 842);
# Save document as PDF
document.save_as_pdf(data_dir + "outputPDF_out.pdf", options)
PostScript to Images Conversion via Python.
For any EPS/PS PostScript to image converter application, the following Python code works well, so take the next steps:
- Initialize input stream with PS source file.
- Create an instance of PsDocument from the created input stream.
- Use ImageSaveOptions to specify AdditionalFontsFolder and SuppressError etc.
- Create an instance of ImageDevice object for specifying an image type and size if needed.
- Save PS/EPS file as and image with an image save options as an array of arrays of bytes. One array of bytes for one page of an input file.
- Save resulting 2-dimensional arrays of bytes to EMF files creating for every bytes array a new file output stream
The ImageSaveOptions are the same as for PS to PDF Conversion.
Python Code for PostScript to Images Conversion
# The following lines must be uncommented and place at the beginning of Python source file
# import aspose
# from aspose.page.eps import *
# from aspose.page.eps.device import *
# import os
# The path to the documents directory.
data_dir = Util.get_data_dir_working_with_document_conversion()
# Initialize an image format
image_format = aspose.page.drawing.imaging.ImageFormat.png
# Initialize PsDocument with the PostScript file
document = PsDocument(data_dir + "inputForImage.ps")
# If you want to convert the Postscript file despite of minor errors set this flag
suppress_errors = True
# Initialize the options object with the necessary parameters.
# Default image size is 595x842 and it is not mandatory to set it in ImageDevice
options = ImageSaveOptions(image_format, suppress_errors)
# But if you need to specify size use constructor with two parameters
# options = ImageSaveOptions(new aspose.page.drawing.Size(595, 842), image_format, suppress_errors)
# If you want to add a special folder where fonts are stored. Default fonts folder in OS is always included.
# options.additional_fonts_folders = [ """{FONT_FOLDER}""" ]
# Save PS document as array of image bytes, one bytes array for one page.
images_bytes = document.save_as_image(options)
i = 0
for image_bytes in images_bytes:
image_path = os.path.abspath(data_dir + "out_image" + str(i) + ".png")
with open(image_path, "wb") as fs:
fs.write(image_bytes[0:0+len(image_bytes)])
i += 1
Convert XPS to Images JPG, PNG, BMP via Python.
Python API deals XPS format that is used for representing page layout. In any scenario, whenever there is a need to convert XPS to images BMP, JPG, PNG, and TIFF programmatically, the following code can easily be integrated within the Python application.
- Initialize an input stream for the input XPS document.
- Create an instance of XpsDocument from the created earlier input stream.
- Specify SmoothingMode, Resolution, and other options of PngSaveOptions .
- Create an instance of ImageDevice .
- Save resulting 2-dimensional arrays of bytes to BMP files creating for every byte array a new file output stream.
Let’s consider ImageSaveOptions. Using this class we can assign different conversion parameters while converting XPS to BMP.
- SmoothingMode assigns a degree of smoothing for lines, curves, and edges of filled areas, which may be AntiAlias, HighQuality, HighSpeed, and Default (none). The default value is HighQuality.
- Resolution controls the resolution of the resulting image. The default value is 96.
- TextRenderingHint assigns the quality of text rendering, which may be AntiAlias, AntiAliasGridFit, ClearTypeGridFit, SingleBitPerPixel, SingleBitPerPixelGridFit, SystemDefault. The default value in XPS to BMP conversion is AntiAliasGridFit.
- InterpolationMode defines an algorithm that is used when scaling or/and rotating an image, which may be Bicubic, Bilinear, High, HighQualityBicubic, HighQualityBilinear, Low, NearestNeighbor, and Default. The default value is HighQualityBicubic.
- PageNumbers represents an array of numbers of pages that will be saved to BMP.
Python Code for XPS to Image(.png) Conversion
# The following lines must be uncommented and place at the beginning of Python source file
# import aspose
# from aspose.page.xps import *
# from aspose.page.xps.presentation.image import *
# import os
# The path to the documents directory.
data_dir = Util.get_data_dir_working_with_document_conversion()
# Load XPS document
document = XpsDocument(dataDir + "input.xps", XpsLoadOptions())
# Initialize the options object with the necessary parameters.
options = PngSaveOptions()
options.smoothing_mode = aspose.pydrawing.drawing2d.SmoothingMode.HIGH_QUALITY
options.resolution = 300
options.page_numbers = [ 1, 2, 6 ]
# Save XPS document to the images byte arrays. The first dimension is for inner documents
# and the second one is for pages within inner documents.
imagesBytes = document.save_as_image(options)
# Iterate through document partitions (fixed documents, in XPS terms)
for i in range(len(imagesBytes)):
# Iterate through partition pages
for j in range(len(imagesBytes[i])):
# Initialize image output stream
with open(os.path.splitext(output_file_name)[0] + "_" + str(i + 1) + "_" + str(j + 1) +
os.path.splitext(output_file_name)[1], "wb") as image_stream:
# Write image
image_stream.write(imagesBytes[i][j][0:0+len(imagesBytes[i][j])])
Convert XPS to PDF via Python.
The process of converting XPS to PDF documents programmatically is simple having high fidelity results among the input and output files.
- Initialize an input stream for the input XPS document.
- Initialize an output stream for output PDF document.
- Create an instance of XpsDocument from the created earlier input stream.
- Specify TextCompression, ImageCompression, JpegQualityLevel, and other options of PdfSaveOptions .
- Save the XPS document as a PDF with PDF save options.
Let’s consider PdfSaveOptions. Using this class we can assign different conversion parameters while converting XPS to PDF.
- JpegQualityLevel controls the quality of images in PDF documents if the ImageCompression algorithm is JPEG and can be from 0 to 100.
- ImageCompression algorithm encapsulated in PdfImageCompression Enumeration may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW) with base or optimized predictor, JPEG, none (raw image bytes) and auto (the most appropriate compression for each image). The default is auto compression.
- TextCompression algorithm encapsulated in PdfTextCompression Enumeration may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW), and none. The default value in XPS to PDF conversion is Flate.
- EncryptionDetails encapsulated in PdfEncryptionDetails . It allows setting encryption algorithms, permissions, and owner and user passwords for PDF documents.
- PageNumbers represents an array of numbers of pages that will be saved to PDF.
- OutlineTreeExpansionLevel and OutlineTreeHeight control view of the document outline.
Python Code for XPS to PDF Conversion
# The following lines must be uncommented and place at the beginning of Python source file
# from aspose.page.xps import *
# from aspose.page.xps.presentation.pdf import *
# The path to the documents directory.
data_dir = Util.get_data_dir_working_with_document_conversion()
# Load an XPS document
document = XpsDocument(data_dir + "input.xps", XpsLoadOptions())
# Initialize an options object with the necessary parameters.
options = PdfSaveOptions()
options.jpeg_quality_level = 100
options.image_compression = PdfImageCompression.JPEG
options.text_compression = PdfTextCompression.FLATE
options.page_numbers = [1, 2, 6]
# Save document as PDF
document.save_as_pdf(pdf_stream, options)
FAQ
1. Can I convert Postscript with this API solution?
Aspose.Page has functionality that allows you to convert PS, XPS, and EPS files to other formats online or programmatically. If you need to transform your files instantly online you may like to use Page Description Language format files Converter cross-platform application.
2. What Page description Languages are supported by the converter?
This conversion functionality supports files with .ps, .eps, and .xps extensions. Such famous PDLs as PDF and SVG are represented as separate solutions in Aspose.products
3. Is the functionality free?
The cross-platform converters are free, when for the API solution you can get a free Trial and then buy the product if needed.
Support and Learning Resources
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Release Notes
- Why Aspose.Page for Python?
- Customers List
- Success Stories