How to preserve bookmarks in DOCX to PDF conversion

Bookmarks give convenience when users want go to specified location and it is clearly to know the contents brief information. Spire.Doc for .NET has a powerful function of operating the word elements of bookmarks. Developers can add bookmarks, Edit/replace bookmarks and remove bookmarks in word documents. Now Spire.Doc starts to support preserve bookmarks in DOCX to PDF conversion. This article will show you how to preserve bookmarks in C# when converting word document into PDF file format.

Download and install Spire.Doc for .NET (Version 5.2.20 or above) and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll".

Here comes to the details of how to preserve the bookmarks from word to PDF conversion in C#.

Step 1: Load a word documents with bookmarks.

Document doc = new Document();
doc.LoadFromFile("test.docx", FileFormat.Docx);

Step 2: Create an instance of ToPdfParameterList

ToPdfParameterList toPdf = new ToPdfParameterList();

Step 3: Set CreateWordBookmarks to true to use word bookmarks when create the bookmarks.

toPdf.CreateWordBookmarks = true;

Step 4: Save the PDF file.

doc.SaveToFile("test.Pdf",toPdf);

Effective screenshot of preserve the bookmarks in result PDF page:

Preserve bookmarks in PDF from word

Full codes:

[C#]
Document doc = new Document();
doc.LoadFromFile("test.docx", FileFormat.Docx);
ToPdfParameterList toPdf = new ToPdfParameterList();
toPdf.CreateWordBookmarks = true;
doc.SaveToFile("test.Pdf", toPdf);
System.Diagnostics.Process.Start("test.Pdf");