How do I Convert PDF into Fillable form PDF, Retrieve the filled out PDF's data and store the data as varBinary code in database?
I understand the PDF fillable form would be a separate file, so I made some changes to the Download function in my Controller as bellow.
When I download the file, it is saved as a new pdf named "output.pdf". But none of the text box and button information is saved over.
View:
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/Home")).EnableAnnotation(true).EnableDownload(true).EnableHandwrittenSignature(true).EnableMagnification(true).EnableToolbar(true).EnablePrint(true).EnableFreeText(true).ValidateFormFields("validateFormFields").EnableFormFieldsValidation(true).ButtonFieldClick("submitButton").DocumentPath(@"~\Files\MyPDF.pdf").DocumentLoad("documentLoad").DownloadEnd("documentLoad").Render()
Controller:
[HttpPost]
public ActionResult Download(jsonObjects jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
var jsonData = JsonConverter(jsonObject);
string documentBase = pdfviewer.GetDocumentAsBase64(jsonData);
string base64String = documentBase.Split(new string[] { "data:application/pdf;base64," }, StringSplitOptions.None)[1];
if (base64String != null || base64String != string.Empty)
{
byte[] byteArray = Convert.FromBase64String(base64String);
System.IO.File.WriteAllBytes(@"~\Files\output.pdf", byteArray);
}
return Content(string.Empty);
}