First, let me notice this excerpt from the Starting LibreOffice Software With Parameters
Windows-specific help:
"{install}\program\soffice.com" {parameter}
…
Use soffice.exe
instead of soffice.com
, when you do not need console
Why is this important for the following? Because using soffice.exe
, you may not see diagnostic information from the detached process. Read more here.
Now let me show that this is not a LibreOffice issue, but something in PowerShell. It looks like your command line should be correct, reading the documentation:
To make double-quotation marks appear in a string, enclose the entire string in single quotation marks.
The example there shows, that command like like
'As they say, "live and learn."'
produces output like
As they say, "live and learn."
And that’s what we need. However, the command line that you use (just replacing the exe
with com
) gives this output to the console:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
PS & 'C:\Program Files\LibreOffice\program\soffice.com' --convert-to 'pdf:writer_pdf_Export:{"PageRange":{"type":"string","value":"3-4"}}' --outdir path\to\ path\to\pages.odt
convert path\to\pages.odt as a Writer document -> path\to\pages.pdf using filter : writer_pdf_Export:{PageRange:{type:string,value:3-4}}
And indeed, the filter options shown there aren’t proper JSON: they need the double quotes. LibreOffice got wrong parameter text from the shell.
Now compare to the output from cmd.exe
console, using the escape syntax required there:
"C:\Program Files\LibreOffice\program\soffice.com" --convert-to "pdf:writer_pdf_Export:{\"PageRange\":{\"type\":\"string\",\"value\":\"3-4\"}}" --outdir path\to\ path\to\pages.odt
convert path\to\pages.odt as a Writer document -> path\to\pages.pdf using filter : writer_pdf_Export:{"PageRange":{"type":"string","value":"3-4"}}
The parameter received by LibreOffice is the correct JSON, and it works.
And suddenly, using the same escaping in PowerShell for the double quotes works, too:
PS & 'C:\Program Files\LibreOffice\program\soffice.com' --convert-to 'pdf:writer_pdf_Export:{\"PageRange\":{\"type\":\"string\",\"value\":\"3-4\"}}' --outdir path\to\ path\to\pages.odt
convert path\to\pages.odt as a Writer document -> path\to\pages.pdf using filter : writer_pdf_Export:{"PageRange":{"type":"string","value":"3-4"}}
Maybe that’s something about use of console vs. shell scripts? I don’t know. But it works in console the way I shown.
It might be a version of PowerShell issue, too. Of course, installing the version of PowerShell from Microsoft Store gives me a different story:
PowerShell 7.4.3
PS & 'C:\Program Files\LibreOffice\program\soffice.com' --convert-to 'pdf:writer_pdf_Export:{"PageRange":{"type":"string","value":"3-4"}}' --outdir path\to\ path\to\pages.odt
convert path\to\pages.odt as a Writer document -> path\to\pages.pdf using filter : writer_pdf_Export:{"PageRange":{"type":"string","value":"3-4"}}
But confusingly, this installation leaves me with two versions installed in parallel, and the older version 5 suggested when I type powershell
in the start menu… Go figure.