Bookmarks |
The HTML to PDF Converter offers an API for adding bookmarks to a PDF document. Using the AddBookmark() methods of the Document class, you can add root or child bookmarks.
The code sample below shows how to work with bookmarks in a PDF document:
// add a page to the PDF document PdfPage firstPage = document.AddPage(); //add a root bookmark to the first page Bookmark firstPageBookmark = document.AddBookmark("First Page", new ExplicitDestination(firstPage)); string imagesPath = System.IO.Path.Combine(Server.MapPath("~"), "Images"); // display image in the available space in page and with a auto determined height to keep the aspect ratio ImageElement imageElement1 = new ImageElement(0, 0, System.IO.Path.Combine(imagesPath, "html-to-pdf-box-250.PNG")); AddElementResult addResult = firstPage.AddElement(imageElement1); // add a child bookmark to this image document.AddBookmark("HTML to PDF Converter", new ExplicitDestination(firstPage, new System.Drawing.PointF(0,0)), firstPageBookmark); // display image in the available space in page and with a auto determined height to keep the aspect ratio ImageElement imageElement2 = new ImageElement(0, 200, System.IO.Path.Combine(imagesPath, "rtftopdf-converter-250.jpg")); addResult = firstPage.AddElement(imageElement2); // add a child bookmark to this image document.AddBookmark("RTF to PDF Converter", new ExplicitDestination(firstPage, new System.Drawing.PointF(0, 200)), firstPageBookmark); //add a new page to document PdfPage secondPage = document.AddPage(); //add a root bookmark to the second page and set a 200% zoom when visiting this bookmark ExplicitDestination secondPageDestination = new ExplicitDestination(secondPage); secondPageDestination.ZoomPercentage = 150; Bookmark secondPageBookmark = document.AddBookmark("Second Page", secondPageDestination); // display image in the available space in page and with a auto determined height to keep the aspect ratio ImageElement imageElement3 = new ImageElement(0, 0, System.IO.Path.Combine(imagesPath, "pdf-toolkit-pro-250.jpg")); addResult = secondPage.AddElement(imageElement3);