Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created July 10, 2024 08:56
Convert HTML to XPS in Java
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment