我怎么能把ODT文件转换成PDF?

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

只需使用libre office打开文档,然后选择Export as PDF …

在此处输入图像描述

对于命令行解决方案,有unoconv 安装NAME 从命令行转换文件:

 unoconv -f pdf mydocument.odt 

注意:仅从Ubuntu 11.10 unoconv开始取决于Libre Office。 以前的unoconv版本(来自Ubuntu <= 11.04)依赖于Open Office(但它也将与Libre Office一起运行)。

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

 libreoffice --headless --convert-to pdf *.odt 

获取有关命令行选项的更多信息:

 man libreoffice 

以下是有关“非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 

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

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

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

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

    如果所有这些都不起作用,当您尝试处理DOCX时:

  7. 对于您尝试使用命令的特定DOCX文件可能存在问题…因此,首先创建一个非常简单的DOCX文档。 为此使用LibreOffice本身。 写下“Hello World!” 在一个空的页面上。 将其另存为DOCX。

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

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

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

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

     $ /path/to/libreoffice -h # if that path exists, which I doubt! $ /path/to/soffice -h $ /path/to/soffice.bin -h 
    • 你有输出吗?
    • 三个二进制文件/符号链接中的哪一个?
    • 记录输出。
    • 告诉我们你的输出!

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

    • 参数名称,大小写,使用的破折号等都有变化吗?

    为了比较,我自己的(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  Specify X-Display to use in Unix/X11 versions. -p  print the specified documents on the default printer. --pt   print the specified documents on the specified printer. --view  open the specified documents in viewer-(readonly-)mode. --show  open the specified presentation and start it immediately --accept= Specify an UNO connect-string to create an UNO acceptor through which other programs can connect to access the API --unaccept= Close an acceptor that was created with --accept= Use --unnaccept=all to close all open acceptors --infilter=[: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:[=] 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文件时,在命令行中再添加一个参数以强制应用输入filter:

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

Nautilus脚本

此脚本使用libreoffice将与LibreOffice兼容的文件转换为PDF。

 #!/bin/bash ## PDFconvert 0.1 ## by Glutanimate (https://askubuntu.com/users/81372/) ## License: GPL 3.0 ## depends on python, libreoffice ## Note: if you are using a non-default LO version (eg because you installed it ## from a precompiled package instead of the official repos) you might have to change ## 'libreoffice' according to the version you're using, eg 'libreoffice3.6' # Get work directory base="`python -c 'import gio,sys; print(gio.File(sys.argv[1]).get_path())' $NAUTILUS_SCRIPT_CURRENT_URI`" #Convert documents while [ $# -gt 0 ]; do document=$1 libreoffice --headless --invisible --convert-to pdf --outdir "$base" "$document" shift done 

有关安装说明,请参阅此处: 如何安装Nautilus脚本?

注意:我决定从这个问题中删除我的答案并在此处发布修改后的版本,当我意识到unoconv根本不处理psw文件时,并且不会将它们成功转换为其他格式。 docxxlsx格式也可能存在问题。


但是, Libreoffice完全支持许多文件类型; 官方网站上提供了完整的文档 ,其中详细介绍了有效的输入和输出格式。

您可以使用命令行libreoffice convert实用程序或unoconv ,它可以在存储库中使用。 我发现unoconv非常有用,它可能就是你想要的。 尽管Takkat曾简要提到过unoconv ,但我认为提供一些更多细节和批量转换单行是有用的。

使用终端你可以cd到包含你的文件的目录,然后通过运行如下所示的单行批量转换所有这些:

 for f in *.odt; do unoconv -f pdf "${f/%pdf/odt}"; done 

(这个单行是对我的翻译脚本的修改, 在这个答案中有特色。)

如果您以后想要使用任何其他文件格式,只需将odtpdf替换为任何其他支持的输入和输出格式。 您可以通过输入unoconv -f odt --show找到文件类型支持的格式。 要转换单个文件,请使用unoconv -f pdf myfile.odt

有关该计划的更多信息和选项,请访问terminal man unoconv或在线访问Ubuntu联机帮助页 。

另一个Nautilus脚本

这个非常简单轻巧的Nautilus脚本使用unoconv将与LibreOffice兼容的选定文件转换为PDF格式:

 #!/bin/sh #Nautilus Script to convert selected LibreOffice-compatible file(s) to PDF # OLDIFS=$IFS IFS=" " for filename in $@; do unoconv --doctype=document --format=pdf "$filename" done IFS=$OLDIFS 

考虑使用docspal服务( http://www.docspal.com )。 它是免费的,快速的,并支持许多格式。 希望,它对你有用。