Create a page tree in C# and VB.NET

With GemBox.Pdf, you can get, create, remove or reorder PDF document pages in your C# or VB.NET application.

The pages of a PDF document are accessed through a structure known as the page tree, which defines the ordering of pages in the document. The tree structure allows PDF consumer applications, using only limited memory, to quickly open a PDF document containing thousands of pages. For more information, see Document Structure help page.

The following example shows how you can create a page tree structure from scratch.

PDF page tree created with GemBox.Pdf C#/VB.NET library
Screenshot of PDF pages created with GemBox.Pdf library
using System;
using GemBox.Pdf;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = new PdfDocument())
        {
            // Get a page tree root node.
            var rootNode = document.Pages;
            // Set page rotation for a whole set of pages.
            rootNode.Rotate = 90;

            // Create a left page tree node.
            var childNode = rootNode.Kids.AddPages();
            // Overwrite a parent tree node rotation value.
            childNode.Rotate = 0;

            // Create an empty page.
            childNode.Kids.AddPage();
            // Create an empty page and set a page media box value.
            childNode.Kids.AddPage().SetMediaBox(0, 0, 200, 400);

            // Create a right page tree node.
            childNode = rootNode.Kids.AddPages();
            // Set a media box value.
            childNode.SetMediaBox(0, 0, 100, 200);

            // Create an empty page.
            childNode.Kids.AddPage();
            // Create an empty page and overwrite a rotation value.
            childNode.Kids.AddPage().Rotate = 0;

            document.Save("Page Tree.pdf");
        }
    }
}
Imports System
Imports GemBox.Pdf

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Using document = New PdfDocument()

            ' Get a page tree root node.
            Dim rootNode = document.Pages
            ' Set page rotation for a whole set of pages.
            rootNode.Rotate = 90

            ' Create a left page tree node.
            Dim childNode = rootNode.Kids.AddPages()
            ' Overwrite a parent tree node rotation value.
            childNode.Rotate = 0

            ' Create an empty page.
            childNode.Kids.AddPage()
            ' Create an empty page And set a page media box value.
            childNode.Kids.AddPage().SetMediaBox(0, 0, 200, 400)

            ' Create a right page tree node.
            childNode = rootNode.Kids.AddPages()
            ' Set a media box value.
            childNode.SetMediaBox(0, 0, 100, 200)

            ' Create an empty page.
            childNode.Kids.AddPage()
            ' Create an empty page And overwrite a rotation value.
            childNode.Kids.AddPage().Rotate = 0

            document.Save("Page Tree.pdf")
        End Using
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Pdf yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.