Libreoffice Command Line Conversion - No Output File

LibreOffice Command Line Conversion - No Output File?

I cant reproduce your error. It works for me, even with pptx files.

Check the bug-tracker of libreoffice. Try another version (I am still running 3.4.something). Investigate the output directory - e.g. do you have write privileges there?

And a rather stupid idea: Hit F5 (or similar) in your file browser (mine is Dolphin) in order to refresh. I needed to do this in this case, so I could see the new file.

Linux LibreOfice Headless Conversion no Output?

Turns out I needed a whole set of dependent RPMs installed first, culminating in libGLU. I've included my additional RPM dependency tree if it will be of use:

            libIDL-0.8.13-2.1.el6.x86_64.rpm
ORBit2-2.14.17-5.el6.x86_64.rpm
sgml-common-0.6.3-33.el6.noarch.rpm
GConf2-2.28.0-6.el6.x86_64.rpm
avahi-glib-0.6.25-15.el6.x86_64.rpm
gnome-vfs2-2.24.2-6.el6.x86_64.rpm

libXxf86vm-1.1.2-2.el6.x86_64.rpm
mesa-dri-filesystem-9.2-0.5.el6_5.2.x86_64.rpm
mesa-private-llvm-3.3-0.3.rc3.el6.x86_64.rpm
mesa-dri1-drivers-7.11-8.el6.x86_64.rpm (--nodeps)
mesa-dri-drivers-9.2-0.5.el6_5.2.x86_64.rpm
mesa-libGL-9.2-0.5.el6_5.2.x86_64.rpm
mesa-libGLU-9.2-0.5.el6_5.2.x86_64.rpm

Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working

  1. I would first of all try it with giving absolute paths to the command.

  2. I suspect that the libreoffice binary does not work -- you have to locate the soffice binary and see if that works.

  3. Then, your --convert-to pdf is not sufficient. It needs to be:

    --convert-to pdf:writer_pdf_Export

    Be sure to follow exactly this capitalization!

  4. Next, the command will not work if there is already a LibreOffice GUI instance up and running on your system. It is caused by bug known since 2011. Add this additional parameter to your command:

     "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"

    This will create a new, separate environment which can be used by a second, headless LO instance without interfering with a possibly running first GUI LO instance started by the same user.

  5. Also, make sure that the --outdir /pdf you specify does exist, and that you have write permission to it. Or, rather use a different output dir. Even if it is just for the first testing and this debugging round:

    $ mkdir ${HOME}/lo_pdfs
  6. Hence:

    /path/to/soffice                                                     \
    --headless \
    "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" \
    --convert-to pdf:writer_pdf_Export \
    --outdir ${HOME}/lo_pdfs \
    /path/to/test.docx

    This works for me on Mac OS X Mavericks 10.9.5 with LibreOffice v4.4.3.2 (using my specific path for the binary soffice which will be different for you anyway...).

    If all this doesn't work:

  7. It may be a problem with the specific DOCX file you try the command with... So create a very simple DOCX document of your own first. Use LibreOffice itself for this. Write "Hello World!" on an otherwise empty page. Save it as DOCX.

  8. Try again. Does it work with the simple DOCX?

  9. If it again doesn't work, repeat step 7, but save as ODT this time.

  10. Repeat step 8, but make sure to reference the ODT this time.

  11. Last: Use full path to soffice, to soffice.bin and to libreoffice and run each with the -h parameter:

    $ /path/to/libreoffice -h
    $ /path/to/soffice -h
    $ /path/to/soffice.bin -h
    • Do you even get an output here?
    • For which one of the three binaries/symlinks?
    • Record the outputs.
    • Tell us your outputs!!!

    Compare them to the command line you used:

    Are there any changes in parameter names, capitalizations, number of dashes used, etc.??

    For comparison, my own output is here:

    $ /Applications/LibreOffice.app/Contents/MacOS/soffice -h

    LibreOffice 4.4.3.2 88805f81e9fe61362df02b9941de8e38a9b5fd16

    Usage: soffice [options] [documents...]

    Options:
    --minimized keep startup bitmap minimized.
    --invisible no startup screen, no default document and no UI.
    --norestore suppress restart/restore after fatal errors.
    --quickstart starts the quickstart service
    --nologo don't show startup screen.
    --nolockcheck don't check for remote instances using the installation
    --nodefault don't start with an empty document
    --headless like invisible but no userinteraction at all.
    --help/-h/-? show this message and exit.
    --version display the version information.
    --writer create new text document.
    --calc create new spreadsheet document.
    --draw create new drawing.
    --impress create new presentation.
    --base create new database.
    --math create new formula.
    --global create new global document.
    --web create new HTML document.
    -o open documents regardless whether they are templates or not.
    -n always open documents as new files (use as template).

    --display <display>
    Specify X-Display to use in Unix/X11 versions.
    -p <documents...>
    print the specified documents on the default printer.
    --pt <printer> <documents...>
    print the specified documents on the specified printer.
    --view <documents...>
    open the specified documents in viewer-(readonly-)mode.
    --show <presentation>
    open the specified presentation and start it immediately
    --accept=<accept-string>
    Specify an UNO connect-string to create an UNO acceptor through which
    other programs can connect to access the API
    --unaccept=<accept-string>
    Close an acceptor that was created with --accept=<accept-string>
    Use --unnaccept=all to close all open acceptors
    --infilter=<filter>[:filter_options]
    Force an input filter type if possible
    Eg. --infilter="Calc Office Open XML"
    --infilter="Text (encoded):UTF8,LF,,,"
    --convert-to output_file_extension[:output_filter_name[:output_filter_options]] [--outdir output_dir] files
    Batch convert files.
    If --outdir is not specified then current working dir is used as output_dir.
    Eg. --convert-to pdf *.doc
    --convert-to pdf:writer_pdf_Export --outdir /home/user *.doc
    --convert-to "html:XHTML Writer File:UTF8" *.doc
    --convert-to "txt:Text (encoded):UTF8" *.doc
    --print-to-file [-printer-name printer_name] [--outdir output_dir] files
    Batch print files to file.
    If --outdir is not specified then current working dir is used as output_dir.
    Eg. --print-to-file *.doc
    --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc
    --cat files
    Dump text content of the files to console
    Eg. --cat *.odt
    --pidfile file
    Store soffice.bin pid to file.
    -env:<VAR>[=<VALUE>]
    Set a bootstrap variable.
    Eg. -env:UserInstallation=file:///tmp/test to set a non-default user profile path.

    Remaining arguments will be treated as filenames or URLs of documents to open.
  12. Add one more argument to your command line to enforce the application of an input filter when soffice opens your DOCX file:

    --infilter="Microsoft Word 2007/2010/2013 XML"

    or

    --infilter="Microsoft Word 2007/2010/2013 XML"
    --infilter="Microsoft Word 2007-2013 XML"
    --infilter="Microsoft Word 2007-2013 XML Template"
    --infilter="Microsoft Word 95 Template"
    --infilter="MS Word 95 Vorlage"
    --infilter="Microsoft Word 97/2000/XP Template"
    --infilter="MS Word 97 Vorlage"
    --infilter="Microsoft Word 2003 XML"
    --infilter="MS Word 2003 XML"
    --infilter="Microsoft Word 2007 XML Template"
    --infilter="MS Word 2007 XML Template"
    --infilter="Microsoft Word 6.0"
    --infilter="MS WinWord 6.0"
    --infilter="Microsoft Word 95"
    --infilter="MS Word 95"
    --infilter="Microsoft Word 97/2000/XP"
    --infilter="MS Word 97"
    --infilter="Microsoft Word 2007 XML"
    --infilter="MS Word 2007 XML"
    --infilter="Microsoft WinWord 5"
    --infilter="MS WinWord 5"

