从7.3.3版本开始,Spire.Doc支持转换Word文档到PDF时,保留Word文档的标题作为PDF书签。本文将介绍如何使用Spire.Doc来实现这一功能。
原Word文档:
C#
using Spire.Doc;
namespace Keep_word_headings_as_pdf_bookmarks {
class Program {
private static void Main(string[] args) {
Document doc = new Document(false);
doc.LoadFromFile("Input.docx");
ToPdfParameterList topdf = new ToPdfParameterList();
topdf.CreateWordBookmarks = true;
topdf.CreateWordBookmarksUsingHeadings = true;
doc.SaveToFile("Output.pdf", topdf);
}
}
}
VB.NET
Imports Spire.Doc
Namespace Keep_word_headings_as_pdf_bookmarks
Class Program
Private Shared Sub Main(ByVal args() As String)
Dim doc As Document = New Document(false)
doc.LoadFromFile("Input.docx")
Dim topdf As ToPdfParameterList = New ToPdfParameterList
topdf.CreateWordBookmarks = true
topdf.CreateWordBookmarksUsingHeadings = true
doc.SaveToFile("Output.pdf", topdf)
End Sub
End Class
End Namespace
生成PDF文档: