在ASP.NET中将MS Word文档转换为PDF
有人提出了类似的问题,但没有一个完全像我的问题,所以去吧。
我们在ASP.NET Web服务器上收集了Microsoft Word文档,其中包含合并字段,这些合并字段的值是由于用户表单提交而填充的。字段合并后,服务器必须将文档转换为PDF并将其流式传输到浏览器。我们的第一个倾向是使用Visual Studio Tools for Office API。但是,我们遇到了来自Microsoft的警告:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
看起来可以使用Open XML SDK进行字段操作,但是在不打开Word的情况下将Word 2007文档转换为PDF的最佳方法是什么?最佳解决方案是低成本,可伸缩,内存占用量小,易于部署以及具有.NET API。
解决方案
查阅Microsoft关于使用Cor VB将Word 2007文档保存为PDF和XPS格式的资源。
ActivePdf DocConverter http://www.activepdf.com/
但这需要在服务器上安装Office才能获得良好的质量转换。
它不是完全开放源代码,但是Aspose有一些可以做到这一点的产品,
Aspose.Pdf.Kit
Aspose.Pdf.Kit is a non-graphical PDF? document manipulation component that enables both .NET and Java developers to manage existing PDF files as well as manage form fields embedded within PDF files. Aspose.Pdf is perfect for creating new PDF files; however, developers often need to edit already existing PDF documents. Aspose.Pdf.Kit allows them to do just that. Aspose.Pdf.Kit allows developers to create powerful applications for merging data directly into PDF documents as well as for updating and managing PDF documents. Aspose.Pdf.Kit is a wonderful product and works great with the rest of our PDF products.
和Aspose.pdf
Aspose.Pdf is a non-graphical PDF? document reporting component that enables either .NET or Java applications to create PDF documents from scratch without utilizing Adobe Acrobat?. Aspose.Pdf is very affordably priced and offers a wealth of strong features including: compression, tables, graphs, images, hyperlinks, security and custom fonts. Aspose.Pdf supports the creation of PDF files through API, XML templates and XSL-FO files. Aspose.Pdf is very easy to use and is provided with 14 fully featured demos written in both C# and Visual Basic.
查看API和演示。我们可以免费下载DLL进行尝试。我以前都用过,而且效果很好。
还有iTextSharp,它是Java PDF转换器iText的Cport。我听说有人尝试了混合结果。
问题是"在ASP.NET中将MS Word文档转换为PDF",所以我很困惑,为什么在上面推荐使用Aspose.Pdf和Aspose.Pdf.Kit。我们需要使用Aspose.Words,因为这是支持Microsoft Word文档到PDF转换的组件。
Aspose.Words可能是最佳选择,但它不能完美地转换所有视觉元素。
看看Muhimbi PDF Converter Web服务。它作为服务在Windows上运行,但可以从任何不支持Windows Web服务的环境(包括Java和.NET)进行访问。
尽管此解决方案要求将MS-Office安装在服务器(不一定与应用程序位于同一服务器)上,但它非常健壮并提供完美的转换保真度。尽最大努力避免Microsoft在其知识库文章中提到的死锁问题。
要生成或者修改MS-Word文件,我建议使用免费的Microsoft Office Open XML SDK。埃里克·怀特(Eric White)维护了一个非常好的博客。
免责声明,我从事此产品的工作。话虽如此,它的效果很好。
我们应该尝试使用OpenOffice。它是免费的,并且支持整个文件转换范围。我已经使用它将DOC和DOCX文件转换为HTML格式,效果非常好。
ABCpdf是另一个受欢迎的组件,它使我们可以在ASP.NET下将Word文档转换为PDF,但是我相信它也利用了Microsoft Office或者OpenOffice。
http://www.websupergoo.com/abcpdf-office-docs.htm