PDF for WinRT
Adding Bookmarks to a PDF Document

When you open a PDF document using Adobe's Acrobat Reader application, you will notice that most long documents contain an outline structure that is displayed on a pane on the left of the reader. The outline makes it easy to browse through a document's structure and find specific topics. The picture below shows a PDF document with an outline:

 

The outline entries are called Bookmarks, and you can add them to your PDF for WinRT documents using the C1PdfDocument.AddBookmark method. The C1PdfDocument.AddBookmark(String,Int32,Double) method takes three parameters: the title of the outline entry, the outline level, and the 'y' position of the entry on the current page (measured in points from the top of the page).

For example, the routine below adds a paragraph to a document and optionally marks it as a level-zero outline entry:

Visual Basic
Copy Code
Private Function RenderParagraph(text As String, font As Font, rect As Rect, rectPage As Rect, outline As Boolean) As Rect

    ' If it doesn't fit on this page, add a page break.
    rect.Height = _c1pdf.MeasureString(text, font, rect.Width).Height
    If rect.Bottom > rectPage.Bottom Then
        _c1pdf.NewPage()
        rect.Y = rectPage.Top
    End If

    ' Draw the string.
    _c1pdf.DrawString(text, font, Colors.Black, rect)

    ' Add headings to outline.
    If outline Then
        _c1pdf.DrawLine(Pens.Black, rect.X, rect.Y, rect.Right, rect.Y)
        _c1pdf.AddBookmark(text, 0, rect.Y)
    End If

    ' Update rectangle for next time.
    rect.Offset(0, rect.Height)
    Return rect
End Function

C#
Copy Code
private Rect RenderParagraph(string text, Font font, Rect rect, Rect rectPage, bool outline)
{
    // If it doesn't fit on this page, add a page break.
    rect.Height = _c1pdf.MeasureString(text, font, rect.Width).Height;
    if (rect.Bottom > rectPage.Bottom)
    {
        _c1pdf.NewPage();
        rect.Y = rectPage.Top;
    }

    // Draw the string.
    _c1pdf.DrawString(text, font, Colors.Black, rect);

    // Add headings to outline.
    if (outline)
    {
        _c1pdf.DrawLine(Pens.Black, rect.X, rect.Y, rect.Right, rect.Y);
        _c1pdf.AddBookmark(text, 0, rect.Y);
    }

    // Update rectangle for next time.
    rect.Offset(0, rect.Height);
    return rect;
}
Note: You can also use more overloads for AddBookmark() method - to pass the boolean to specify whether the children of bookmark are initially visible or to pass the target name of the document.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback