Free Support Forum - aspose.com

Converting Word Table of Contents to PDF Bookmark

I use TC fields to create a TOC in word. When converting to PDF I get the PDF and they link to the pages - however I would also like to have the PDF bookmarks displayed.


Can this be done using TC fields ?

Hi Neil,


Thanks for your inquiry.

Every node of TOC field is represented by a HYPERLINK field. When you click on a TOC item, the control jumps to a particular location in your document pointed by a hidden Bookmark. I think, in your case, you can simply insert temporary Bookmarks inside those hidden Bookmarks before saving to PDF as follows:

Document
doc = new Document(@“C:\Temp\in.docx”);

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Bookmark bm in doc.Range.Bookmarks)

{

if (bm.Name.StartsWith("_Toc"))

{

builder.MoveToBookmark(bm.Name, false, false);

builder.StartBookmark(bm.Text);

builder.EndBookmark(bm.Text);

}

}

PdfSaveOptions saveOptions = new PdfSaveOptions();

saveOptions.BookmarksOutlineLevel = 1;

doc.Save(@"C:\Temp\out.pdf", saveOptions);


I hope, this helps.

Best regards,

Thanks Awais,


I did take a similar approach and then hit this issue.


Hi Neil,


Thanks for the additional information. I have replied you here, please follow that thread for further proceedings.

Best regards,