public static void convertPDFDoc(string fileDir, string fileName, string fileExtension) { var Readengine = new FileHelperAsyncEngine <Record>(); //read document goes line by line Readengine.BeginReadFile(DSConfig.CsvTags); using (Readengine) { using (FileStream fileIn = new FileStream(fileDir + "\\" + fileName, FileMode.Open, FileAccess.Read)) { TallComponents.PDF.Document document = new TallComponents.PDF.Document(fileIn); foreach (Record r in Readengine) { //create document TextFindCriteria criteria = new TextFindCriteria(r.CompetitorTag, false, false); TextMatchEnumerator enumerator = document.Find(criteria); overlayText(enumerator, r.DocusignTag); } using (FileStream fileOut = new FileStream(DSConfig.DropoffDir + "\\" + fileName.Substring(0, fileName.Length - fileExtension.Length) + "_converted" + fileExtension, FileMode.Create, FileAccess.Write)) { document.Write(fileOut); } } } }
void open(string path) { this.path = path; file = new FileStream(path, FileMode.Open, FileAccess.Read); document = new pdf.Document(file); initializePagesList(); }
void close() { if (null != file) { file.Dispose(); file = null; document = null; path = null; } }
public ActionResult Download(string id) { string path = Server.MapPath(string.Format("~/Download/{0}.json", id)); string json = System.IO.File.ReadAllText(path); System.IO.File.Delete(path); PanelPage[] pages = new JavaScriptSerializer().Deserialize <PanelPage[]>(json); Dictionary <string, FileStream> streams = new Dictionary <string, FileStream>(); Dictionary <string, kit.Document> documents = new Dictionary <string, kit.Document>(); kit.Document newPdf = new kit.Document(); foreach (PanelPage page in pages) { FileStream file; kit.Document pdf; if (!streams.ContainsKey(page.Guid)) { file = new FileStream(Server.MapPath(string.Format("~/Upload/{0}.pdf", page.Guid)), FileMode.Open, FileAccess.Read); streams[page.Guid] = file; pdf = new kit.Document(file); documents[page.Guid] = pdf; } else { pdf = documents[page.Guid]; } newPdf.Pages.Add(pdf.Pages[page.Index].Clone()); } using (MemoryStream memory = new MemoryStream()) { newPdf.Write(memory); foreach (FileStream file in streams.Values) { file.Close(); file.Dispose(); } byte[] buffer = memory.GetBuffer(); Response.AddHeader("Content-Disposition", "attachment; filename=out.pdf"); return(File(buffer, "application/pdf")); } }
public ActionResult Upload() { HttpPostedFileBase upload = Request.Files[0]; Guid guid = Guid.NewGuid(); kit.Document pdf = new kit.Document(upload.InputStream); upload.SaveAs(Server.MapPath(string.Format("~/Upload/{0}.pdf", guid))); return(PartialView("Index", new PanelModel() { DocumentGuid = guid.ToString(), Document = pdf })); }
public ActionResult Upload(FormCollection form) { HttpPostedFileBase file = Request.Files[0]; Guid guid = Guid.NewGuid(); kit.Document pdf = new kit.Document(file.InputStream); file.SaveAs(Server.MapPath(string.Format("~/Upload/{0}.pdf", guid))); String Idc = form["IdClient"].ToString(); String Csp = form["CodeCSP"].ToString(); String Url = file.FileName; ViewBag.Idc = TempData["Idc"]; ViewBag.Cs = TempData["Cs"]; ViewBag.Url = TempData["Url"]; var cSP_DOC = db.CSP_DOC.Where(c => c.CodeCSP == Csp & c.CodeDoc != "Glob").ToList(); return(PartialView("_Panel", new PanelModel() { DocumentGuid = guid.ToString(), Document = pdf, Idc = Idc, Cs = Csp, Url = Url, cSP_DOC = cSP_DOC })); }