Cómo agregar marcadores y esquemas PDF en C# usando IronPDF

How to Add PDF Bookmarks and Outline

This article was translated from English: Does it need improvement?
Translated
View the article in English

Including PDF outlines, also known as bookmarks, in your C# project can greatly enhance usability and UX design. PDF outlines function as a navigation tool, allowing users to easily access key pages within the document, similar to a Table of Contents. By incorporating PDF outlines, you can provide a more intuitive and user-friendly experience for your document.

Quickstart: Adding Bookmarks to Your PDF in C#

Get started quickly with IronPDF by adding bookmarks to your PDF documents effortlessly. This guide demonstrates how to load an existing PDF, add bookmarks for easy navigation, and save the updated document. Perfect for developers looking to enhance PDF functionality in their C# projects with minimal effort and maximum efficiency.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    var pdf = new IronPdf.PdfDocument("example.pdf");
    pdf.Bookmarks.AddBookMarkAtEnd("Chapter 1", 1);
    pdf.SaveAs("bookmarked.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

Add Outlines & Bookmarks Example

In Adobe Acrobat Reader, outlines (also known as bookmarks) are displayed in the left sidebar, providing a convenient way to jump to key sections of the document.

With IronPDF, you have the capability to import PDF documents and perform various operations on existing outlines, such as adding, reordering, editing properties, and deleting bookmarks. This gives you full control over the organization and structure of your PDF files.

ConsejosAll the pages index follow zero-based indexing.

Add Single Layer of Bookmarks

Adding a bookmark in IronPDF is a straightforward process. You can use the AddBookmarkAtEnd method, which requires specifying the bookmark name and the corresponding page index. Below is an example code snippet:

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-single-layer-bookmark.cs
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");
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")
$vbLabelText   $csharpLabel

Single-layer Bookmarks Document

Add Multiple Layers of Bookmarks

With IronPDF, you can add bookmarks in a tree structure, which is particularly useful for maintaining navigability in large PDF documents. This feature comes in handy when dealing with extensive collections of examination papers, sales reports, or receipt records from various dates and locations in a single PDF document.

The AddBookMarkAtEnd method returns an IPdfBookMark object, allowing you to add child bookmarks. For example, you can use Children.AddBookMarkAtStart("Date1", 0) or Children.AddBookMarkAtEnd("Date1", 0) to add child bookmarks to the "Examination" bookmark. The following code demonstrates this concept:

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-multi-layer-bookmark.cs
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");
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")
$vbLabelText   $csharpLabel

Multi-layer Bookmarks Document

Retrieve Bookmarks List

With IronPDF, you can easily retrieve and view the bookmarks in a PDF document. Navigating through the bookmark tree is straightforward and provides seamless access to different sections. Let's consider the multi-layer bookmarks document example above.

The "Examination" bookmark will have a Children property that points to the "Date1" and "Date2" bookmarks. The "Date1" bookmark, in turn, has a NextBookmark property that points to the "Date2" bookmark. Additionally, the "Date1" bookmark has a Children property that contains the "Paper" bookmark.

To retrieve all the bookmarks present in the opened PDF document, you can use the GetAllBookmarks method. This will provide you with a comprehensive list of all bookmarks, allowing you to further analyze and utilize the bookmark structure.

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-retrieve-bookmark.cs
using IronPdf;

// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");

// Retrieve bookmarks list
var 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()
$vbLabelText   $csharpLabel

Por favor notaMerging two PDF documents that have bookmarks with identical names can lead to a disruption in the bookmark list.

AdvertenciaOnly bookmarks created from page index are supported. Bookmarks made from other parts or elements in PDF document will get the page index value set to -1.

Learn how to create a Table of Contents when generating PDF from HTML in the following article: "Creating a Table of Contents with IronPDF."

Ready to see what else you can do? Check out our tutorial page here: Organize PDFs

Preguntas Frecuentes

¿Cómo empiezo a usar IronPDF para agregar marcadores en un PDF?

Para comenzar a usar IronPDF para agregar marcadores, descarga IronPDF desde NuGet, carga un PDF existente o renderiza uno nuevo y usa el método `AddBookmarkAtEnd` para agregar marcadores a tu documento.

¿Cuál es el papel de los marcadores en un documento PDF?

Los marcadores en un documento PDF actúan como una herramienta de navegación, permitiendo a los usuarios saltar fácilmente a secciones clave, similar a una tabla de contenidos, lo que mejora la usabilidad del documento.

¿Cómo puedo agregar varias capas de marcadores a un PDF?

Con IronPDF, puedes crear varias capas de marcadores en una estructura de árbol usando el método `AddBookMarkAtEnd`, lo cual es útil para organizar documentos grandes con contenido jerárquico.

¿Cuál es el proceso para recuperar marcadores de un PDF usando IronPDF?

Puedes recuperar marcadores de un PDF utilizando el método `GetAllBookmarks` de IronPDF, que proporciona una lista de todos los marcadores, facilitando la navegación y el análisis del documento.

¿Puedo editar o eliminar marcadores en un PDF con IronPDF?

Sí, IronPDF te permite gestionar marcadores añadiendo, reordenando, editando propiedades y eliminando marcadores, dándote control total sobre la estructura organizativa del PDF.

¿Qué se debe considerar al fusionar PDF con marcadores?

Al fusionar documentos PDF con marcadores, asegúrate de que los marcadores tengan nombres únicos, ya que fusionar PDF con nombres de marcadores idénticos puede interrumpir la estructura del marcador.

¿Cómo puedo crear una Tabla de Contenidos en un PDF generado desde HTML?

Para crear una Tabla de Contenidos en un PDF generado desde HTML, consulta el artículo 'Creating a Table of Contents with IronPDF,' que ofrece una guía detallada sobre este proceso.

¿Qué sucede si un marcador se crea a partir de un elemento que no es de índice de página?

Los marcadores creados a partir de elementos distintos del índice de página tendrán el valor de índice de página establecido en -1, ya que IronPDF solo admite marcadores hechos directamente desde índices de página.

¿IronPDF es totalmente compatible con .NET 10 al utilizar marcadores?

Sí — IronPDF es totalmente compatible con .NET 10, incluyendo todas las funciones de marcadores y esquemas. Las mismas API para añadir, recuperar, editar y eliminar marcadores funcionan de forma inmediata en aplicaciones .NET 10, al igual que en versiones anteriores compatibles.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado