命令`libreoffice –headless –convert-to pdf test.docx –outdir / pdf`不工作

在使用这个旨在将DOCX转换为PDF的LibreOffice命令之后,我必须等很长时间:

libreoffice --headless --convert-to pdf test.docx --outdir /pdf

但我没有得到任何回应,也没有错误。 没有文件被转换。 它看起来像terminal挂。

那么,有什么方法可以跟踪这个错误吗?

  1. 我首先尝试给绝对path的命令。

  2. 我怀疑libreoffice二进制文件不起作用 – 你必须findsoffice二进制文件,看看是否有效。

  3. 那么,你的--convert-to pdf是不够的。 它需要是:

     --convert-to pdf:writer_pdf_Export 

    一定要按照这个大写!

  4. 接下来,如果您的系统上已经安装了LibreOffice GUI实例,那么该命令将不起作用。 这是自2011年以来已知的臭虫造成的。 将这个额外的参数添加到您的命令:

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

    这将创build一个新的独立的环境,可以被第二个无头的LO实例使用,而不会干扰同一个用户启动的可能运行的第一个GUI LO实例。

  5. 此外,请确保您指定的--outdir /pdf确实存在,并且您有写入权限。 或者,而是使用不同的输出目录。 即使只是第一次testing和debugging一轮:

     $ mkdir ${HOME}/lo_pdfs 
  6. 因此:

     /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 

    这适用于我在Mac OS X小牛10.9.5与LibreOffice v4.4.3.2(使用我的具体path的二进制soffice ,这将是不同的,无论如何…)。

    如果这一切都不起作用:

  7. 这可能是一个特定的DOCX文件的问题,你尝试使用命令…所以先创build一个非常简单的DOCX文档。 使用LibreOffice本身。 写下“Hello World!” 在另一个空的页面上。 将其另存为DOCX。

  8. 再试一次。 它是否适用于简单的DOCX?

  9. 如果再次不起作用,重复步骤7,但这次保存为ODT。

  10. 重复第8步,但确保这次参考ODT。

  11. 最后:使用完整pathsofficesoffice.binlibreoffice并运行每个与-h参数:

     $ /path/to/libreoffice -h $ /path/to/soffice -h $ /path/to/soffice.bin -h 
    • 你甚至在这里得到一个输出?
    • 三个二进制文件/符号链接中的哪一个?
    • logging输出。
    • 告诉我们您的输出!

    将它们与您使用的命令行进行比较:

    参数名称,大小写,破折号的数量是否有变化?

    为了比较,我自己的输出在这里:

     $ /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. soffice打开DOCX文件时,在命令行中添加一个参数来强制执行inputfilter的应用程序:

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

    要么

     --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" 

更新

LibreOffice不仅可以在命令行上将DOCX转换为PDF:

  • 它可以处理任何可以打开和“读”的input格式:DOC,XLS,XLSX,PPT,PPTX,…
  • 它可以转换为任何可以“写入”的输出格式:DOC,XLS,XLSX,PPT,PPTX,…

当然,结果永远不会是完美的,有时甚至是不可接受的。

回覆。 输出为PDF

要控制哪个LibreOffice组件生成PDF输出,可以使用以下变体:

 --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 

回覆。 input不是DOCX

为了强制非DOCXinput格式的渗透,你可以使用(列表不完整):

 --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 

回覆。 输出不是PDF

要转换为特定的输出格式,您可以使用(列表不完整):

 --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 

可能听起来很愚蠢,但是我受到这样的困扰:在Ubuntu 14.04中,仅仅安装libreoffice-core包或者-common来转换为PDF是不够的,但是您需要另外安装libreoffice-writer。 重要的是要注意的是libreoffice-core | common似乎带来了一些functionlibreoffice的基础,因此名称;-),如果执行转换某个文件不会错误,而是似乎只是在一些套接字上等待或者这样的input或任何…在我安装libreoffice作家,其具有作为一个依赖的核心,将一些ODT文件转换为PDF工作像一个魅力与以前使用完全相同的命令行。

似乎有点疯狂,应用程序看起来像它的工作原理,但根本不能因为缺less包,并没有告诉任何事情。

更新

当前版本的libreoffice正在工作:v5.2.6.2(mac)

我正在使用以下命令

 /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir . the_file_to_convert 

看起来转换不能在新版本(> 4.2.4.2)中使用我正在使用libreoffice 4.2.4.2您可以从http://downloadarchive.documentfoundation.org/libreoffice/old/4.2.4.2/下载旧版本;

linux(使用deb包):
libreoffice4.2 –headless –convert-to pdf myfile.odt

视窗:
swriter.exe –headless –convert-to pdf myfile.odt

我也使用LibreOffice 4.2.8.2(在GNU / Linux上),但我试图将DOC文件转换为HTML文件。 我已经安装了libreoffice-headless ,但terminal也挂了。 我已经尝试了Kurt Pfeifle的每一个子弹,但是它不工作…

解决办法很简单:安装libreoffice-writer (也许libreoffice-filters也可以,但是依赖于libreoffice-writer和LibreOffice的其他大组件)。

希望这会有所帮助。