Questions tagged [reportlab]

A library for generating PDF in Python.

ReportLab is an open source Python library that generates PDFs. It offers two main tools for creating PDFs: direct drawing to a PDF canvas and Platypus, an object-oriented document building framework (All can be combined). Unlike its commercial variant (ReportLab Plus) ReportLab does not support the use of to generate PDFs.

This is a basic example of usage:

from reportlab.pdfgen import canvas
from reportlab.lib.units import inch

c = canvas.Canvas("hello.pdf")

c.translate(inch,inch)  # move the origin up and to the left
c.setFont("Helvetica", 80)  # define a large font

c.setStrokeColorRGB(0.2,0.5,0.3)  # choose some colors
c.setFillColorRGB(1,0,1)

c.rect(inch,inch,6*inch,9*inch, fill=1)  # draw a rectangle
c.rotate(90)  # make text go straight up
c.setFillColorRGB(0,0,0.77)  # change color

# say hello (note after rotate the y coord needs to be negative!)
c.drawString(3*inch, -3*inch, "Hello World")

c.showPage()
c.save()

The primary support documents for ReportLab are the ReportLab PDF Library User Guide and the ReportLab PDF API Reference.

1269 questions
50
votes
3 answers

How to set any font in reportlab Canvas in python?

I'm using reportlab to create pdfs. When I try to set a font using the following method, I get a KeyError: pdf = Canvas('test.pdf') pdf.setFont('Tahoma', 16) But if I use 'Courier' instead of 'Tahoma' there isn't a problem. How can I use Tahoma?
srisar
  • 1,495
  • 5
  • 18
  • 27
42
votes
6 answers

Export Pandas DataFrame into a PDF file using Python

What is an efficient way to generate PDF for data frames in Pandas?
b8con
  • 459
  • 1
  • 6
  • 10
37
votes
3 answers

dict_items object has no attribute 'sort'

First of all I am new to Python. I am using PTVS http://pytools.codeplex.com/. Next I installed reportlab. Then I run a sample demo at https://github.com/nakagami/reportlab/blob/master/demos/colors/colortest.py#L68 But at line, all_colors =…
Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322
34
votes
4 answers

How to change text/font color in reportlab.pdfgen

I want to use a different color of text in my auto-generated PDF. According to the reportlab docs all I need to do is: self.canvas.setFillColorRGB(255,0,0) self.canvas.drawCentredString(...) But that doesn't do anything. The text is black no matter…
Goro
  • 9,919
  • 22
  • 74
  • 108
33
votes
3 answers

Transparency in PNGs with reportlab 2.3

I have two PNGs that I am trying to combine into a PDF using ReportLab 2.3 on Python 2.5. When I use canvas.drawImage(ImageReader) to write either PNG onto the canvas and save, the transparency comes out black. If I use PIL (1.1.6) to generate a…
Dire Fungasaur
  • 433
  • 1
  • 5
  • 7
31
votes
1 answer

Multiple pages using Reportlab - Django

I'm working in a site using Django and I print a .pdf file using Repotlab. Now, I want the file to have multiple pages, how can I do it? My code: from reportlab.pdfgen import canvas from django.http import HttpResponse def Print_PDF(request): …
Andres
  • 4,323
  • 7
  • 39
  • 53
26
votes
4 answers

Wrap text in a table reportlab?

I use a table but, I draw in in a canvas to control the position of the flowables, this because I have a template in a pdf, an I merge with pyPDF. The wrap is done in a table but the text go up, not down that's what I hope. c is the canvas Code from…
Alquimista
  • 862
  • 2
  • 10
  • 24
26
votes
4 answers

Insert image into Reportlab either from PIL image or StringIO

I'm trying to insert a barcode image into Reportlab. I know there are a lot of questions asked on this, but all of them assume that you already have the image file in the directory or on the filesystem. Due to the fact that Reportlab has issues…
Mark
  • 2,137
  • 4
  • 27
  • 42
23
votes
5 answers

Reportlab : How to switch between portrait and landscape?

I am using reportlab to generate a pdf report automatically from dynamic data. As the content sometimes is too large to be displayed in portrait, I am trying to switch to landscape for large content. Here is how my report generation works : Main…
Mathieu C.
  • 453
  • 1
  • 4
  • 10
21
votes
5 answers

A multiline(paragraph) footer and header in reportlab

What is a best way to have a footer and header in reportlab, that not just a single line, that can be drawed with canvas.drawString in onPage function. Didn`t find a way to put something like Paragraph into header/footer in onPage function. What is…
Aldarund
  • 17,312
  • 5
  • 73
  • 104
21
votes
3 answers

ReportLab: How to align a textobject?

I have the following ReportLab code: t = c.beginText() t.setFont('Arial', 25) t.setCharSpace(3) t.setTextOrigin(159,782) t.textLine("Some string") c.drawText(t) What I want to achieve is: have a 3 (pixels?) space between…
Nicu Surdu
  • 8,172
  • 9
  • 68
  • 108
21
votes
1 answer

Add page break to Reportlab Canvas object

I need to generate a 2 pages pdf report. Pages are completely independent. tried using: mycanvas.drawString(x, y, "Printing on Page 1") mycanvas._pageNumer = 2 mycanvas.drawString(x, y, "Printing on Page 2") and: mycanvas.drawString(x, y, "Printing…
juanefren
  • 2,818
  • 6
  • 32
  • 41
21
votes
3 answers

ReportLab: working with Chinese/Unicode characters

TL;DR: Is there some way of telling ReportLab to use a specific font, and fallback to another if glyphs for some characters are missing? Alternatively, Do you know of a condensed TrueType font which contains the glyphs for all European languages,…
ztorage
  • 323
  • 2
  • 6
20
votes
5 answers

How to Repeat Table Column Headings over Page Breaks in PDF output from ReportLab

I'm using ReportLab to write tables in PDF documents and am very pleased with the results (despite not having a total grasp on flowables just yet). However, I have not been able to figure out how to make a table that spans a page break have its…
PolyGeo
  • 1,340
  • 3
  • 26
  • 59
19
votes
6 answers

Installation: Reportlab: "ImportError: No module named reportlab.lib"

I've installed reportlab, via pip install reportlab (also tried via easy_install reportlab ) ..but I get the above error. There are other RL imports before that - it's the .lib that it's objecting to. I've had RL working great in the past, but IT…
DeltaG
  • 760
  • 2
  • 9
  • 28
1
2 3
84 85