convert-eps-to-png-in-java

EPS (Encapsulated PostScript) is a graphics file format, used to describe images or drawings. EPS file may contain any combination of text, graphics and images. PostScript PS/EPS files are commonly used for printing purposes as they are based on Page Description Languages. We can easily convert EPS or PS files to PNG images programmatically. In this article, we will learn how to convert EPS to PNG in Java.

The following topics shall be covered in this article:

  1. Java EPS to PNG Converter API – Free Download
  2. Convert EPS to PNG Image

Java EPS to PNG Converter API – Free Download

For converting EPS to PNG, we will be using the Aspose.Page for Java API. It allows loading, merging, converting, and rendering of XPS, PS, and EPS documents in Java applications.

The PsDocument class of the API encapsulates PS/EPS documents. The ImageSaveOptions class of the API contains the options necessary for managing the image-saving process. The ImageDevice class encapsulates the rendering of the document to image. The getImagesBytes() method gets the resulting images in bytes. The save(Device, SaveOptions) method saves the PS/EPS document to a device. The ImageFormat enumeration contains possible names of image formats that are supported by PS/EPS to Image conversion.

Please either download the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository> 
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-page</artifactId>
    <version>22.7</version>
</dependency>

Convert EPS to PNG Image using Java

We can convert PostScript EPS or PS files to PNG images by following the steps given below:

  1. Load EPS file in the FileInputStream.
  2. Create an instance of the PsDocument class with the stream object.
  3. Initialize the ImageSaveOptions class object with the necessary parameters.
  4. Set the output ImageFormat as PNG.
  5. Create an instance of the ImageDevice class.
  6. Call the save() method to save the image in ImageDevice.
  7. After that, call the Device.getImagesBytes() method to get image bytes.
  8. Finally, save it as an image.

The following code example shows how to convert EPS or PS file to a PNG image using Java.

Convert-EPS-to-PNG-Image-using-Java

Convert EPS to PNG Image

Free API License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to convert a PostScript EPS/PS file to PNG images programmatically using Java. Besides, you can learn more about Aspose.Page for Java API using the documentation. In case of any ambiguity, please feel free to contact us on our forum.

See Also