In my previous post, I have shown you how easy it is to create or edit PostScript (PS/EPS) and XPS documents programmatically using Aspose.Page for C++. In this article, I’ll demonstrate how to convert PS/EPS or XPS documents to PDF or raster image formats including PNG, JPEG, TIFF, and BMP using C++. The rest of the article is composed of the following sections:
- Convert a PostScript PS/EPS to PDF in C++
- Convert a PostScript PS/EPS to Image in C++
- Convert XPS to PDF in C++
- Convert XPS to image in C++
Before we start, I assume that you have downloaded Aspose.Page for C++ and referenced it in your C++ project. However, if you haven’t, you can get it installed from NuGet or download the complete package along with a plug and play console application from the Downloads section.
Convert a PostScript PS/EPS to PDF in C++
The following are the steps to convert a PostScript PS/EPS document to PDF:
- Create a FileStream object for the output PDF file.
- Load the input PostScript document in a FileStream object.
- Create and initialize the PsDocument object with the input stream.
- Create and initialize the PdfDevice object with the output stream.
- Process the document and save it as a PDF file using the PsDocument->Save method.
The following code sample shows how to convert a PostScript PS document to PDF in C++.
Convert a PostScript PS/EPS to Image in C++
The following are the steps to convert PS/EPS to an image format.
- Create an object of ImageFormat to set the format of the output image, i.e. PNG.
- Load the input PostScript document in a FileStream object.
- Create and initialize the PsDocument object with the input stream.
- Create an object of ImageDevice.
- Process the document and save it as an image using the PsDocument->Save method.
The following code sample shows how to convert PostScript PS/EPS to image in C++.
Convert an XPS to PDF in C++
The following are the steps to convert an XPS document to PDF:
- Create FileStream objects for input XPS and output PDF files.
- Load the XPS document stream into an XpsDocument object.
- Create an object of the PdfDevice class and initialize it with the output stream.
- Convert the XPS document to PDF using the XpsDocument->Save method.
The following code sample shows how to convert the XPS document to PDF in C++.
Convert an XPS to Image in C++
The following are the steps to convert an XPS document to raster image formats:
- Load the input XPS document into a FileStream object.
- Create an object of XpsDocument and initialize it with the input stream object.
- Set the save options by creating an object of the PngSaveOptions class.
- Convert XPS to image using XpsDocument->Save method.
The following code sample shows how to convert XPS to PNG image in C++.
For converting the XPS document to BMP, TIFF, and JPEG, please visit the following article.
Learn more about Aspose.Page for C++
In this article, you have seen how to convert PS, EPS and XPS document to PDF, PNG, JPEG, TIFF, and BMP using C++. You can learn more about Aspose.Page for C++ using the documentation and the source code examples.