当前位置:首页> 正文

Spire.Doc 教程:如何将Word转换为PDF-docx文件

这是将Word转换为PDF的一体化解决方案。 在此解决方案中,我们从头开始创建一个单词,或者从文件夹加载单词模板,然后根据需要编辑文档在C#,VB.NET中将单词转换为PDF。 转换可以是PDF格式或docx到PDF格式。

Spire.Doc for .NET是一个专业的.NET库,使用户可以直接管理Word编辑,而不需要安装Microsoft Word,编辑完成后,您可以通过两步将文档转换为PDF。

以下是将被转换为PDF文档的有效截图,在图片末尾,可以找到目标PDF。

Spire.Doc 教程:如何将Word转换为PDF

免费下载Spire.Doc for .NET并将其转换为PDF以供个人使用或评估。 在C#中将Word转换为PDF的整个过程可以描述为2个简单的步骤。

1.通过使用ocument.LoadFromFile方法声明您准备的文档和加载文档,传递给该方法的参数是文件名字符串。

2.使用document.SaveToFile方法将Word文档另存为PDF,传递给此方法的参数是文件名字符串和文件格式,文件格式必须为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

运行演示后,您将会在计算机上发现一个PDF文档:

Spire.Doc 教程:如何将Word转换为PDF
展开全文阅读

相关内容