We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to merge annotations with the PDF on serverside?

Hi,

I have a Angular web app which loads the PDF viewer where the user adds the annotations to the PDF file and exports the annotations to a flat file.

In my usecase, at later point of time, the system should merge the original PDF file with the annotations from the exported annotations file on server side without loading the PDF and annotations file again on front-end.

We use Angular as front-end and Asp.net core 6.0 as back-end. 

Please suggest.

Thanks



10 Replies 1 reply marked as answer

CK Chinnamunia Karthik Chinna Thambi Syncfusion Team November 21, 2022 02:37 PM UTC

You can use the download option in the PDF Viewer to merge the PDF file with the imported annotations. We have shared the documentation link for your reference.


Documentation: https://ej2.syncfusion.com/angular/documentation/pdfviewer/download/


Screenshot:




Kindly let us know if this helps your requirement.




SR Sriraman November 22, 2022 02:28 AM UTC

I know there is a download button in the UI to download the PDF with annotations. As per my requirement, I need to accomplish this task via server side where user does not require any interaction. As mentioned in my original post, I would like to merge the annotations with the PDF on serverside (on .net core web api itself).

Let me know.

Thanks



SK Sinthiya Kalimuthu Syncfusion Team November 22, 2022 01:43 PM UTC

You can merge the annotation while loading the document. We have shared the sample for your reference. Refer to it and revert to us if you have any concerns about it.


Sample - https://stackblitz.com/edit/angular-p2ejpy-wnt2df?file=app.component.ts,angular.json


Web Service - https://www.syncfusion.com/downloads/support/directtrac/general/7z/Web_Service983755123.7z


Code snippet :




Steps to run the above mentioned sample:


• Run the web services

• Copy the URL produced by the web service project

• In the stack blitz sample, paste the URL in the service URL field.

• Now run the stack blitz and test the reported issue



Regards,

Sinthiya K




SR Sriraman replied to Sinthiya Kalimuthu November 24, 2022 04:33 PM UTC

Hi Sinthiya,

Thanks for your reply. As mentioned in my original post, in my use case, I need to generate the PDF embedded with annotations via backend (no front-end UI involved while generating the pdf).



IJ Irfana Jaffer Sadhik Syncfusion Team November 25, 2022 10:22 AM UTC

We have attached a sample to add annotations to the pdf document without involving any UI. Please try this on your end and let us know the result.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/NetCoreSample-829543986


Follow the below links for more information,

https://help.syncfusion.com/file-formats/pdf/working-with-annotations

https://www.syncfusion.com/document-processing/pdf-framework/net/pdf-library/pdf-annotation

If this does not satisfy your requirement, we request you to share more details on this. so that we can assist further in this.




SR Sriraman November 25, 2022 11:58 AM UTC

My usecase is like this:

  1. I have a dashboard in my UI where the job details are displayed.
  2. User1 clicks a button which opens a page with PDF viewer.
  3. User1 adds annotation to that PDF file using PDF viewer as needed.
  4. User1 clicks the save button in our UI which saves the annotation as xfdf file in the backend.
  5. User2 again visit that job details page and clicks a button which opens a page with PDF viewer.
  6. Now the PDF file is loaded with annotations (created by user 1)
  7. User 2 reviews the annotations added by user 1 and approves the changes or adds additional annotation.
  8. backend time triggered job is getting executed once an hour should send a PDF with embedded annotations via email to certain users.
I am looking for solution for the last point where no user is involved. No UI is accessed. It has access to PDF file and xfdf file. It should embed the annotations with the PDF and send it via email to certain users.

Let me know in case of any queries.


IJ Irfana Jaffer Sadhik Syncfusion Team November 28, 2022 01:32 PM UTC

On further analyzing your requirement we can able to know that your requirement is to import annotations to the pdf document, save it and add any additional annotations if needed to the existing pdf document and wants to send the resultant pdf to the email.

We have created and attached a sample to import annotations to the PDF document and to share the resultant PDF to the mail without any UI involved. Please try this on your end and let us know whether it satisfies your requirement or not.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/NetCoreSample-153425936

Please follow the below links for more information,

https://www.syncfusion.com/kb/13085/how-to-generate-and-send-a-pdf-document-as-attachment-in-an-email-using-net-core-c

https://help.syncfusion.com/file-formats/pdf/working-with-annotations

https://help.syncfusion.com/file-formats/pdf/working-with-annotations?cs-save-lang=1&cs-lang=csharp#importing-annotations-from-xfdf-file





Marked as answer

SR Sriraman January 10, 2023 09:09 AM UTC

That is what I am looking for. This is what my final piece of code (.net 6).

using Syncfusion.Pdf.Parsing;

string documentPath =Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"input.pdf");
string xfdfPath =Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"input.xfdf");
string outFile =Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"out.pdf");
File.Delete(outFile);
using MemoryStream pdfStream =new(File.ReadAllBytes(documentPath));
using PdfLoadedDocument loadedDocument =new(pdfStream);
using MemoryStream xfdfStream =new(File.ReadAllBytes(xfdfPath));
loadedDocument.ImportAnnotations(xfdfStream,AnnotationDataFormat.XFdf);
MemoryStream loadedPdfStream =new();
loadedDocument.Save(loadedPdfStream);
loadedDocument.Close(true);
File.WriteAllBytes(outFile, loadedPdfStream.ToArray());

Thank you :)



FE Fernando February 21, 2023 03:53 PM UTC

Hi,

I'm trying this code to merge server side the annotation in json format and export one page as image but the image exported hasn't the annotations.

I tried with xfdf format and it works only if i use FlattenAnnotation.

How can i use the json format?


JSONAnnotations is the json exported from frontend with

pdfViewer.exportAnnotationsAsObject();


                PdfRenderer pdfExportImage = new PdfRenderer();

                //Loads the PDF document

                MemoryStream msPdf = new MemoryStream();

                //Read file from storage to stream

                _fileManager.StreamFromFile(pathFile, msPdf);


                PdfLoadedDocument loadedDocument = new(msPdf);

                byte[] bytes = Encoding.Unicode.GetBytes(JSONAnnotations);


                MemoryStream xfdfStream = new(bytes);


                xfdfStream.Seek(0, SeekOrigin.Begin);

                loadedDocument.ImportAnnotations(xfdfStream, AnnotationDataFormat.Json);

                MemoryStream loadedPdfStream = new();

                loadedDocument.FlattenAnnotations();

                loadedDocument.Save(loadedPdfStream);


                loadedDocument.Close(true);

                pdfExportImage.Load(loadedPdfStream);

                SKBitmap skiabitmapimage = pdfExportImage.ExportAsImage(1, false);

                Bitmap murkupImage = skiabitmapimage.ToBitmap();

                murkupImage.Save("D:\\Test.jpeg", ImageFormat.Jpeg);


Thanks



SN Santhiya Narayanan Syncfusion Team February 22, 2023 03:06 PM UTC

The JSON structures of the PDF Viewer and the PDF library are different. We have logged this as a feature request “JSON export/import structure modification based on PDF library”. We will implement this feature in our upcoming 2023, Volume 1 release, and it will be expected to be rolled out on the end of March 2023 (tentatively). You can track the status using the below feedback link.


Feedback link:  JSON export/import structure modification based on PDF library | Feature Feedback


Loader.
Live Chat Icon For mobile
Up arrow icon