PDF Mosaic: How to add outlines and bookmarks to PDF document


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code

 

This sample shows how to add document outlines (bookmarks) in your PDF file.

Use PDFOutline class to outline.

Use PDFOutline class to outline in PDF Mosaic
 

using PDFMosaic;
using System;
 
namespace Outlines
{
    class Oultines
    {
        static void Main()
        {
            PDFDocument document = new PDFDocument();
            document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
            document.PageMode = PDFPageMode.Outlines;
 
            PDFOutline first = new PDFOutline("First");
            PDFOutline tmp = new PDFOutline("Bold Title");
 
            tmp.Bold = true;
            first.Kids.Add(tmp);
 
            tmp.Bold = false;
            tmp.Italic = true;
            tmp.Title = "Italic Title";
            first.Kids.Add(tmp);
 
            tmp.Bold = true;
            tmp.Title = "Bold Italic Title";
            first.Kids.Add(tmp);
            document.Outlines.Add(first);
 
            PDFOutline second = new PDFOutline("Second");
            tmp.Bold = false;
            tmp.Italic = false;
            tmp.Title = "Red";
            tmp.Color = new PDFColorRGB(255, 0, 0);
            second.Kids.Add(tmp);
 
            tmp.Title = "Green";
            tmp.Color = new PDFColorRGB(0, 255, 0);
            second.Kids.Add(tmp);
 
            tmp.Title = "blue";
            tmp.Color = new PDFColorRGB(0, 0, 255);
            second.Kids.Add(tmp);
            document.Outlines.Add(second);
 
            PDFOutline third = new PDFOutline("Hidden Children");
            for (int i = 0; i < 10; ++i)
                third.Kids.Add(new PDFOutline("Kid " + (i + 1).ToString()));
            third.HideChildren = true;
            document.Outlines.Add(third);
 
            document.Save("TestAddOutlines.pdf", true);
        }
    }
}

 


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code