How to read an image from the appearance stream of a stamp annotation?

154 views
Skip to first unread message

Support

unread,
Jan 10, 2007, 2:06:01 PM1/10/07
to PDFTron PDFNet SDK
Q:
I am trying to get an image which is stored in the appearance stream of
a stamp annotation. Could you supply some sample code to get this
annotation please? Any general annotation code would be great too.

----

A:

You may want to take a look at 'Annot' sample project
(http://www.pdftron.com/net/samplecode.html#Annotation) for an example
of how to traverse all annotations on the page.

To extract the image used in the stamp annotation appearance stream you
could use the following C# pseudo-code:

// The images in stamp annotations are stored separately as part of
// annotation objects (which are drawn in a separate layer on top of
page content).
// You can extract the annotation appearances by iterating through page
annotations
// as follows:
Page page = itr.Current();
int num_annots = page.GetNumAnnots();
ElementReader reader = ElementReader();
for (int i=0; i<num_annots; ++i) {
Annot annot = page.GetAnnot(i);
Console.WriteLine("Annot Type: {0:s}",
annot.GetSDFObj().Get("Subtype").Value().GetName());
Rect bbox = annot.GetRect();
Console.WriteLine(" Position: {0:f}, {1:f}, {2:f}, {3:f}", bbox.x1,
bbox.y1, bbox.x2, bbox.y2);
if (annot.GetType() == Annot.Type.e_Stamp)
{
Obj app_stm = annot.GetAppearance();
// then you can use Element reader to read annotation
appearance.
if (app_stm != null) {
reader.Begin(app_stm);
//... You may also need to recursively process form XObjects
ProcessElement(reader); // See ElementReader sample project
for
// an example of how to use implement this function
reader.End()
}
}

Reply all
Reply to author
Forward
0 new messages