Page 1 of 1

annotationManager.DeleteAnnotation() does not work

Posted: Mon Sep 14, 2015 4:22 pm
by pete
Hi, I have come across very strange behavior. I have set up my DocuVieware 11 in ASP.MVC 5, Visual Studio 2013.

I have created custom action "TestRemoveAnnotationsFromPage" - which is basically a code example from tutorials, but the only thing it does is to iterate through annotations on a current page, deletes all annotations, saves it and redraws the page. What happens however is, that method "DeleteAnnotation" does not work correctly for me, even though methong "GetAnnotationCount" gets correct number of annotations on page. For ex.: When I create one annotation on the page, it will get count of 1, but it never gets deleted it. When I add another annotation, it deletes the first one, but never the second one, even though the count was 2 this time and so on...

Is there anything I am doing wrong?

My Custom action is:

Code: Select all

            if (e.actionName == "TestRemoveAnnotationsFromPage")
            {

                if (DocuVieware1.GetDocumentType() == GdPicture11.DocumentType.DocumentTypePDF)
                {
                    GdPicture11.GdPicturePDF gdPicturePDF;
                    //Getting native PDF
                    if (DocuVieware1.GetNativePDF(out gdPicturePDF) == GdPicture11.GdPictureStatus.OK)
                    {
                        //Using an AnnotationManager object to parse PDF annotations
                        using (GdPicture11.AnnotationManager annotationManager = new GdPicture11.AnnotationManager())
                        {
                            if (annotationManager.InitFromGdPicturePDF(gdPicturePDF) == GdPicture11.GdPictureStatus.OK)
                            {

                                int annotationCount = annotationManager.GetAnnotationCount();
                                //Iterating through all annotation
                                for (int i = 0; i < annotationCount; i++)
                                {

                                    annotationManager.DeleteAnnotation(i);
                                }


                                annotationManager.SaveAnnotationsToPage();
                                annotationManager.Close();

                                DocuVieware1.RedrawPage();

                            }
                        }
                    }
                }
            }

Re: annotationManager.DeleteAnnotation() does not work

Posted: Thu Sep 17, 2015 3:46 pm
by pete
After communication with GdPicture team, download the lastest version and use this code:

Code: Select all

for (int i = annotationCount -1; i >=0; --)
{
annotationManager.DeleteAnnotation(i);
}
instead of the original:

Code: Select all

for (int i = 0; i < annotationCount; i++)
{
annotationManager.DeleteAnnotation(i);
}

Re: annotationManager.DeleteAnnotation() does not work

Posted: Thu Sep 17, 2015 3:46 pm
by Loïc
Hello,

This is an algorithmic problem. Just replace:

Code: Select all

 for (int i = 0; i < annotationCount; i++)
                                {

                                    annotationManager.DeleteAnnotation(i);
                                }
by:

Code: Select all

for (int i = 0; i < annotationCount; i++)
{
      annotationManager.DeleteAnnotation(annotationCount - i - 1);
}

Re: annotationManager.DeleteAnnotation() does not work

Posted: Mon Jan 03, 2022 3:29 pm
by SMOsama
Hi,

These two solutions are not working for me. Even after annotationManager.DeleteAnnotation I am checking the status using GetStat() and it is returning Ok. But annotations are not deleted.

var vwr = new GdViewer();
vwr.DisplayFromFile(copyFileName);

using (AnnotationManager oAnnotationManager = new AnnotationManager())
{
oAnnotationManager.InitFromGdViewer(vwr);
for (int i = 1; i <= vwr.PageCount; i++)
{
GdPictureStatus annotationResult = oAnnotationManager.SelectPage(i);
if (annotationResult == GdPictureStatus.OK)
{
int annotCount = oAnnotationManager.GetAnnotationCount();
for (int j = 0; j < annotCount; j++)
{
oAnnotationManager.DeleteAnnotation(annotCount - j - 1);
}
}
}
oAnnotationManager.SaveAnnotationsToPage();
oAnnotationManager.SelectPage(1);

}