Implementing interactive annotation editing features

Q: I am trying to implement some of the editing features using PDFNet
V4.

I am adding Highlight and Square annotations and this seems to be
successful, but when I try to delete these annotations the appearance
is still in the document, though the annotation is successfully
deleted.

I have checked the forums and am calling
annot.GetSDFObj().Erase(“AP”); before pg.AnnotRemove(annot);

My code seems to work correctly with annotations added in Acrobat so
perhaps I am missing something when adding my annotations? Again I am
trying to follow the sample code and forum examples.

Any help would be appreciated.

Highlight annotations functions as follows;

// C++ sample

Obj MyPDFView::CreateHighlightAppearance(Rect bbox, ColorPt
higlight_color) {
PDFDoc& doc = GetDoc();

// Create a Highlight appearance stream

ElementBuilder build;
ElementWriter writer;
writer.Begin( doc.GetPage( GetCurrentPage() ));

// Draw background
Element element = build.CreateRect(bbox.x1, bbox.y1, bbox.x2 -
bbox.x1, bbox.y2 - bbox.y1);
element.SetPathFill(true);
element.SetPathStroke(false);
GState gs = element.GetGState();

gs.SetFillColorSpace(ColorSpace::CreateDeviceRGB());
gs.SetFillColor(higlight_color);
gs.SetBlendMode(GState::e_bl_multiply);

writer.WriteElement(element);
Obj stm = writer.End();

// Set the bounding box
stm.PutRect(“BBox”, bbox.x1, bbox.y1, bbox.x2, bbox.y2);
stm.PutName(“Subtype”, “Highlight”);

return stm;
}

// Create Highlight Annotation.
Annot MyPDFView::CreateHighlightAnnot(Rect bbox, ColorPt
highlight_color)
{
PDFDoc& doc= GetDoc();
Annot a = Annot::Create(doc.GetSDFDoc(), Annot::e_Highlight,
Rect(bbox.x1,bbox.y1,bbox.x2,bbox.y2));
Obj app_stream;

a.SetColor( highlight_color );
app_stream = CreateHighlightAppearance(bbox, highlight_color);
a.SetAppearance( app_stream, Annot::AnnotationState::e_normal,
“Normal”);

Obj quads = doc.CreateIndirectArray();

a.GetSDFObj().Put(“QuadPoints”, quads);
quads.PushBackNumber(bbox.x1);
quads.PushBackNumber(bbox.y2);
quads.PushBackNumber(bbox.x2);
quads.PushBackNumber(bbox.y2);
quads.PushBackNumber(bbox.x1);
quads.PushBackNumber(bbox.y1);
quads.PushBackNumber(bbox.x2);
quads.PushBackNumber(bbox.y1);

Page pg = doc.GetPage(_cur_page);
pg.AnnotPushBack(a);

return a;
}


A: Calling AnnotRemove should be enough to remove the annotation
(including its appearance) from the page. In case you are implementing
interactive tool you may want to call PDFView.Update() method to
refresh the view so that the annotation is not drawn. Also you may
want to lock the document (doc.Lock()/doc.Unlock()) whenever you are
accessing the document for read or write operations (this is necessary
to prevent a collision with the rendering thread).