public PSPDFAnnotation [] GetAnnotationsForPage(nuint pageIndex) { if (annotations == null) { annotations = new Dictionary <nuint, PSPDFAnnotation []> ((int)document.PageCount); } if (annotations.ContainsKey(pageIndex)) { return(annotations [pageIndex]); } // it's important that this method is: // - fast // - thread safe // - and caches annotations (don't always create new objects!) lock (this) { // create new note annotation and add it to the dict. var documentProvider = ProviderDelegate.ParentDocumentProvider; var pageInfo = documentProvider.Document.GetPageInfo(pageIndex); var noteAnnotation = new PSPDFNoteAnnotation { PageIndex = pageIndex, DocumentProvider = documentProvider, Contents = string.Format("Annotation from the custom annotationProvider for page {0}.", pageIndex + 1), // place it top left (PDF coordinate space starts from bottom left) BoundingBox = new CGRect(100, pageInfo.RotatedRect.Size.Height - 100, 32, 32), Editable = false }; annotations.Add(pageIndex, new PSPDFAnnotation [] { noteAnnotation }); } return(annotations [pageIndex]); }
public PSPDFAnnotation[] AnnotationsForPage(nuint page) { if (annotations == null) { annotations = new PSPDFAnnotation[document.PageCount].ToList(); } // it's important that this method is: // - fast // - thread safe // - and caches annotations (don't always create new objects!) lock (this) { if (annotations [(int)page] == null) { // create new note annotation and add it to the dict. var documentProvider = ProviderDelegate.ParentDocumentProvider; var pageInfo = documentProvider.Document.GetPageInfo(page); PSPDFNoteAnnotation noteAnnotation = null; InvokeOnMainThread(() => noteAnnotation = new PSPDFNoteAnnotation { Page = page, DocumentProvider = documentProvider, Contents = string.Format("Annotation from the custom annotationProvider for page {0}.", page + 1), // place it top left (PDF coordinate space starts from bottom left) BoundingBox = new CGRect(100, pageInfo.RotatedRect.Size.Height - 100, 32, 32), Editable = false }); annotations [(int)page] = noteAnnotation; } } return(new PSPDFAnnotation[] { annotations[(int)page] }); }
public AnnotationsFromCodeViewController(NSUrl document) : base(new PSPDFDocument(document)) { // Sets the Delegate to listen for 'IPSPDFViewControllerDelegate' events like 'DidSelectAnnotations'. // Any NSObject derived class can be set to 'Delegate' property as long as it implements 'IPSPDFViewControllerDelegate'. Delegate = this; Document.Title = "Programmatically create annotations"; Document.AnnotationSaveMode = PSPDFAnnotationSaveMode.Disabled; var annotationsList = new List <PSPDFAnnotation> (); uint targetPage = 0; var pageInfo = Document.GetPageInfo(targetPage); CGRect viewRect = UIScreen.MainScreen.Bounds; var maxHeight = pageInfo.Size.Height; for (int i = 0; i < 5; i++) { var note = new PSPDFNoteAnnotation { // width/height will be ignored for note annotations. BoundingBox = new CGRect(100, (50 + i * maxHeight / 5), 32, 32), Contents = string.Format("Note {0}", (5 - i)) // notes are added bottom-up }; annotationsList.Add(note); } // Ink Annotation sample var inkAnnot = new PSPDFInkAnnotation(); var linesArr = NSArray <NSValue> .FromNSObjects( NSValue.FromCGPoint(new CGPoint(480.93079f, 596.0625f)), NSValue.FromCGPoint(new CGPoint(476.8027f, 592.96881f)), NSValue.FromCGPoint(new CGPoint(468.54639f, 585.75f)), NSValue.FromCGPoint(new CGPoint(456.1619f, 574.40631f)), NSValue.FromCGPoint(new CGPoint(436.5531f, 550.6875f)), NSValue.FromCGPoint(new CGPoint(357.086f, 434.15631f)), NSValue.FromCGPoint(new CGPoint(294.1315f, 359.90631f)), NSValue.FromCGPoint(new CGPoint(226.01691f, 284.625f)), NSValue.FromCGPoint(new CGPoint(176.4789f, 222.75f)) ); var lines = new NSArray <NSValue> [] { linesArr }; inkAnnot.Lines = PSPDFInkAnnotation.ConvertViewLinesToPdfLines(lines, pageInfo, viewRect); inkAnnot.LineWidth = 5; inkAnnot.Color = UIColor.White; annotationsList.Add(inkAnnot); annotationsArr = annotationsList.ToArray(); Document.AddAnnotations(annotationsArr, options: null); }
public AnnotationsFromCodeViewController(NSData documentData) : base(new PSPDFDocument(documentData)) { Document.Title = "Programmatically create annotations"; Document.AnnotationSaveMode = PSPDFAnnotationSaveMode.Disabled; var annotationsList = new List <PSPDFAnnotation> (); var maxHeight = Document.GetPageInfo(0).RotatedRect.Size.Height; for (int i = 0; i < 5; i++) { var note = new PSPDFNoteAnnotation() { // width/height will be ignored for note annotations. BoundingBox = new CGRect(100, (50 + i * maxHeight / 5), 32, 32), Contents = string.Format("Note {0}", (5 - i)) // notes are added bottom-up }; annotationsList.Add(note); } // Ink Annotation sample var inkAnnot = new PSPDFInkAnnotation(); inkAnnot.Lines = new List <NSValue[]> () { new [] { NSValue.FromCGPoint(new CGPoint(480.93079f, 596.0625f)), NSValue.FromCGPoint(new CGPoint(476.8027f, 592.96881f)), NSValue.FromCGPoint(new CGPoint(468.54639f, 585.75f)), NSValue.FromCGPoint(new CGPoint(456.1619f, 574.40631f)), NSValue.FromCGPoint(new CGPoint(436.5531f, 550.6875f)), NSValue.FromCGPoint(new CGPoint(357.086f, 434.15631f)), NSValue.FromCGPoint(new CGPoint(294.1315f, 359.90631f)), NSValue.FromCGPoint(new CGPoint(226.01691f, 284.625f)), NSValue.FromCGPoint(new CGPoint(176.4789f, 222.75f)) } }; inkAnnot.LineWidth = 5; inkAnnot.Color = UIKit.UIColor.White; annotationsList.Add(inkAnnot); annotationsArr = annotationsList.ToArray(); Document.AddAnnotations(annotationsArr, null); }
public override PSPDFAnnotation[] AnnotationsForPage(uint page) { lock (this) { // create new note annotation and add it to the dict. PSPDFNoteAnnotation noteAnnotation = new PSPDFNoteAnnotation(); noteAnnotation.Page = page; //noteAnnotation.DocumentProvider = this.ProviderDelegate.ParentDocumentProvider; noteAnnotation.Contents = string.Format("Annotation from the custom annotationProvider for page {0}.", page + 1); // place it top left (PDF coordinate space starts from bottom left) //Console.WriteLine(this.ProviderDelegate.ParentDocumentProvider); //Console.WriteLine(this.ProviderDelegate.ParentDocumentProvider.Document); //PSPDFPageInfo pageInfo = this.ProviderDelegate.ParentDocumentProvider.Document.PageInfoForPage(page); noteAnnotation.BoundingBox = new RectangleF(100f, 500f - 100f, 32f, 32f); noteAnnotation.Editable = false; return(new PSPDFAnnotation[] { noteAnnotation }); } }