Headless LibreOffice as a PDF report generator?

Hi there,

I hope it’s Ok to post a complete naive question here:

I’m looking for advice on whether scripting LibreOffice would be suitable for the following:

General Question

I’m looking to generate PDF reports, based on a combination of a “template” and a set of data (currently in JSON format) and inserted images.

This would act as a headless service that gets invoked when necessary from a web server, when a user requests a PDF report (on linux).

We have a need to frequently modify/customise/generate new templates.

Background

This is in contrast to using an approach of using a PDF library like Reportlab directly within the web server, and having to build up the template/report programmatically.

As LibreOffice is obviously a lot faster for generating good looking reports, this is a question about doing both the template generation, plus final template + data → PDF generation all directly within LibreOffice.

Some more specifics

The data values would mostly either be substituted into fields in the template, with no to minimal processing of values required.

However, there would be situations where some of the data is in “sets” that would be shown in a table type view, and the number of fields (and so number of table rows for instance) would need to vary per report, based on the number of values in that particular JSON data.

Additionally, I’d need to be able to include (“import”) images into the report. Some of the JSON data would be paths to image files, and I’d like to include those. Again for these, the number of image may vary between each report.

If LO is a good option for this, what is the best language to script in? Does LO support python 3?

You can create templates and use variable fields inside every template. Then you can fill your fields from out source. Then you can use options “–convert-to” and “–headless” to convert your template in to PDF.

Yes, you can write Python macros for LibreOffice. More info by link:

https://wiki.openoffice.org/wiki/Python

https://wiki.documentfoundation.org/Macros/Python_Design_Guide

Thanks for the info!