Hello,
I use the EJS component to edit my pdf files. I would like add custom data in the front call and get it in the Dictionary<string, string> jsonObject like the documentPath contained in the "document" entry.
To call the load, i use the DocumentPath in the declaration of ejs in html (and open document is hided) :
<ejs-pdfviewer id="pdfviewer" style="height:1200px" serviceUrl="/api/Signature" zoomValue="100" documentPath="@Model.Filename"></ejs-pdfviewer>
Thanks
|
Client-side:
<div style="width:100%;height:1200px">
<ejs-pdfviewer id="pdfviewer1" serviceUrl="/api/PdfViewer" documentPath="HTTP Succinctly.pdf" ajaxRequestInitiate ="ajaxRequestInitiate"></ejs-pdfviewer>
</div>
<script>
function ajaxRequestInitiate(args) {
var viewer = document.getElementById("pdfviewer1").ej2_instances[0];
if (viewer.serverActionSettings.load == "Load") {
args.JsonData['documentId'] = '1001';
viewer.setJsonData(args.JsonData);
}
}
</script>
Server-side:
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/Load")]
public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
{
Console.WriteLine("Load called");
//Initialize the PDF viewer object with memory cache object
PdfRenderer pdfviewer = new PdfRenderer(_cache);
MemoryStream stream = new MemoryStream();
object jsonResult = new object();
string id = jsonObject["documentId"];
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
if (bool.Parse(jsonObject["isFileName"]))
{
string documentPath = GetDocumentPath(jsonObject["document"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
stream = new MemoryStream(bytes);
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
stream = new MemoryStream(bytes);
}
}
jsonResult = pdfviewer.Load(stream, jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
} |
Thank you!
Hi Alex Santos,
You're
welcome. If you need any further assistance, please don't hesitate to reach out
to us.
Regards,
Sathiyaseelan K