如何使用vb.net将word文件转换为pdf [英] how to convert word file into pdf using vb.net

查看:240
本文介绍了如何使用vb.net将word文件转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

i希望使用vb.net 2012将ms word文件转换为pdf文件。

解决方案

< blockquote>为了阅读Word文件,我建议使用Microsoft Open XML SDK,并编写PDF - iText,更准确地说,它的.NET端口,iTextSharp。

请参阅我的过去答案:问题将单词转换为PDF,无需offce或openoffice [ ^ ]。



如果你的话这是非常好的document是新格式的.docx。如果这是较旧的.doc,专有格式,这也是可能的,但更令人不快。特别是,Libre Office是开源的,具有处理旧.doc文件的代码,并提供它的开发API。有关详细信息,请参阅我之前引用的过去的答案:如何从中添加microsoft excel 15.0对象库在MS Visual Studio 2010中添加引用 [ ^ ]。



-SA


如果您有能力购买第三方工具包(例如Docentric Toolkit),您将能够使用您的文档执行各种操作。您可以通过Docentric API从头开始创建文档。或者您在MS Word中创建一个模板,然后将其与来自.NET可以读取的任何源的数据合并。



生成的文档可以是原生MS Word文档(docx)或固定文档,如pdf或xps。模板支持任何Word功能:表格,图表,页眉,页脚,条件内容,高级格式等。



生成文档后,它采用docx格式。下面的代码片段显示了如何以pdf格式保存它。不过,这个代码段是在C#中。



文档文档; 
使用(FileStream fileStream = File.OpenRead(TestBase.WordDocumentsPath + @ Test1.docx))
{
document = Document.Load(fileStream); }
document.Save(TestBase.WordDocumentsPath + @ Test1.pdf);
}


hello,
i want to convert ms word file into pdf file using vb.net 2012.

解决方案

For reading Word file, I would recommend using Microsoft Open XML SDK, and for writing PDF — iText, more exactly, its .NET port, iTextSharp.
Please see my past answer: Question Convert word to PDF without offce or openoffice[^].

This is so good if your Word document is in new format, .docx. If this is older .doc, proprietary format, this is also possible, but much more unpleasant. In particular, Libre Office is open source and has the code dealing with old .doc files, and offers it's development API. For further detail, please see my past answers referenced in on of them: How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].

—SA


If you can afford to purchase 3rd party toolkit (like Docentric Toolkit, for example), you will be able to do all sorts of things with your documents. You can create a document from scratch via Docentric APIs. Or you create a template in MS Word and then merge it with data from any source .NET can read.

Generated documents can be native MS Word documents (docx) or fixed documents like pdf or xps. Any Word feature is supported in templates: tables, charts, headers, footers, conditional content, advanced formatting, etc.

Once the document is generated it is in docx format. The code snippet below shows how to save it in pdf format. This snippet is in C#, though.

Document document;
using (FileStream fileStream = File.OpenRead(TestBase.WordDocumentsPath + @"Test1.docx"))
{
	document = Document.Load(fileStream);		}
	document.Save(TestBase.WordDocumentsPath + @"Test1.pdf");
}


这篇关于如何使用vb.net将word文件转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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