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
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.
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
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
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).
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.
My usecase is like this:
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://help.syncfusion.com/file-formats/pdf/working-with-annotations
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 :)
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
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