public List <Dictionary <string, object> > GetAllForminfo(string formid) { var pdffile = Path.Combine(pdfroot, formid + ".pdf"); if (System.IO.File.Exists(pdffile)) { var pdfDoc = new PdfParser(pdffile); return(pdfDoc.GetFieldsInfo()); } else { return(null); } }
public ActionResult <Stream> GetFile(string formid, int pageid) { //var configfile = Path.Combine(pdfroot,string.Format("{0}.{1}.json",formid,pageid)); var db = new DbHelper(); var jsonObj = db.LoadFormData(formid, pageid); if (jsonObj.Count > 0) { var pdffile = Path.Combine(pdfroot, formid + ".pdf"); var pdfDoc = new PdfParser(pdffile); if (pageid > pdfDoc.GetPageNumber() || pageid < 1) { return(null); } var newpdf = Path.Combine(pdfroot, string.Format("{0}.{1}.pdf", formid, pageid)); var downpdfname = string.Format("myform.{0}.{1}.pdf", formid, pageid); if (pdfDoc.PageToNewPdf(pageid, newpdf)) { var pdfDocForm = new PdfParser(newpdf); if (pdfDocForm.GetFieldsInfo().Count < 1) { return(null); } // edit post content pdfDocForm.SetFieldsValues(jsonObj, Path.Combine(pdfroot, downpdfname)); // edit finished } string localFilePath = Path.Combine(pdfroot, downpdfname); string fileName = Path.GetFileName(localFilePath); //long fileSize = (new FileInfo(localFilePath)).Length; var dataBytes = System.IO.File.ReadAllBytes(localFilePath); var dataStream = new MemoryStream(dataBytes); return(dataStream); // HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); // response.Content = new StreamContent(dataStream); // response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); // response.Content.Headers.ContentDisposition.FileName = fileName; // response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); //return response; } else { return(null); } }