Welcome
Guest
•
Login
PDFsharp and MigraDoc Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
File Management
Create Account
Quick Search
»
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.
Back
PDFsharp Sample: Bookmarks
Modified on 2015/09/14 10:23
by
Thomas Hövel
Categorized as
PDFsharp Samples
,
Samples
{s:navigationPrevUpNext|Booklet-sample|PDFsharpSamples|ColorsCMYK-sample} 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: {s:PdfLink|Bookmark-sample%2fBookmarks_output.pdf|output.pdf} (5 kB) ==Screen Shots== Here is a sample screen shot (click to enlarge): {s:ImageThumbLink|Bookmarks PDF file|Bookmark-sample%2fBookmarkth.png|Bookmark-sample%2fBookmark.png} ==Source Code== This is the source code that demonstrates the creation of bookmarks: {s:beginCsharp} // 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); {s:endCsharp} {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
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