
On my Mac, the following command unzips the document into the directory unzipped.
Libreoffice save as pdf zip#
This is a trick you might not know-LibreOffice documents are ZIP files. (This is true of all documents that follow the Open Document Format for Office Applications). You can unzip them with command line tools, or with the zipfile module in Python’s standard library. If you want to play along with this blog post, here’s the LibreOffice document that I’ll use in the examples below. Your job during this step is to create a LibreOffice document that will serve as a skeleton (or template, or form) for your final documents. For content that you don’t know (words in paragraphs, images, bullet points in a list, table contents, etc.), leave placeholders. a list of account transactions) should be formatted, even if we don’t know in advance the exact values of each transaction. For instance, in the bank example above, we know what the cover page will look like, where each section should appear in the document, and how a section (e.g. We usually know in advance at least some of the content we want. This step will probably require the most work. Create a LibreOffice Document to Use as a Template We’re not going to write a single line of Python code, just explore a process. Writing Python would come later when you automate steps 2 – 5.
Libreoffice save as pdf pdf#
Ask LibreOffice to export the document in PDF format.


The first page after that will be a summary of the customer’s accounts, and then subsequent pages contain information about the account-a list of transactions, changes in values of stocks, etc.Įach PDF will be different, but similar because they follow a template. The cover page will always contain the bank’s logo, some legal boilerplate, the month and year, and a bland stock photo of happy customers doing something unrelated to banking, like this one. For instance, you might work for a bank that wants to produce end-of-month account statements for each of its 100,000 customers.


When I talk about creating PDFs programmtically, I’m thinking of the situation where one wants to create a lot of PDFs that follow a template. BackgroundĬreating PDFs programmatically is a task most Python programmers encounter at least once. I’ll compare and contrast the two in another blog post. In this post I just want to describe the technique I’m advocating. This technique offers some unique benefits, and in some common use cases-most importantly, perhaps in your case-it can be much more efficient than the alternative. In the talk and in this series, I advocate a technique for creating PDFs that uses LibreOffice (or OpenOffice) to do most of the hard work, and I contrast that to the common solution of using ReportLab (or a library like it).
Libreoffice save as pdf series#
It’s the first of a series on this subject which is a bit too big for just one blog post. This post is a supplement to a talk I’m giving at PyOhio about using Python to create PDFs “the lazy way”.
