Convert HTML to XPS using a Java HTML Library

Introduction

Java HTML Library Installation

  • We will learn how to install this enterprise-level Java API.

Convert HTML to XPS in Java - Code Sample

  • The implementation of the functionality will take place here with the help of a code sample.

HTML File Converter - Online Tool

  • This is where we will explore an online tool for HTML to XPS conversion.

Aspose.HTML for Java is a rich-featured API that offers the creation, manipulation, and conversion of HTML files to other popular file formats. This guide will mainly focus on the HTML to XPS conversion in Java programmatically. So, by the end of this blog post, you will have a strong idea of how to use this Java HTML library to programmatically convert HTML files to XPS files.

Java HTML Library Installation

Aspose.HTML for Java offers a huge stack of features along with complete documentation. However, for quick installation, you can download the JAR file or follow the Maven configurations mentioned here:

Java-HTML-Library-Installation

Convert HTML to XPS in Java - Code Sample

This phase covers the demonstration with the help of the required steps and the code snippet. So, you can follow the steps mentioned below:

package com.example;
import com.aspose.html.HTMLDocument;
import com.aspose.html.saving.XpsSaveOptions;
import com.aspose.html.converters.Converter;
// Convert HTML to XPS in Java
public class main
{
public static void main(String[] args) throws java.io.IOException
{
String dataDir = "/Desktop/";
// Load the source HTML file by initializing an instance of the HTMLDocument class.
HTMLDocument htmlDocument = new HTMLDocument(dataDir+"sample.html");
// Instantiate an object of the XpsSaveOptions class.
XpsSaveOptions options = new XpsSaveOptions();
// Set the background color by setting the value of setBackgroundColor property.
options.setBackgroundColor(com.aspose.html.drawing.Color.getCyan());
// Output file path
String outputFile = dataDir+"output.html.to.xps";
// Convert HTML to XPS by calling the convertHTML method.
Converter.convertHTML(htmlDocument, options, outputFile);
}
}
You can see the output in the image:

Convert-HTML-to-XPS-in-Java

HTML File Converter - Online Tool

This is an amazing tool powered by Aspose.HTML for Java. It is an online app that offers robust conversion and file-uploading features. In addition, it is free and you can embed it into your business applications easily. Moreover, it is lightweight and you can boost the HTML to XPS conversion using this HTML file converter.

HTML-File-Converter

Get a Free License

You can get a free temporary license to try this Java HTML library beyond evaluation limitations.

Summing up

We are ending this guide here with the hope you have learned how to convert HTML to XPS in Java programmatically. Further, we went through the steps and the code sample to elaborate on each aspect of using this Java HTML library. Moreover, you can head over to the documentation, GitHub repo, and API references. Finally, you will see new blog posts consistently, so stay tuned for the updates.

Feel Free to Reach Out

You can let us know about your questions or queries on our forum.

See Also