Home arrow Samples arrow Watermark Make Text BiggerMake Text SmallerReset Text Size
Bookmarks

This sample shows how to create bookmarks.
Bookmarks are called outlines in the PDF reference manual, that's why you deal with the class PdfOutline.

A screen shot for the Bookmark sample (click image to enlarge):

Bookmarks
Bookmarks

// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create a font
XFont font = new XFont("Verdana", 16);
 
// Create first page
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("Page 1", font, XBrushes.Black, 20, 50, XStringFormat.Default);
 
// Create the root bookmark. You can set the style and the color.
PdfOutline outline = document.Outlines.Add("Root", page, true,
  PdfOutlineStyle.Bold, XColors.Red);
 
// Create some more pages
for (int idx = 2; idx <= 5; idx++)
{
  page = document.AddPage();
  gfx = XGraphics.FromPdfPage(page);
 
  string text = "Page " + idx.ToString();
  gfx.DrawString(text, font, XBrushes.Black, 20, 50, XStringFormat.Default);
 
  // Create a sub bookmark
  outline.Outlines.Add(text, page, true);
}
 
// Save the document...
string filename = "Bookmarks.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
 
< Prev   Next >
New! We no longer maintain this site. Visit the new PDFsharp and MigraDoc Foundation Homepage. © 2009 empira Software GmbH | Impressum | Created with Joomla!