Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active August 23, 2024 18:57
Show Gist options
  • Save groupdocs-cloud-gists/3d6ca05b08b1dfb3332e14c1226febce to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/3d6ca05b08b1dfb3332e14c1226febce to your computer and use it in GitHub Desktop.
Convert HTML to XPS

Convert HTML to XPS using C# .NET


The conversion of HTML to XPS is essential for scenarios where high-quality, fixed-layout documents are required for printing, archiving, or sharing. In this section, we explore the need for converting HTML to XPS using C# .NET and guide you through the process, highlighting the benefits of using this approach.



For more details, please visit Convert HTML to Word Document Using .NET REST API.

html to xps

Important Links

Product Page | Docs | Live Demo | API Reference | Code Samples | Source Code | New Releases | Blog | Free Support | Free Trial

How to convert HTML to XPS with C# .NET
// More examples over https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-dotnet
// Obtain your API credentials
string clientId = "XXXXXX-XXXXXXXXX-4088-9ca0-55c38f4b7f22";
string clientSecret1 = "XXXXXXXXXXXXXXXXXXXX";
// Create an instance of the Configuration class and initialize it with the Client ID & Client Secret.
var configurations = new Configuration(clientId, clientSecret1);
// Define the value of ApiBaseUrl to set the base url for HTML to XPS conversion API.
configuration.ApiBaseUrl = "https://api.groupdocs.cloud";
// Initialize an instance of the ConvertApi class with an object of Configuration class.
var apiInstance = new ConvertApi(configurations);
// load the input HTML from local drive
using (var stream = System.IO.File.OpenRead("input.html"))
{
// create an instance of FileApi
var fileUpload = new FileApi(configurations);
// upload the input HTML to cloud storage
fileUpload.UploadFile(new UploadFileRequest("input.html", stream));
// create ConvertSettings where we define the name of source HTML and the name for resultant XPS file
var settings = new ConvertSettings
{
StorageName = "default",
FilePath = "input.html",
Format = "xps",
OutputPath = "resultant.xps"
};
// Invoke the ConvertDocument method for HTML to XPS conversion operation.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
if (response != null && response.Equals("OK"))
{
// print success message
Console.WriteLine("The HTML to XPS conversion completed successfully !");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment