A simple, powerful way to annotate PDFs in Python: pdf-annotate

Michael Bryant
PlanGrid Technology
2 min readJul 3, 2019

Today, we are releasing our simple Python library to add annotations to PDFs: pdf-annotate. Why? Even as information moves into more structured formats like BIM, the PDF remains at the heart of the construction industry. What’s missing is an easy way to add PDF-spec compliant annotations from Python.

Now available on GitHub and PyPI!

Despite an impressive collection of useful PDF libraries in Python, there isn’t one that makes it easy to add PDF-spec compliant annotations — lines, rectangles, circles, etc. — to PDFs. We are releasing pdf-annotate as both a useful and simple library to add annotations, but also as a building block for others to hopefully contribute more structured functionality to add useful annotations to PDFs.

Annotating PDFs

Pdf-annotate follows in the tradition of other great Python PDF tools — reportlab and PyPDF2, to name two — and makes it very easy to get up and running. To add a red rectangle to the bottom-left of a PDF, you would simply do the following:

It’s simple to make slight modifications to the rectangle’s appearance. For example, to make the rectangle 50% opaque, simply swap in (1, 0, 0, 0.5) for the fill. For most use cases, this allows you to ignore the complexities of the PDF spec (transparency in PDFs involves soft-masks, for example) and just concentrate on what you want to draw. Crucially, for these simple baseline annotations, pdf-annotate produces PDF-spec compliant annotations, meaning they can be viewed and edited from popular PDF viewers like Adobe Acrobat.

Used in production

The pdf-annotate library doesn’t fully implement all aspects of the PDF spec’s annotations functionality, but it is flexible, simple, and used in production here at PlanGrid. We hope that if the community finds this useful, additional functionality will be added and we welcome issues and pull requests.

--

--