annotationManager.DeleteAnnotation() does not work

Discussions about DocuVieware integration in GdPicture.NET.
Post Reply
pete
Posts: 21
Joined: Wed Mar 25, 2015 10:11 pm

annotationManager.DeleteAnnotation() does not work

Post by pete » Mon Sep 14, 2015 4:22 pm

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();

                            }
                        }
                    }
                }
            }

pete
Posts: 21
Joined: Wed Mar 25, 2015 10:11 pm

Re: annotationManager.DeleteAnnotation() does not work

Post by pete » Thu Sep 17, 2015 3:46 pm

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);
}

User avatar
Loïc
Site Admin
Posts: 5858
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: annotationManager.DeleteAnnotation() does not work

Post by Loïc » Thu Sep 17, 2015 3:46 pm

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);
}

SMOsama
Posts: 18
Joined: Tue Aug 10, 2021 8:17 pm

Re: annotationManager.DeleteAnnotation() does not work

Post by SMOsama » Mon Jan 03, 2022 3:29 pm

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);

}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest