Reportlab is awesome. It took me about a day or two to figure out how to programmatically produce quite complex PDF-files. I installed Reportlab into my venv and then I created a folder inside my project called pdf_generator. I created a file called factory.py. I have a method in there which takes a… Answer from Spidiffpaffpuff on forum.djangoproject.com
🌐
Django Forum
forum.djangoproject.com › using django › forms & apis
How to create a pdf report Reportlab - Forms & APIs - Django Forum
July 24, 2020 - 0 I was wondering how could I create a pdf report using reportlab. I’m developing a web site and I’m using Django. In my project I charged a lot of icons, and I was using a Javascript function(PrintThisjs), but it doesn’t work well. Seems like Reportlab is a good solution. Thanks 🙂
🌐
Eric Saupe's Blog
eric.sau.pe › reportlab-and-django-part-1-the-set-up-and-a-basic-example
ReportLab and Django - Part 1 - The Set Up and a Basic Example
January 14, 2014 - This is limiting because it is difficult to add headers and footers, positioning objects on the page is tricky, and we have a bad problem with it printing blank pages due to random overflow of the elements. We needed a better solution and we have found it with ReportLab.
Discussions

python - Generate PDF from HTML using Django and Reportlab - Stack Overflow
I am coming back with a new question which I am unable to answer, having scratched my head the whole day on it. I want to generate a PDF from a webpage by clicking on a "Download PDF" button. I tr... More on stackoverflow.com
🌐 stackoverflow.com
ReportLab in Django - Stack Overflow
I'm making a bar graph using ReportLab in Django. I'm able to get the pdf generated, but it is saved in my root directory. Instead I want that the PDF should opened in the browser itself. How can I... More on stackoverflow.com
🌐 stackoverflow.com
January 5, 2015
ReportLab and Python 3.12 with Django 5.0.6
wsgi is not using the shell venv. i would check the environment in which wsgi is running. dm can jump on call More on reddit.com
🌐 r/djangolearning
5
1
June 30, 2024
Django, ReportLab PDF Generation attached to an email - Stack Overflow
What's the best way to use Django and ReportLab to generate PDFs and attach them to an email message? I'm using a SimpleDocTemplate and can attach the generated PDF to my HttpResponse - which is g... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reportlab
docs.reportlab.com
ReportLab Docs
Our flagship commercial tool for making beautiful PDFs quickly using Report Markup Language and a preprocessor. Create PDFs the same way you create dynamic web pages · The engine for ReportLab Plus, containing most but not all of the building blocks. Create a graph of Python objects and render ...
🌐
Django
django.readthedocs.io › en › 2.0.x › howto › outputting-pdf.html
Outputting PDFs with Django — Django 2.0.14.dev20190701080343 documentation
This document explains how to output PDF files dynamically using Django views. This is made possible by the excellent, open-source ReportLab Python PDF library.
🌐
ASSIST Software Romania
assist-software.net › blog › how-create-pdf-files-python-django-application-using-reportlab
How to create PDF files in a Python/Django application using ReportLab | ASSIST Software
Official Django documentation contains a basic tutorial about saving data in PDF (Portable Document Format). First of all, in order to use this library you need to install it. You can install it using pip or easy_install by typing: pip install reportlab or easy_install reportab in your virtual environment.
🌐
Netlify
ericsaupe.netlify.app › reportlab-and-django-–-part-3-–-paragraphs-and-tables
ReportLab and Django – Part 3 – Paragraphs and Tables | Blog
It holds text or images and will wrap when it reaches the end of the drawable area. You can set a style for a Paragraph by creating a ParagraphStyle and applying it to your Paragraph. ReportLab comes with a number of built in styles but I found that I preferred creating my own styles to give ...
Find elsewhere
🌐
Django Documentation
docs.djangoproject.com › en › 5.0 › howto › outputting-pdf
How to create PDF files | Django documentation | Django
This document explains how to output PDF files dynamically using Django views. This is made possible by the excellent, open-source ReportLab Python PDF library.
🌐
Medium
medium.com › @saijalshakya › generating-pdf-with-reportlab-in-django-ee0235c2f133
Generating PDF with reportLab in Django | by Saijal Shakya | Medium | Medium
April 27, 2019 - from io import BytesIOfrom reportlab.pdfgen import canvasfrom django.http import HttpResponsefrom reportlab.lib.pagesizes import letter, landscapefrom reportlab.lib.pagesizes import A4
🌐
Coffee bytes
coffeebytes.dev › home › english › django › generating pdfs with django and reportlab
Generating PDFs with Django and Reportlab | Coffee bytes
June 13, 2026 - Tutorial about how to generate a PDF in Django using Reportlab and learn how to position text, change text color, generate it dynamically using models from the database and how to return it as a HTTP response
🌐
Fundor333
fundor333.com › post › 2022 › django-return-pdf-with-reportlab
Django Return Pdf With Reportlab | Fundor333
February 28, 2022 - Sometime you need to print a pdf from your site or your web app with some custom data. In Python you can make pdf with ReportLab12 and some other module but I LOVE ReportLab3.
🌐
Simple is Better Than Complex
simpleisbetterthancomplex.com › tutorial › 2016 › 08 › 08 › how-to-export-to-pdf.html
How to Export to PDF
August 8, 2016 - There are a few ways to export data to a PDF file using Django. All of them requires a third-party library so to generate the file itself. First I will show how to return a PDF response, which can also be used if you are just serving an existing PDF file. Then I will show how to use ReportLab and WeasyPrint.
🌐
Reddit
reddit.com › r/djangolearning › reportlab and python 3.12 with django 5.0.6
r/djangolearning on Reddit: ReportLab and Python 3.12 with Django 5.0.6
June 30, 2024 -

