Passing in JSON parameters into Writer for the --convert-to option

Version: 7.4.5.1

When I try to run the following command to execute a headless conversion of a document to PDF, such as the below:

"C:\Program Files\LibreOffice\program\soffice.exe" --convert-to pdf:draw_pdf_Export:{"SelectPdfVersion":{"type":"long","value":"14"}} --outdir "C:\Users\<user>\Documents" "C:\Users\<user>\Documents\test-document.docx"

…it creates the PDF successfully but is created as a PDF version 1.6, not a 1.4 as I expected it might (following the guidence from here: What is Miklos hacking – Improved PDF export options in the command-line and in Online).

The only difference between my invocation and the example I found…

soffice --convert-to 'pdf:draw_pdf_Export:{"SelectPdfVersion":{"type":"long","value":"15"}}' test.odg

…is that there is a wrapping of the JSON parameters with ‘’. I did try this but it didn’t work and that the PDF created was a .'pdf file. Anyone able to see what I am doing wrong here?

This is because of use of single quotes. Miklos’ blog suggested the command line syntax as used in many Linux shells. In Windows, the single quotes do not work as boundaries of a single command line argument. There’s no space in the argument; but there are internal double quotes, and you need to escape them using \. If you had spaces inside the argument, you would also enclose the whole argument into outer (unescaped) double quotes.

Note also, that use of soffice.exe in command line is discouraged, better use soffice.com or plain soffice. This is because soffice.exe is a GUI application, which can’t use console properly, and so you would miss any diagnostic output.

The SelectPdfVersion option can only treat some specific values, not everything. It is handled in filter/source/pdf/pdfexport.cxx, writing its value to mnPDFTypeSelection; and the latter is checked against this set:

default case  → PDF_1_6
0             → PDF_1_6
1             → PDF_A_1
2             → PDF_A_2
3             → PDF_A_3
15            → PDF_1_5
16            → PDF_1_6

No PDF v.1.4 export support in LibreOffice.

1 Like

I changed to using soffice.com but using the 15 option doesn’t appear to change anything, the PDF created is still a 1.6.

Please try escaping all internal double quotes by prepending them with backlash.

"C:\Program Files\LibreOffice\program\soffice" --convert-to "pdf:draw_pdf_Export:{\"SelectPdfVersion\":{\"type\":\"long\",\"value\":\"15\"}}" --outdir "C:\Users\<user>\Documents" "C:\Users\<user>\Documents\test-document.docx"