convert .pptx and .xlsx files to pdf using libreoffice cli

Viewed 45

I'm using LibreOffice CLI to convert two files I have:

  • .XLSX to .PDF;
  • .PPTX to .PDF;

To do the task I'm using the below command:

import subprocess
from subprocess import Popen, PIPE
import re

args = ['libreoffice', '--headless', '--convert-to',
        'pdf', '--outdir', 'output', 'my_file.pptx']
process = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=25)
re.search('-> (.*?) using filter', process.stdout.decode())

It is converting the files to pdf, but unfortunately, it's not keeping the same layout style

enter image description here

Continuation of the previous page (with the footer) and header of the next page: enter image description here

As you can see in the images, the headers have different size and it also has a weird value in the header "x000a"

I would like to understand if there are a alternative to fix this kind of problems?

Regards, Leonardo

1 Answers

You should not expect a 100% replica of Microsoft Office output from LibreOffice. Anyway, if you think this is a bug, you can report the bug to LibreOffice Bugzilla with a good description and a sample documents to reproduce the bug:
https://bugs.documentfoundation.org/

There are faster ways to convert a document to PDF, if you can have a running LibreOffice in the background. For example, see this project which is written in Python:

Python script to automate document conversions using LibreOffice/OpenOffice.org
https://github.com/mirkonasato/pyodconverter

Related