如何将 ODT 文件转换为 PDF?

Sof*_*mur 72 pdf openoffice.org libreoffice

有谁知道如何将ODT文件 (LibreOffice)转换为PDF?

Tap*_*per 102

您还可以根据libreoffice自己的目的使用命令行。这为您提供了批量转换的优势。但单个文件也是可能的。本示例将当前目录中的所有 ODT 文件转换为 PDF:

libreoffice --headless --convert-to pdf *.odt
Run Code Online (Sandbox Code Playgroud)

通过以下方式获取有关命令行选项的更多信息:

man libreoffice
Run Code Online (Sandbox Code Playgroud)

  • Thi9s 可以工作,但它有一个问题:如果 GUI 处于打开状态,该命令将不执行任何操作(甚至不显示错误)。丑陋,但使用此解决方法您可以打开一个新实例:`--env:UserInstallation=file:///path/to/some/directory`。 (6认同)
  • 对于那些想知道 Unoconv 与 Libreoffice 命令行的优缺点的人来说,这个问题可能会有所帮助:https://github.com/dagwieers/unoconv/issues/364 (3认同)
  • 手册页对 `--convert-to` 说“`它意味着 --headless`”。因此,`libreoffice --convert-to pdf *.odt` 应该也能工作(至少对于 5.1.6.2 版)。 (3认同)
  • @tokland:有一个错误报告:https://bugs.freedesktop.org/show_bug.cgi?id=37531 (2认同)

Tak*_*kat 76

只需使用 libre office 打开文档并选择Export as PDF...

在此处输入图片说明

对于命令行解决方案,unoconv可以从命令行转换文件:

unoconv -f pdf mydocument.odt
Run Code Online (Sandbox Code Playgroud)

注意: unoconv 依赖于 Libre Office。

  • 感谢提到`unoconv`,太棒了! (3认同)

Kur*_*fle 8

以下是有关“非 GUI”方法的更多详细信息。

  1. 您不仅可以使用此方法将 ODT 文件转换为 PDF。它也适用于 MS Word DOCX 文件(它与 LibreOffice 能够处理特定 ODT 一样有效),并且通常适用于 LibreOffice 可以打开的所有文件类型。

  2. 我不认为有一个二进制文件被命名libreoffice为建议的其他答案之一。但是,有soffice(.bin)-- 可用于从命令行启动 LibreOffice 的二进制文件。它通常位于/usr/lib/libreoffice/program/; 并且很多时候,符号链接/usr/bin/soffice指向那个位置。

  3. 那么,在大多数情况下,参数--headless --convert-to pdf是不够的。它必须是:

    --headless --convert-to pdf:writer_pdf_Export
    
    Run Code Online (Sandbox Code Playgroud)

    一定要完全遵循这个大写!

  4. 接下来,如果您的系统上已经启动并运行了 LibreOffice GUI 实例,则该命令将不起作用。它是由自 2011 年以来已知的错误#37531引起的。将此附加参数添加到您的命令中:

     "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"
    
    Run Code Online (Sandbox Code Playgroud)

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

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

    $ mkdir ${HOME}/lo_pdfs
    
    Run Code Online (Sandbox Code Playgroud)
  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
    
    Run Code Online (Sandbox Code Playgroud)

    这在 Mac OS X Yosemite 10.10.5 和 LibreOffice v5.1.2.2 上对我有用(使用我的二进制文件的特定路径,soffice无论如何在 Ubuntu 上会有所不同......)。它也适用于 Debian Jessie 8.0(使用 path /usr/lib/libreoffice/program/soffice)。抱歉,现在无法在 Ubuntu 上测试它....

    如果这一切都不起作用,当您尝试处理 DOCX 时:

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

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

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

  10. 重复步骤 8,但这次一定要引用 ODT。

  11. 最后:使用完整路径 to soffice, tosoffice.bin和 tolibreoffice并使用-h参数运行每个:

    $ /path/to/libreoffice -h  # if that path exists, which I doubt!
    $ /path/to/soffice -h
    $ /path/to/soffice.bin -h
    
    Run Code Online (Sandbox Code Playgroud)
    • 你在这里得到输出吗?
    • 三个二进制文件/符号链接中的哪一个?
    • 记录输出。
    • 告诉我们你的输出!!!
       

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

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

    为了比较,我自己的(Mac OS X)输出在这里:

     $ /Applications/LibreOffice.app/Contents/MacOS/soffice -h 
    
     LibreOffice 5.1.2.2 d3bf12ecb743fc0d20e0be0c58ca359301eb705f
    
     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 user interaction 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 (implies --headless).
           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.
    
    Run Code Online (Sandbox Code Playgroud)
  12. 在命令行中再添加一个参数,以在soffice打开 DOCX 文件时强制应用输入过滤器:

    --infilter="Microsoft Word 2007/2010/2013 XML"
    
    Run Code Online (Sandbox Code Playgroud)

    或者

    --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"
    
    Run Code Online (Sandbox Code Playgroud)