As you already know how to use ReportLab, I guess that this would do the job : https://github.com/xhtml2pdf/xhtml2pdf

xhtml2pdf

A library for converting HTML into PDFs using ReportLab

Sample code, taken from the Github :

# -*- coding: utf-8 -*-
# Copyright 2010 Dirk Holtwick, holtwick.it
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "$Revision: 194 $"
__author__  = "$Author: holtwick $"
__date__    = "$Date: 2008-04-18 18:59:53 +0200 (Fr, 18 Apr 2008) $"

import os
import sys
import cgi
import cStringIO
import logging

import xhtml2pdf.pisa as pisa

# Shortcut for dumping all logs to the screen
pisa.showLogging()

def dumpErrors(pdf, showLog=True):
    #if showLog and pdf.log:
    #    for mode, line, msg, code in pdf.log:
    #        print "%s in line %d: %s" % (mode, line, msg)
    #if pdf.warn:
    #    print "*** %d WARNINGS OCCURED" % pdf.warn
    if pdf.err:
        print "*** %d ERRORS OCCURED" % pdf.err

def testSimple(
    data="""Hello <b>World</b><br/><img src="img/test.jpg"/>""",
    dest="test.pdf"):

"""
Simple test showing how to create a PDF file from
PML Source String. Also shows errors and tries to start
the resulting PDF
"""

    pdf = pisa.CreatePDF(
        cStringIO.StringIO(data),
        file(dest, "wb")
        )

    if pdf.err:
        dumpErrors(pdf)
    else:
        pisa.startViewer(dest)

def testCGI(data="Hello <b>World</b>"):

    """
    This one shows, how to get the resulting PDF as a
    file object and then send it to STDOUT
    """

    result = cStringIO.StringIO()

    pdf = pisa.CreatePDF(
        cStringIO.StringIO(data),
        result
        )

    if pdf.err:
        print "Content-Type: text/plain"
        print
        dumpErrors(pdf)
    else:
        print "Content-Type: application/octet-stream"
        print
        sys.stdout.write(result.getvalue())

def testBackgroundAndImage(
    src="test-background.html",
    dest="test-background.pdf"):

    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(
        file(src, "r"),
        file(dest, "wb"),
        log_warn = 1,
        log_err = 1,
        path = os.path.join(os.getcwd(), src)
        )

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)

def testURL(
    url="http://www.htmltopdf.org",
    dest="test-website.pdf"):

    """
    Loading from an URL. We open a file like object for the URL by
    using 'urllib'. If there have to be loaded more data from the web,
    the pisaLinkLoader helper is passed as 'link_callback'. The
    pisaLinkLoader creates temporary files for everything it loads, because
    the Reportlab Toolkit needs real filenames for images and stuff. Then
    we also pass the url as 'path' for relative path calculations.
    """
    import urllib

    pdf = pisa.CreatePDF(
        urllib.urlopen(url),
        file(dest, "wb"),
        log_warn = 1,
        log_err = 1,
        path = url,
        link_callback = pisa.pisaLinkLoader(url).getFileName
        )

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)

if __name__=="__main__":

    testSimple()
    # testCGI()
    #testBackgroundAndImage()
    #testURL()

Or you can use pdfkit :

https://pypi.python.org/pypi/pdfkit

Before using it you need to install some things :

pip install pdfkit
sudo apt-get install wkhtmltopdf

Sample code to generate pdf :

import pdfkit

pdfkit.from_url('http://stackoverflow.com', 'out.pdf')
pdfkit.from_file('test.html', 'out2.pdf')
pdfkit.from_string('Thanks for reading!', 'out3.pdf')
Answer from CyborgForever on Stack Overflow
🌐
Reportlab
docs.reportlab.com › rml › userguide › Chapter_1_Introduction
Chapter 1: Introduction - ReportLab Docs
RML2PDF is a central component of the toolkit: a translator which converts high level XML markup into PDF documents. Report Markup Language describes the precise layout of a printed document, and RML2PDF converts this to a finished document in one step. In a dedicated reporting application, ...
🌐
GitHub
github.com › kelvin0 › PyXML2PDF
GitHub - kelvin0/PyXML2PDF: Create PDF from XML file
PyXML2PDF allows to generate pixel precise PDF documents in any page size. It can generate very complex pages while being easily edited as an XML file. PyXML2PDF wraps over the excellent Reportlab python module to generate PDFs.
Starred by 11 users
Forked by 5 users
Languages   Python 100.0% | Python 100.0%
Discussions

looking for an "low dependency" or pythonesque way to generate PDF's
Honestly all the good options I've found have required licenses, or are extremely low level, and a pain to use Eventually I always end up just outgrowing them and using a html -> pdf converter https://gotenberg.dev - this is what I use now, you can host your own and have all your clients use it via API calls (just post an html + CSS file and it returns a PDF) Alternatively just pop open a page in their default browser and have them print it to PDF More on reddit.com
🌐 r/Python
58
191
October 10, 2022
¿Is there an easy (and free) way of converting '.xml' files to '.pdf'? (using python, of course)
Do a Google for pypdf2. Am on my phone or if provide a link to the github page. I user it to merge PDFs, but can easily write PDFs. Should probably write the XML parser part just for the same of having full control. More on reddit.com
🌐 r/learnpython
7
0
November 13, 2014
🌐
Reportlab
docs.reportlab.com
ReportLab Docs
Direct Python access to our PDF parsing and reuse code (in ReportLab PLUS) Docs · The fast, validating XML parser we use to parse RML (GPL).
Top answer
1 of 2
8

As you already know how to use ReportLab, I guess that this would do the job : https://github.com/xhtml2pdf/xhtml2pdf

xhtml2pdf

A library for converting HTML into PDFs using ReportLab

Sample code, taken from the Github :

# -*- coding: utf-8 -*-
# Copyright 2010 Dirk Holtwick, holtwick.it
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "$Revision: 194 $"
__author__  = "$Author: holtwick $"
__date__    = "$Date: 2008-04-18 18:59:53 +0200 (Fr, 18 Apr 2008) $"

import os
import sys
import cgi
import cStringIO
import logging

import xhtml2pdf.pisa as pisa

# Shortcut for dumping all logs to the screen
pisa.showLogging()

def dumpErrors(pdf, showLog=True):
    #if showLog and pdf.log:
    #    for mode, line, msg, code in pdf.log:
    #        print "%s in line %d: %s" % (mode, line, msg)
    #if pdf.warn:
    #    print "*** %d WARNINGS OCCURED" % pdf.warn
    if pdf.err:
        print "*** %d ERRORS OCCURED" % pdf.err

def testSimple(
    data="""Hello <b>World</b><br/><img src="img/test.jpg"/>""",
    dest="test.pdf"):

"""
Simple test showing how to create a PDF file from
PML Source String. Also shows errors and tries to start
the resulting PDF
"""

    pdf = pisa.CreatePDF(
        cStringIO.StringIO(data),
        file(dest, "wb")
        )

    if pdf.err:
        dumpErrors(pdf)
    else:
        pisa.startViewer(dest)

def testCGI(data="Hello <b>World</b>"):

    """
    This one shows, how to get the resulting PDF as a
    file object and then send it to STDOUT
    """

    result = cStringIO.StringIO()

    pdf = pisa.CreatePDF(
        cStringIO.StringIO(data),
        result
        )

    if pdf.err:
        print "Content-Type: text/plain"
        print
        dumpErrors(pdf)
    else:
        print "Content-Type: application/octet-stream"
        print
        sys.stdout.write(result.getvalue())

def testBackgroundAndImage(
    src="test-background.html",
    dest="test-background.pdf"):

    """
    Simple test showing how to create a PDF file from
    PML Source String. Also shows errors and tries to start
    the resulting PDF
    """

    pdf = pisa.CreatePDF(
        file(src, "r"),
        file(dest, "wb"),
        log_warn = 1,
        log_err = 1,
        path = os.path.join(os.getcwd(), src)
        )

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)

def testURL(
    url="http://www.htmltopdf.org",
    dest="test-website.pdf"):

    """
    Loading from an URL. We open a file like object for the URL by
    using 'urllib'. If there have to be loaded more data from the web,
    the pisaLinkLoader helper is passed as 'link_callback'. The
    pisaLinkLoader creates temporary files for everything it loads, because
    the Reportlab Toolkit needs real filenames for images and stuff. Then
    we also pass the url as 'path' for relative path calculations.
    """
    import urllib

    pdf = pisa.CreatePDF(
        urllib.urlopen(url),
        file(dest, "wb"),
        log_warn = 1,
        log_err = 1,
        path = url,
        link_callback = pisa.pisaLinkLoader(url).getFileName
        )

    dumpErrors(pdf)
    if not pdf.err:
        pisa.startViewer(dest)

if __name__=="__main__":

    testSimple()
    # testCGI()
    #testBackgroundAndImage()
    #testURL()

Or you can use pdfkit :

https://pypi.python.org/pypi/pdfkit

Before using it you need to install some things :

pip install pdfkit
sudo apt-get install wkhtmltopdf

Sample code to generate pdf :

import pdfkit

pdfkit.from_url('http://stackoverflow.com', 'out.pdf')
pdfkit.from_file('test.html', 'out2.pdf')
pdfkit.from_string('Thanks for reading!', 'out3.pdf')
2 of 2
8

If you use django framework you could use django-easy-pdf. I think it's the least painfull way to generate PDF from Html. Here's the template and views of my project:

#Import the easy_pdf rendering
from easy_pdf.rendering import render_to_pdf_response

#Here's the detail view function
def detail_to_pdf(request,id):
    template = 'renderdetail.html'
    kucing = Kucing.objects.get(id = id)
    context = {'kucing' : kucing}
    return render_to_pdf_response(request,template,context)

The Template is:

{% extends "base.html" %}

{% block extra_style %}
    <style type="text/css">
        body {
            font-family: "Helvetica", "sans-serif";
            color: #333333;
        }
    </style>
{% endblock %}

{% block content %}
    <div id="content">
        <div class="main">
            <h1>PROFILE : {{ kucing.nama }}- ID:{{ kucing.id }}</h1>
            <img src="/media/{{ kucing.foto }}"><br>
            <p>Nama : {{ kucing.nama }}</p><br>
            <p>Hp : {{ kucing.hp}}</p><br>
            <p>Poin : {{ kucing.poin }}</p><br>
            <a href="{% url 'kucing_makan' kucing.id %}">Makan</a>
            <a href="{% url 'kucing_berburu' kucing.id %}">Berburu</a>
            <hr>
            <h5><a href="{% url 'kucing_home' %}">Back To Home</a></h5>|
            <h5><a href="{% url 'kucing_list' %}">See Another Kucing</a></h5>
        </div>
    </div>
{% endblock %}

You also able to use Class Based Views by overriding PDFTemplateViews. You can see more on the Docs.

🌐
Reportlab
docs.reportlab.com › rmlfornewbies
Quick Start Guide - ReportLab Docs
The template is loaded into preppy along with any dynamic data. Preppy then evaluates any python expressions and substitutes any variables, and outputs the result as text - so in this case, you are left with complete rml text which only has to be run through rml2pdf to create a pdf document.
🌐
Reportlab
docs.reportlab.com › webintegration › Integrating_ReportLab_into_your_website
Web Integration - ReportLab Docs
Report Markup Language from ReportLab is the simplest way to programatically produce great looking PDF documents with the minimum of fuss. It's an XML dialect which, combined with a python module which converts the XML files into PDF.
🌐
Reportlab
docs.reportlab.com › rml › tutorials › product-catalogue
Product catalogue - ReportLab Docs
XML product listing converted to a fully customisable PDF in seconds. Welcome to the new ReportLab tutorial. Here you can get a basic introduction to a common application architecture and start experimenting with some fundamental ReportLab technologies.
Find elsewhere
🌐
woteq
woteq.com › home › using reportlab to generate pdfs from xml data sources in python
Using ReportLab to generate PDFs from XML data sources in Python - woteq Softwares
December 6, 2025 - This article will guide you through the process of using ReportLab to parse XML data and generate dynamic PDFs. ReportLab is the de facto standard for PDF generation in Python.
🌐
Mouse Vs Python
blog.pythonlibrary.org › home › parsing xml and creating a pdf invoice with python
Parsing XML and Creating a PDF Invoice with Python - Mouse Vs Python
January 31, 2020 - Next we create our PDFOrder class which accepts two arguments: an xml file and a pdf file path. In our initialization method, we create a couple class properties, read the XML file and return an XML object.
🌐
GitHub
github.com › iamjarret › xml2pdf
GitHub - iamjarret/xml2pdf: xml2pdf in python using reportlab
Built on reportlab, makePDF takes an xml file and generates a fully rendered pdf, mimicking a powerpoint presentation · seperate design decisions and content decisions · implement catch-all slides · add fully rendered presentations easily ...
Author   iamjarret
🌐
Reportlab
reportlab.com › docs › rml2pdf-userguide.pdf pdf
RML User Guide Report Markup Language
January 25, 2026 - RML2PDF is a central component of the toolkit: a translator which converts high level XML markup into PDF · documents. Report Markup Language describes the precise layout of a printed document, and RML2PDF con- verts this to a finished document in one step. In a dedicated reporting application, ...
🌐
pdf noodle
pdfnoodle.com › home › blog › how to generate pdf using reportlab in python (updated 2025)
How to Generate PDF Using ReportLab in Python (Updated 2025) - pdf noodle
October 15, 2025 - Learn how to generate PDFs from HTML using ReportLab in Python. Step-by-step example covering setup, customization, and dynamic data generation.
🌐
ActiveState
code.activestate.com › recipes › 578561-xml-to-pdf-book-with-elementtree-and-xtopdf
XML to PDF book with ElementTree and xtopdf « Python recipes « ActiveState Code
September 3, 2021 - This recipe shows how to create a PDF book from XML text content. It requires my xtopdf toolkit, the ElementTree module (from Python's standard library) and the open source version of the ReportLab toolkit.
🌐
Reportlab
reportlab.com › docs › reportlab-userguide.pdf pdf
ReportLab PDF Library User Guide ReportLab Version 4.4.10
If you need to use Python 2, please use the latest ReportLab 2.7 package that is suitable for you. ... ReportLab is an Open Source project. Although we are a commercial company we provide the core PDF gen-
🌐
Openacs
openacs.org › rubick › pdf
rubick - Dynamically generating PDF files with ReportLab
You need to edit your pdf-defs.tcl file to include the new type in pdf_generate_pdf. Also create a new pdf-xxx.py Python file, and set it up as you like it.
🌐
GeeksforGeeks
geeksforgeeks.org › creating-pdf-documents-with-python
Creating PDF Documents With Python - GeeksforGeeks
March 21, 2024 - A very famous module named pypdf2 is used to modify and read existing pdfs but its major disadvantage is that it cannot create new pdf files. So Today we are looking to learn about another python module named report lab that helps us to create new pdf files and edit our heart's content on them. ... Reportlab: This module is used to handle PDF files.
🌐
DOKUMEN.PUB
dokumen.pub › reportlab-pdf-processing-with-python-1983154547-9781983154546.html
ReportLab: PDF Processing with Python 1983154547, 9781983154546 - DOKUMEN.PUB
In this book, you will learn how to use Reportlab to create PDFs too. This book will be split into three sections. We will be covering the following topics in the first section: The canvas Drawing Working with fonts PLATYPUS Paragraphs Tables Other Flowables Graphics and More! In the second section, we will learn about data processing. The idea here is to take in several different data formats and turn them into PDFs. For example, it is quite common to receive data in XML or JSON.
🌐
Reddit
reddit.com › r/python › looking for an "low dependency" or pythonesque way to generate pdf's
r/Python on Reddit: looking for an "low dependency" or pythonesque way to generate PDF's
October 10, 2022 -

I need to generate PDF's.

While pdfkit looks very promising with its ability to render HTML with styling (Which would absolutely be the most epicness as almost no new templating would have to be made) it also depends on wkhtmltopdf and maybe even a virtual X server.

I want my tool to be deployable without the hastle to install non pythonesque tools. I want people to be able to install my package and use it after installing its requirements.txt. previously I've been using FPDF but its also not so modern..

So anyone has any hints?

I'd also be open to hints about deployment if this is not as big of an issue as I think . As this is basically a webapp which people might run on their own PC's, I'm open to good firefox/chrome hints to print a styled page aswell.

🌐
Pythonrepo
pythonrepo.com › repo › xhtml2pdf-xhtml2pdf-python-working-with-html-and-xml
A library for converting HTML into PDFs using ReportLab | PythonRepo
February 19, 2022 - pyquery: a jquery-like library for python pyquery allows you to make jquery queries on xml documents. The API is as much as possible the similar to jq ... pdf-scraper-with-ocr With this tool I am aiming to facilitate the work of those who need to scrape PDFs either by hand or using tools that doesn't imp ... pdfdoc-py Python utility library for compositing PDF documents with reportlab.