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