|
Code snippet:
SfPdfViewerServer pdfviewer;
public async void export()
{ await pdfviewer.ExportAnnotations(); } public async void exportxfdf() { await pdfviewer.ExportAnnotations(AnnotationDataFormat.XFdf); } public async void import() { await pdfviewer.ImportAnnotations("blazor-succinctly.xfdf", AnnotationDataFormat.XFdf); } |
|
Client side package |
|
|
Blazor Client |
|
|
Blazor Sever |
|
|
Service side package |
ASP.NET Core :
https://www.nuget.org/packages/Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows/ https://www.nuget.org/packages/Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux/
ASP.NET MVC:
|
|
Query |
Details | |
|
Are there changes to the PDFViewerController to support this new functionality?
https://ej2.syncfusion.com/documentation/pdfviewer/how-to/create-pdfviewer-service seems out of date.
|
We have created the Wen service project with the latest features in Asp.Net Core and shared the same in the below link,
Also we will update the documentation with latest changes | |
|
Where is the output of
ExportAnnotations()? Do they get downloaded in the browser?
|
Yes, the exported annotations will be downloaded in xfdf format in the browser | |
|
My requirement is to programaticaly save and restore the annotations behind the scenes. I don't see how these APIs can satisfy that need. Is there a way to do what I want - perhaps in the PDFViewerController? FYI, I have a client side Blazor webassembly app. |
We can import/export the annotations in XFDF format using the below code,
|
|
public async void import()
{
await Viewer.ImportAnnotations("PDF Succinctly.xfdf", Syncfusion.Blazor.PdfViewer.AnnotationDataFormat.Xfdf);
}
[AcceptVerbs("Post")]
[HttpPost("ImportAnnotations")]
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
[Route("[controller]/ImportAnnotations")]
//Post action to import annotations
public IActionResult ImportAnnotations([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string jsonResult = string.Empty;
object JsonResult;
if (jsonObject != null && jsonObject.ContainsKey("fileName"))
{
string documentPath = GetDocumentPath(jsonObject["fileName"]);
if (!string.IsNullOrEmpty(documentPath))
{
jsonResult = System.IO.File.ReadAllText(documentPath);
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
else
{
string extension = Path.GetExtension(jsonObject["importedData"]);
if (extension != ".xfdf")
{
JsonResult = pdfviewer.ImportAnnotationFromXFdf(jsonObject);
return Content(JsonConvert.SerializeObject(JsonResult));
}
else
{
string documentPath = GetDocumentPath(jsonObject["importedData"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
//jsonObject["importedData"] = Convert.ToBase64String(bytes);
jsonObject["importedData"] = "77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjx4ZmRmIHhtbDpzcGFjZT0icHJlc2VydmUiIHhtbG5zPSJodHRwOi8vbnMuYWRvYmUuY29tL3hmZGYvIj4NCiAgPGFubm90cz4NCiAgICA8ZnJlZXRleHQgcGFnZT0iMCIgcmVjdD0iMTcxLjc1LDY1OC41LDI4NSw3MDEuMjUiIHRpdGxlPSJHdWVzdCIgZGF0ZT0iRDoyMDIwMTExNzE3MDI1OSswNSczMCciIG5hbWU9ImI4Nzc5YjY4LTM0NGItNDVlYy1hYjhjLWY4YjcyZjdhOGVhMiIgc3ViamVjdD0iVGV4dCBCb3giIHJvdGF0aW9uPSIwIiBib3JkZXI9IjAsMCwxIiBmbGFncz0icHJpbnQiIGZyaW5nZT0iMCwwLDAsMCIgcT0iMCIgSVQ9IkZyZWVUZXh0VHlwZVdyaXRlciIgaGVhZD0iT3BlbkFycm93Ij4NCiAgICAgIDxkZWZhdWx0YXBwZWFyYW5jZT4xIDEgMSByZyA8L2RlZmF1bHRhcHBlYXJhbmNlPg0KICAgICAgPGRlZmF1bHRzdHlsZT5mb250OkhlbHZldGljYSAxMnB0O3N0eWxlOlJlZ3VsYXI7IGNvbG9yOiMwMDAwMDA8L2RlZmF1bHRzdHlsZT4NCiAgICAgIDxjb250ZW50cz5lcmZnM2Y8L2NvbnRlbnRzPg0KICAgIDwvZnJlZXRleHQ+DQogIDwvYW5ub3RzPg0KICA8ZiBocmVmPSJBbm5vdGF0aW9ucy54ZmRmIiAvPg0KPC94ZmRmPg==";
JsonResult = pdfviewer.ImportAnnotationFromXFdf(jsonObject);
return Content(JsonConvert.SerializeObject(JsonResult));
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
}
return Content(jsonResult);
}
|
|
Blazor Sever |
|
|
Service side package |
ASP.NET Core :
https://www.nuget.org/packages/Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows/ https://www.nuget.org/packages/Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux/
ASP.NET MVC:
|
|
<button @onclick="ExportXFDF">ExportXFDF</button>
<button @onclick="ImportXFDF">ImportXFDF</button>
<SfPdfViewerServer @ref="@PDFViewer" />
@code{
public SfPdfViewerServer PDFViewer { get; set; }
Stream annotationData;
public async void ExportXFDF()
{
annotationData = await PDFViewer.ExportAnnotationAsStream(AnnotationDataFormat.Xfdf);
}
public async void ImportXFDF()
{
await PDFViewer.ImportAnnotation(annotationData, AnnotationDataFormat.Xfdf);
}
} |
|
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
jsonObject["importedData"] = Convert.ToBase64String(bytes);
JsonResult = pdfviewer.ExportAnnotation(jsonObject);
return Content(JsonConvert.SerializeObject(JsonResult)); |