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

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

问题描述

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

解决方案

这是一项艰巨的任务,如果您想要完美的结果(如果不使用Word则是不可能的),例如要为您完成全部工作的API数量,则将变得更加困难.在纯Java中,开源是零,我相信(更新:我错了,请参阅下文).

您的基本选项如下:

  1. 使用JNI/C#Web服务/等脚本MS Office(仅100%完美效果的选择)
  2. 使用可用的API脚本Open Office(90%完美)
  3. 使用Apache POI& iText(非常大的工作,永远不会完美).

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

转换Microsoft Office(Word,Excel)文档以Java格式转换为PDF

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

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

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

Snowbound Imaging SDK 纯Java封闭源代码 Snowbound似乎是100%的Java解决方案,价格超过2500美元.它包含描述如何在评估下载中转换文档的示例.

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

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

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?

解决方案

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).

Your basic options are as follows:

  1. Using JNI/a C# web service/etc script MS Office (only option for 100% perfect results)
  2. Using the available APIs script Open Office (90+% perfect)
  3. Use Apache POI & iText (very large job, will never be perfect).

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.

Converting Microsoft Office (Word, Excel) documents to PDFs in Java

Three products that I know of can render Office documents:

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

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 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 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 - 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天全站免登陆