I am not able to save a edited PDF in the PDFviewer and see only how to save the original PDF.
|
<button onclick="save()">SaveDocument</button>
<script>
function save() {
var pdfViewer = document.getElementById('pdfviewer1').ej2_instances[0];
pdfViewer.serverActionSettings.download = "SaveDocument";
pdfViewer.download();
pdfViewer.serverActionSettings.download = "Download";
}
</script>
public ActionResult SaveDocument([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
string base64String = documentBase.Split(new string[] { "data:application/pdf;base64," }, StringSplitOptions.None)[1];
if (base64String != null || base64String != string.Empty)
{
byte[] byteArray = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(byteArray);
var path = _hostingEnvironment.ContentRootPath;
System.IO.File.WriteAllBytes(path + "/ouptut.pdf", byteArray);
}
return Content(string.Empty);
}
|
Excuse me, in your example the document is save as ouput.pdf as I would do if I want to save it with a name that I send from the client. thank you
|
viewer.ajaxRequestInitiate = (args) => {
if (args.JsonData.action == 'SaveDocument') {
args.JsonData['path'] = '';
viewer.setJsonData(args.JsonData);
}
};
|
|
public ActionResult SaveDocument([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
string base64String = documentBase.Split(new string[] { "data:application/pdf;base64," }, StringSplitOptions.None)[1];
if (base64String != null || base64String != string.Empty)
{
byte[] byteArray = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(byteArray);
jsonObject["path"] = _hostingEnvironment.ContentRootPath;
System.IO.File.WriteAllBytes(jsonObject["path"] + "/ouptut.pdf", byteArray);
}
return Content(string.Empty);
}
|
Is there any way to show success message after saving pdf file. I don't want to download the file
Hi Zachariah,
We have a
downloadEnd event that is triggered after the downloading/saving the document.
You can utilize this event to display a success message. Below is the code
snippet and sample for implementing this functionality.
Code snippet:
|
<ejs-pdfviewer id="pdfviewer" style="height:641px" downloadEnd="downloadEnd" documentPath="FormDesigner.pdf" serviceUrl="/PdfViewer"></ejs-pdfviewer>
function downloadEnd(args) { alert("Document saved successfully") } |
Steps to show the success message: