Convert XPS with Aspose.Page Node.js via C++ API
This article explains how to convert XPS files using Node.js on the example of XPS to PDF Conversion.
Aspose.Page lets you convert XPS files using Node.js to high-quality BMP, JPG, TIFF, PNG, and PDF documents.
You can check the quality of Aspose.Page XPS to PDF conversion and view the results via free online XPS to PDF Converter
Aspose.Page Node.js via C++ XPS to PDF converter allows conversion of XPS documents to PDF on Windows and Linux.
It is necessary to perform several steps to convert XPS to PDF:
- Create file reader ‘const file_reader = new FileReader();’ and read file ‘file_reader.readAsArrayBuffer(e.target.files[0]);’.
- On load event handler call AsposeXPSSaveAsPdf and pass the file content and its name, and SuppressError boolean values to it.
- The result JSON contains the file name in fileNameResult.
- If the SuppressErrors value was true, as it is by default, it is possible to see what errors were thrown during the conversion of XPS to PDF.
- You can download files by using the DownloadFile function: ‘DownloadFile(JSON.fileNameResult, “image/pdf”);’
The following code snippet shows how to convert XPS to PDF document in Node.js:
For more examples and data files, please go to github.com/aspose-page/Aspose.Page-for-Node.js-C
Let’s consider PdfSaveOptions. Using this class, we can assign different conversion parameters while converting XPS to PDF.
- 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, 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, 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 the PDF document.
- PageNumbers represents an array of numbers of pages that will be saved to PDF.
- OutlineTreeExpansionLevel and OutlineTreeHeight controls view of document outline.
For converting XPS to an image format, there are the following parameters:
- 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 quality of text rendering, may be AntiAlias, AntiAliasGridFit, ClearTypeGridFit, SingleBitPerPixel, SingleBitPerPixelGridFit, SystemDefault. The default value in XPS to PNG conversion is AntiAliasGridFit.
- InterpolationMode defines an algorithm that is used when scaling or/and rotating an 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 that will be saved to PNG.
Check XPS conversion online on our XPS cross-platform Converter. You can convert several XPS files to PDF at once and download the results in a few seconds.
You can download examples and data files from GitHub.