Creating Annotations from Universal Viewer Programmatically

416 views
Skip to first unread message

Matt Parizeau

unread,
Apr 10, 2014, 8:49:35 PM4/10/14
to pdfnet-w...@googlegroups.com
Q: 

What is the best practice for programmatically creating annotations? We've got two basic types: rectangles and rectangles with text. Can you provide me with sample code to create (and display) annotations? I'm having trouble figuring it out based on the documentation. Also, I'm going to be running this javascript from the main universal page (which I believe hosts the iFrame that actually has the HTML 5 reader).

A:

You could put this code in a button click handler or something similar.
// get inner HTML5 viewer window
var innerWindow = $('iframe')[0].contentWindow;
var annotManager = innerWindow.readerControl.docViewer.GetAnnotationManager();
var Annotations = innerWindow.Annotations;

var rectangle = new Annotations.RectangleAnnotation();
rectangle
.X = 100;
rectangle
.Y = 100;
rectangle
.Width = 200;
rectangle
.Height = 50;
rectangle
.PageNumber = 1;

annotManager
.AddAnnotation(rectangle);

var freeText = new Annotations.FreeTextAnnotation();
freeText
.X = 150;
freeText
.Y = 200;
freeText
.Width = 150;
freeText
.Height = 50;
freeText
.setPadding(new Annotations.Rect(0, 0, 0, 0)); // this is a workaround for creating free text annotations, we'll improve this in the future so this line isn't required
freeText
.PageNumber = 1;
freeText
.setContents("My Text");
freeText
.FillColor = new Annotations.Color(0, 255, 255);

annotManager
.AddAnnotation(freeText);
Reply all
Reply to author
Forward
Message has been deleted
0 new messages