Merge Annotations

Hi,

Is it possible to merge annotations with pdf document in pdfViewer by code ?


Thanks.


7 Replies 1 reply marked as answer

SM Selvakumar Murugan Syncfusion Team September 13, 2021 12:29 PM UTC

Hi Serreau, 
 
Thanks for contacting Syncfusion support. 
 
In our PDF Viewer, We can merge the annotations using our Import and Export annotation methods. Kindly refer the below documentation and samples for more information. 
 
 
 
Please let us know if you have any concerns about this. 
 
Regards,
Selvakumar 



FS Frederic Serreau September 27, 2021 01:38 PM UTC

Hi,

This is not exactly what I want.


I need merge pdf document and annotations for have possibility of download the pdf document with annotations in an unique pdf file.



VS Vasugi Sivajothi Syncfusion Team September 28, 2021 09:41 AM UTC

Hi Serreau, 
 
In our PDF Viewer, you can download the file with annotation using the download icon in the default toolbar or by using the Download method. Please refer to the documentation link and find the code snippet below.  
 
Code Snippet: 
 
 Viewer.DownloadAsync();  
 
Note: It will download the PDF document directly into the downloads folder.  
 
 
But there is no support to merge the PDF document using the PDF Viewer control. However, we can merge multiple PDF documents using the PDF library. For more information, please refer to the below link. 
 
Please let us know if this suits your requirement. If not, please share more details about your requirement. This will be helpful to investigate further and provide the solution at the earliest. 
 
Regards, 
Vasugi. 



FS Frederic Serreau September 28, 2021 09:50 AM UTC

Ok, I understood, but merge 2 differents pdf it's not what I need.


In my case, I would take a pdf file in database, add annotations with pdfViewer, and update the pdf file with annotations to database.


The ideal case would be a method like this :

var pdfDocWithAnnotations = Syncfusion.Pdf.PdfDocument.Merge(pdfDocument, jsonAnnotations);


(with pdfDocument is the pdf file in pdfViewer)


Thanks.



VS Vasugi Sivajothi Syncfusion Team September 29, 2021 10:00 AM UTC

Hi Frederic, 
 
Thank you for the update. You can add annotations in the PDF document using the annotation tools or programmatically import the annotations using the below code snippet. 
 
Code Snippet for Export and import Annotations: 
 
<SfButton OnClick="ImportAnnotationFromFile">ImportAnnotation1</SfButton> 
<SfButton OnClick="ExportAnnotationFile">ExportAnnotation</SfButton> 
<SfButton OnClick="ImportAnnotationJson">ImportAnnotationJson</SfButton> 
<SfButton OnClick="ExportAnnotationJson">ExportAnnotationJson</SfButton> 
 
 
@code { 
    Stream annotationData; 
     
    private void ImportAnnotationFromFile() 
    { 
        pdfviewer.ImportAnnotation("wwwroot/data/Import1.json", AnnotationDataFormat.Json); // Need to place the imported data in specified folder 
    } 
 
    private async void ExportAnnotationJson() 
    { 
        annotationData = await pdfviewer.ExportAnnotationAsStream(AnnotationDataFormat.Json); 
    } 
    private void ImportAnnotationJson() 
    { 
        pdfviewer.ImportAnnotation(annotationData, AnnotationDataFormat.Json); 
    } 
 
    private void ExportAnnotationFile() 
    { 
         pdfviewer.ExportAnnotation(); 
    }} 
 
 
 
Note: We can only import annotations on the PDF document using the exported annotations from the syncfusion PDF Viewer control. 
 
After adding annotations, you can save the PDF document with annotations using the below code snippet. We have shared the simple sample for your reference which can be downloaded from the below link. For more information, please refer to the below documentation.  
 
Code Snippet to get document with annotation as stream: 
 
byte[] data; 
data = await pdfviewer.GetDocument(); 
//PDF document file stream 
Stream stream = new MemoryStream(data); 
 
 
 
Documentation:  
 
Kindly try this and let us know if you have any concerns about this. 
 
Regards, 
Vasugi. 
 


Marked as answer

FS Frederic Serreau October 5, 2021 07:02 AM UTC

This solution is ok for me.


Thanks.



VS Vasugi Sivajothi Syncfusion Team October 6, 2021 10:58 AM UTC

Hi Frederic, 
 
Thank you for your update. We are glad to hear that your requirement is achieved. Please revert to us if you need any further assistance. 
 
Regards, 
Vasugi. 


Loader.
Up arrow icon