Convert HTML, SVG, EPUB, MHTML, and Markdown in Python

Aspose.HTML for Python via .NET converts HTML, SVG, EPUB, MHTML, and Markdown to supported outputs such as PDF, XPS, DOCX, raster images, MHTML, and HTML. Choose a source-format guide below, then open the article for the required output format and Python workflow.

Most conversion workflows use the Converter class. Provide the source document, file, stream, or content supported by the selected method, create save options for the output format, and call the corresponding conversion method. For device-based rendering and more control over the output process, see Fine-Tuning Converters.

Choose a Converter Guide

Converter API and Rendering API

Aspose.HTML for Python via .NET provides two main conversion patterns:

ApproachUse it when
Converter methodsYou need a direct source-to-output workflow. Use convert_html(), convert_svg(), convert_epub(), convert_mhtml(), or convert_markdown() for the corresponding source format.
Rendering APIYou need explicit control over a renderer, output device, or device-specific options. Use HTMLDocument.render_to() for an HTML document, or use a format-specific renderer with PdfDevice, XpsDevice, DocDevice, or ImageDevice.

The Converter API is the usual choice for a straightforward file conversion. The Renderers, Rendering Devices, and Rendering Options articles explain the lower-level rendering workflow.

Basic HTML to PDF Example

The following example demonstrates the common conversion sequence:

  1. Provide the source HTML file.
  2. Create PdfSaveOptions for PDF output.
  3. Call Converter.convert_html() and specify the output PDF path.
1# Convert HTML to PDF in Python
2
3import aspose.html.converters as conv
4import aspose.html.saving as sav
5
6# Convert HTML to PDF
7conv.Converter.convert_html("document.html", sav.PdfSaveOptions(), "output.pdf")

For examples that load an HTMLDocument or customize page layout, PDF metadata, security, and other settings, see Convert HTML to PDF in Python.

Related Conversion Topics

Other Platforms

Try Online Conversion

Use the free online Converters for quick manual conversions without writing code. Use Aspose.HTML for Python via .NET when conversion must run programmatically in a Python application, service, batch job, or document-processing workflow.

Free Online HTML, SVG, EPUB, MHTML, and Markdown Converters