How to set the Selection parameter to convert to pdf using the command line

just like:
./soffice --headless --convert-to ‘pdf:calc_pdf_Export:{“PageRange”:{“type”:“string”,“value”:“1”}}’ --outdir /d/tmp/ /d/tmp/3.xlsx

Can I set Selection parameters and if so how?
Or how to export the selected sheet to pdf using the command line?

the libreOffice version:7.5.2.2| windows

thanks!

See at the following link some hints on different use of single quotes in linux and windows.
.
Also im not sure your path with /d/ works, but I don’t know your setup.

thank you for your reply.
It’s not a problem with the file path, I have successfully executed the following command to export the first page of the file as pdf:

./soffice --headless --convert-to ‘pdf:calc_pdf_Export:{“PageRange”:{“type”:“string”,“value”:“1”}}’ --outdir /d/tmp/ /d/tmp/3.xlsx

But what I actually need to achieve is to export the selected sheets to pdf,How do I pass parameters?
Or where can I find more examples such as:What is Miklos hacking – Improved PDF export options in the command-line and in Online

This you should already know, as you passed a parameter “PageRange”.
.
So two problems left:
First is available Parameters. Sometimes I use the macro-recorder for this, you can also try inspection with xray/mri.
.
Second problem: What is “selected sheets” for an xlsx when you start from command-line? Obviously you can’t select something, so at best it will be something active before last save.

I didn’t understand the first question, what is xray/mri;
The second question is to save the document after each xlxi switches the sheet. Going down to open this document will open the selected sheets by default. Let me change the question.


the range for export to pdf default is “All”, I want to choose “Selection” to export from command-line. can i do it?

Did anyone figure this out? I can’t figure out how to use the “Selection” parameter to only export the selected sheet for an xlsx file. The selected sheet is the default option when using the GUI, but if you use the command line version and switch between other office formats, the setting is not maintained. I tried both options below but neither work…

./soffice --headless --convert-to 'pdf:calc_pdf_Export:{"Selection":{"type":"any","value":"true"}}' worksheet.xlsx
./soffice --headless --convert-to 'pdf:calc_pdf_Export:{"PageRange":{"type":"string","value":"Selection"}}' worksheet.xlsx

Options Reference

There is no “selection” in command line. There is no “active sheet” in command line. They are only GUI concepts (or may be managed in a macro).

PageRange may be a string like 2- or 3,5-9. A value of “Selection” has no meaning there.

In essence: the selection parameter only can be used in a macro. No way to do what you want from the command line. At all.

1 Like

Thanks for the response, but if thats the case why is “Selection” included in the documentation for PDF Export Command Line Parameters? Or am I misinterpreting the use of that property?

That documentation is the complete reference for the options that filter accepts. It is not limited to command line, and it makes sense in other contexts. Since the help is for command line, it may make sense to add “has no meaning in command line”-like notice there. You are welcome to file a bug report.

Was anyone able to figure out how to use a selection to export headlessly? I tried using macros but I’m pretty new to this so I wasn’t able to get the output I wanted

In a way… Headless, from command line there is no selection, so expect no output or an empty page.

Open your own thread for this, show your code and describe there what you wish to select, then maybe you get help.

@hanlin Did you ever figure out how to print all PageRange or Selection working in the command line for calc_pdf_Export?

Don’t know, if he figured it out but as time goes by they updated help:
https://help.libreoffice.org/latest/en-US/text/shared/guide/pdf_params.html

1 Like