HTML to XPS Conversion

Summary

Converting between formats is required for various reasons: to work in a familiar, convenient format or to take advantage of different formats for specific tasks. XPS is a document storage and viewing format developed by Microsoft. An XPS file is a ZIP archive using the Open Packaging Conventions containing the files that make up the document. It has a set of advantages that support security features, such as digital signatures to provide greater document security and more.

This article demonstrates how to convert HTML file to XPS by direct REST API calls or using SDKs.

cURL Example

This example demonstrates how to convert an HTML file located in the default cloud storage to XPS with default parameters using the cURL utility (in the console, or using the system shell script - .bat file or PowerShell script in Windows, bash script in Linux etc.).

Step 1: Get JWT token for the user authentication

Step 2: Initialize an asynchronous conversion process using the POST method

The curl -X POST command specifies a request method (POST) to use when communicating with the HTTP server. The POST method is usually used in requests for adding data; in this case, an empty parameter list is passed -d "{}".

Step 3: Check the previously started conversion process status using the GET method

The GET method allows checking the previously started operation state by its ID and returns the state object.

SDK Examples

These examples demonstrate how to convert HTML to XPS using available SDKs.

Case 1. Convert an HTML document from the storage by its name to XPS and save to the storage

In the following example, we consider the case when the source HTML document is in the storage, and you want to convert it to XPS format and save to the storage.

In the example, we use methods of the ConverterBuilder class: FromStorageFile(inputPath), To(ConversionOptions) and SaveToStorage(outputDirectory) that specify input data, the output format and the target directory for a conversion result. HTML to XPS conversion occurs with the default conversion options: the resulting XPS document’s width and height correspond to A4, all margins have zero value.

More details about available conversion parameters for HTML files are in the SDK Conversion Options section.

Case 2. Convert a Web page by its URL to XPS and save to the local file system

Aspose.HTML Cloud SDK allows you to get HTML page from the web by its URL, convert it to another format and save into the local file system. The example below demonstrates how to convert HTML to XPS with the conversion parameters specifying.

This example demonstrates how to convert HTML to XPS using available SDKs.

In the example, we use methods of the ConverterBuilder class: FromUrl(urlAddress), To(ConversionOptions) and SaveToStorage(outputDirectory) that specify input data, the output format and the target directory for a conversion result.

You can get information about all the API resources from Aspose.HTML for Cloud API Reference.