Welcome GuestLogin

PDFsharp and MigraDoc Wiki

RSS RSS

Navigation




Quick Search
»

PoweredBy

Visit the new Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6 and find information about the new version for Windows, Linux, and other platforms.

<< Previous^UpNext >>
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.

Acrobat uses the term “bookmark” in its English version and “Lesezeichen” in the German version.

PDF Output File

See the PDF file created by this sample: output.pdf (5 kB)

Screen Shots

Here is a sample screen shot (click to enlarge):

Bookmarks PDF file

Source Code

This is the source code that demonstrates the creation of 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, XStringFormats.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;
  gfx.DrawString(text, font, XBrushes.Black, 20, 50, XStringFormats.Default);
 
  // Create a sub bookmark
  outline.Outlines.Add(text, page, true);
}
 
// Save the document...
const string filename = "Bookmarks_tempfile.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);

Note: The samples on this site usually show and discuss code snippets only. The complete source code of the samples with solutions for Visual Studio is available from the download area on CodePlex.


Visit the new Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6 and find information about the new version for Windows, Linux, and other platforms.



Miscellaneous
Home
PDFsharp
FAQ
Samples
Articles
MigraDoc
FAQ
Samples
Articles

ScrewTurn Wiki version 3.0.5.600. Some of the icons created by FamFamFam.

Impressum - Privacy Policy, Data Protection Declaration, Legal Notice