using IronPDF,您可以导入 PDF 文档,并对现有大纲执行各种操作,如添加、重新排序、编辑属性和删除书签。 这使您可以完全控制 PDF 文件的组织和结构,类似于您可以 合并或分割 PDFs 以进行文档管理。
提示: 所有页面索引均采用从零开始的索引方式。
如何添加单层书签?
在 IronPDF 中添加书签非常简单。 使用AddBookmarkAtEnd方法,指定书签名称和相应的页面索引。 该功能与其他 PDF 操作(如添加页眉和页脚或设置自定义页边距)很好地集成在一起,以创建专业文档。 下面是一个示例:
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")
如何检索和浏览现有书签?
IronPDF 可轻松检索和查看 PDF 文档中的书签。 通过书签树导航变得简单,并无缝访问不同部分。 在处理需要编辑的现有 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()
IronPDF 的书签功能可在 Windows、Linux 和 macOS 环境下无缝运行。无论您的操作系统如何,您都可以添加、编辑和管理 PDF 书签,确保在不同平台上实现一致的功能。
我可以对现有 PDF 书签执行哪些操作?
using IronPDF,您可以对现有的 PDF 大纲执行各种操作,包括添加新书签、重新排列书签顺序、编辑书签属性以及删除不需要的书签。这样,您就可以完全控制 PDF 文件的组织和结构。
用户打开 PDF 时如何显示书签?
在 Adobe Acrobat Reader 和类似的 PDF 阅读器中,使用 IronPDF 创建的书签会在左侧边栏显示为轮廓。它们具有交互式目录的功能,允许读者通过点击跳转到特定部分来高效地浏览复杂的文档。
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.