SOLVED: Does anybody use ReportLab with Django 5 and Python 3.12?

I think mainly my issue is with using 3.12 but also I think it would be strange that ReportaLab works fine in dev using the same setup, Django and Python versions.

Basically I get a ‘ModuleNotFoundError: reportlab not found. ‘ when I launch the application with wsgi and Apache. However, when in a shell I use ‘from reportlab.pdfgen import canvas ‘ and then some more stuff to print a pdf and save it, I get the test.pdf just fine. Which should mean the Python interpreter is having no issue, and maybe it’s with my wsgi.py.

I’ve rebuilt the venv last night just in case that was the issue. Right now the app is in production and usable just without the pdf functionality.

🌐
Packt
packtpub.com › en-us › learning › how-to-tutorials › django-12-e-commerce-generating-pdf-reports-python-using-reportlab
Django 1.2 E-commerce: Generating PDF Reports from Python using ReportLab
ReportLab is an open source project available at http://www.reportlab.org. It is a very mature tool and includes binaries for several platforms as well as source code. It also contains extension code written in C, so it's relatively fast. It is possible for ReportLab to insert PNG and GIF image files into PDF output, but in order to do so we must have the Python Imaging Library (PIL) installed.
Top answer
1 of 3
11

Using ReportLab


try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter, A4
from reportlab.lib.units import inch

def createPDF(request):
 x=100
 y=100
 buffer=StringIO()
 p=canvas.Canvas(buffer,pagesize=letter)
 p.drawString(x,y,"HELLOWORLD")
 p.showPage()
 p.save() 
 pdf=buffer.getvalue()
 buffer.close() 
 return pdf

def someView(request):
 EmailMsg=mail.EmailMessage(YourSubject,YourEmailBodyCopy,'[email protected]',["[email protected]"],headers={'Reply-To':'[email protected]'})
 pdf=createPDF(request)
 EmailMsg.attach('yourChoosenFileName.pdf',pdf,'application/pdf')
 EmailMsg.send()

Works perfectly!!

2 of 3
6

OK - I figured it out based on piecing a few things together -

First off - my requirements: - I only wanted to create the PDFs in memory - I don't want the files hanging around, as they take up space, and I don't want what might be sensitive data hanging around unprotected on the server.

So - I picked ReportLab and Platypus functionality for generating my documents. I've invested enough time into it now, that's it's easy. So here's my approach that lets me use the DocTempates in ReportLab, allows me to use Django's email capabilities to send emails.

Here's how I'm doing it:

 # Create the PDF object, using the buffer object as its "file."
  buffer = StringIO()
  doc = SimpleDocTemplate(buffer, pagesize=letter)
  Document = []

  # CRUFT PDF Data

  doc.build(Document)
  pdf = buffer.getvalue()
  buffer.close()

  email = EmailMessage('Hello', 'Body', '[email protected]', ['[email protected]'])
  email.attach('invoicex.pdf', pdf , 'application/pdf')
  email.send()

My issue from moving from web generation to email generation was getting the right object that could be "attached" to an email. Creating a buffer, then grabbing the data off the buffer did it for me...

🌐
Reportlab
docs.reportlab.com › demos
Demos - ReportLab Docs
4) graphic_card/ - This shows the use of reportlab/graphics to make a very simple "image card", 5) fundfacts/ - A Django project with some sample data and a landscape PDF report showing the techniques to create tables, charts and various types of content in our framework.