Merge XPS documents to PDF

JavaScript API solution to combine several XPS files into a single PDF document

 

The XPS file format allows the storage of multiple documents within a single file and is also able to contain multiple pages. Aspose.Page API Solution for JavaScript offers the ability to merge multiple files into one, resulting in an XPS or PDF file that contains the combined content of all the original files.

Discover how simple it is to merge XPS files using our API with the provided code example. For web-based integration or online merging, be sure to check out our cross-platform XPS Merger tool.

Here you will find a code example of how to use the API for merging XPS files. To explore how this functionality can be integrated into a web solution or used for online file merging, you can try out the cross-platform XPS Merger tool.

To merge XPS files, you need:

  • To merge XPS files, you need:

  • Visit our site.

Steps to merge several XPS files into a single file with JavaScript.

  1. Create file reader ‘const file_reader = new FileReader();’ and read file ‘file_reader.readAsArrayBuffer(e.target.files[0]);’
  2. Load needed files by using AsposePagePrepare .
  3. After the loading of the last file, call AsposeXPSMergeToXps and pass the array of file names, the result file name, and SuppressError boolean values to it.
  4. 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 merge of XPS files.
  5. You can download files by using the DownloadFile function: ‘DownloadFile(json.fileNameResult, ‘application/xps’);’

Merge XPS files

var fXps2Xps = function (e) {
 	 const file_reader = new FileReader();
 	 file_reader.onload = (event) => {
 	 function readFile(index) {
 	 	 if (index >= e.target.files.length) {
 	 	 	 const fileNames = Array.from(e.target.files).map((x) => x.name).toString();
 	 	 	 const json = AsposeXPSMergeToXps(fileNames, 'ResultMerge.xps', true);
 	 	 	 if (json.errorCode == 0) {
 	 	 	 	 DownloadFile(json.fileNameResult, 'application/xps');
 	 	 	 }
 	 	 	 else
 	 	 	 	 document.getElementById('output').textContent = json.errorText;
 	 	 	 return;
 	 	 }
 	 	 const file = e.target.files[index];
 	 	 file_reader.onload = function (event) {
 	 	 	 AsposePagePrepare(event.target.result, file.name);
 	 	 	 readFile(index + 1);
 	 	 }
 	 	 file_reader.readAsArrayBuffer(file);
 	 }
 	 readFile(0);
 }

Steps to merge several XPS files to PDF with JavaScript.

  1. Create file reader ‘const file_reader = new FileReader();’ and read file ‘file_reader.readAsArrayBuffer(e.target.files[0]);’
  2. Load needed files by using AsposePagePrepare .
  3. After the loading of the last file, call AsposeXPSMergeToPdf and pass the array of file names, the result file name, and SuppressError boolean values to it.
  4. 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 merge of XPS files.
  5. You can download files by using the DownloadFile function: ‘DownloadFile(json.fileNameResult, ‘application/xps’);’

Merge XPS files to PDF

var fXps2Pdf = function (e) {
 	 const file_reader = new FileReader();
 	 file_reader.onload = (event) => {
 	 function readFile(index) {
 	 	 if (index >= e.target.files.length) {
 	 	 	 const fileNames = Array.from(e.target.files).map((x) => x.name).toString();
 	 	 	 const json = AsposeXPSMergeToPdf(fileNames, 'ResultMerge.pdf', true);
 	 	 	 if (json.errorCode == 0) {
 	 	 	 	 DownloadFile(json.fileNameResult, 'application/pdf');
 	 	 	 }
 	 	 	 else
 	 	 	 	 document.getElementById('output').textContent = json.errorText;
 	 	 	 return;
 	 	 }
 	 	 const file = e.target.files[index];
 	 	 file_reader.onload = function (event) {
 	 	 	 AsposePagePrepare(event.target.result, file.name);
 	 	 	 readFile(index + 1);
 	 	 }
 	 	 file_reader.readAsArrayBuffer(file);
 	 }
 	 readFile(0);
 }

XPS What is XPS File Format

XPS format is similar to PDF format. Both are page description language (PDL) formats. EPS is based on HTML and not on PostScript language. The .eps file is capable to contain a markup of the document's structure along with the information on how the document would look like. There are also added instructions on how to print and render the document. The feature of the format is that it fixes the document's description which means that it will look the same no matter who and from what operational system opens it.