This gist repository contains Python code examples used in the Converting Between Formats chapter of the Aspose.HTML for Python via .NET documentation. You will find examples for various common scenarios for HTML, XHTML, MHTML, SVG, EPUB, and Markdown conversion.
- File Conversion – Convert HTML, SVG, EPUB, MHTML, and Markdown files into various output formats, including PDF, DOCX, XPS, and popular image formats, while preserving layout, styles, and embedded resources.
- Customizable Rendering Options – Fine-tune the conversion process using device-specific settings, such as page size, margins, resolution, compression, and other output format options to achieve precise control over the final document.
- Convert HTML programmatically in Python in different ways – Use
convert_html()from the Converter class,render_to()from HTMLDocument, orrender()from Renderer, depending on your workflow.
This repository provides examples for converting:
- HTML – Shows how to convert an HTML document to PDF, XPS, DOCX, images, MD, and MHTML formats.
- SVG – Provides information on how to convert SVG to PDF and image formats.
- EPUB – Demonstrates how to convert EPUB to PDF, XPS, DOCX, and image formats.
- MHTML – Describes how to convert MHTML to PDF, XPS, DOCX, and image formats.
- Markdown – Provides information on how to convert MD to HTML, PDF, XPS, DOCX, and various image file formats.
- Fine-Tuning Converters – Alternative ways to render HTML and HTML-based documents that can give you more control over the rendering process in your Python application.
- Python 3.5 or newer
- .NET Core / .NET 5+ runtime installed
- Supported OS: Windows, macOS, Linux
- Aspose.HTML for Python via .NET installed from PyPI
- Install the Aspose.HTML Python package:
pip install aspose-html-net
- Clone or download this Gist to your local computer to access the code snippets.
- Verify and set the correct input/output paths, data directories, and any custom font folders referenced in the code.
- Run the specific Python example to execute the conversion logic and see the result in action.
Aspose.HTML for Python via .NET is a robust API that provides headless browser capabilities for working with HTML documents and other supported web formats, such as MHTML, Markdown, SVG, and EPUB. It allows you to create new HTML files or load existing ones from various sources. Once loaded, you can manipulate the document's contents, such as adding, removing, or replacing nodes, as well as render it or convert it to popular formats, including PDF, DOCX, XPS, or images.
For detailed API usage, download instructions, and advanced conversion scenarios, please consult the official Aspose.HTML resources: