[PDFNet] How do I add a custom image RubberStamp annotation?

313 views
Skip to first unread message

Support

unread,
May 12, 2010, 1:02:19 PM5/12/10
to PDFTron PDFNet SDK

Q: How do I add a custom image RubberStamp annotation?

------------------
A: The following sample snippet was contributed by one of PDFNet
users:

public static void drawAnnot(PDFDoc doc, Page page, Rect pos, string
imgFullPath)
{
pdftron.PDF.Image img = pdftron.PDF.Image.Create(doc,
imgFullPath);
pdftron.PDF.Annots.RubberStamp stamp =
pdftron.PDF.Annots.RubberStamp.Create(doc, pos);
stamp.SetAppearance(CreateImageAppearance(doc, img));
page.AnnotPushBack(stamp);
}

static pdftron.SDF.Obj CreateImageAppearance(PDFDoc doc,
pdftron.PDF.Image img)
{
ElementBuilder builder = new ElementBuilder();
ElementWriter writer = new ElementWriter();
writer.Begin(doc);
Element element = builder.CreateImage(img, new
pdftron.Common.Matrix2D());
Rect bbox = new Rect();
element.GetBBox(bbox);
element.GetGState().SetFillOpacity(0.9);
writer.WriteElement(element);
pdftron.SDF.Obj stm = writer.End();
writer.Dispose();
builder.Dispose();

stm.PutRect("BBox", bbox.x1, bbox.y1, bbox.x2, bbox.y2);
stm.PutName("Subtype", "Form");
return stm;
}

--
You received this message because you are subscribed to the "PDFTron PDFNet SDK" group. To post to this group, send email to sup...@pdftron.com
To unsubscribe from this group, send email to pdfnet-sdk-...@googlegroups.com. For more information, please visit us at http://www.pdftron.com
Reply all
Reply to author
Forward
0 new messages