html to xps

HTML to XPS conversion with C# .NET.

HTML is the go-to format for presenting content on the web, but there are situations where a more reliable and fixed document format is required. This is where converting HTML to XPS (XML Paper Specification) becomes crucial. XPS is a standardized format that ensures consistent page layout, making it ideal for creating print-ready documents, reports, and archives where precise formatting is essential.

.NET HTML to XPS Conversion API

GroupDocs.Conversion Cloud SDK for .NET provides a robust and efficient way to convert HTML files to XPS format. With this SDK, the integration of conversion capabilities into your .NET applications is straightforward and enables seamless transform of HTML content into high-quality XPS documents. The first step in this approach is to install the SDK by searching GroupDocs.Conversion-Cloud in NuGet package manager and click the Install button. Another option is to execute the following command in package manager console.

NuGet\Install-Package GroupDocs.Conversion-Cloud -Version 24.2.0

After the installation is completed, please obtain your personalized API credentials(i.e. Client ID and Client Secret). You may visit this short tutorial explaining the details on how to get the API credentials.

HTML to XPS in C# .NET

This section explains the details on how we can generate fixed-layout reports or create print-ready documents by converting HTML to XPS format using C# .NET.

  1. Create an instance of Configuration class where we pass client credentials as arguments.
var configurations = new Configuration(clientId, clientSecret1);
  1. Initialize the ConvertApi where we pass Configuration object as an input argument.
var apiInstance = new ConvertApi(configurations);
  1. Upload the input HTML file to the cloud storage.
fileUpload.UploadFile(new UploadFileRequest("sourceFile.html", stream));
  1. Create an instance ConvertSettings where we specify the name for input HTML, resultant format as xps and the name for resultant XPS document as arguments.
var settings = new ConvertSettings{...}
  1. Call the ConvertDocumentRequest API to perform HTML to XPS conversion and save the resultant XPS file to the cloud storage.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
html to xps

Image:- A preview of HTML to XPS conversion.

The resultant XPS file generated in the above example can be downloaded from resultantFile.xps.

Convert HTML to XPS using cURL Commands

The conversion of HTML to XPS using GroupDocs.Conversion Cloud and cURL commands offers a flexible and efficient approach when you prefer command-line tools and automation. Furthermore, this approach is particularly useful in scenarios where automated or batch processing is required, making it ideal for developers integrating document conversion into scripts or server-side workflows.

The first step in this approach is to generate a JWT access token and then, execute the following cURL command to transform the webpage to XPS file. The resultant file is then stored in the cloud storage.

curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"default\",  \"FilePath\": \"{sourceFile}\",  \"Format\": \"xps\",\"OutputPath\": \"{resultantFile}\"}"

Please replace sourceFile with the name of input HTML file, resultantFile with the name of resultant XPS file and accessToken with personalized JWT access token.

  • If your requirement is to save the resultant XPS file on local drive, please try using the following cURL command.
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"default\",  \"FilePath\": \"{sourceFile}\",  \"Format\": \"xps\"}" \
-o "{resultantFile}"

Free HTML to XPS Converter

You may consider exploring the powerful capabilities of GroupDocs.Conversion Cloud REST API by using our free HTML to XPS Conversion App. It’s a lightweight and super-efficient App, enabling you to experience the powerful capabilities of API within a web browser.

html to xps app

Conclusion

Converting HTML to XPS is crucial for creating consistent, high-quality documents suitable for printing, archiving, and sharing across platforms. Whether you choose to use the comprehensive GroupDocs.Conversion Cloud SDK for .NET or the lightweight cURL command approach, both methods offer reliable and flexible solutions for achieving this conversion. We encourage you to explore our API and leverage its capabilities to streamline your document conversion needs and effortlessly deliver professional, fixed-layout outputs.

We highly recommend visiting the following links to learn more about: