You can check Celery. The idea is to use asynchronous task queue/job queue based on distributed message passing using a broker like RabbitMQ or Redis

http://www.celeryproject.org/

Ideally, your background task should run on servers different from the application servers so that they can scale independently and won't affect each other.

Answer from randy on Stack Overflow
🌐
PyPI
pypi.org › project › django-weasyprint
django-weasyprint · PyPI
A Django WeasyPrint integration providing class-based view and response class for generating PDF from templates.
Discussions

django - Python Weasyprint - Stack Overflow
Please bear with me as i put these into words, I am running Weasyprint on Python Django Framework, I have have 15 page html to render to PDF. Rendering takes about 70% to 80% of my CPU when on... More on stackoverflow.com
🌐 stackoverflow.com
django-bootyprint: A django pdf rendering app for WeasyPrint with a CSS companion
Curious about your take on what's the benefit of using a 3rd party library over the `django.template.loader.render_to_string`passed to Weasyprints HTML object and calling `write_pdf` method on the HTML object? from django.template.loader import render_to_string from weasyprint import HTML context = {} html_string = render_to_string("template.html", context=context) rendered_html = HTML(string=html_string) pdf_file_obj = rendered_html.write_pdf() More on reddit.com
🌐 r/Python
2
8
June 25, 2025
Pdfkit vs weasyprint ?
My experience with weasyprint was very good. No experience with pdfkit. Reportlab is junk btw. More on reddit.com
🌐 r/django
21
16
April 14, 2023
Django convert HTML to PDF using "django-weasyprint"

Hi,

Here's a simple example using function based views.

def download_my_pdf (request, template="yourpdf.html"):
    from weasyprint import HTML, CSS
    from django.shortcuts import HttpResponse

    pdf_html = render_to_string(template, locals())
    pdf_file = HTML(string=pdf_html).write_pdf(stylesheets=[CSS(string='@page { size: letter portrait; margin: 1cm }')])

    response = HttpResponse(pdf, content_type='application/pdf')
    response['Content-Disposition'] = 'filename="mypdf.pdf"'
    return response

Just put something in the yourpdf.html template, create a line urls.py to point to this view, for example with :

re_path(r'^download_my_pdf/$', myviews.download_my_pdf, name="download_my_pdf"),    

it should download a PDF when you visit the url.

More on reddit.com
🌐 r/django
6
1
May 24, 2022
People also ask

Why are my images and CSS missing in the WeasyPrint PDF?
Almost always a base_url problem. WeasyPrint receives only an HTML string, so relative URLs have nothing to resolve against. Pass base_url=request.build_absolute_uri('/') (or absolute file:// paths) and make sure those assets are actually reachable. In production with DEBUG=False, confirm your static files are collected and served, or point WeasyPrint at files on disk via staticfiles finders.
🌐
micropyramid.com
micropyramid.com › home › blog › django › generate pdf files from html in django with weasyprint
Generate PDF Files from HTML in Django Using WeasyPrint | MicroPyramid
Does WeasyPrint run JavaScript when generating a PDF?
No. WeasyPrint renders HTML and CSS only — it has no JavaScript engine. If your page draws content with JavaScript (for example a Chart.js graph or a React dashboard), render that data into static HTML/SVG on the server first, or use a headless-Chrome/Playwright pipeline. For server-rendered Django templates, the lack of a JS engine is a feature: WeasyPrint is lighter and more predictable.
🌐
micropyramid.com
micropyramid.com › home › blog › django › generate pdf files from html in django with weasyprint
Generate PDF Files from HTML in Django Using WeasyPrint | MicroPyramid
Can WeasyPrint fill in or edit an existing PDF form?
No — WeasyPrint creates new PDFs from HTML and CSS; it does not edit, merge or fill existing PDF files. For that, combine it with a library like pypdf or pikepdf (to merge or stamp pages) or ReportLab's form tools. A common pattern is to render the body with WeasyPrint and then merge it with a pre-made cover page using pypdf.
🌐
micropyramid.com
micropyramid.com › home › blog › django › generate pdf files from html in django with weasyprint
Generate PDF Files from HTML in Django Using WeasyPrint | MicroPyramid
🌐
GitHub
github.com › fdemmer › django-weasyprint
GitHub - fdemmer/django-weasyprint: A Django class-based view generating PDF resposes using WeasyPrint · GitHub
A Django WeasyPrint integration providing class-based view and response class for generating PDF from templates.
Author: fdemmer
🌐
GitHub
github.com › fdemmer › django-weasyprint › releases
Releases · fdemmer/django-weasyprint
A Django class-based view generating PDF resposes using WeasyPrint - Releases · fdemmer/django-weasyprint
Author: fdemmer
🌐
MicroPyramid
micropyramid.com › home › blog › django › generate pdf files from html in django with weasyprint
Generate PDF Files from HTML in Django Using WeasyPrint | MicroPyramid
June 10, 2026 - Generate PDF files from HTML templates in Django with WeasyPrint: install Pango deps, render with base_url, style with @page CSS, and email PDFs via Celery.
Find elsewhere
🌐
GitHub
github.com › fdemmer › django-weasyprint › blob › main › CHANGELOG.md
django-weasyprint/CHANGELOG.md at main · fdemmer/django-weasyprint
Improve URL Fetcher to return redirected_url with 'file://' prefix for image cache using LazyLocalImage with WeasyPrint v59.0 (#74) Add Python 3.12 and Django 5.0 to test matrix, remove Django 4.0 and 4.1
Author: fdemmer
🌐
DEV Community
dev.to › bielmartin › weasyprint-pdf-generator-using-html-in-django-2lij
"weasyprint" pdf generator using HTML - in django - DEV Community
March 20, 2022 - To handle the information in your html file, weasyprint accepts resources like jinja to handle your queries.
🌐
Reddit
reddit.com › r/python › django-bootyprint: a django pdf rendering app for weasyprint with a css companion
r/Python on Reddit: django-bootyprint: A django pdf rendering app for WeasyPrint with a CSS companion
June 25, 2025 -

Hi,

I'd like to introduce a generic library to create PDF documents with WeasyPrint.

This django app has always the latest BootyPrint CSS framework bundled, so you can just load the css and use css classes similar to Bootstrap.

Source: https://github.com/SvenBroeckling/django-bootyprint

What My Project Does

This django app contains a low level generate_pdf function to create a WeasyPrint PDF file from HTML source. This is extended by Django mechanics like a Response class for easy returning PDF from a View as well as template tags.

Its companion is the BootyPrint CSS framework which resembles Bootstrap, but for print media created with WeasyPrint.

With the template tag {% bootyprint_css %} in the template, a lot of Bootstrap style classes are available.

Future plans

This library will be extended in the future. Planned features are:

  • Rendering of PDF previews/thumbnails as png

  • Providing more control over the render process. Rendering in memory (instead of the current temp file)

Target Audience

This is a library used in production. It is used to create roleplay rule books, character sheets and job application letters.

Comparison

Alternatives are:

  • django-weasyprint

🌐
DEV Community
dev.to › bowmanjd › python-pdf-generation-from-html-with-weasyprint-538h
Python PDF Generation from HTML with WeasyPrint - DEV Community
February 9, 2026 - django-weasyprint provides a WeasyTemplateView view base class or a WeasyTemplateResponseMixin mixin on a TemplateView
🌐
Reddit
reddit.com › r/django › pdfkit vs weasyprint ?
r/django on Reddit: Pdfkit vs weasyprint ?
April 14, 2023 -

I have a pretty heavy website and want to generate pdf tickets , can be up to 20 per user per order, I already have pdfkit installed and working nicely with a small users number. But as my website grows I ask myself what is the better option between those two? Or is there a better third option …

My main concern is scalability and performance, my setup is a docker compose with django and celery for async pdf generation, hosted on aws elastic beanstalk with their auto scaling.

Can someone share his experience with pdf generation in django ?

Thanks guys for reading

🌐
PyPI
pypi.org › project › django-weasypdf
django-weasypdf · PyPI
April 20, 2023 - A Django class-based view helper to generate PDF with WeasyPrint
      » pip install django-weasypdf
    
Published: Apr 20, 2023
Version: 0.1.2
🌐
Reddit
reddit.com › r/django › django convert html to pdf using "django-weasyprint"
r/django on Reddit: Django convert HTML to PDF using "django-weasyprint"
May 24, 2022 -

Hello everyone, so for the past 3 nights Ive been trying to figure out how to export an HTML template to a PDF. I managed to make it work with "xhtml2pdf" but it seems its funcionality regarding styling is very limited and not very practical.

I found something called "django-weasyprint" which is a " A Django class-based view generating PDF responses using WeasyPrint. "

If you go to Weasyprint website, the PDFs are very nice, thats what Im aiming for.

The problem is, I cant manage to make it work with "django-weasyprint" which is supposed to make it easier to convert from html to pdf, instead of using "weasyprint" from scratch.

The "django-weasyprint" docs:

django-weasyprint/README.rst at main · fdemmer/django-weasyprint (github.com)

In the "Usage" section, I can't understand completely what they are saying, I'm a noob in web dev, but used class based views before, django REST framework etc. Here what they say:

"Usage

Use WeasyTemplateView as class based view base class or the just the mixin WeasyTemplateResponseMixin on a TemplateView (or subclass thereof)."

and the main "weasyprint" site is:

WeasyPrint

Can someone help me with a basic example of how to use it, I dont want super fancy code just enough to understand how it works and display a pdf from an html template.

Thanks for any help, good night!

🌐
Pyplane
blog.pyplane.com › blog › generate-pdf-files-with-django-weasyprint
pyplane - django blog | Generate PDF Files with Django WeasyPrint
October 10, 2019 - pip install WeasyPrint Now let's head over to the views.py and take a look at our view: from django.http import HttpResponse from django.template.loader import render_to_string from weasyprint import HTML import tempfile def get_generated_problems_in_pdf(request): # queryset problems = Problem.objects.all() # context passed in the template context = {'problems': problems} # render html_string = render_to_string( 'reports/problems.html',context) html = HTML(string=html_string) result = html.write_pdf() # http response response = HttpResponse(content_type='application/pdf;') response['Content-Di
🌐
Medium
medium.com › @betancourt.francisco › episode-2-creating-a-pdf-generating-django-application-73a31f332fd4
Episode 2 — Creating a PDF generating Django Application | by Francisco Betancourt | Medium
February 6, 2024 - We’ll be using Django signals to handle the PDF generation once a requests exists. In particular we’ll use the post save signal to run code when a new PageRequest is created: The code that renders the page as PDF uses weasyprint to do it’s job and lives in the tasks file:
🌐
Malnossi
malnossi.github.io › blog › django-weasyprint
Create PDF files with Django & Weasyprint
November 5, 2025 - While Django handles the HTML web interface easily, turning HTML + CSS into a polished PDF can be tricky. That’s where WeasyPrint comes in: it’s a library that renders HTML and CSS to PDF and works nicely in a Django context.
🌐
GitHub
github.com › NinjyaMaster › Docker-Django-PDF-Generator-WeasyPrint
GitHub - NinjyaMaster/Docker-Django-PDF-Generator-WeasyPrint: This project uses WeasyPrint and Django in a Docker container to produce a PDFs. It offers a consistent and reliable method for PDF generation in Django apps.
By harnessing WeasyPrint's HTML-to-PDF capabilities and Django's dynamic rendering, users can produce customized PDF outputs. Docker encapsulates the dependencies, ensuring consistent results across different environments.
Author: NinjyaMaster
🌐
Django Forum
forum.djangoproject.com › using django › mystery errors
Image not showing in pdf generated with weasyprint
December 5, 2024 - I have an app that allows you to upload an image and I need to generate a pdf with that image. I use weasyprint to generate the pdf but it does not show the image. In an html file the image does show, but in a pdf file it does not. What am I doing wrong? view.py def Export_pdf(request, student_id): student = get_object_or_404(Student, id=student_id) # return render(request, 'sendInfo/home_page.html', {'student' : student}) html_string = render(request, 'sendInfo/home_page.h...