Change appearance of an Annotation

619 views
Skip to first unread message

Hector Kikuchi Martins

unread,
Aug 21, 2014, 5:22:39 PM8/21/14
to pdfne...@googlegroups.com
Hi, I'm trying put a custom icon on a pdftron.PDF.Annots.Text, but I had no success. Researching on group I've found some suggestions using the property setAppearance, but apparently the component doesn't use the image I passed and loads a default icon. The image I'm trying to load is a png stored in android drawable resources. Follow the code I used in my tests:

ElementBuilder build = new ElementBuilder();
ElementWriter writer = new ElementWriter();
writer.begin(doc);
Image img = Image.create(doc, BitmapFactory.decodeResource(context.getResources(), R.drawable.my_icon));
int w = img.getImageWidth(), h = img.getImageHeight();
Element img_element = build.createImage(img, 0, 0, w, h);
writer.writePlacedElement(img_element);
Obj obj = writer.end();
pdftron.PDF.Annots.Text text = pdftron.PDF.Annots.Text.create(doc, p);
text.setAppearance(obj);
text.refreshAppearance();

Am I missing something?

Thanks in advance,

Hector Martins

Aaron

unread,
Aug 22, 2014, 4:49:45 PM8/22/14
to pdfne...@googlegroups.com
Hello Hector,

Since RefreshAppearance() overwrites the value set by SetAppearance(), you should not call it.  You also need to set the BBox of the appearance stream.  Something similar to the following should work:

ElementBuilder build = new ElementBuilder();
ElementWriter writer = new ElementWriter();
writer.Begin(doc);
Image img = Image.Create(doc,input_path + "butterfly.png");
int w = img.GetImageWidth(),h = img.GetImageHeight();
Element img_element = build.CreateImage(img,0,0,w,h);
writer.WritePlacedElement(img_element);
pdftron.PDF.Annots.Text text = pdftron.PDF.Annots.Text.Create(doc,new Rect(161, 388, 180, 406),"Hello World");
Obj appearance_stream = writer.End();
appearance_stream.PutRect("BBox",0,0,w,h);
text.SetAppearance(appearance_stream);
page.AnnotPushBack(text);




Reply all
Reply to author
Forward
0 new messages