public override void Run( ) { // 1. Opening the PDF file... string filePath = PromptFileChoice("Please select a PDF file"); using (File file = new File(filePath)) { Document document = file.Document; Pages pages = document.Pages; // 2. Inserting page destinations... NamedDestinations destinations = document.Names.Destinations; /* * NOTE: Here we are registering page 1 multiple times to test tree structure sorting and splitting. */ Destination page1Destination = new LocalDestination(pages[0]); destinations[new PdfString("d31e1142")] = page1Destination; destinations[new PdfString("Z1")] = page1Destination; destinations[new PdfString("d38e1142")] = page1Destination; destinations[new PdfString("B84afaba8")] = page1Destination; destinations[new PdfString("z38e1142")] = page1Destination; destinations[new PdfString("d3A8e1142")] = page1Destination; destinations[new PdfString("f38e1142")] = page1Destination; destinations[new PdfString("B84afaba6")] = page1Destination; destinations[new PdfString("d3a8e1142")] = page1Destination; destinations[new PdfString("Z38e1142")] = page1Destination; if (pages.Count > 1) { LocalDestination page2Destination = new LocalDestination(pages[1], Destination.ModeEnum.FitHorizontal, 0, null); destinations[new PdfString("N84afaba6")] = page2Destination; // Let the viewer go to the second page on document opening! /* * NOTE: Any time a named destination is applied, its name is retrieved and used as reference. */ document.Actions.OnOpen = new GoToLocal( document, page2Destination // Its name ("N84afaba6") is retrieved behind the scenes. ); // Define a link to the second page on the first one! new Link( pages[0], new RectangleF(0, 0, 100, 50), "Link annotation", page2Destination // Its name ("N84afaba6") is retrieved behind the scenes. ); if (pages.Count > 2) { destinations[new PdfString("1845505298")] = new LocalDestination(pages[2], Destination.ModeEnum.XYZ, new PointF(50, Single.NaN), null); } } // 3. Serialize the PDF file! Serialize(file, "Named destinations", "manipulating named destinations", "named destinations, creation"); } }
public override void Run( ) { // 1. Opening the PDF file... string filePath = PromptFileChoice("Please select a PDF file"); using (var file = new File(filePath)) { Document document = file.Document; // 2. Named objects extraction. Names names = document.Names; if (!names.Exists()) { Console.WriteLine("\nNo names dictionary."); } else { Console.WriteLine("\nNames dictionary found (" + names.DataContainer.Reference + ")"); NamedDestinations namedDestinations = names.Destinations; if (!namedDestinations.Exists()) { Console.WriteLine("\nNo named destinations."); } else { Console.WriteLine("\nNamed destinations found (" + namedDestinations.DataContainer.Reference + ")"); // Parsing the named destinations... foreach (KeyValuePair <PdfString, Destination> namedDestination in namedDestinations) { PdfString key = namedDestination.Key; Destination value = namedDestination.Value; Console.WriteLine(" Destination '" + key + "' (" + value.DataContainer.Reference + ")"); Console.Write(" Target Page: number = "); object pageRef = value.Page; if (pageRef is Int32) // NOTE: numeric page refs are typical of remote destinations. { Console.WriteLine(((int)pageRef) + 1); } else // NOTE: explicit page refs are typical of local destinations. { Page page = (Page)pageRef; Console.WriteLine(page.Number + "; ID = " + ((PdfReference)page.BaseObject).Id); } } Console.WriteLine("Named destinations count = " + namedDestinations.Count); } } } }
public override void Run( ) { // 1. Opening the PDF file... string filePath = PromptFileChoice("Please select a PDF file"); using (File file = new File(filePath)) { Document document = file.Document; Pages pages = document.Pages; // 2. Inserting page destinations... NamedDestinations destinations = document.Names.Destinations; destinations[new PdfString("d31e1142")] = new LocalDestination(pages[0]); if (pages.Count > 1) { destinations[new PdfString("N84afaba6")] = new LocalDestination(pages[1], Destination.ModeEnum.FitHorizontal, 0, null); destinations[new PdfString("d38e1142")] = new LocalDestination(pages[1]); destinations[new PdfString("M38e1142")] = new LocalDestination(pages[1]); destinations[new PdfString("d3A8e1142")] = new LocalDestination(pages[1]); destinations[new PdfString("z38e1142")] = new LocalDestination(pages[1]); destinations[new PdfString("f38e1142")] = new LocalDestination(pages[1]); destinations[new PdfString("e38e1142")] = new LocalDestination(pages[1]); destinations[new PdfString("B84afaba6")] = new LocalDestination(pages[1]); destinations[new PdfString("Z38e1142")] = new LocalDestination(pages[1]); if (pages.Count > 2) { destinations[new PdfString("1845505298")] = new LocalDestination(pages[2], Destination.ModeEnum.XYZ, new PointF(50, Single.NaN), null); } } // 3. Serialize the PDF file! Serialize(file, "Named destinations", "manipulating named destinations", "named destinations, creation"); } }