/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { PDFNet.Initialize(); // Relative path to the folder containing test files. string input_path = "../../TestFiles/"; string output_path = "../../TestFiles/Output/"; try // Extract logical structure from a PDF document { using (PDFDoc doc = new PDFDoc(input_path + "tagged.pdf")) { doc.InitSecurityHandler(); bool example1 = true; bool example2 = true; bool example3 = true; if (example1) { Console.WriteLine("____________________________________________________________"); Console.WriteLine("Sample 1 - Traverse logical structure tree..."); STree tree = doc.GetStructTree(); if (tree.IsValid()) { Console.WriteLine("Document has a StructTree root."); for (int i = 0; i < tree.GetNumKids(); ++i) { // Recursively get structure info for all all child elements. ProcessStructElement(tree.GetKid(i), 0); } } else { Console.WriteLine("This document does not contain any logical structure."); } Console.WriteLine(); Console.WriteLine("Done 1."); } if (example2) { Console.WriteLine("____________________________________________________________"); Console.WriteLine("Sample 2 - Get parent logical structure elements from"); Console.WriteLine("layout elements."); ElementReader reader = new ElementReader(); for (PageIterator itr = doc.GetPageIterator(); itr.HasNext(); itr.Next()) { reader.Begin(itr.Current()); ProcessElements(reader); reader.End(); } Console.WriteLine(); Console.WriteLine("Done 2."); } if (example3) { Console.WriteLine("____________________________________________________________"); Console.WriteLine("Sample 3 - 'XML style' extraction of PDF logical structure and page content."); //A map which maps page numbers(as Integers) //to page Maps(which map from struct mcid(as Integers) to //text Strings) Hashtable mcid_doc_map = new Hashtable(); ElementReader reader = new ElementReader(); for (PageIterator itr = doc.GetPageIterator(); itr.HasNext(); itr.Next()) { Page pg = itr.Current(); reader.Begin(pg); Hashtable page_mcid_map = new Hashtable(); mcid_doc_map.Add(pg.GetIndex(), page_mcid_map); ProcessElements2(reader, page_mcid_map); reader.End(); } STree tree = doc.GetStructTree(); if (tree.IsValid()) { for (int i = 0; i < tree.GetNumKids(); ++i) { ProcessStructElement2(tree.GetKid(i), mcid_doc_map, 0); } } Console.WriteLine(); Console.WriteLine("Done 3."); } doc.Save(output_path + "bookmark.pdf", 0); } } catch (PDFNetException e) { Console.WriteLine(e.Message); } }