Get, create or edit bookmarks (outlines) in C# and VB.NET

With PDF .Net, you can get, create or edit PDF document bookmarks (outlines) in your C# or VB.NET application.

The following example shows how to delete existing PDF .Net.Outlines and create new PDF .Net.Outlines in a PDF document.

Complete code

using System;
using SautinSoft.Pdf;
using System.IO;

class Program
{
	static void Main()
	{
		// This property is necessary only for licensed version.
		//SautinSoft.Pdf.Serial = "XXXXXXXXXXX";
		using (var document = new PdfDocument())
		{
			// Remove all bookmarks.
			document.Outlines.Clear();
			// Get the number of pages.
			int numberOfPages = document.Pages.Count;
			for (int i = 0; i < numberOfPages; i += 10)
			{
				// Add a new outline item (bookmark) at the end of the document outline collection.
				var bookmark = document.Outlines.AddLast(string.Format("PAGES {0}-{1}", i + 1, Math.Min(i + 10, numberOfPages)));
				// Set the explicit destination on the new outline item (bookmark).
				bookmark.SetDestination(document.Pages[i], PdfDestinationViewType.FitRectangle, 0, 0, 100, 100);
				for (int j = 0; j < Math.Min(10, numberOfPages - i); j++)
				// Add a new outline item (bookmark) at the end of parent outline item (bookmark) and set the explicit destination.
				bookmark.Outlines.AddLast(string.Format("PAGE {0}", i + j + 1)).SetDestination(document.Pages[i + j], PdfDestinationViewType.FitPage);
			}
			document.PageMode = PdfPageMode.UseOutlines;
			document.Save("hamlet_PDF_FolgerShakespeares.pdf");
		}
	}
}

            

Download.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.