Update

LibreOffice cannot only convert DOCX to PDF on the command line:

  • It can process any input format which it can open and "read": DOC, XLS, XLSX, PPT, PPTX, ...
  • It can convert to any output format which it can "write": DOC, XLS, XLSX, PPT, PPTX, ...

Of course, results will never be perfect, and sometimes they will even be un-acceptable to you.

Re. output as PDF:

To control, which LibreOffice component generates PDF output, you can use these variants:

--convert-to pdf:writer_pdf_Export
--convert-to pdf:calc_pdf_Export
--convert-to pdf:draw_pdf_Export
--convert-to pdf:impress_pdf_Export
--convert-to pdf:writer_web_pdf_Export

Re. input which is not DOCX:

To enforce infilters for non-DOCX input formats, you could use (list is not complete):

--infilter="HTML Document"                      # for HTML input
--infilter="MediaWiki" # for MediaWiki input
--infilter="Text CSV" # for CSV spreadsheet input
--infilter="Microsoft PowerPoint 2007/2010 XML" # for PPTX input
--infilter="Microsoft PowerPoint 97/2000/XP" # for PPT input
--infilter="Windows Metafile" # for WMF input
--infilter="Enhanced Metafile" # for EMF input
--infilter="Scalable Vector Graphics" # for SVG input
--infilter="Microsoft Excel 2007/2010 XML" # for XLSX input
--infilter="Microsoft Excel 97/2000/XP" # for XLS input
--infilter="Microsoft Excel 95" # for some XLS input
--infilter="Microsoft Excel 5.0" # for some XLS input

