命令`libreoffice --headless --convert-to pdf test.docx --outdir/pdf`不起作用 [英] Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working

查看:1511
本文介绍了命令`libreoffice --headless --convert-to pdf test.docx --outdir/pdf`不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to wait for long after using this LibreOffice command which is intended to convert DOCX into PDF:

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

但是我没有任何回应,也没有错误.没有文件被转换.好像终端挂了.

But I'm getting no response and no error. No file is converted. It looks like terminal is hanging.

那么,有什么办法可以跟踪错误?

So, is there is any way to track the error?

推荐答案

  1. 首先,我将尝试提供命令的绝对路径.

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

我怀疑libreoffice二进制文件不起作用-您必须找到soffice二进制文件并查看它是否有效.

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

然后,您的--convert-to pdf是不够的.它必须是:

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!

接下来,如果您的系统上已经有一个LibreOffice GUI实例正在运行,则该命令将不起作用.这是由2011年以来已知的错误引起的.将此附加参数添加到您的命令中:

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

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

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.

此外,请确保您指定的--outdir /pdf确实存在,并且您对其具有写权限.或者,而是使用其他输出目录.即使只是第一次测试和此轮调试:

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

  • 因此:

  • 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
    

    这对我在带有LibreOffice v4.4.3.2的Mac OS X Mavericks 10.9.5上有效(使用二进制soffice的特定路径,无论如何您都会...).

    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:

    您尝试使用该命令的特定DOCX文件可能有问题.因此,请首先创建一个自己的非常简单的DOCX文档.为此,请使用LibreOffice本身.写下"Hello World!"在原本为空的页面上.将其另存为DOCX.

    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.

    再试一次. 它可以与简单的DOCX一起使用吗?

    Try again. Does it work with the simple DOCX?

    如果再次无法使用,请重复步骤7,但这次另存为ODT.

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

    重复第8步,但是请确保这次引用ODT.

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

    最后:使用sofficesoffice.binlibreoffice的完整路径,并使用-h参数运行每个路径:

    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.
        

      • 在命令行中添加另一个参数以在soffice打开DOCX文件时强制应用输入过滤器:

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

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


        Update

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

        • 它可以处理任何可以打开并读取"的 输入格式:DOC,XLS,XLSX,PPT,PPTX,...
        • 它可以转换为它可以写入"的任何输出格式:DOC,XLS,XLSX,PPT,PPTX,...
        • 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.

        重新.输出为 PDF :

        Re. output as PDF:

        要控制哪个LibreOffice组件生成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
        

        重新. 不是DOCX 的输入:

        Re. input which is not DOCX:

        要对非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
        

        重新. 不是PDF 的输出:

        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 --headless --convert-to pdf test.docx --outdir/pdf`不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