How do I use libreoffice to convert a text file to "pdf" with the output pdf in landscape using (libreoffice –-headless –-invisible –convert-to pdf "filename.txt" )? The text file is 132 columns wide causing the heading and rows to wrap. Can the page size be set to prevent it from wrapping?

I have several text files that need to be converted to “pdf” format and when they are converted using the following command libreoffice –-headless –-invisible –convert-to pdf “filename.txt” the output is in portrait mode instead of landscape.

Is there a way to pass a parameter to force libreoffice to orient the pdf output in landscape?

–Gilbert

1 Like

Please use a short descriptive title instead of details into a title.

When LibreOffice converts files to different formats, it doesn’t edit the original documents according to come command line parameters: everything is taken from the documents. If your PDFs arrive portrait, it only means that your original documents were formatted portrait.

EDIT: In newer versions of LibreOffice, some related options appeared:

  1. In version 6.4, Whole sheet export feature was introduced, allowing one to output the whole sheet to a single page. Since then, setting that option in the PDF export dialog in GUI would store the default settings used in later headless export;
  2. In version 7.4, improved PDF export options in the command-line were introduced. That allows to use SinglePageSheets in the command line to avoid dependence on the default setting stored through the GUI. Something like
soffice --convert-to 'pdf:calc_pdf_Export:{"SinglePageSheets":{"type":"boolean","value":"true"}}' test.csv

Still that might fail if the data is long, and output to a single sheet would be impossible (require some kilometers of paper).

Thank you for response…
The text file exceeds the standard page size width (8.5 x 11) or 80 columns causing the heading as well as the rows to wrap. Editing the text file with “vi” shows the column width to be 132 columns. Since the original text file arrive with 132 columns, can the page size/or columns be set to prevent it from wrapping the rows?

Hi
In LO either open the document or create a new document and enter some small lorem ipsum.

On the toolbar: format / page / page / in the dialog box choose the page tab / in the dialog box choose landscape / apply.

Making sure that you are in the new format of the document / go back to file / export as / choose .pdf if you have other export options such as .epub etc.

in dialog box enter a name and verify that the extension is .pdf.

If you have preview thumbnails enabled you should see both the document ( possibly .odt) and the .pdf in landscape format.

jamess

OP asked about a command line parameter to achieve landscape while executing libreoffice –-headless –-invisible –convert-to pdf "filename.txt" - your solution requires GUI.