Re. output which is not PDF:

To convert to specific output formats, you could use (list not complete):

--convert-to html:HTML
--convert-to html:draw_html_Export # force "Draw" to generate the HTML
--convert-to mediawiki:MediaWiki_Web # generate MediaWiki output
--convert-to csv:"Text - txt - csv (StarCalc)" # generate CSV spreadsheet output
--convert-to pptx:"Impress MS PowerPoint 2007 XML" # generate PPTX
--convert-to ppt:"MS PowerPoint 97" # generate PPT
--convert-to wmf:impress_wmf_Export # force "Impress" to generate the WMF
--convert-to wmf:draw_wmf_Export # force "Draw" to generate the WMF
--convert-to emf:impress_emf_Export # force "Impress" to generate the EMF
--convert-to emf:draw_emf_Export # force "Draw" to generate the EMF
--convert-to svg:impress_svg_Export # force "Impress" to generate the SVG
--convert-to svg:draw_svg_Export # force "Draw" to generate the SVG
--convert-to xlsx:"Calc MS Excel 2007 XML" # generate XLSX
--convert-to xls:"MS Excel 97" # generate XLS like Excel 97
--convert-to xls:"MS Excel 95" # generate XLS like Excel 95
--convert-to xls:"MS Excel 5.0/95" # generate XLS like Excel 5.0/95

Libreoffice only convert from odt to pdf, not other formats

This is a known issue in LibreOffice that was fixed in version 5.3.0. Before this fix when an instance of LibreOffice is running --convert-to or any other command would silently terminate without doing anything.

If your version is older than that you could consider the solution suggested by Frank Yin here. That is close all open LibreOffice documents before running the conversion.

If you cannot close all open LibreOffice documents to run the conversion, or if you find it inconvenient, you could try a solution suggested in the comments to the original bug.

If you have LibreOffice version before 4.5 run

soffice -env:UserInstallation=file:///$HOME/.libreoffice-headless/ \
--headless --convert-to pdf test.docx

If you are running LibreOffice version between 4.5 and 5.3 run

soffice -env:UserInstallation=file:///$HOME/.libreoffice-headless/ \
--convert-to pdf test.docx

Here $HOME/.libreoffice-headless is a new profile directory different from your main LibreOffice profile.

Libreoffice converting HTML to PDF on command line produces empty page

You should try writhing this:

soffice.exe --headless --norestore --writer --convert-to pdf YOURFILE

it worked for me, the point was to add --writer option



Related Topics



Leave a reply



Submit