XPS (XML Paper Specifications) format was introduced by Microsoft that is used to represent page layout. It uses XML tags to represent the appearance of the pages and the composition of the document. In various scenarios, you may need to convert XPS documents to other document formats. In accordance with that, in this article, you will learn about the conversion of XPS documents to raster image formats programmatically. Particularly, the article will cover how to convert XPS to BMP, JPEG, PNG, and TIFF using Java.
- Java XPS to Image Converter API
- Convert XPS to PNG
- Convert XPS to JPEG
- XPS to BMP Conversion
- Convert XPS to TIFF
XPS to Image Converter API – Free Download
Aspose.Page for Java is designed to work with PS, EPS, and XPS documents from within the Java applications. The API’s built-in converter lets you perform high-quality conversion of XPS to raster image formats including PNG, JPEG, BMP, and TIFF images. You can either download the API’s JAR or install it within your Maven-based applications.
<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>20.11</version>
</dependency>
Convert XPS to Raster Images in Java
Aspose.Page for Java provides separate classes in order to customize the XPS to raster image conversion. For example, you can set the resolution of the output image, specify the pages you want to convert, and so on. The following is the list of the classes that you may use accordingly.
- PngSaveOptions for XPS to PNG
- JpegSaveOptions for XPS to JPEG
- BmpSaveOptions for XPS to BMP
- TiffSaveOptions for XPS to TIFF
Convert XPS to PNG in Java
The following are the steps to convert the XPS documents to PNG images using Aspose.XPS for Java.
- Load the XPS document using XpsDocument class.
- Create an instance of PngSaveOptions class to set additional options.
- Create an instance of ImageDevice class.
- Use XpsDocument.save(ImageDevice, PngSaveOptions) to save converted PNG image into ImageDevice object.
- Use ImageDevice to save the image as a PNG file.
The following code sample shows how to convert XPS to PNG using Java.
Convert XPS to JPEG in Java
The following are the steps to convert XPS to JPEG using Aspose.Page for Java.
- Load the XPS document using XpsDocument class.
- Use JpegSaveOptions class to set additional options for the converted JPEG image.
- Create an instance of ImageDevice class.
- Use XpsDocument.save(ImageDevice, JpegSaveOptions) to save converted JPEG image into ImageDevice object.
- Use ImageDevice to save the image as a JPEG file.
The following code sample shows how to convert XPS to JPEG.
Convert XPS to BMP in Java
You can convert the XPS files to BMP images in the same way you have done for PNG and JPEG. The following are the steps for it.
- Use XpsDocument class to load the XPS document.
- Create an instance of BmpSaveOptions class to set additional options for the converted BMP image.
- Use XpsDocument.save(ImageDevice, BmpSaveOptions) method to save converted BMP image into an ImageDevice object.
- Use ImageDevice to save the image as a BMP file.
The following code sample shows how to convert an XPS file to BMP.
Convert XPS to TIFF in Java
The following are the steps to convert XPS document to TIFF image.
- Use XpsDocument class to load the XPS document.
- Create an instance of TiffSaveOptions class to set additional options for the converted TIFF image.
- Use XpsDocument.save(ImageDevice, TiffSaveOptions) method to save converted TIFF image into an ImageDevice object.
- Use ImageDevice to save the image as a TIFF file.
The following code sample shows how to convert XPS document to TIFF image in Java.
Conclusion
In this article, you have learned how to convert XPS files to raster image formats using Java. The step-by-step guide, API references, and code samples have shown how to convert XPS to PNG, JPEG, TIFF, and BMP images. You can explore other features of the Java XPS API using the documentation.