public static void ExportQuickReferenceAsBookmark(Annotation annotation, Document document) { KnowledgeItem quickReference = (KnowledgeItem)annotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Source; string bookmarkTitle = quickReference.CoreStatement; pdftron.PDF.Bookmark bookmark = pdftron.PDF.Bookmark.Create(document, bookmarkTitle); Quad firstQuad = annotation.Quads.FirstOrDefault(); int page = firstQuad.PageIndex; double left = firstQuad.MinX; double top = firstQuad.MaxY; Destination destination = Destination.CreateXYZ(document.GetPage(page), left, top, 0); pdftron.PDF.Bookmark foo = document.GetFirstBookmark().Find(bookmarkTitle); if (foo.IsValid() && foo.GetAction().GetDest().GetPage().GetIndex() == page) { foo.SetAction(pdftron.PDF.Action.CreateGoto(destination)); return; } document.AddRootBookmark(bookmark); bookmark.SetAction(pdftron.PDF.Action.CreateGoto(destination)); }
static void AnnotationLowLevelAPI(PDFDoc doc) { Page page = doc.GetPage(1); Obj annots = page.GetAnnots(); if (annots == null) { // If there are no annotations, create a new annotation // array for the page. annots = doc.CreateIndirectArray(); page.GetSDFObj().Put("Annots", annots); } // Create the Text annotation Obj text_annot = doc.CreateIndirectDict(); text_annot.PutName("Subtype", "Text"); text_annot.PutBool("Open", true); text_annot.PutString("Contents", "The quick brown fox ate the lazy mouse."); text_annot.PutRect("Rect", 266, 116, 430, 204); // Insert the annotation in the page annotation array annots.PushBack(text_annot); // Create a Link annotation Obj link1 = doc.CreateIndirectDict(); link1.PutName("Subtype", "Link"); Destination dest = Destination.CreateFit(doc.GetPage(2)); link1.Put("Dest", dest.GetSDFObj()); link1.PutRect("Rect", 85, 705, 503, 661); annots.PushBack(link1); // Create another Link annotation Obj link2 = doc.CreateIndirectDict(); link2.PutName("Subtype", "Link"); Destination dest2 = Destination.CreateFit(doc.GetPage(3)); link2.Put("Dest", dest2.GetSDFObj()); link2.PutRect("Rect", 85, 638, 503, 594); annots.PushBack(link2); // Note that PDFNet APi can be used to modify existing annotations. // In the following example we will modify the second link annotation // (link2) so that it points to the 10th page. We also use a different // destination page fit type. link2.Put("Dest", Destination.CreateXYZ(doc.GetPage(10), 100, 792 - 70, 10).GetSDFObj()); // Create a third link annotation with a hyperlink action (all other // annotation types can be created in a similar way) Obj link3 = doc.CreateIndirectDict(); link3.PutName("Subtype", "Link"); link3.PutRect("Rect", 85, 570, 503, 524); // Create a URI action Obj action = link3.PutDict("A"); action.PutName("S", "URI"); action.PutString("URI", "http://www.pdftron.com"); annots.PushBack(link3); }