Developer Rent
Developer Rent

Reputation: 15

Nested Bookmarks in PDF

I use the HTML to PDF converter from EVO to create a PDF document and I use the following code to generate bookmarks for H tags:

// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();

// Select the HTML elements to bookmark by setting a list of CSS selectors
htmlToPdfConverter.PdfBookmarkOptions.HtmlElementSelectors = new string[] { "H1", "H2", "H3" };

// Display the bookmarks panel in PDF viewer when the generated PDF is opened
htmlToPdfConverter.PdfViewerPreferences.PageMode = ViewerPageMode.UseOutlines;

// Convert the HTML page to a PDF document in a memory buffer
byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(urlTextBox.Text);

The bookmarks appear in viewer but they are all at the same level. I would like to have them organized in a tree with H1 tags at first level, H2 tags at the second level and so on. I found another software which can organize the bookmarks the way I want, but I would like to avoid using another tool just for this. I want to generate the bookmarks directly in a tree.

Upvotes: 0

Views: 623

Answers (1)

EvoPdf
EvoPdf

Reputation: 523

There are 2 methods to automatically create bookmarks in generated PDF document. One is through API and is the method you already used but that does no produce a hierarchy of bookmarks as you would like.

The other method is to set the following line in your code:

// Enable the creation of a hierarchy of bookmarks from H1 to H6 tags
htmlToPdfConverter.PdfBookmarkOptions.AutoBookmarksEnabled = true;

This will enable the creation of a tree of bookmarks based on the heading tags in your HTML.

Upvotes: 1

Related Questions