如何从 linux 服务器从 .docx 生成 PDF 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4702511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Generate PDF file from .docx from linux server?
提问by Revelation
We use on our production server: Ubuntu 10 server edition. We need to create a document that includes text , images and tables in the content and images in header and footer. Now we use http://phpword.codeplex.com/to create it and it does a great job generating docx files but we need the pdf version of that file. How can we convert the docx to pdf ? Or any other library to generate pdf files that allows images in header /footer ? Using windows components is not a solution. Using openOffice maybe? can it be used on an ubuntu server edition ? any other convertor for docx to pdf in linux - server environment ?
我们在生产服务器上使用:Ubuntu 10 服务器版。我们需要创建一个文档,其中包含内容中的文本、图像和表格以及页眉和页脚中的图像。现在我们使用http://phpword.codeplex.com/来创建它,它在生成 docx 文件方面做得很好,但我们需要该文件的 pdf 版本。我们如何将 docx 转换为 pdf ?或者任何其他库来生成允许页眉/页脚中的图像的pdf文件?使用 Windows 组件不是解决方案。可能使用 openOffice?它可以在 ubuntu 服务器版本上使用吗?在 linux 服务器环境中还有其他用于 docx 到 pdf 的转换器吗?
采纳答案by Restless
If your documents include images using OpenOffice is definitely a good solution. Check out PyODConverterif you want to try this out.
如果您的文档包含图像,使用 OpenOffice 绝对是一个不错的解决方案。如果您想尝试一下,请查看PyODConverter。
If it's simple text you might want to consider using a simpler solution like PHPDocx, unoconv, AbiWord or LiveDocx.
如果是简单的文本,您可能需要考虑使用更简单的解决方案,如 PHPDocx、unoconv、AbiWord 或 LiveDocx。
I've used OOo in the past for this (and still use to convert Odt files to Pdf) and it works great. :) I only got one problem with it, but has already been resolved. You can check that out here: Docx to pdf using openoffice headless way too slow
我过去为此使用过 OOo(并且仍然用于将 Odt 文件转换为 Pdf)并且效果很好。:) 我只有一个问题,但已经解决了。你可以在这里查看:Docx to pdf using openoffice headless way too slow
EDIT:
编辑:
I've created a bash script "/etc/init.d/openoffice" to start openoffice with the correct options. The file contents are the following:
我创建了一个 bash 脚本“/etc/init.d/openoffice”来使用正确的选项启动 openoffice。文件内容如下:
#!/bin/bash
# openoffice.org headless server script
#
# chkconfig: 2345 80 30
# description: headless openoffice server script
# processname: openoffice
OOo_HOME=/usr/lib/openoffice
SOFFICE_PATH=$OOo_HOME/program/soffice
if [ "" == "start" ]; then
echo "Starting OpenOffice headless server"
$SOFFICE_PATH --headless --accept="pipe,name=beubi_OOffice;urp;StarOffice.ServiceManager" --invisible --norestore --nodefault --nolockcheck --nofirstwizard
exit
fi
if [ "" == "stop" ]; then
echo "Stopping OpenOffice headless server."
killall -9 soffice.bin && killall -9 soffice
exit
fi
echo "Usage: ##代码## {start|stop}"
exit 1
Then just set execute permission on it and you should be ready to go.
然后只需对其设置执行权限,您就可以开始使用了。
回答by JasonPlutext
You could try docx4j (Java). It can generate pdfs, and images in headers shouldn't be a problem.
你可以试试 docx4j (Java)。它可以生成 pdf,标题中的图像应该不成问题。
Update May 2016
2016 年 5 月更新
For the last year or so, we've been offering a high quality commercial docx to PDF converter which runs on Linux (and Solaris for that matter); try it at http://converter-eval.plutext.com/where you can also download an installer.
在过去一年左右的时间里,我们一直在提供一个高质量的商业 docx 到 PDF 转换器,它可以在 Linux(和 Solaris)上运行;在http://converter-eval.plutext.com/上尝试一下,您也可以在其中下载安装程序。