Entries tagged with “Reportlab”.

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 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! (more…)

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). (more…)

Have you ever needed to add page numbers to your Reportlab generated PDF but didn’t know how? Well you’ve come to the right place. We’re going to look at how to add page number in three different circumstances:

  1. How to add page numbers with just the canvas object
  2. How to add page numbers using the SimpleDocTemplate
  3. How to add “Page # of #” (i.e. Page 1 of 10)

Are you ready? Let’s do this thing! (more…)

This week I was trying to figure out how to make Reportlab do something I had never attempted before. Namely, I wanted to create about a half page’s worth of static text positioned exactly and then have a table of line items that could potentially fill the rest of the page and continue for N pages thereafter. The problem is that mixing Reportlab’s canvas object with flowables can be messy. Reportlab talks a little about using templates in its user guide, but it only shows how to add header and footer type information. That’s actually all the information I needed, but it took me quite a while to realize that. I asked about how to do this sort of thing on the Reportlab mailing list. At the time of this writing, no one on there told me how to do it. Anyway, I figured it out on my own and now I’m going to show you! If you’d like to follow along, you’ll probably need to go get a free copy of Reportlab yourself. (more…)

Have you ever wondered how to embed custom fonts in Reportlab? Or maybe you just want to switch fonts or change the font’s color. Well in this tutorial, we’ll take a look at all of these questions. You’ll need to go out and download a copy of Reportlab as it isn’t a part of the standard Python installation. You can go to PyPI or the official Reportlab website to get the package. Reportlab only works with Python 2.5-2.7, so keep that in mind. Once you’re ready, we can continue. (more…)

The Reportlab library is a great way to generate PDFs in Python. Recently, I noticed that it has the ability to do barcodes. I had heard about it being able to generate QR codes, but I hadn’t really dug under the covers to see what else it could do. In this tutorial, we’ll take a look at some of the barcodes that Reportlab can generate. If you don’t already have Reportlab, go to their website and get it before jumping into the article. (more…)

Recently I needed the ability to use Reportlab’s flowables, but place them in fixed locations. Some of you are probably wondering why I would want to do that. The nice thing about flowables, like the Paragraph, is that they’re easily styled. If I could bold something or center something AND put it in a fixed location, then that would rock! It took a lot of Googling and trial and error, but I finally got a decent template put together that I could use for mailings. In this article, I’m going to show you how to do this too. (more…)

I was recently asked to convert a few hundred images into PDF pages. A friend of mine draws comics and my brother wanted to be able to read them on a tablet. Alas, if you had a bunch of files named something like this:

'Jia_01.Jpg', 'Jia_02.Jpg', 'Jia_09.Jpg', 'Jia_10.Jpg', 'Jia_11.Jpg', 'Jia_101.Jpg'

the Android tablet would reorder them into something like this:

'Jia_01.Jpg', 'Jia_02.Jpg', 'Jia_09.Jpg', 'Jia_10.Jpg', 'Jia_101.Jpg', 'Jia_11.Jpg'

And it got pretty confusing the more files you had that were out of order. Sadly, even Python sorts files this way. I tried using the glob module on the directly and then sorting the result and got the exact same issue. So the first thing I had to do was find some kind of sorting algorithm that could sort them correctly. It should be noted that Windows 7 can sort the files correctly in its file system, even though Python cannot. (more…)

A lot of websites are doing year-end retrospectives this week, so I thought you might find it interesting to know which articles on this blog were the most popular this year. Below you will find links to each article along with the page view count I got from Google Analytics:

  1. A Simple Step-by-Step Reportlab Tutorial, 9,709 page views, posted 03/08/2010
  2. Another Step-by-Step SqlAlchemy Tutorial Part 1, 7,746 page views, posted 02/03/2010
  3. Another Step-by-Step SqlAlchemy Tutorial Part 2, 4,858 page views, posted 02/03/2010
  4. Manipulating PDFs with Python and pyPdf, 4,511 page views, posted 05/15/2010
  5. Python 101: Introspection, 4,473 page views, posted 10/14/2010
  6. wxPython: Grid Tips and Tricks, 3,476 page views, posted 04/04/2010
  7. wxPython: Creating a Simple MP3 Player, 3,401 page views, posted 04/20/2010
  8. Python and Microsoft Office – Using PyWin32, 3,323 page views, posted 07/16/2010
  9. wxPython and Threads, 3,183 page views, posted 05/22/2010

It would seem that SqlAlchemy and Reportlab are pretty popular topics. Are there any articles about either of these cool packages that you think I should write? As you can see, wxPython makes it into the top ten 3 times! What should I write about next regarding wxPython?

This upcoming year, I plan to write about some of the other GUI toolkits. Which one do you think I should do first? Tkinter, PySide, PyGUI or something else? What packages or standard libraries do you think I should cover? Feel free to let me know via the comments below or via my contact form (link at top). I’m looking forward to another year of Python tinkering and writing and I hope you are too! Thanks for your readership and encouragement this year!