Click or drag to resize

Automatic Bookmarks Generation

The converter can create the bookmarks (the outline shown next to the document in PDF readers) from the headings or other elements of the HTML page. Each bookmark takes the text of its element and goes to the place where the element is in the PDF.

Automatic bookmarks

List the elements to bookmark as CSS selectors in HtmlElementSelectors (property PdfBookmarkOptions). Without selectors, no bookmarks are created. "h1" selects all h1 elements, "*.chapter" the elements with the CSS class chapter, "*#summary" the element with the id summary.

PdfConverter converter = new PdfConverter();
converter.RenderingEngine = RenderingEngine.Chromium;

// a bookmark for every h1 and h2 heading of the page
converter.PdfBookmarkOptions.HtmlElementSelectors = new string[] { "h1", "h2" };

converter.SavePdfFromUrlToFile("https://www.example.com/manual", "manual.pdf");

MaxTitleLength limits the length of the bookmark titles. Automatic bookmarks work with the Chromium, Blink and WebKit engines, and with HTML added to a document with the HtmlToPdfElement.

To build a bookmark tree of your own - nested bookmarks, titles that are not in the page - convert to a Document and add the bookmarks yourself, using the positions of the elements (see HTML elements mapping and Bookmarks).

See Also