public bool CreateAndFill(Stream output, Dictionary <string, string> keys, StampAction action = null) { try { bool result = false; PackingSlip ps = new Pdf.PackingSlip(Template); if (action == null) { result = StampPdf(this.StampAction, output, Template.TemplateBytes); } else { result = StampPdf(action, output, Template.TemplateBytes); } if (result) { //fill data result = ps.Fill(output, keys); if (result) { return(true); } else { return(false); } } return(true); } catch { return(false); } }
public bool CreateAndFill(string file, Dictionary <string, string> keys, StampAction action = null) { var temp = HttpContext.Current.Server.MapPath("/Account/PackingLists/" + Guid.NewGuid() + ".pdf"); try { bool result = false; Pdf.PackingSlip ps = new Pdf.PackingSlip(Template); using (MemoryStream ms = new MemoryStream()) { if (action == null) { result = StampPdf(this.StampAction, temp, Template.TemplateBytes); } else { result = StampPdf(action, temp, Template.TemplateBytes); } if (result) { //fill data using (MemoryStream fms = new MemoryStream()) { result = Pdf.FillInForm(temp, file, keys); } } } File.Delete(temp); return(result); } catch { return(false); } }
public static bool StampPdf(StampAction stampAction, Stream output, string template) { try { using (PdfReader reader = new PdfReader(template)) using (PdfStamper stamper = new PdfStamper(reader, output)) { stampAction.Invoke(stamper); } return(true); } catch { return(false); } }
public static bool StampPdf(StampAction stampAction, Stream output, byte[] template) { try { PdfReader reader = new PdfReader(template); PdfStamper stamper = new PdfStamper(reader, output); { stampAction.Invoke(stamper); } reader.Close(); return(true); } catch { return(false); } }
public static bool StampPdf(StampAction stampAction, string filename, byte[] template) { try { using (PdfReader reader = new PdfReader(template)) using (FileStream fs = new FileStream(filename, FileMode.Create)) using (PdfStamper stamper = new PdfStamper(reader, fs)) { stampAction.Invoke(stamper); } return(true); } catch { return(false); } }