Exemple #1
0
        public ActionResult GetUploadFileFields(string json = "")
        {
            try
            {
                PdfDocument PDFDocument = null;

                if (Request.Form.Files.Count > 0 && Request.Form.Files[0].Length > 0)
                {
                    var    file     = Request.Form.Files[0];
                    string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    byte[] memPDF   = Helper.ReadFully(file.OpenReadStream(), 0); // critical to grab a full memory copy - or else performance will be terrible!

                    PDFDocument = PdfReader.Open(new MemoryStream(memPDF));
                }
                else if (json != "")
                {
                    JSONPDFFillPost jsonPost = JsonConvert.DeserializeObject <JSONPDFFillPost>(json);
                    byte[]          data     = Convert.FromBase64String(jsonPost.Base64PDF);
                    var             stream   = new MemoryStream(data, 0, data.Length);
                    PDFDocument = PdfReader.Open(stream);
                }


                return(Json(GetFieldsFromPDF(PDFDocument)));
            }
            catch (System.Exception ex)
            {
                return(Json("Error: " + ex.Message));
            }
        }
Exemple #2
0
 public ActionResult jlistfieldsPost([FromBody] JSONPDFFillPost JPost)
 {
     try {
         byte[] data   = Convert.FromBase64String(JPost.Base64PDF);
         var    stream = new MemoryStream(data, 0, data.Length);
         return(Json(GetFieldsFromPDF(PdfReader.Open(stream))));
     } catch (System.Exception ex) {
         return(Json("Error: " + ex.Message));
     }
 }
Exemple #3
0
        public ActionResult jFillPDFPost([FromBody] JSONPDFFillPost JPost)
        {
            try {
                byte[] data        = Convert.FromBase64String(JPost.Base64PDF);
                var    stream      = new MemoryStream(data, 0, data.Length);
                var    PDFDocument = PdfReader.Open(stream);

                FillPDF(JPost.FormFields, PDFDocument);

                var fsr = new MemoryStream();
                PDFDocument.Flatten();
                PDFDocument.Save(fsr);
                return(new FileStreamResult(fsr, "application/pdf"));
            } catch (System.Exception ex) {
                return(new StatusCodeResult(400)); // Json("Fill failed: " + ex.Message);
            }
        }
Exemple #4
0
        public ActionResult FileUploadPdfFile(string formvaluesjson = "", string json = "")
        {
            try
            {
                PdfDocument                 PDFDocument     = null;
                JSONPDFFillPost             jsonPost        = null;
                Dictionary <string, string> submittedFields = null;
                if (Request.Form.Files.Count > 0 && Request.Form.Files[0].Length > 0)
                {
                    string fileName = ContentDispositionHeaderValue.Parse(Request.Form.Files[0].ContentDisposition).FileName.Trim('"');

                    byte[] memPDF = Helper.ReadFully(Request.Form.Files[0].OpenReadStream(), 0);   // critical to grab a full memory copy - or else performance will be terrible!
                    PDFDocument = PdfReader.Open(new MemoryStream(memPDF));
                }
                else if (json != "")
                {
                    jsonPost = JsonConvert.DeserializeObject <JSONPDFFillPost>(json);
                    byte[] data   = Convert.FromBase64String(jsonPost.Base64PDF);
                    var    stream = new MemoryStream(data, 0, data.Length);
                    PDFDocument = PdfReader.Open(stream);
                }

                if (formvaluesjson != "")
                {
                    submittedFields = JsonConvert.DeserializeObject <Dictionary <string, string> >(formvaluesjson);
                }
                else
                {
                    submittedFields = jsonPost.FormFields;
                }

                FillPDF(submittedFields, PDFDocument);

                var fsr = new MemoryStream();
                PDFDocument.Flatten();
                PDFDocument.Save(fsr);
                return(new FileStreamResult(fsr, "application/pdf"));
            }
            catch (System.Exception ex)
            {
                return(Json("Fill failed: " + ex.Message));
            }
        }
Exemple #5
0
        public async Task <ActionResult> FillPDFPost(string token, string filePath, string forvaluesjson = "", string json = "")
        {
            try {
                PdfDocument                 PDFDocument     = null;
                JSONPDFFillPost             jsonPost        = null;
                Dictionary <string, string> submittedFields = null;
                var fileParts    = Helper.GetPathAndName(filePath);
                var fileResponse = await _docstoreClient.GetFileContent(fileParts.Item2, fileParts.Item1);

                PDFDocument = PdfReader.Open(new MemoryStream(fileResponse));
                if (json != "")
                {
                    jsonPost = JsonConvert.DeserializeObject <JSONPDFFillPost>(json);
                    byte[] data   = Convert.FromBase64String(jsonPost.Base64PDF);
                    var    stream = new MemoryStream(data, 0, data.Length);
                    PDFDocument = PdfReader.Open(stream);
                }

                if (forvaluesjson != "")
                {
                    submittedFields = JsonConvert.DeserializeObject <Dictionary <string, string> >(forvaluesjson);
                }
                else
                {
                    submittedFields = jsonPost.FormFields;
                }

                FillPDF(submittedFields, PDFDocument);
                var fsr = new MemoryStream();
                PDFDocument.Flatten();
                PDFDocument.Save(fsr);
                var contents = fsr.ToArray();
                var response = await _docstoreClient.UpsertDocument(fileParts.Item2, fileParts.Item1, contents, new Dictionary <string, string>());

                return(Json(response.Response.Url));
            } catch (System.Exception ex) {
                return(Json("Fill failed: " + ex.Message));
            }
        }
Exemple #6
0
        public async Task <ActionResult> listfieldsPost(string token, string filePath, string json = "")
        {
            try {
                var         fileparts   = Helper.GetPathAndName(filePath);
                PdfDocument PDFDocument = null;
                var         response    = await _docstoreClient.GetFileContent(fileparts.Item2, fileparts.Item1);

                PDFDocument = PdfReader.Open(new MemoryStream(response));

                if (json != "")
                {
                    JSONPDFFillPost jsonPost = JsonConvert.DeserializeObject <JSONPDFFillPost>(json);
                    byte[]          data     = Convert.FromBase64String(jsonPost.Base64PDF);
                    var             stream   = new MemoryStream(data, 0, data.Length);
                    PDFDocument = PdfReader.Open(stream);
                }


                return(Json(GetFieldsFromPDF(PDFDocument)));
            } catch (System.Exception ex) {
                return(Json("Error: " + ex.Message));
            }
        }