【问题标题】:Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working [closed]命令`libreoffice --headless --convert-to pdf test.docx --outdir /pdf`不起作用[关闭]
【发布时间】:2015-08-01 16:37:52
【问题描述】:

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

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

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

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

【问题讨论】:

  • 您在 Ubuntu-14.04 上运行的是哪个 LibreOffice 版本?
  • LibreOffice 4.2.8.2 420m0(Build:2)
  • 你为什么不接受任何答案?
  • 我试过 soffice- 同样的问题
  • 看我的回答on this thread

标签: libreoffice


【解决方案1】:

听起来可能很愚蠢,但我遇到了这样的问题:在 Ubuntu 14.04 中,仅安装包 libreoffice-core-common 以转换为 PDF 是不够的,但您需要安装 libreoffice-writer 代替/附加。需要注意的重要一点是libreoffice-core|common 似乎引入了一些功能性的 libreoffice 基础,因此得名 ;-)。如果执行以转换某些文件,这不会出错,而是似乎只是在等待某个套接字或诸如此类的输入或其他什么...在我安装 libreoffice-writer 后,它具有 [...]-core|common 作为依赖项,转换一些 ODT使用与以前使用的完全相同的命令行,将文件转换为 PDF 就像一个魅力。

该应用程序看起来以某种方式工作,但由于缺少软件包而根本无法运行,并且没有提供任何相关信息,这似乎有点疯狂。

【讨论】:

    【解决方案2】:

    我在使用 libreoffice 将 HTML 转换为 xlsx 时遇到了问题。其他转换为选项工作正常。原来它还需要--calc 标志。以防其他人遇到同样的麻烦。在 LibreOffice-6.4.3.2 上测试。

    致谢:Libreoffice converting html to xls or xlsx

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,卡了一整天;愚蠢的我最后发现我正在尝试从网络文件系统转换为网络文件系统;即使我写了正确的 libreoffice 似乎也不支持它,或者至少在我的配置中不支持。

      我通过转换为/tmp 然后手动移动文件解决了这个问题。希望对您有所帮助。

      【讨论】:

        【解决方案4】:

        更新

        当前版本的 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
          

        【讨论】:

        • 您好 4.2 也同样的问题根本没有响应!
        • 你试过4.2.4.2吗?以后的版本对我不起作用。我已经从给定链接的软件包中安装了它
        • 4.2.4.2 仅我从上面的链接安装,将 10 页文档转换为 PDF 需要超过 5 分钟我在 VPS(AWS)中尝试过 - Ubuntu 14.04
        • 似乎当前版本已经修复了pdf创建器。如果使用以下命令使用 5.2.6.2 检查它: /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir 。 theodtfile.odt
        • 这对我有帮助。我有最新的 Centos 6 libreoffice。在转换请求时没有输出到 shell,没有转换的文件。只是无声的退出。我记得在一切正常之前。回滚到 4.0.4.2(Centos 6.6 存储库)使一切恢复正常。
        【解决方案5】:

        我也在使用 LibreOffice 4.2.8.2(在 GNU/Linux 上),但我尝试将 DOC 文件转换为 HTML 文件。我已经安装了libreoffice-headless,但终端也挂了。 Kurt Pfeifle 的每一颗子弹我都试过了,但都没有效果……

        解决方案很简单:安装libreoffice-writer(也许libreoffice-filters 也可以,但这取决于libreoffice-writer 以及LibreOffice 的其他重要组件)。

        希望这会有所帮助。

        【讨论】:

          【解决方案6】:
          1. 我会首先尝试给出命令的绝对路径。

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

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

            --convert-to pdf:writer_pdf_Export
            

            一定要完全按照这个大小写!

          4. 接下来,如果您的系统上已经有一个 LibreOffice GUI 实例启动并运行,该命令将不起作用。这是由错误known since 2011 引起的。将此附加参数添加到您的命令中:

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

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

          5. 另外,请确保您指定的--outdir /pdf 确实存在,并且您对其具有写入权限。或者,宁可使用不同的输出目录。即使只是第一次测试和这一轮调试:

            $ 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
            

            这适用于带有 LibreOffice v4.4.3.2 的 Mac OS X Mavericks 10.9.5(使用我的二进制文件 soffice 的特定路径,无论如何这对你来说会有所不同......)。

            如果这一切都不起作用:

          7. 这可能是您尝试使用该命令的特定 DOCX 文件的问题...所以首先创建一个您自己的非常简单的 DOCX 文档。为此,请使用 LibreOffice 本身。写“你好世界!”在一个空白的页面上。将其另存为 DOCX。

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

          9. 如果还是不行,重复第 7 步,但这次保存为 ODT。

          10. 重复第 8 步,但确保这次引用 ODT。

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

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

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

            参数名称、大小写、使用的破折号数量等是否有任何变化??

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

            $ /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 文件时,在你的命令行中再添加一个参数来强制应用输入过滤器:

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

          • 它可以处理任何可以打开和“读取”的输入格式: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
          

          回复。 不是 DOCX 的输入:

          要对非 DOCX 输入格式强制执行过滤器,您可以使用(列表不完整):

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

          【讨论】:

          • @vishal:我的回答非常具体。尽管已明确要求您提供版本,但您甚至都懒得告诉您的版本。你也没有说,如果你的 'soffice' 和 'libreoffice' 二进制文件存在......对不起,我对你的问题调试的支持到此结束。
          • Kurt,我发现详细的回复很有帮助。感谢您花时间回答问题。
          • @dat:谢谢你说“谢谢”。这里太多的野蛮人已经不熟悉这种礼节了。
          • 感谢您对此进行概述! #4 对我来说是错的。
          • @KurtPfeifle 喜欢这样的细节
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-11-14
          相关资源
          最近更新 更多