Converting PostScript EPS or PS files to regular image formats is a common task that you may be required to do. If you have a large number of such files, it will be more efficient to convert them programmatically. In light of this, this article will teach you how to convert PostScript EPS/PS files to PNG or JPG image format using C++.
- C++ API for Converting PostScript EPS/PS Files to PNG or JPG Images
- Convert PostScript EPS/PS Files to PNG Image Format using C++
- Converting PostScript EPS/PS Files to JPG Image Format using C++
C++ API for Converting PostScript EPS/PS Files to PNG or JPG Images
Aspose.Page for C++ is a C++ library for rendering and manipulating XPS and PostScript files. You can use it to process and convert XPS and EPS/PS files to several other formats such as PDF, JPEG, BMP, TIFF, etc. You can either install the API through NuGet or download it directly from the downloads section.
PM> Install-Package Aspose.Page.Cpp
Convert PostScript EPS/PS Files to PNG Image Format using C++
The following are the steps to convert EPS or PS files to PNG image format.
- Initialize the PostScript input stream.
- Create an instance of the PsDocument class using the input stream.
- Instantiate an object of the ImageSaveOptions class.
- Create an instance of the ImageDevice class.
- Save the PostScript file to the ImageDevice using the PsDocument->Save(System::SharedPtrAspose::Page::Device device, System::SharedPtr options) method.
- Retrieve the image bytes using the ImageDevice->get_ImagesBytes() method.
- Iterate through the image bytes.
- Initialize the output stream and save the PNG image.
The following sample code shows how to convert PostScript EPS/PS files to PNG image format using C++.
Converting PostScript EPS/PS Files to JPG Image Format using C++
In order to convert EPS or PS files to JPG image format, use the steps given below.
- Initialize the PostScript input stream.
- Create an instance of the PsDocument class using the input stream.
- Create an instance of the ImageSaveOptions class.
- Instantiate an object of the ImageFormat class.
- Create an instance of the ImageDevice class using the ImageFormat object.
- Save the PostScript file to the ImageDevice using the PsDocument->Save(System::SharedPtrAspose::Page::Device device, System::SharedPtr options) method.
- Retrieve the image bytes using the ImageDevice->get_ImagesBytes() method.
- Iterate through the image bytes.
- Initialize the output stream and save the JPG image.
The following sample code demonstrates how to convert PostScript EPS/PS files to JPG image format using C++.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
Conclusion
In this article, you have learned how to convert PostScript EPS/PS files to PNG and JPG image formats using C++. You have seen the complete code snippet along with the steps required to achieve this. Aspose.Page for C++ provides many additional features that you can explore in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.