Convert HTML to PDF in Python

Overview

Aspose.PDF for Python via .NET is a professional solution that allows you to create PDF files from web pages and raw HTML code in your applications.

This article explains how to convert HTML to PDF using Python. It covers the following topics.

Format: HTML

Python HTML to PDF Conversion

Aspose.PDF for Python is a PDF manipulation API that lets you convert any existing HTML documents to PDF seamlessly. The process of converting HTML to PDF can be flexibly customized.

Convert HTML to PDF

The following Python code sample shows how to convert an HTML document to a PDF.

  1. Create an instance of the HtmlLoadOptions class.
  2. Initialize Document object.
  3. Save output PDF document by calling Document.Save() method.

    import aspose.pdf as ap

    input_pdf = DIR_INPUT + "little_html.html"
    output_pdf = DIR_OUTPUT + "convert_html_to_pdf.pdf"
    options = ap.HtmlLoadOptions()
    document = ap.Document(input_pdf, options)
    document.save(output_pdf)