Tag Archives: Reportlab

ReportLab Book Kickstarter’s – 2 Days Left

There is only a little over 2 days left for my ReportLab book Kickstarter. This is your only chance to purchase a signed copy of the book and it’s also probably the cheapest way of getting the eBooks too!

I currently have 7 chapters done with number 8 nearing completion. There are over 170 pages in these chapters alone. I hope you’ll check it out as ReportLab is a fun way to use Python to design dynamic reports in a PDF format.

ReportLab Book Chapter Sampler

I thought it would be fun to create a sample of the book so you can get an idea of what the book will be like. So I created a PDF that contains the first 3 chapters of the book for you.

Download Sample

Note that the format of this sample is not quite right as I had to generate it from a more complete version, so the PDF’s table of contents shows more than what is actually in the document.

Also I just broke through the 100 page boundary over the weekend. I am finishing up chapter 5 and will be cranking out another couple of chapters this week if all goes well.

Thanks for your support!
Mike

ReportLab Book Cover Story

I really like coming up with fun covers for my books. I also like to find new artists for each book so that they all end up looking unique. I do plan to re-use one or two artists at some point though.

Anyway, for the ReportLab book I happened to stumble across Therese Larsson’s website and I really liked how she did her lighting in her artwork. She is from Sweden and has worked with some fairly big companies, including Disney, Google, and Adidas. You can read more about her on Behance.

I ended up commissioning the cover from her and I described what I wanted. Here is the initial sketch:

ReportLab Cover Sketch

Continue reading ReportLab Book Cover Story

ReportLab 101: The textobject

The ReportLab toolkit provides multiple ways for you to generate text on your PDFs. The most popular examples that I have seen are using canvas methods or using PLATYPUS. The canvas method that you will likely see the most is drawString. Here is an example:

from reportlab.pdfgen import canvas
 
c = canvas.Canvas("hello.pdf")
c.drawString(100, 100, "Welcome to Reportlab!")
c.showPage()
c.save()

Basically all that does is draw a string at the x/y coordinates given. Using PLATYPUS is significantly more complicated:

from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
 
def hello():
    doc = SimpleDocTemplate("hello_platypus.pdf",
                            pagesize=letter,
                            rightMargin=72,
                            leftMargin=72,
                            topMargin=72,
                            bottomMargin=18)
    styles = getSampleStyleSheet()
 
    flowables = []
 
    text = "Hello, I'm a Paragraph"
    para = Paragraph(text, style=styles["Normal"])
    flowables.append(para)
 
    doc.build(flowables)
 
if __name__ == '__main__':
    hello()

You will note that most of the time when you use PLATYPUS, you will need to use a template, a style and a paragraph or some other Flowable. But let’s go back to the canvas. It actually has another method of generating text that ReportLab calls the textobject. Frankly I have never had the need for one of these as ReportLab’s Paragraph class gives you more than enough control over the presentation of your text. But if you depend on using the low level canvas for generating your PDFs, then you will like to know that a textobject will make PDF generation faster because it doesn’t use individual calls to drawString. Continue reading ReportLab 101: The textobject

ReportLab Book Funded + TOC

After collating the various ideas that people have been giving me during the Kickstarter campaign, I have decided to firm up my table of contents. I had already planned to cover 80-90% or more of what was in ReportLab’s user guide, but in more depth, as I thought most of those topics should be covered in book form. The rest of the book was going to be some HOW-TO type chapters and other Python packages that work with PDFs. With that in mind, here is what the table of contents is looking like:

Part I – The ReportLab Toolkit

  • Chapter 1 – The Canvas
  • Chapter 2 – Fonts
  • Chapter 3 – PLATYPUS
  • Chapter 4 – Paragraphs
  • Chapter 5 – Tables
  • Chapter 6 – Other Flowables
  • Chapter 7 – Custom Flowables
  • Chapter 8 – Charts / Graphs
  • Chapter 9 – Other Graphics
  • Chapter 10 – PDF Special Features (Forms, Links, Encryption)
  • Chapter 11 – Bar Codes / QR Codes

Part II – Tutorials / HOW-Tos

  • Chapter 12 – Turning XML into Multipage PDFs
  • Chapter 13 – Custom headers and footers, page numbers
  • Chapter 14 – Creating a table of contents (Stretch goal) 
  • Chapter 15 – Exporting Data from PDFs (pdfminer) (Stretch goal) 
  • Chapter 16 – Filling in PDF Forms with Python (pdfforms) (Stretch goal)
  • Chapter 17 – PyPDF2 / pdfrw
  • Chapter 18 – Converting Markup to PDF (rst2pdf, html2pdf, etc) (Stretch goal)
  • Chapter 19 – pyfpdf, An Alternative to ReportLab

Note that the chapter titles are subject to change. Also note that I have marked some of the chapters as “stretch goal” chapters. They may or may not get added depending on whether or not we reach our stretch goal.

Stretch Goal(s)

My stretch goal is to hit $6000 or 500 backers. If we hit either of those, than all of the chapters above will get added. If we don’t, then I will evaluate how close we got and I may put out a survey to see which two chapters we will keep and which two will be voted out of the book.

The last thing I would like to make note of is that the first 3 chapters of the book is over 60 pages of content all by themselves, so even if I only did the first section of the book (i.e. 11 or 12 chapters), the book would still be over 200 pages in length.

If you’d like to get early access to the book, then please go check out the Kickstarter!

ANN: ReportLab PDF Processing with Python Kickstarter

Have you ever wondered how to create PDF Reports programmatically? If so, then this is the book for you! In ReportLab: PDF Processing with Python, you will learn how to generate PDFs using the popular Python programming language. The code in this book will run on all 3 major platforms:

  • Windows
  • Mac
  • Linux

ReportLab is used by WikipediaNASAFidelityHP and many other large and small organizations.

ReportLab is fast and reliable. I have been using it for the past 10+ years professionally. It’s also quite easy to learn. In this book you will learn all you need to know to generate your own PDFs.

Here’s a sample of just some of things you will learn:

  • How to embed fonts
  • Generate multipage documents
  • Add tables
  • Insert photos
  • Add graphs to your PDF
  • Add barcodes to your PDF
  • Draw shapes
  • Generate multi-column pages
  • Tutorials on generating specific complex examples

This book will be split into two main parts. The first part will contain pretty thorough coverage of the various parts of ReportLab. The second part will be a short series of chapters on how to create various layouts with ReportLab.

I am also planning a section (or series of appendices) of the book that will introduce you to other Python PDF packages such as PyPDF2 and rst2pdf and how you might use them.

If you would like to be a part of this project, then check out my Kickstarter now!

Reportlab – How to Add Charts / Graphs

Reportlab is really nice tool for creating PDFs in Python. A little known fact is that they now support adding charts or graphs to your PDF. Previously if you wanted that functionality, you would have to do all the drawing code yourself. Unfortunately, the Reportlab guide doesn’t really explain how to use their charts, what kinds of charts are supported or what their parameters / attributes / etc are. They do have some example code snippets on their website though. In this article, we’ll go over a couple of simple examples to show you how to use Reportlab’s charting capabilities.

Continue reading Reportlab – How to Add Charts / Graphs

Reportlab for Python 3 is here!

Reportlab recently released version 3.1 which now fully supports Python 3 and Python 2.7. They had actually released a Python 3 compatible version about a month or so ago, but this one sounds like they’ve worked the bugs out of that initial release as this version also supports their commercial customers. I find this exciting in that one of my favorite Python packages finally supports Python 3. I haven’t moved to Python 3 myself because I use so many packages that are only available for Python 2 (and also because I have yet to work for a place that uses Python 3). There aren’t really any awesome new features in Reportlab 3.1 as of yet, but you can read through their release notes and decide for yourself.

One cool new feature of Reportlab is that you can now install it with pip or easy_install. They have also introduced Python wheel packages as their primary installation type, although you can still download the source. See PyPI for the open source downloads.

Check it out and let me know what you think!

Reportlab: How to Create Custom Flowables

Reportlab is a very flexible PDF creation package for Python. You can layout your documents using absolute positioning or by using Flowable objects, such as a Paragraph, a Table or Frame. You can even mix the two together! In this article, we will be looking at how to create some custom Flowables. For example, what do you do if you need to add a line to demarcate the start of a new section in your document? There isn’t really a built-in Flowable for that, so we’ll design our own. We will also design a flowable that has a line and a box with text inside of it.

Let’s get started! Continue reading Reportlab: How to Create Custom Flowables

Reportlab: How to Create Landscape Pages

The other day I had an interesting task I needed to complete with Reportlab. I needed to create a PDF in landscape orientation that had to be rotated 90 degrees when I saved it. To make it easier to lay out the document, I created a class with a flag that allows me to save it in landscape orientation or flip it into portrait. In this article, we’ll take a look at my code to see what it takes. If you’d like to follow along, I would recommend downloading a copy of Reportlab and pyPdf (or pyPdf2). Continue reading Reportlab: How to Create Landscape Pages