Spire.Doc是一款全方位的Word文档创建、浏览、编辑和转换控件,可以快速转换word为PDF,通过改产品您可以直接创建word文件或者通过本地word模板创建,并把创建好的word文件转换为PDF,所有这些操作,客户电脑上都不需要安装任何Microsoft Word组件
使用该产品转换Word为PDF仅需要简单的2步即可完成
1.下载Spire.Doc for .NET 试用版,安装并在项目里引用控件动态链接库
2. 使用控件提供的LoadFromFile()方法加载Word文件,并使用SaveToFile()方法保存为PDF
具体的代码如下:
[c#]
using System;
using Spire.Doc;
using Spire.Doc.Documents;
namespace DoctoPDF
{
class toPDF
{
static void Main(string[] args)
{
//Load Document
Document document = new Document();
document.LoadFromFile(@"E:\work\documents\TestSample.docx");
//Convert Word to PDF
document.SaveToFile("toPDF.PDF", FileFormat.PDF);
//Launch Document
System.Diagnostics.Process.Start("toPDF.PDF");
}
}
}
[VB.NET]
Imports System
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace DoctoPDF
Friend Class toPDF
Shared Sub Main(ByVal args() As String)
'Load Document
Dim document As New Document()
document.LoadFromFile("E:\work\documents\TestSample.docx")
'Convert Word to PDF
document.SaveToFile("toPDF.PDF", FileFormat.PDF)
'Launch Document
System.Diagnostics.Process.Start("toPDF.PDF")
End Sub
End Class
End Namespace
转换后的截图如下: