1

I hope it’s Ok to post a complete naive question here for LO or OO experts.

I’m looking for advice on whether scripting LibreOffice or OpenOffice 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, hence the reluctance to go down a route of using something like Reportlab (plus I don't know Reportlab at all, so face huge learning curve that way

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/OpenOffice is obviously a lot faster for generating good looking report "templates", 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.

This wouldn't be high frequency at all, so would not need to run either LO/OO as a service, but could simply invoke when required with a sys call. Conceptually something like "LibreOffice --template 'make_fancy.report' <data.json> <output_file.pdf>"

If this approach would be reasonable in either LO or OO, what languages are best to script in? (Hopefully python3).

Richard
  • 3,024
  • 2
  • 17
  • 40
  • Hi Richard You could 1) load a template from Macro or Uno https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=9427 2) Parse Json file https://stackoverflow.com/a/29371552/1123335 Or convert to csv http://blog.appliedinformaticsinc.com/how-to-parse-and-convert-json-to-csv-using-python/ –  Jan 02 '20 at 07:52
  • You could use uno http://www.openoffice.org/udk/basic/ This is a great start http://www.openoffice.org/api/basic/man/tutorial/tutorial.pdf If you want to use Python this may help you https://wiki.openoffice.org/wiki/Python This is a python start uno https://wiki.openoffice.org/wiki/PyUNO_bridge Python as a macro language https://wiki.openoffice.org/wiki/Python_as_a_macro_language –  Jan 02 '20 at 07:56
  • Thanks for the reply! I ended up going with an approach based on word docs using a module python-docx-template. It will generate word docs from substitued templates really well, and then I can use OO to convert those to PDF. – Richard Jan 02 '20 at 20:38
  • Interesting Richard. Thank you –  Jan 03 '20 at 04:40

0 Answers0