Convert XPS using API for Java
This article explains how to convert XPS files using C# on the example of XPS to JPEG Conversion.
Aspose.Page lets you convert XPS files using Java in high-quality BMP, JPG, TIFF, PNG, and PDF documents.
You can try the quality of Aspose.Page XPS to JPG conversion and view the results via free online XPS to JPG Converter or XPS Viewer
Aspose.Page Java XPS to JPG converter allows to convert XPS document to JPG image on any OS for which the Java Virtual Machine exists.
Take the next steps in order to run XPS to JPG conversion:
Initialize an input stream for the input XPS document.
Create an instance of the XpsDocument from the created earlier input stream.
Specify SmoothingMode, Resolution, and other options of the JpegSaveOptions(or PdfSaveOptions if you convert to PDF format other save option from the listed).
Create an instance of the ImageDevice(or PdfDevice if you convert to PDF format).
Save the XPS document as an image with JPEG save options to an array of arrays of bytes. One array of bytes for one page of input document.
Save resulting 2-dimensional arrays of bytes to JPG files creating for every byte array a new file output stream.
Create an instance of XpsDocument from the XPS file.
Specify SmoothingMode, Resolution and other options of JpegSaveOptions(or PdfSaveOptions if you convert to PDF or other save option from the listed).
Save the XPS document as image with the save options to an array of arrays of bytes. One array of bytes for one page of an input document.
Save resulting 2-dimensional arrays of bytes to JPEG files creating for every byte array a new file output stream.
Let’s consider JpegSaveOptions. Using this class we can assign different conversion parameters while converting XPS to JPG.
- ImageSize specifies the resulting image width and height.
- SmoothingMode assigns a degree of smoothing for lines, curves, and edges of filled areas, which may be AntiAlias, HighQuality, HighSpeed, and Default (none). The default value is HighQuality.
- Resolution controls the resolution of the resulting image. The default value is 96.
- TextRenderingHint assigns the quality of text rendering, and it may be AntiAlias, AntiAliasGridFit, ClearTypeGridFit, SingleBitPerPixel, SingleBitPerPixelGridFit, SystemDefault. The default value in XPS to JPG conversion is AntiAliasGridFit.
- InterpolationMode defines an algorithm that is used when scaling or/and rotating an image, and it may be Bicubic, Bilinear, High, HighQualityBicubic, HighQualityBilinear, Low, NearestNeighbor, and Default. The default value is HighQualityBicubic.
- PageNumbers represents an array of numbers of pages that will be saved to JPG.
For converting XPS to PDF there are next parameters here:
- JpegQualityLevel controls the quality of images in PDF documents if the ImageCompression algorithm is JPEG and can be from 0 to 100.
- ImageCompression algorithm encapsulated in PdfImageCompression Enumeration, and it may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW) with base or optimized predictor, JPEG, none (raw image bytes) and auto (the most appropriate compression for each image). The default is auto compression.
- TextCompression algorithm encapsulated in PdfTextCompression Enumeration, and it may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW) and none. The default value in XPS to PDF conversion is Flate.
- EncryptionDetails encapsulated in PdfEncryptionDetails. It allows setting encryption algorithm, permissions, owner, and user passwords for PDF documents.
- PageNumbers represents an array of numbers of pages that will be saved to PDF.
- OutlineTreeExpansionLevel and OutlineTreeHeight controls view of document outline.
Evaluate XPS online in our XPS cross-platform Converter. You can convert several XPS files to JPG at once and download results in a few seconds.
You can download examples and data files from GitHub.