Back to Devexpress

PdfBookmark.Children Property

officefileapi-devexpress-dot-pdf-dot-pdfbookmark-a42b371f.md

latest4.9 KB
Original Source

PdfBookmark.Children Property

Gets or sets the collection of bookmark children for a document with a tree-structured hierarchy.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public IList<PdfBookmark> Children { get; set; }
vb
Public Property Children As IList(Of PdfBookmark)

Property Value

TypeDescription
IList<PdfBookmark>

A list of PdfBookmark objects that are the collection of bookmark child nodes.

|

Remarks

A list of bookmark children can’t be null. If you set the Children property to null , the argument null exception occurs.

An instance of the PdfBookmark class is accessible via the PdfDocument.Bookmarks property.

Important

The bookmark hierarchy must contain only distinct instances of the PdfBookmark class. The following code snippet shows this prohibited action.

csharp
PdfBookmark bookmark = new PdfBookmark();
bookmark.Children.Add(bookmark);
vb
Dim bookmark As PdfBookmark = New PdfBookmark() 
bookmark.Children.Add(bookmark)

You can create bookmarks hierarchy using, for example, the following code.

csharp
using DevExpress.Pdf;

namespace DocumentCreationAPI {
    class Program {

        static void Main(string[] args) {
            #region #DocumentCreation
            using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
                // Create an empty document using PDF creation options.
                processor.CreateEmptyDocument("..\\..\\Result.pdf", new PdfCreationOptions() {
                    Compatibility = PdfCompatibility.PdfA2b,
                    DisableEmbeddingAllFonts = false
                });
                // Add a page to the PDF.
                processor.AddNewPage(PdfPaperSize.Letter);
                AddBookmarks(processor);
                // Save the document with bookmarks.
                processor.SaveDocument("..\\..\\Result.pdf");

            }
            #endregion #DocumentCreation
        }

        static void AddBookmarks(PdfDocumentProcessor processor) {
            PdfBookmark bookmark1 = new PdfBookmark() { Title = "1" };
            PdfBookmark bookmark2 = new PdfBookmark() { Title = "1.1" };
            PdfBookmark bookmark3 = new PdfBookmark() { Title = "1.1.1" };
            bookmark1.Children.Add(bookmark2);
            bookmark2.Children.Add(bookmark3);
            processor.Document.Bookmarks.Add(bookmark1);
        }
    }
}
vb
Imports DevExpress.Pdf

Namespace DocumentCreationAPI
    Class Program

        Shared Sub Main(ByVal args() As String)
            #region #DocumentCreation
            Imports (PdfDocumentProcessor processor = New PdfDocumentProcessor()) {
                ' Create an empty document using PDF creation options. 
                Private Function PdfCreationOptions() As processor.CreateEmptyDocument("..\\..\\Result.pdf",Shadows
                    Compatibility = PdfCompatibility.PdfA2b,
                    DisableEmbeddingAllFonts = False
                End Function
)
                ' Add a page to the PDF. 
                processor.AddNewPage(PdfPaperSize.Letter)
                AddBookmarks(processor)
                ' Save the document with bookmarks. 
                processor.SaveDocument("..\\..\\Result.pdf")

        End Sub
            #End Region #DocumentCreation
    End Class

        Shared Sub AddBookmarks(ByVal processor As PdfDocumentProcessor)
            PdfBookmark bookmark1 = Function PdfBookmark() As Shadows
                 Title = "1"
            End Function

            PdfBookmark bookmark2 = Function PdfBookmark() As Shadows
                 Title = "1.1"
            End Function

            PdfBookmark bookmark3 = Function PdfBookmark() As Shadows
                 Title = "1.1.1"
            End Function

            bookmark1.Children.Add(bookmark2)
            bookmark2.Children.Add(bookmark3)
            processor.Document.Bookmarks.Add(bookmark1)
        End Sub
End Namespace
}

See Also

PdfBookmark Class

PdfBookmark Members

DevExpress.Pdf Namespace