public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "Outline.pdf"; using (PdfDocument pdf = new PdfDocument()) { pdf.PageMode = PdfPageMode.UseOutlines; pdf.AddPage(); pdf.AddPage(); for (int i = 0; i < pdf.PageCount; ++i) { PdfCanvas canvas = pdf.Pages[i].Canvas; canvas.DrawString(260, 50, "Page " + (i + 1).ToString()); } PdfOutlineItem root = pdf.OutlineRoot; PdfOutlineItem outlineForPage1 = root.AddChild("Page 1", 0); PdfOutlineItem outlineForPage2 = root.AddChild("Page 2", 1); PdfOutlineItem childOutlineForPage3 = outlineForPage2.AddChild("Page 3", 2); pdf.Save(pathToFile); } Process.Start(pathToFile); }
private static void BuildTestOutline(PdfDocument pdf) { PdfOutlineItem root = pdf.OutlineRoot; PdfOutlineItem lastParent = null; PdfFont times = pdf.AddFont(PdfBuiltInFont.TimesItalic); double pageWidth = pdf.GetPage(0).Width; PdfPage page = pdf.GetPage(pdf.PageCount - 1); for (int i = 1; i < 30; i++) { if (i > 1) { page = pdf.AddPage(); } page.Canvas.Font = times; page.Canvas.FontSize = 16; string titleFormat = string.Format("Page {0}", i); double textWidth = page.Canvas.GetTextWidth(titleFormat); page.Canvas.DrawString(new PdfPoint((pageWidth - textWidth) / 2, 100), titleFormat); PdfGoToAction action = pdf.CreateGoToPageAction(i - 1, 0); if (i == 1 || i == 10 || i == 20) { lastParent = root.AddChild(titleFormat, action); } else { lastParent.AddChild(titleFormat, action); } } }