using IronPdf;// Create a new PDF or edit an existing document.PdfDocument pdf = PdfDocument.FromFile("existing.pdf");// Add a bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0);// Add a sub-bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1);pdf.SaveAs("singleLayerBookmarks.pdf");
using IronPdf;
// Create a new PDF or edit an existing document.
PdfDocument pdf = PdfDocument.FromFile("existing.pdf");
// Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0);
// Add a sub-bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1);
pdf.SaveAs("singleLayerBookmarks.pdf");
ImportsIronPdf' Create a new PDF or edit an existing document.Private pdf AsPdfDocument = PdfDocument.FromFile("existing.pdf")' Add a bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0)' Add a sub-bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1)pdf.SaveAs("singleLayerBookmarks.pdf")
Imports IronPdf
' Create a new PDF or edit an existing document.
Private pdf As PdfDocument = PdfDocument.FromFile("existing.pdf")
' Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0)
' Add a sub-bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1)
pdf.SaveAs("singleLayerBookmarks.pdf")
using IronPdf;// Load existing PDF documentPdfDocument pdf = PdfDocument.FromFile("examinationPaper.pdf");// Assign IPdfBookMark object to a variablevar mainBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Examination", 0);// Add bookmark for daysvar date1Bookmark = mainBookmark.Children.AddBookMarkAtStart("Date1", 1);// Add bookmark for type of testvar paperBookmark = date1Bookmark.Children.AddBookMarkAtStart("Paper", 1);paperBookmark.Children.AddBookMarkAtEnd("PersonA", 3);paperBookmark.Children.AddBookMarkAtEnd("PersonB", 4);// Add bookmark for daysvar date2Bookmark = mainBookmark.Children.AddBookMarkAtEnd("Date2", 5);// Add bookmark for type of testvar computerBookmark = date2Bookmark.Children.AddBookMarkAtStart("Computer", 5);computerBookmark.Children.AddBookMarkAtEnd("PersonC", 6);computerBookmark.Children.AddBookMarkAtEnd("PersonD", 7);pdf.SaveAs("multiLayerBookmarks.pdf");
using IronPdf;
// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("examinationPaper.pdf");
// Assign IPdfBookMark object to a variable
var mainBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Examination", 0);
// Add bookmark for days
var date1Bookmark = mainBookmark.Children.AddBookMarkAtStart("Date1", 1);
// Add bookmark for type of test
var paperBookmark = date1Bookmark.Children.AddBookMarkAtStart("Paper", 1);
paperBookmark.Children.AddBookMarkAtEnd("PersonA", 3);
paperBookmark.Children.AddBookMarkAtEnd("PersonB", 4);
// Add bookmark for days
var date2Bookmark = mainBookmark.Children.AddBookMarkAtEnd("Date2", 5);
// Add bookmark for type of test
var computerBookmark = date2Bookmark.Children.AddBookMarkAtStart("Computer", 5);
computerBookmark.Children.AddBookMarkAtEnd("PersonC", 6);
computerBookmark.Children.AddBookMarkAtEnd("PersonD", 7);
pdf.SaveAs("multiLayerBookmarks.pdf");
ImportsIronPdf' Load existing PDF documentPrivate pdf AsPdfDocument = PdfDocument.FromFile("examinationPaper.pdf")' Assign IPdfBookMark object to a variablePrivate mainBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Examination", 0)' Add bookmark for daysPrivate date1Bookmark = mainBookmark.Children.AddBookMarkAtStart("Date1", 1)' Add bookmark for type of testPrivate paperBookmark = date1Bookmark.Children.AddBookMarkAtStart("Paper", 1)paperBookmark.Children.AddBookMarkAtEnd("PersonA", 3)paperBookmark.Children.AddBookMarkAtEnd("PersonB", 4)' Add bookmark for daysDim date2Bookmark = mainBookmark.Children.AddBookMarkAtEnd("Date2", 5)' Add bookmark for type of testDim computerBookmark = date2Bookmark.Children.AddBookMarkAtStart("Computer", 5)computerBookmark.Children.AddBookMarkAtEnd("PersonC", 6)computerBookmark.Children.AddBookMarkAtEnd("PersonD", 7)pdf.SaveAs("multiLayerBookmarks.pdf")
Imports IronPdf
' Load existing PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("examinationPaper.pdf")
' Assign IPdfBookMark object to a variable
Private mainBookmark = pdf.Bookmarks.AddBookMarkAtEnd("Examination", 0)
' Add bookmark for days
Private date1Bookmark = mainBookmark.Children.AddBookMarkAtStart("Date1", 1)
' Add bookmark for type of test
Private paperBookmark = date1Bookmark.Children.AddBookMarkAtStart("Paper", 1)
paperBookmark.Children.AddBookMarkAtEnd("PersonA", 3)
paperBookmark.Children.AddBookMarkAtEnd("PersonB", 4)
' Add bookmark for days
Dim date2Bookmark = mainBookmark.Children.AddBookMarkAtEnd("Date2", 5)
' Add bookmark for type of test
Dim computerBookmark = date2Bookmark.Children.AddBookMarkAtStart("Computer", 5)
computerBookmark.Children.AddBookMarkAtEnd("PersonC", 6)
computerBookmark.Children.AddBookMarkAtEnd("PersonD", 7)
pdf.SaveAs("multiLayerBookmarks.pdf")
using IronPdf;var renderer = new ChromePdfRenderer();// Master switch: auto-generate bookmarks from HTML headings (h1-h6) during renderingrenderer.RenderingOptions.AutoBookmarksFromHeadings = true;var html = @"<h1>Annual Report</h1><h2>Executive Summary</h2><p>Overview of the year.</p><h2>Financial Results</h2><h3>Revenue</h3><h3>Expenses</h3><h2>Outlook</h2><p>Looking forward.</p>";var pdf = renderer.RenderHtmlAsPdf(html);// pdf.Bookmarks is already populated with a hierarchical outline matching the heading structurepdf.SaveAs("auto-bookmarked.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
// Master switch: auto-generate bookmarks from HTML headings (h1-h6) during rendering
renderer.RenderingOptions.AutoBookmarksFromHeadings = true;
var html = @"
<h1>Annual Report</h1>
<h2>Executive Summary</h2>
<p>Overview of the year.</p>
<h2>Financial Results</h2>
<h3>Revenue</h3>
<h3>Expenses</h3>
<h2>Outlook</h2>
<p>Looking forward.</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
// pdf.Bookmarks is already populated with a hierarchical outline matching the heading structure
pdf.SaveAs("auto-bookmarked.pdf");
ImportsIronPdfDim renderer As New ChromePdfRenderer()' Master switch: auto-generate bookmarks from HTML headings (h1-h6) during renderingrenderer.RenderingOptions.AutoBookmarksFromHeadings = TrueDim html AsString = "<h1>Annual Report</h1><h2>Executive Summary</h2><p>Overview of the year.</p><h2>Financial Results</h2><h3>Revenue</h3><h3>Expenses</h3><h2>Outlook</h2><p>Looking forward.</p>"Dim pdf = renderer.RenderHtmlAsPdf(html)' pdf.Bookmarks is already populated with a hierarchical outline matching the heading structurepdf.SaveAs("auto-bookmarked.pdf")
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Master switch: auto-generate bookmarks from HTML headings (h1-h6) during rendering
renderer.RenderingOptions.AutoBookmarksFromHeadings = True
Dim html As String = "
<h1>Annual Report</h1>
<h2>Executive Summary</h2>
<p>Overview of the year.</p>
<h2>Financial Results</h2>
<h3>Revenue</h3>
<h3>Expenses</h3>
<h2>Outlook</h2>
<p>Looking forward.</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
' pdf.Bookmarks is already populated with a hierarchical outline matching the heading structure
pdf.SaveAs("auto-bookmarked.pdf")
using IronPdf;using System;var renderer = new ChromePdfRenderer();// Configure which elements should be queryable after renderingrenderer.RenderingOptions.ElementQuerySelectors = new[] { "h1", ".kpi-card" };var html = @"<h1>Q4 Dashboard</h1><div class='kpi-card'>Revenue: $1.2M</div><div class='kpi-card'>Growth: 18%</div><h1>Q3 Comparison</h1><div class='kpi-card'>Previous: $1.0M</div>";var pdf = renderer.RenderHtmlAsPdf(html);// Retrieve the rendered page location of each matched elementforeach (var location in pdf.GetElementLocations()){Console.WriteLine($"'{location.Text}' on page {location.PageIndex + 1} " + $"at ({location.Rectangle.X}, {location.Rectangle.Y})");}pdf.SaveAs("dashboard.pdf");
using IronPdf;
using System;
var renderer = new ChromePdfRenderer();
// Configure which elements should be queryable after rendering
renderer.RenderingOptions.ElementQuerySelectors = new[] { "h1", ".kpi-card" };
var html = @"
<h1>Q4 Dashboard</h1>
<div class='kpi-card'>Revenue: $1.2M</div>
<div class='kpi-card'>Growth: 18%</div>
<h1>Q3 Comparison</h1>
<div class='kpi-card'>Previous: $1.0M</div>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Retrieve the rendered page location of each matched element
foreach (var location in pdf.GetElementLocations())
{
Console.WriteLine($"'{location.Text}' on page {location.PageIndex + 1} " +
$"at ({location.Rectangle.X}, {location.Rectangle.Y})");
}
pdf.SaveAs("dashboard.pdf");
ImportsIronPdfImportsSystemDim renderer = New ChromePdfRenderer()' Configure which elements should be queryable after renderingrenderer.RenderingOptions.ElementQuerySelectors = New String() {"h1", ".kpi-card"}Dim html = "<h1>Q4 Dashboard</h1><div class='kpi-card'>Revenue: $1.2M</div><div class='kpi-card'>Growth: 18%</div><h1>Q3 Comparison</h1><div class='kpi-card'>Previous: $1.0M</div>"Dim pdf = renderer.RenderHtmlAsPdf(html)' Retrieve the rendered page location of each matched elementFor Each location In pdf.GetElementLocations()Console.WriteLine($"'{location.Text}' on page {location.PageIndex + 1} " & $"at ({location.Rectangle.X}, {location.Rectangle.Y})")Nextpdf.SaveAs("dashboard.pdf")
Imports IronPdf
Imports System
Dim renderer = New ChromePdfRenderer()
' Configure which elements should be queryable after rendering
renderer.RenderingOptions.ElementQuerySelectors = New String() {"h1", ".kpi-card"}
Dim html = "
<h1>Q4 Dashboard</h1>
<div class='kpi-card'>Revenue: $1.2M</div>
<div class='kpi-card'>Growth: 18%</div>
<h1>Q3 Comparison</h1>
<div class='kpi-card'>Previous: $1.0M</div>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
' Retrieve the rendered page location of each matched element
For Each location In pdf.GetElementLocations()
Console.WriteLine($"'{location.Text}' on page {location.PageIndex + 1} " &
$"at ({location.Rectangle.X}, {location.Rectangle.Y})")
Next
pdf.SaveAs("dashboard.pdf")
using IronPdf;using System;var renderer = new ChromePdfRenderer();// Auto-generate bookmarks from top-level headings onlyrenderer.RenderingOptions.AutoBookmarksFromHeadings = true;renderer.RenderingOptions.AutoBookmarkMaxHeadingLevel = 2;// Also track the page location of invoice totals after renderingrenderer.RenderingOptions.ElementQuerySelectors = new[] { ".invoice-total" };var html = @"<h1>Invoice #2026-001</h1><h2>Line Items</h2><p>Services rendered for Q1.</p><p class='invoice-total'>Subtotal: $4,500.00</p><h1>Invoice #2026-002</h1><h2>Line Items</h2><p>Consulting hours for Q2.</p><p class='invoice-total'>Subtotal: $7,200.00</p>";var pdf = renderer.RenderHtmlAsPdf(html);// Bookmarks are populated automatically; locations can be queried after renderingforeach (var location in pdf.GetElementLocations()){Console.WriteLine($"{location.Text} appears on page {location.PageIndex + 1}");}pdf.SaveAs("invoices.pdf");
using IronPdf;
using System;
var renderer = new ChromePdfRenderer();
// Auto-generate bookmarks from top-level headings only
renderer.RenderingOptions.AutoBookmarksFromHeadings = true;
renderer.RenderingOptions.AutoBookmarkMaxHeadingLevel = 2;
// Also track the page location of invoice totals after rendering
renderer.RenderingOptions.ElementQuerySelectors = new[] { ".invoice-total" };
var html = @"
<h1>Invoice #2026-001</h1>
<h2>Line Items</h2>
<p>Services rendered for Q1.</p>
<p class='invoice-total'>Subtotal: $4,500.00</p>
<h1>Invoice #2026-002</h1>
<h2>Line Items</h2>
<p>Consulting hours for Q2.</p>
<p class='invoice-total'>Subtotal: $7,200.00</p>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Bookmarks are populated automatically; locations can be queried after rendering
foreach (var location in pdf.GetElementLocations())
{
Console.WriteLine($"{location.Text} appears on page {location.PageIndex + 1}");
}
pdf.SaveAs("invoices.pdf");
ImportsIronPdfImportsSystemDim renderer As New ChromePdfRenderer()' Auto-generate bookmarks from top-level headings onlyrenderer.RenderingOptions.AutoBookmarksFromHeadings = Truerenderer.RenderingOptions.AutoBookmarkMaxHeadingLevel = 2' Also track the page location of invoice totals after renderingrenderer.RenderingOptions.ElementQuerySelectors = New String() {".invoice-total"}Dim html AsString = "<h1>Invoice #2026-001</h1><h2>Line Items</h2><p>Services rendered for Q1.</p><p class='invoice-total'>Subtotal: $4,500.00</p><h1>Invoice #2026-002</h1><h2>Line Items</h2><p>Consulting hours for Q2.</p><p class='invoice-total'>Subtotal: $7,200.00</p>"Dim pdf = renderer.RenderHtmlAsPdf(html)' Bookmarks are populated automatically; locations can be queried after renderingFor Each location In pdf.GetElementLocations()Console.WriteLine($"{location.Text} appears on page {location.PageIndex + 1}")Nextpdf.SaveAs("invoices.pdf")
Imports IronPdf
Imports System
Dim renderer As New ChromePdfRenderer()
' Auto-generate bookmarks from top-level headings only
renderer.RenderingOptions.AutoBookmarksFromHeadings = True
renderer.RenderingOptions.AutoBookmarkMaxHeadingLevel = 2
' Also track the page location of invoice totals after rendering
renderer.RenderingOptions.ElementQuerySelectors = New String() {".invoice-total"}
Dim html As String = "
<h1>Invoice #2026-001</h1>
<h2>Line Items</h2>
<p>Services rendered for Q1.</p>
<p class='invoice-total'>Subtotal: $4,500.00</p>
<h1>Invoice #2026-002</h1>
<h2>Line Items</h2>
<p>Consulting hours for Q2.</p>
<p class='invoice-total'>Subtotal: $7,200.00</p>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
' Bookmarks are populated automatically; locations can be queried after rendering
For Each location In pdf.GetElementLocations()
Console.WriteLine($"{location.Text} appears on page {location.PageIndex + 1}")
Next
pdf.SaveAs("invoices.pdf")
using IronPdf;// Load existing PDF documentPdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");// Retrieve bookmarks listvar mainBookmark = pdf.Bookmarks.GetAllBookmarks();
using IronPdf;
// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");
// Retrieve bookmarks list
var mainBookmark = pdf.Bookmarks.GetAllBookmarks();
ImportsIronPdf' Load existing PDF documentPrivate pdf AsPdfDocument = PdfDocument.FromFile("multiLayerBookmarks.pdf")' Retrieve bookmarks listPrivate mainBookmark = pdf.Bookmarks.GetAllBookmarks()
Imports IronPdf
' Load existing PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("multiLayerBookmarks.pdf")
' Retrieve bookmarks list
Private mainBookmark = pdf.Bookmarks.GetAllBookmarks()
Does IronPDF support bookmark manipulation in existing PDF documents?
Yes, IronPDF allows for various operations on existing PDF outlines such as adding, reordering, editing properties, and deleting bookmarks, giving you full control over the PDF document's structure.
What environments does IronPDF support for adding bookmarks to PDFs?
IronPDF supports adding bookmarks to PDFs on Windows, Linux, and macOS environments, providing cross-platform compatibility for developers.
Can IronPDF track the rendered locations of HTML elements in a PDF?
IronPDF can report the rendered page and coordinates of specific HTML elements in a PDF using the `GetElementLocations` method, helping developers precisely locate elements within the PDF document.
What are the key steps to get started with adding bookmarks in IronPDF?
The key steps to add bookmarks in IronPDF include downloading IronPDF from NuGet, loading or rendering a new PDF document, adding single or multi-layer bookmarks, and saving the updated document.