There are times when you want to rotate images or other objects in ReportLab while creating a PDF. For example, you might want to rotate an image by 45 degrees for watermarking purposes. Or you might need an image that runs vertically along one of the edges of the PDF.
You can rotate images by using ReportLab’s canvas methods or by using its higher level Flowables that you can find in the platypus. module. Let’s start by looking at how to do this with the canvas directly!
Rotating Images Using Canvas
Rotating images using the canvas is kind of confusing. The reason being that when you rotate the canvas, you may end up inadvertently rotating other elements on your canvas if you’re not careful.
Let’s take a look at the code: Continue reading Rotating Images in ReportLab
In honor of PyCon 2019 that is starting this week, I am putting three of my books on sale. You can get any of the following books for $9.99 through May 6th by clicking on the links:
Python 201 is a fun book for those of you who would be interested in learning intermediate and advanced topics in Python.
My ReportLab book covers how to create PDFs using Python and ReportLab. It also covers many other topics related to PDFs, such as splitting, merging and overlaying PDFs to name a few.
Finally my Jupyter Notebook 101 book is a good way for you to learn about the Jupyter Notebook and many of its capabilities.
I recently released a new book entitled ReportLab: PDF Processing with Python. In celebration of a successful launch, I have decided to do a little contest.
- Post a comment telling me why you would want a copy
- The most clever or heartfelt commenter will be chosen by me
The contest will run starting now until Friday, August 17th @ 11:59 p.m. CST.
Runners up will receive a free copy of the eBook. The grand prize will be a signed paperback copy + the eBook version!
My latest book, ReportLab: PDF Processing with Python is now available for purchase.
ReportLab has been around since the year 2000 and has remained the primary package that Python developers use for creating reports in the PDF format. It is an extremely powerful package that works across all the major platforms. This book will also introduce the reader to other Python PDF packages.
You can get the book at the following online retailers:
The ReportLab toolkit allows you to create interactive fillable forms. The PDF standard actually has a fairly rich set of interactive elements. ReportLab doesn’t support all of these elements, but it does cover most of them. In this section, we will look at the following widgets:
All of these widgets are created by calling various methods on the canvas.acroform property. Note that you can only have one form per document. Let’s take a look at the widgets that ReportLab supports! Continue reading Creating Interactive PDF Forms in ReportLab with Python
Fillable forms have been a part of Adobe’s PDF format for years. One of the most famous examples of fillable forms in the United States are documents from the Internal Revenue Service. There are lots of government forms that use fillable forms. There are many different approaches for filling in these forms programmatically. The most time consuming method I have heard about is to just recreate the form in ReportLab by hand and then fill it in. Frankly I think this is probably the worst idea, except when your company is in charge of creating the PDFs itself. Then that might be a viable option because you then have complete control over the PDF creation and the inputs that need to go into it.
Creating a Simple Form
We need a simple form to use for our first example. ReportLab has built-in support for creating interactive forms, so let’s use ReportLab to create a simple form. Here is the code: Continue reading Filling PDF Forms with Python
There are many times where you will want to extract data from a PDF and export it in a different format using Python. Unfortunately, there aren’t a lot of Python packages that do the extraction part very well. In this chapter, we will look at a variety of different packages that you can use to extract text. We will also learn how to extract some images from PDFs. While there is no complete solution for these tasks in Python, you should be able to use the information herein to get you started. Once we have extracted the data we want, we will also look at how we can take that data and export it in a different format.
Let’s get started by learning how to extract text!
Extracting Text with PDFMiner
Probably the most well known is a package called PDFMiner. The PDFMiner package has been around since Python 2.4. It’s primary purpose is to extract text from a PDF. In fact, PDFMiner can tell you the exact location of the text on the page as well as father information about fonts. For Python 2.4 – 2.7, you can refer to the following websites for additional information on PDFMiner:
PDFMiner is not compatible with Python 3. Fortunately, there is a fork of PDFMiner called PDFMiner.six that works exactly the same. You can find it here: https://github.com/pdfminer/pdfminer.six Continue reading Exporting Data from PDFs with Python
ReportLab has native support for generating SVGs, but not for embedding SVGs in their PDFs. Fortunately, Dinu Gherman created the svglib package, a pure-Python package that can read SVG files and convert them to other formats that ReportLab can use. The official website for svglib is on Github.
The svglib package will work on Linux, Mac OS and Windows. The website states that it works with Python 2.7 – 3.5, but it should work in newer versions of Python as well.
You can use svglib to read your existing SVG giles and convert them into ReportLab Drawing objects. The svglib package also has a command-line tool, svg2pdf, that can convert SVG files to PDFs. Continue reading Adding SVGs to PDFs with Python and ReportLab
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.
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.
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!