|
public IActionResult Download([FromBody] Dictionary<string, string> jsonObject)
{
MemoryStream stream = new MemoryStream();
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);
//Create the form if the form does not exist in the loaded document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(byteArray);
//Get the loaded form.
PdfLoadedForm loadedForm = loadedDocument.Form;
PdfLoadedFormFieldCollection fields = loadedForm.Fields;
//Flatten the whole form.
loadedForm.Flatten = true;
//Save the document into stream
loadedDocument.Save(stream);
stream.Position = 0;
loadedDocument.Close();
documentBase = string.Concat("data:application/pdf;base64,", Convert.ToBase64String(stream.ToArray()));
}
return Content(documentBase);
} |