Specifying printing options to LibreOffice on the command line?

3

I'm attempting to come up with some means of converting .pptx files to a PDF format from the command line. I have set up a cups-pdf printer to which I can actually send jobs, and so far I have it boiled down to the following command:

libreoffice -pt PDF somePowerpointFilePath.pptx

where PDF is the name of my printer. As is, however, libreoffice prints my documents in portrait orientation when I would like to use landscape.

I've taken a look at these questions, but none of them seem to suit my needs here.

https://superuser.com/questions/486130/printing-from-the-command-line-with-libreoffice-lpr-commands
https://superuser.com/questions/135495/how-do-i-convert-this-filetype-to-pdf

I have also read about the unoconv options, but I'd rather not have to play with my Python libraries to get this set up.

I also noticed the --convert-to option for the libreoffice command, but it is not behaving how I expect it to. I expect to be able to use that by libreoffice --convert-to pdf myFileName.pptx, but this command runs in no time at all (telling whenever you're working with libreoffice), and doesn't appear to deposit any sort of pdf file in the current working directory (as it is supposed to according to the man page).

If anyone can shed any light on how to get either of these two approaches working (printing through CUPS or using the --convert-to option), I would appreciate it.

matthugs

Posted 2014-04-28T22:55:25.827

Reputation: 31

sometimes this will help you.

– Renju Chandran chingath – 2014-05-19T09:00:35.137

I can achieve what you describe by means of libreoffice --headless --convert-to pdf mystuff.pptx; lp -d myprinter -o landscape mystuff.pdf. You should thus give us something more, dmesg output, error messages, log files, in order to understand what is going on. I repeat, these commands work perfectly on my system. – MariusMatutiae – 2014-05-20T09:07:26.940

Well, I can't replicate the issue (in my defense, 23 days). Thanks very much for the bounty and helpful comments, but I seem to be able to use echo *.pptx | xargs -L 1 libreoffice --headless --convert-to pdf {}, without need for the second step of printing the file again with lp to correct orientation. It was probably an idiotic mistake on my end, specifying some of the syntax incorrectly for libreoffice.

What's the best etiquette for closing this question in this situation? Should I delete it? If I have a guess as to what I was doing wrong, should I post it as an answer? – matthugs – 2014-05-22T14:40:09.617

@matthugs Yes, you are encouraged to post answers to your own question if you have one. – Jason – 2014-05-22T20:37:47.773

Answers

0

You can run LibreOffice in 'headless' mode (i.e. as a command line utility without a GUI). But it will not work if at the same time a LibreOffice instance is running with a GUI.

One command to do what you want even if a GUI instance is active at the same time could look similar to this:

mkdir $HOME/pdf ;
/path/to/soffice                                   \
   --headless                                      \
   --infilter="Microsoft PowerPoint 2007/2010 XML" \
   "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" \
   --convert-to pdf:impress_pdf_Export             \
   --outdir $HOME/pdf                              \
     test.docx

Here 'soffice' is a command line tool which is installed in every LibreOffice installation. Most likely it is in /usr/bin/soffice.

For more details see my other answer, over at StackOverflow:

Kurt Pfeifle

Posted 2014-04-28T22:55:25.827

Reputation: 10 024