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.

Kurt Pfeifle
  • 13,079
matthugs
  • 31
  • 1
  • 4

2 Answers2

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
  • 13,079
0

Whilst the OP question was geared towards Linux and Super Users may be using a recent Windows. The modern recommended answer is locate in the portable or installed program directory the soffice.com file. Then you can write a one line batch file for use with a shortcut, or call or drag and drop on icon.

For printing

"c:\path to\soffice.com" --pt "printer_name" "%~1" 

For pdf file convert see https://help.libreoffice.org/latest/en-US/text/shared/guide/pdf_params.html

NOTE the many newer options (even digital signing!)
Related to question includes such as export pages can be:
Export:{"PageRange":{"type":"string","value":"1"}} for just the "first" page. So as to allow for later edits we below convert all pages "value":" " using an initial template command such as:

"c:\path to\libreoffice\program\soffice.com" --convert-to "pdf:impress_pdf_Export:{"PageRange":{"type":"string","value":" "}}" "%~1"
pause

BEWARE, windows command lines have buffer limitations, so keep all paths short as the command line total characters of all command lines combined can easily exceed that limitation which may even be as low as about 250 characters for combined lines when running.

When you use drag and drop (a PPTX) it can be any other similar presentation file such as here I use a PPTM file.

enter image description here

While Running a "Black console window" will appear and on completion disappear. This is highly desirable function of Windows Console that allows you to see if any errors occur or confirm completion. Ideally we should thus include a pause on the line after soffice.

So here we see the template must have had some internal referenced resource since the PDF has clearly been generated (and works as intended) but with a visible error.

enter image description here

K J
  • 1,248