GdViewer.DeleteAnnotation not working

Discussions about annotation support.
Post Reply
gspiljar
Posts: 7
Joined: Mon Apr 28, 2014 9:51 am

GdViewer.DeleteAnnotation not working

Post by gspiljar » Wed Apr 30, 2014 1:17 pm

Hi, I'm the code above to "convert" GdPicture annotation to "PDF" annotation, and everything works fine but deleting interactive annotation from gdViewer.

Why interactive annotation remains after executing this code?

Code: Select all

void m_GdViewer_AnnotationEndEditingText(int AnnotationIdx)
        {
            string path = m_GdViewer.GetLastPath();

            GdPictureStatus status = new GdPictureStatus();
            GdPicturePDF pdf = new GdPicturePDF();
            AnnotationManager manager = new AnnotationManager();

            pdf.LoadFromFile(path, false);
            pdf.SelectPage(m_GdViewer.CurrentPage);
            pdf.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
            manager.InitFromGdPicturePDF(pdf);

            GdPicture10.Annotations.Annotation a = m_GdViewer.GetAnnotationFromIdx(AnnotationIdx);

            pdf.AddStickyNoteAnnotation(PdfStickyNoteAnnotationIcon.PdfAnnotationIconNote, a.Left, a.Top, a.Author, a.Subject, ((GdPicture10.Annotations.AnnotationStickyNote)(a)).Text, ((GdPicture10.Annotations.AnnotationStickyNote)(a)).Opacity, false, 255, 255, 0, 5, 5, 6, 6);

            string tempPath = Path.Combine(Consts.TempFolderPath, Path.GetFileName(path));

            status = pdf.SaveToFile(tempPath);
            if (status != GdPictureStatus.OK)
                throw new Exception("Saving file failed. Error details: Status=" + status);

            m_GdViewer.DeleteAnnotation(AnnotationIdx);

            manager.Close();
            pdf.CloseDocument();
            m_GdViewer.CloseDocument(false);
                      
            status = m_GdViewer.DisplayFromFile(tempPath);
            if (status != GdPictureStatus.OK)
                throw new Exception("Displaying document failed. Error details: Status=" + status.ToString());

            m_GdViewer.ReloadAnnotations();
            m_GdViewer.Redraw();
            AnnotationEditingEnded();
        }

SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: GdViewer.DeleteAnnotation not working

Post by SamiKharma » Mon May 05, 2014 1:37 pm

Hi,

Please use the gdViewer.GetStat() method after you call the DeleteAnnotation method to see if the function failed and why.

Best,
Sami

gspiljar
Posts: 7
Joined: Mon Apr 28, 2014 9:51 am

Re: GdViewer.DeleteAnnotation not working

Post by gspiljar » Mon May 05, 2014 2:25 pm

Hi Sami,

I get "OK" status but interactive annotation is still there.

SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: GdViewer.DeleteAnnotation not working

Post by SamiKharma » Mon May 05, 2014 8:46 pm

Hi,

I tried reproducing the problem but was unable to. Could you please attach a standalone application that reproduces the problem and the problem only.

Best,
Sami

gspiljar
Posts: 7
Joined: Mon Apr 28, 2014 9:51 am

Re: GdViewer.DeleteAnnotation not working

Post by gspiljar » Tue May 06, 2014 10:50 am


SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: GdViewer.DeleteAnnotation not working

Post by SamiKharma » Tue May 06, 2014 12:33 pm

Hi,

There are many problems with the code. I have removed a lot from it in order to get it to work. In any case, the DeleteAnnotation works fine.
The main idea you have to see is that you have one function doing too any things - GdViewer1_AnnotationEndEditingText:
1. Reading paths
2. loads a pdf
3. copies the annotation to the pdf
4. deletes the current annotation

which is all fine,

but then you close the document anyways and load a new document.

All the above can work, and it does work using the latest V10 once you debug the code and get it to work through and through including the deletion of the annotation. But again the event handling is doing too many things (i suggest you segment into different functions) so you can better trace your error, because it is not in the DeleteAnnotation function.

Best,
Sami

gspiljar
Posts: 7
Joined: Mon Apr 28, 2014 9:51 am

Re: GdViewer.DeleteAnnotation not working

Post by gspiljar » Thu May 08, 2014 9:31 am

Hi Sami,
thank you for the code review..I'll definitely refactor my code for the production version.
I tested my code furthermore but I still have problems when trying to delete interactive annotation.

I'll try to explain my case with more details.
In my implementation of gdpicture I want to enable users to create and edit sticky notes using interactive annotations, but I also want to enable them to read/edit annotations trough other PDF readers like Adobe,Foxit or something else.
So my workflow goes like this:
1. Create interactive annotation on gdviewer

