Re-rendering a changing Document Using PdfDocumentView

Hello,

I am building an application which allows the user to edit pdf atributes and then view those changes in a PdfDocumentView object.
Each time a user changes a PDF element, the document is reloaded and there are a few seconds of latency. I do this using the following code:
     PdfView.Unload(false);
     PdfView.Load(DocLoaderViewer.Document);
Is there a way I can edit the pdf document and have the PdfDocumentView display the changes made without a full reload of the PDF Document?

Best,
David

3 Replies

PE Priyanga Elangovan Syncfusion Team June 14, 2018 12:37 PM UTC

Hi David,

Thank you for contacting Syncfusion support.

We do support adding shape annotation, ink annotation and text mark-up annotation to the loaded PDF document and it does not require to reload the PDF document in the PdfDocumentView or PdfViewerControl to display the annotations. Please refer the below UG documentation link to add the annotations to the loaded PDF document.

https://help.syncfusion.com/wpf/pdfviewer/working-with-annotations

Regarding “Is there a way I can edit the pdf document”:
Can you please let us know what kind of edit operation you need to perform over the PDF document? So that we can proceed further and provide you the proper solution at the earliest.

Regards,
Priyanga.E
 



DM David Meskin June 14, 2018 02:21 PM UTC

Whenever I run the following codeblock:
                           PdfLoadedDocument doc = DocLoaderViewer.Document;
            PdfView.InkAnnotationSettings.Thickness = 5;
            PdfView.InkAnnotationSettings.InkColor = Colors.Purple;
            PdfView.AnnotationMode = PdfDocumentView.PdfViewerAnnotationMode.Rectangle;
            RectangleF rect = new RectangleF(0f, 0f, 100f, 100f);
            PdfRectangleAnnotation annotate = new PdfRectangleAnnotation(rect, "Test");
            doc.Pages[0].Annotations.Add(annotate);
I get the following error:
                              'Unable to cast object of type 'Syncfusion.Pdf.Interactive.PdfRectangleAnnotation' to type                                   'Syncfusion.Pdf.Interactive.PdfLoadedAnnotation'.'


PE Priyanga Elangovan Syncfusion Team June 20, 2018 12:07 PM UTC

Hi David,

We are able to reproduce the issue “Type casting error is thrown while directly loading the annotation added document in PdfDocumentView”. On analyzing the provided code snippet, you have directly loaded the PDF document once after adding the annotation. The modified PdfLoadedDocument object has to be saved before loading in the PDF viewer control and it is the behavior. Kindly use the below modified code snippet to resolve this issue.
 
PdfLoadedDocument doc = new PdfLoadedDocument(@"Input.pdf"); 
RectangleF rect = new RectangleF(0f, 0f, 101f, 100f); 
PdfRectangleAnnotation annotate = new PdfRectangleAnnotation(rect, "test"); 
annotate.Opacity = 1; 
annotate.Color = new Syncfusion.Pdf.Graphics.PdfColor(System.Drawing.Color.Black); 
doc.Pages[0].Annotations.Add(annotate); 
MemoryStream stream = new MemoryStream(); 
doc.Save(stream); 
doc.Close(); 
doc.Dispose(); 
PdfView.Load(stream); 

Please let us know if this helps. 
Regards,
Priyanga.E
 


Loader.
Up arrow icon