如何将 Word 文档转换为 PDF? [英] How can I convert a Word document to PDF?

查看:29
本文介绍了如何将 Word 文档转换为 PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Word 文档转换为 PDF,其中文档包含各种内容,例如表格.尝试使用 iText 时,原始文档看起来与转换后的 PDF 不同.是否有我可以使用的开源 API/库,而不是调用可执行文件?

How can I convert a Word document to PDF where the document contains various things, such as tables. When trying to use iText, the original document looks different to the converted PDF. Is there an open source API / library, rather than calling out to an executable, that I can use?

推荐答案

这是一项非常艰巨的任务,如果您想要完美的结果(如果不使用 Word 就不可能),那么就更难了,例如可以为您完成所有工作的 API 数量我相信纯 Java 和开源为零(更新:我错了,见下文).

This is quite a hard task, ever harder if you want perfect results (impossible without using Word) as such the number of APIs that just do it all for you in pure Java and are open source is zero I believe (Update: I am wrong, see below).

您的基本选项如下:

  1. 使用 JNI/a C# 网络服务/等脚本 MS Office(100% 完美结果的唯一选项)
  2. 使用可用的 API 脚本 Open Office(90+% 完美)
  3. 使用 Apache POI &iText(非常大的工作,永远不会完美).

更新 - 2016-02-11这是我关于此主题的博客文章的精简副本,其中概述了在 Java 中支持 Word-to-PDF 的现有产品.

Update - 2016-02-11 Here is a cut down copy of my blog post on this subject which outlines existing products that support Word-to-PDF in Java.

转换Microsoft Office(Word、Excel)文档到 Java 格式的 PDF

我知道的三种产品可以呈现 Office 文档:

Three products that I know of can render Office documents:

yeokm1/docs-to-pdf-converter不定期维护,纯 Java,开源将多个库联系在一起以执行转换.

yeokm1/docs-to-pdf-converter Irregularly maintained, Pure Java, Open Source Ties together a number of libraries to perform the conversion.

xdocreport积极开发、纯 Java、开源它是 Java API,用于将使用 MS Office (docx) 或 OpenOffice (odt)、LibreOffice (odt) 创建的 XML 文档与 Java 模型合并以生成报告并将其转换为其他格式(PDF、XHTML ...).

xdocreport Actively developed, Pure Java, Open Source It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).

Snowbound 成像 SDK闭源,纯 JavaSnowbound 似乎是 100% Java 解决方案,成本超过 2,500 美元.它包含描述如何在评估下载中转换文档的示例.

Snowbound Imaging SDK Closed Source, Pure Java Snowbound appears to be a 100% Java solution and costs over $2,500. It contains samples describing how to convert documents in the evaluation download.

OpenOffice API开源,非纯 Java - 需要安装 Open OfficeOpenOffice 是一个支持 Java API 的原生 Office 套件.这支持阅读 Office 文档和编写 PDF 文档.SDK 包含文档转换示例 (examples/java/DocumentHandling/DocumentConverter.java).要编写 PDF,您需要传递writer_pdf_Export"编写器而不是MS Word 97"编写器.或者您可以使用包装器 API JODConverter.

OpenOffice API Open Source, Not Pure Java - Requires Open Office installed OpenOffice is a native Office suite which supports a Java API. This supports reading Office documents and writing PDF documents. The SDK contains an example in document conversion (examples/java/DocumentHandling/DocumentConverter.java). To write PDFs you need to pass the "writer_pdf_Export" writer rather than the "MS Word 97" one. Or you can use the wrapper API JODConverter.

JDocToPdf - 截至 2016 年 2 月 11 日死亡使用 Apache POI 读取 Word 文档和 iText 编写 PDF.完全免费,100% Java,但有一些限制.

JDocToPdf - Dead as of 2016-02-11 Uses Apache POI to read the Word document and iText to write the PDF. Completely free, 100% Java but has some limitations.

这篇关于如何将 Word 文档转换为 PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