Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/1c9de9ca4dcb63c8a2d660ef9941fbb6 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1c9de9ca4dcb63c8a2d660ef9941fbb6 to your computer and use it in GitHub Desktop.
Convert HTML or MHTML to XPS Programmatically in C#
// Load input HTML file
using (HTMLDocument document = new HTMLDocument("test.html"))
{
// Initialize XpsSaveOptions
Saving.XpsSaveOptions options = new Saving.XpsSaveOptions();
options.BackgroundColor = Color.Gray;
options.PageSetup.AnyPage = new Drawing.Page(new Drawing.Size(600, 800), new Drawing.Margin(72, 72, 72, 72));
options.VerticalResolution = 250;
// Convert HTML to XPS
Converters.Converter.ConvertHTML(document, options, "output.xps");
}
// Load input HTML file
HTMLDocument document = new HTMLDocument("test.html");
// Initialize XpsSaveOptions
XpsSaveOptions options = new XpsSaveOptions();
// Convert HTML or MHTML to XPS
Converter.ConvertHTML(document, options, "output.xps");
// Specify URL for input HTML.
Uri uri = new Uri("https://www.aspose.com/");
// Load input HTML with HTMLDocument class.
HTMLDocument document = new HTMLDocument(uri.AbsoluteUri);
// Initialize XpsSaveOptions class object.
XpsSaveOptions options = new XpsSaveOptions();
// Convert HTML from URL to XPS file.
Converter.ConvertHTML(document, options, "test.xps");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment