Changes to Annotations Not Showing

I have a WinForms project that uses an ElementHost to host a WPF PdfViewer control.

Using this method, I can open and display PDFs and add annotations easily using the WPF version of PDFViewer.

I'm looking to wire up a button on my form that will either show or hide all of the annotations in the loaded document.  (There are only rectangle type annotations used.)  However, when I try to iterate through the Annotations collection I have two issues:
  1. If I try to iterate through the Annotations collection, I find that it is empty.  Upon closer inspection, it appears as if there are two annotations collections.
     Here is what I have done:
     Load a pdf from a file into the viewer.

          private void TsbEditOpen_Click(object sender, EventArgs e)
        {
            ofd = new OpenFileDialog();
            ofd.Filter = "PDF Files (*.pdf)|*.pdf|TIF Files (*.tif, *.tiff)|*.tif;*.tiff";
            ofd.Multiselect = false;
            ofd.ShowDialog();

            if (ofd.FileName == "") return;
            
            wpfPdf.pdfViewer.Load(ofd.FileName);            
        }

          Enter Rectangle annotation mode and add several annotations manually:
                
                wpfPdf.pdfViewer.AnnotationMode = Syncfusion.Windows.PdfViewer.PdfDocumentView.PdfViewerAnnotationMode.Rectangle;
               
          Exit annotation mode:

               wpfPdf.pdfViewer.AnnotationMode = Syncfusion.Windows.PdfViewer.PdfDocumentView.PdfViewerAnnotationMode.None;

          Try to iterate through the annotations collection:

               foreach (PdfLoadedPage pg in wpfPdf.pdfViewer.LoadedDocument.Pages)
                    {                        
                        PdfLoadedAnnotationCollection pdfAnnotation = pg.Annotations;
                        foreach (Syncfusion.Pdf.Interactive.PdfLoadedAnnotation annotation in pdfAnnotation)
                        {
                            annotation.Opacity = 0f;
                        }                        
                    }          

          However, the pdfAnnotation collection is always empty.  But if I drill down into the details of the PdfLoadedPage pg, I can see there there are two separate annotation collections.  One is empty (Annotations) and the other (Annotations (Syncfusion.Pdf.PdfPageBase)) contains my annotations.  How can I access this second annotation collection?     
               

               2. Secondly, if I save the Loaded Document to a stream and then reload the stream into the viewer, then both annotations collections contain my annotations.  However, when I iterate through them all and change their opacity to 0, I am only changing the Annotations collection (not the Annotation (Syncfusion.Pdf.PdfPageBase) collection) and the document in the viewer does not change.  

Thank for for any help that you can provide!

-Greg

8 Replies 1 reply marked as answer

US Uthandaraja Selva Sundara Kani Syncfusion Team July 3, 2020 02:59 PM UTC

Hi Greg, 
 
Thanks for contacting Syncfusion support. 

We are able to reproduce the reported behaviour in our side with the provided details. We have forwarded this to our development team for further analysis and we will update further details on July 7th, 2020.
 
 
Regards, 
Uthandaraja S 



US Uthandaraja Selva Sundara Kani Syncfusion Team July 7, 2020 02:59 PM UTC

Hi Greg, 
 
We appreciate your patience. 
 
On analyzed further, The PdfViewerControl LoadedDocument property is used only for getting the details of the annotations, form fields, layers etc and the changes done in the PdfViewerControl LoadedDocument property does not reflect to the PdfViewerControl until we save and reload the PDF document to the PdfViewerControl. So, we need to save and reload the PDF document to PdfViewerControl in sample level in order to achieve your requirement of hide and show the rectangle annotation in UI. Please find the code snippet below, 
 
 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
            PdfLoadedDocument copiedDoc = pdfViewer.LoadedDocument; 
 
            for (int pageIndex = 0;pageIndex < copiedDoc.Pages.Count;pageIndex++) 
            { 
                for(int i=0;i< copiedDoc.Pages[pageIndex].Annotations.Count;i++) 
                { 
                    // Get the rectangle or square annotation from the PdfViewer. 
                    Syncfusion.Pdf.Interactive.PdfSquareAnnotation annotation = copiedDoc.Pages[pageIndex].Annotations[i] as Syncfusion.Pdf.Interactive.PdfSquareAnnotation; 
                    if (annotation != null) 
                        annotation.Opacity = 0F; 
                } 
            } 
            MemoryStream stream = new MemoryStream(); 
 
            // Save the changes in a stream. 
            copiedDoc.Save(stream); 
 
            stream.Position = 0; 
 
            // Reload the PDF document. 
            pdfViewer.Load(stream); 
} 
 
 
private void Button_Click_1(object sender, RoutedEventArgs e) 
{ 
            PdfLoadedDocument copiedDoc = pdfViewer.LoadedDocument; 
 
            for (int pageIndex = 0; pageIndex < copiedDoc.Pages.Count; pageIndex++) 
            { 
                for (int i = 0; i < copiedDoc.Pages[pageIndex].Annotations.Count; i++) 
                { 
                    // Get the rectangle or square annotation from the PdfViewer. 
                    Syncfusion.Pdf.Interactive.PdfSquareAnnotation annotation = copiedDoc.Pages[pageIndex].Annotations[i] as Syncfusion.Pdf.Interactive.PdfSquareAnnotation; 
                    if (annotation != null) 
                        annotation.Opacity = 1F; 
                } 
            } 
            MemoryStream stream = new MemoryStream(); 
 
            // Save the changes in a stream. 
            copiedDoc.Save(stream); 
 
            stream.Position = 0; 
 
            // Reload the PDF document. 
            pdfViewer.Load(stream); 
} 
 
 
We have created the sample for the same and it can be downloaded from below link, 
 
 
Please let us know if you need further assistance. 
 
Regards, 
Uthandaraja S 



PN Preethi Nesakkan Gnanadurai Syncfusion Team September 8, 2020 04:22 AM UTC

From: Greg Saladino Sent: Friday, September 4, 2020 4:06 PM
To: Syncfusion Support <[email protected]>
Subject: RE: Syncfusion support community forum 155706, Changes to Annotations Not Showing, has been updated. 


Thank you very much for the clear response.  I have implemented your code and it works. 

However, I have noticed the following behavior; I am using filled rectangle annotations.  When I set the annotation.Opacity = 0, both the annotation.Color.a gets set to 0 and the annotation.InnerColor.a is set to 0.  However, when I set the opacity = 1, only the annotation.Color.a get set to 255 – the annotation.InnerColor.a remains at 0.  And I cannot find a way to set the InnerColor.a value without setting the InnerColor to a new color. 

Is this by design?  And if so, is there a way to just set the InnerColor.a back to 255 so that I don’t lose the color that was originally stored there? 

Thanks,  

Greg 



VS Vikas Sekar Syncfusion Team September 8, 2020 10:03 AM UTC

Hi Greg,  
  
Thanks for contacting Syncfusion support.  
 
We are able to reproduce the reported behavior in our side with the provided details. We have forwarded this to our development team for further analysis and we will update further details on September 10th, 2020.  
  
Regards,  
Vikas S 



GS Greg Saladino September 15, 2020 02:53 PM UTC

I'm glad to hear that this error is reproducible on your end.  Is this something that will be patched in the next update?  Thanks.


DG Deepak Gunasekaran Syncfusion Team September 16, 2020 05:27 PM UTC

Hi Greg, 
 
Sorry for the delay. We confirm this as a defect, and we have logged defect report for the same. The patch for this fix is expected to be available on 7th October 2020. 
 
Regards, 
Deepak G 



PN Preethi Nesakkan Gnanadurai Syncfusion Team September 17, 2020 04:36 AM UTC

From: Greg Saladino 
Sent: Wednesday, September 16, 2020 3:04 PM
To: Syncfusion Support <[email protected]>
Subject: RE: Syncfusion support community forum 155706, Changes to Annotations Not Showing, has been updated. 


Thank you very much for your excellent customer service!! 

Regards, 

Greg 



VS Vikas Sekar Syncfusion Team October 7, 2020 02:24 PM UTC

Hi Greg,  
 
We appreciate your patience.   
 
The issue "Setting the opacity the fill color was not visible” has been fixed and the patch for this fix can be downloaded from the following location  
 
Recommended approach - exe will perform automatic configuration  
 
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment  
 
 
Assembly Version: 17.2.0.34  
 
Installation Directions :  
This patch should replace the files “Syncfusion.Pdf.Base.dll, Syncfusion.PdfViewer.WPF.dll” under the following folder.  
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.6  
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\9.3.0.61\precompiledassemblies\9.3.0.61\4.0   
To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.   
 
Note :  
You can change how you receive bug fixes by navigating to the following link and updating your preferences.   
   
Disclaimer :  
Please note that we have created this patch for version 17.2.0.34 specifically to resolve the following issue(s) reported in this/the Forum. 155706   
If you have received other patches for the same version for other products, please apply all patches in the order received.  
 
This fix will be included in our 2020 Volume 3 SP-1 release which will be available in November 2020.   
 
Regards, 
Vikas 


Marked as answer
Loader.
Up arrow icon