How can I set default export to PDF settings when running --convert-to pdf from command line

I use this command to convert many .docx, .pptx, and .xlsx files to pdf with a powershell script:

& “C:\Program Files\LibreOffice\program\soffice” --headless --convert-to pdf $inputFile --outdir $outputSubFolder

This works great but if there is a .xlsx file with too many columns it prints on many pages and becomes hard to read and understand. When exporting manually from LibreOffice Calc, I can change the format to be landscape and to fit to page width, which produces the desired outcome. I tried making these settings the default template but still every time I try to export a new file the old default comes back and it prints to many pages in portrait again. How can I make all .xlsx files export with the settings I want?

I try to export a new file the old default comes back

AFAIK - It’s not the old default but the setting within the .xlsx (which may be based on a template). In other words: If the file you are converting doesn’t have the correct settings, you can’t change that on the command line (which tries to create a PDF as identical as possible with the orginal document). Command line doesn’t have any switches which intentionally changes any document to be converted (that’s how I understand the convert-to procedure).

I can change the format to be landscape and to fit to page width, which produces the desired outcome.

This is called editing the document (and its settings). --convert-to dos not edit documents by design: it tries to preserve everything in the new document as it was in the original document, as much as possible for the conversion. So the process can’t include such changes as you want.

Alright and there is no way to edit the document from the command line using something else other than --convert-to?

See also: Libreoffice .xls to .pdf conversion breaks single page content into multiple pages on Ubuntu 18.04 - it provides an alternative, so that it doesn’t split to many pages, and it doesn’t need a change in the file (it uses the new Whole sheet export feature (renamed from “Full-Sheet Previews”)).

Thanks Mike, I’ll check those out.

While the correct answer to your question is “You can’t change settings with convert-to.”, there may be another approach possible:

It is possible to call a macro from command-line. Some examples here: at ask.libreoffice

So you need a macro to export the open document after changing the page-settings to landscape.
This has to be placed in your global “My Macros”-collection, as your documents can’t contain the macro - especially considering your xlsx-files.

I never tried to call a macro for a opened xlsx, but as the file is converted during opening it should not behave different as .ods. And if necessary, you could convert-to .ods before, if this is a problem.

I have not tested this, so it is only a way to try, not a well treaded psth…

I’ll give it a shot

The link Mike Kaganski gave after the accepted answer uses the outlined approach for xls to pdf conversion script to use whole-sheet-export

If I remember fine, it uses the same settings as the last used to export as PDF, opening LibreOffice

… but the question talks about document settings, not PDF export settings…