Convert XPS to JPG PNG Java

XPS files are used to save documents in the page description language. You may need to convert an XPS file to an image for previewing the contents or creating thumbnails. In accordance with such scenarios, this article covers how to convert XPS to JPG or PNG images using Java.

XPS to JPG or PNG Image Converter – Java API Installation

XPS files can be converted to different image formats. Simply configure Aspose.Page for Java API by downloading the JAR files or with the following Maven configurations to download the APIs from Aspose Repository:

Repository:

 <repositories>
     <repository>
         <id>snapshots</id>
         <name>repo</name>
         <url>http://repository.aspose.com/repo/</url>
     </repository>
</repositories>

Dependency:

 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-page</artifactId>
        <version>21.12</version>
    </dependency>
</dependencies>

Convert XPS to JPG Image in Java

You can convert an XPS to JPG Image in Java with the following steps:

  1. Load input XPS file with XpsDocument class.
  2. Initialize JpegSaveOptions object with necessary parameters.
  3. Create rendering device for image.
  4. Write output JPG file.

The following code snippet shows how to convert XPS file to JPG image programmatically in Java:

Convert XPS to PNG Image in Java

You can convert an XPS to PNG Image in Java with the following steps:

  1. Load the source XPS document using XpsDocument class.
  2. Instantiate PngSaveOptions instance to set different properties.
  3. Initialize a rendering device using ImageDevice class.
  4. Write the output PNG image.

The code snippet below demonstrates how to convert an XPS file to PNG image programmatically in Java:

Get Free Evaluation License

You can evaluate the API in its full capacity by requesting a free temporary license.

Conclusion

In this article, you have learned how to convert an XPS file to JPG or PNG image programmatically using Java. Furthermore, you can explore many other features offered by the API by visiting the documentation. Please feel free to get in touch with us at the forum.

See Also

Convert a Postscript PS or EPS file to PDF using Java