15

我有一些在OpenOffice中编写的文档,我想在最终版本交付中将它作为PDF文件包含在其中。我想用自动构建脚本来做到这一点。OpenOffice命令行PDF创建

有没有办法使用命令行命令从OpenOffice创建PDF文件?

回答

12

Art of Solving也有一个很好的API来执行Java中的转换。这有点慢,但它很简单。这是我如何使用它:

 File inputFile = new File("C:\\oreyes\\hola.doc"); 
     File outputFile = new File("C:\\oreyes\\hola.pdf"); 
     OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 
     try { 
      connection.connect(); 
     } catch(Exception e) {} 

     DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 
     converter.convert(inputFile, outputFile); 
     connection.disconnect(); 

您可以创建一个jar并从命令行处理它。

+1

有没有相同的方式,你的描述,但指定`OpenOfficeConnection officeConnection =新SocketOpenOfficeConnection( “my_local_vm_ip”,8100);`,但我得到一个错误的所有时间。 `线程中的异常“main”com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException:转换失败:无法加载输入文件` – Eugene 2011-07-21 10:12:53

+0

如果你想导出某些选项(例如带标签的PDF),你首先需要设置它们在OpenOffice或LibreOffice中? – 2016-08-12 15:20:04

16

有一个很棒的工具叫做“unoconv”,它在我的Ubuntu库中。它将ODF,.ods,...转换为PDF格式,我认为也适用于其他格式。

我也可以将PowerPoint文件转换为PDF。

+0

像一个魅力工作,谢谢! – 2010-03-16 09:47:25

1

anytopdf。还没有尝试过自己。

报价...

anytopdf is a perl script that converts OpenOffice.org, Microsoft Office (Word DOC, Excel XLS), RTF, HTML, and other openoffice.org readable file formats to the PDF format. It will automatically install the supporting 'AnyToPDF' OpenOffice.org Basic macro library in the current user's OpenOffice.org configuration if it's not already present.

Dedicated to peace, love, understanding and respect for all beings.

28

截至2012年9月,LibreOffice的可以通过命令行的文件转换为PDF:

lowriter --headless --convert-to pdf yourfile.odt 

它也有批量转换支持:

lowriter --headless --convert-to pdf yourfiles*.odt 

会将所有符合该模式的文件转换为相应的PDF文件。

运行此命令时,不得打开LibreOffice窗口。

2

尽管这个问题是有点老了,这里的东西记录一些常见的陷阱与LibreOffice的解决方案的宗旨是:

  • 如果lowriter因为它忽略了命令行参数,并提出了不为你工作图形用户界面只是尝试调用libreofficeloffice二进制代码:

    loffice --headless --convert-to pdf yourfile.odt

  • 如果您收到此消息

    Error: Please reverify input parameters...

    尝试运行它作为根(例如通过sudo)。这帮助我在安装了LibreOffice 3的Ubuntu 12.04 LTS上运行,也可能是没有正确配置的情况下此转换未在网络服务器上运行的原因(Libreoffice --headless refuses to convert unless root, won't work from PHP script

  • 另外请确保您没有任何其他LibreOffice实例正在运行,否则它只会失败而不做任何转换。