Code: Select all

 m_GdViewer.AddStickyNoteAnnotationInteractive("New annotation", Color.Black, "Arial", System.Drawing.FontStyle.Regular, 20, 1, 0);
2. When user actually create annotation and is done editing (AnnoatationEndEditingText event)
I create new annotation on gdpicturepdf object and initialize it with data picked from interactive annotation.
After that I delete interactive annotation and I save gdpicturepdf to file on disk, after saving I want to refresh gdviewer accordingly.

Code: Select all

 string path = m_GdViewer.GetLastPath();
            GdPictureStatus status = new GdPictureStatus();

            m_GdViewer.ForceTemporaryModeForPDF = true;

            GdPicturePDF pdf = new GdPicturePDF();
            AnnotationManager manager = new AnnotationManager();
            status = pdf.LoadFromFile(path, true);
            status = pdf.SelectPage(m_GdViewer.CurrentPage);
            pdf.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
            status = manager.InitFromGdPicturePDF(pdf);

            GdPicture10.Annotations.Annotation a = m_GdViewer.GetAnnotationFromIdx(AnnotationIdx);

            pdf.AddStickyNoteAnnotation(PdfStickyNoteAnnotationIcon.PdfAnnotationIconNote, a.Left, a.Top, a.Author,
                a.Subject, ((GdPicture10.Annotations.AnnotationStickyNote)(a)).Text,
                ((GdPicture10.Annotations.AnnotationStickyNote)(a)).Opacity, false, 255, 255, 0, 5, 5, 6, 6);

            m_GdViewer.CloseDocument();

            status = pdf.SaveToFile(path);
            if (status != GdPictureStatus.OK)
                throw new Exception("Saving file failed. Error details: Status=" + status);

            m_GdViewer.DeleteAnnotation(AnnotationIdx);
                status = m_GdViewer.GetStat();

            manager.Close();

            m_GdViewer.DisplayFromGdPicturePDF(pdf);
            m_GdViewer.Refresh();
Creating works great, I'm able to get exactly what I want.
But I have problem with editing.

Editing:
1. I delete gdpicturepdf annotation, and I create new interactive annotation initialized with date from gdpicturepdf annotation.

Code: Select all

            DeleteAnnotation(annotation);

            m_GdViewer.ForceTemporaryModeForPDF = true;
            m_GdViewer.CloseDocument();

            string path = m_GdViewer.GetLastPath();

            GdPictureStatus status = new GdPictureStatus();

            GdPicture10.AnnotationManager annotationManager = new AnnotationManager();
            GdPicturePDF pdf = new GdPicturePDF();
            pdf.LoadFromFile(path, true);
            pdf.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);

            status = pdf.SelectPage(annotation.Page);
            if (status != GdPictureStatus.OK)
                throw new Exception("Page selection failed. Error details: Status=" + status);

            status = annotationManager.InitFromGdPicturePDF(pdf);

            GdPicture10.Annotations.AnnotationStickyNote a = annotationManager.AddStickyNoteAnnot(1, 1, 3, 4, annotation.Text);
            a.Author = annotation.Author;
            a.Subject = annotation.Subject;
            a.FontSize = 20;
            a.Opacity = 1;
            annotationManager.SaveAnnotationsToPage();

            string tempPath = Path.Combine(Consts.TempFolderPath, document.OriginalFileName);

            status = pdf.SaveToFile(path);
            if (status != GdPictureStatus.OK)
                throw new Exception("Saving file failed. Error details: Status=" + status);

            pdf.CloseDocument();
            annotationManager.Close();

            status = m_GdViewer.DisplayFromFile(path);
            if (status != GdPictureStatus.OK)
                throw new Exception("Displaying document failed. Error details: Status=" + status.ToString());
2. When editing is done I do the same thing like when I'm creating but interactive annotation remains - that's the problem where I need your help.

kind regards,
Goran Spiljar

SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: GdViewer.DeleteAnnotation not working

Post by SamiKharma » Sun May 11, 2014 12:55 pm

Hi,

I understood what you were trying to do with the application, that being said, I could delete the annotation in your own application, thus I could not reproduce the problem.
Here is what I suggest:
1. Make sure you are using the latest version.
2. If the problem persists, try to isolate the problem, meaning, try to get rid of all the code that is not related to the deletion of the annotation. Which means in your application when the user exists editing mode, you delete the annotation, nothing else.
3. once you have accomplished 2, you can start to add features one by one and checking the return state for each.

I hope this helps.
Best,
Sami

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest