Convert XPS files | .NET API Solution
This article explains how to convert XPS files using C# on the example of PS to PDF Conversion.
Aspose.Page lets you convert XPS files using C# in BMP, JPG, TIFF, PNG, and PDF formats.
C# XPS to PNG Conversion
You can check the quality of Aspose.Page XPS to PNG conversion and view the results via free online XPS to PNG Converter XPS Viewer, and other other apps, to manipulate PS files
Aspose.Page .NET XPS to PNG converter allows to convert XPS file with of any language supported by .NET platform: C#, VB, J#. All the conversions are performed in a similar way to the one shown in the example below.
Steps to perform XPS to PNG conversion:
- Create an instance of XpsDocument from an input XPS file.
- Specify SmoothingMode, Resolution and other options of PngSaveOptions(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 PNG files creating for every byte array a new file output stream.
Let’s consider PngSaveOptions. Using this class we can assign different conversion parameters while converting XPS to PNG.
- ImageSize specifies the resulting image width and height.
- SmoothingMode assigns a degree of smoothing for lines, curves and edges of filled areas, may be AntiAlias, HighQuality, HighSpeed and Default (none). The default value is HighQuality.
- Resolution controls resolution of the resulting image. The default value is 96.
- TextRenderingHint assigns the quality of the rendering text, may be AntiAlias, AntiAliasGridFit, ClearTypeGridFit, SingleBitPerPixel, SingleBitPerPixelGridFit, SystemDefault. The default value in XPS to PNG conversion is AntiAliasGridFit.
- InterpolationMode defines the algorithm that is used when scaling or/and rotating image, may be Bicubic, Bilinear, High, HighQualityBicubic, HighQualityBilinear, Low, NearestNeighbor and Default. The default value is HighQualityBicubic.
- PageNumbers represents an array of numbers of pages which will be saved to PNG.
For converting XPS to PDF there are next parameters here:
- JpegQualityLevel controls the quality of images in the PDF document if ImageCompression algorithm is JPEG and can be from 0 to 100.
- ImageCompression algorithm is encapsulated in PdfImageCompression Enumeration, and may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW) with base or optimized pedictor, JPEG , none (raw image bytes) and auto (the most appropriate compression for each image). The default is auto compression.
- TextCompression algorithm is encapsulated in PdfTextCompression Enumeration, and may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW), and none. The default value in XPS to PDF conversion is Flate.
- EncryptionDetails is encapsulated in PdfEncryptionDetails. It allows setting the encryption algorithm, permisions, owner and user passwords for the PDF document.
- PageNumbers represents an array of numbers of pages which will be saved to PDF.
- OutlineTreeExpansionLevel and OutlineTreeHeight controls the view of the document outline.
Try XPS functionality conversion online on our XPS Converter. There you can convert several PS files at once and dowload results in a few seconds.
You can download examples and data files from GitHub.