如何以编程方式将 Word 和 Excel 文档转换为 PDF?
我们正在开发一个小应用程序,给定一个包含 PDF 文件的目录,创建一个包含该目录中所有 PDF 文件的唯一 PDF 文件。 这是使用 iTextSharp 的一个简单任务。 如果目录中存在一些文件(例如 Word 文档或 Excel 文档),则会出现此问题。
我的问题是,有没有办法以编程方式将word、excel文档转换为PDF? 更好的是,如果运行该应用程序的计算机上没有安装办公套件,这是否可能?
We are developing a little application that given a directory with PDF files creates a unique PDF file containing all the PDF files in the directory. This is a simple task using iTextSharp. The problem appears if in the directory exist some files like Word documents, or Excel documents.
My question is, is there a way to convert word, excel documents into PDF programmatically? And even better, is this possible without having the office suite installed on the computer running the application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
将文件转换为 pdf 的最常见方法是将其打印到 pdf 打印机驱动程序。 有很多这样的驱动程序,据我所知,可以完成这项工作的一个是 Black Ice。
另一种是使用Adobe Acrobat 的SDK。 从我的记忆中它非常昂贵。
自从我真正完成任何 PDF 转换工作以来,已经有一段时间了,情况可能已经发生了变化。
The most common way to convert files to a pdf is to print them to a pdf printer driver. There are a number of such drivers, one that i know of that will do the job is Black Ice.
Another is to use Adobe Acrobat's SDK. from memory its very expensive.
Its been a while since i have actually done any work with converting pdf's and the landscape may have changed.
TallPDF.NET(价格昂贵)允许您从任何地方提供动态 PDF .NET 应用程序,包括 ASP.NET 页面和 Web 服务。
PDFEdit(免费且开源)是一个用于操作 PDF 文档的编辑器。 它有 GUI 版本和命令行界面。 脚本在编辑器中被广泛使用,几乎任何东西都可以编写脚本。 可以创建您自己的脚本或插件。
TallPDF.NET (comes with a hefty price tag) allows you to serve dynamic PDF from any .NET application including ASP.NET pages and web services.
PDFEdit (free and open source) is an editor for manipulating PDF documents. It has a GUI version and a command-line interface. Scripting is used to a great extent in the editor and almost anything can be scripted. It is possible to create your own scripts or plugins.
Office 2007 允许这样做。 我发现 PDFCreator 很好,VBA 包含在示例文件中,并且听说 < a href="http://www.cutepdf.com/" rel="nofollow noreferrer">CutePDF 也不错。 PDFCreator 和 CutePDF 是免费的。
据我所知,要在没有 Office 的情况下工作,您需要查看器:
http://www.microsoft.com/downloads/details.aspx microsoft.com/downloads/details.aspx?FamilyID=c8378bf4-996c-4569-b547-75edbd03aaf0&displaylang=EN
http://www.microsoft.com/downloads/details.aspx?familyid=95E24C87-8732-48D5-8689-AB826E7B8FDF& ;displaylang=zh
Office 2007 allows for this. I have found PDFCreator to be good, the VBA is included in sample files, and have heard that CutePDF is also good. PDFCreator and CutePDF are free.
To work without Office, you would need viewers, as far as I know:
http://www.microsoft.com/downloads/details.aspx?FamilyID=c8378bf4-996c-4569-b547-75edbd03aaf0&displaylang=EN
http://www.microsoft.com/downloads/details.aspx?familyid=95E24C87-8732-48D5-8689-AB826E7B8FDF&displaylang=en
我很惊讶这里没有提到 Aspose,它简单、简单且可靠。 缺点是它不是免费的。
我过去用过 iTextSharp,它真的很好,很容易安装(我相信是一个 DLL),合并需要一点tindering,所以它不像 Aspose 那样容易使用,但是嘿,它是免费的,所以这是最好的部分。
I'm surprised Aspose wasn't mentioned here, it's easy, simple, and reliable. Downside is that it is not free.
I've used iTextSharp in the past, it's really good, easy to install (one DLL I believe), the merge takes a bit of tindering so it's not as easy to use as Aspose, but hey, it's free so that is the best part.
我需要自己执行此操作,但设法使用 .Net 完成此操作,并且无需第三方工具:
MSDN:将 Word 2007 文档保存为 PDF 和 XPS 格式
非常简单,大约 50 行代码。 不过,我认为您需要在计算机上安装 Word 2007,并且能够另存为 PDF
I needed to do this myself, but managed to get it done with .Net and without 3rd party tools:
MSDN: Saving Word 2007 Documents to PDF and XPS Formats
Pretty simple, about 50 lines of code. However I think you will need Word 2007 installed on the machine as well as the ability to Save As PDF
要将 Word 文档转换为 PDF,请查看 jWordConvert,这是一个完全可以做到这一点的 Java 库。 但这不适用于 Excel 文件,仅适用于 Word 文件。 该语言不是 Sharp,而是 Java,但您可以改用 IText(即 java)而不是 ITextSharp。
To convert Word documents to PDF, take a look at jWordConvert, a java library that can do exactly that. This will not work with the Excel files though, only with the Word files. The language is not Sharp, it's Java but you could switch to use IText (which is java) instead of ITextSharp.
您还可以使用 activePDF 的 DocConverter 等组件来转换批次< /strong> 格式为 PDF。
You can also use a component like activePDF's DocConverter to convert a lot formats to PDF.
使用adobe 7-9附带的PDF制作器
我刚刚使用了这段代码 将文档转换为 PDF
Use PDF maker that comes with adobe 7- 9
I just used this code Covert Doc to PDF