Support
unread,Nov 27, 2007, 8:41:57 PM11/27/07Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PDFTron PDFNet SDK
Q: We are working on creating Line Annot from pdftron library. For the
same we need to create Appearance Stream. Could you please provide us
with some sample code for
1. Setting the line color
2. To draw a line on given page in the apearance stream
-------------
A:
Like with other annotation types you can build the appearance stream
for line annotation using ElementBuilder/ElementWriter. To set the
resulting appearance use annot.SetAppearance(appearance_stream).
For example:
// Create 'line' annotation -------------------------
Obj line_annot = doc.CreateIndirectDict();
line_annot.Put("Subtype", Obj.CreateName("Line"));
line_annot.Put("Open", Obj.CreateBool(false));
line_annot.Put("Contents", Obj.CreateString("This is a Line
Annotation"));
line_annot.Put("Rect", Rect.CreateSDFRect(300, 200, 600, 700));
// Setting color
Obj annot_color = Obj.CreateArray();
line_annot.Put("C", annot_color);
annot_color.PushBack(Obj.CreateNumber(0.8));
annot_color.PushBack(Obj.CreateNumber(0.3));
annot_color. PushBack(Obj.CreateNumber(0.4));
// Setting Line Coordinates
Obj coords = Obj.CreateArray();
line_annot.Put("L", coords);
coords.PushBack(Obj.CreateNumber(300));
coords.PushBack(Obj.CreateNumber(200));
coords.PushBack(Obj.CreateNumber(600));
coords.PushBack(Obj.CreateNumber(700));
// Create appearance stream for the annotation --------
ElementWriter writer = new ElementWriter();
ElementBuilder eb = new ElementBuilder();
writer.Begin(doc);
eb.PathBegin(); // start constructing the path
eb.MoveTo(300, 200);
eb.LineTo(600, 700);
Element element = eb.PathEnd();
element.SetPathFill(false);
element.GetGState().SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
element.GetGState().SetStrokeColor(new ColorPt(1, 0, 0)); // red
writer.WriteElement(element);
Obj appearance_stream = writer.End();
// Set annotation appearance...
myannot.SetAppearance(appearance_stream);
//-----------------------------------------------------
// Append the annotation to the first page...
Page page = doc.PageBegin.Current();
Obj annots = page.GetAnnots();
annots.PushBack(line_annot);