// samples taken from // http://www.c-sharpcorner.com/uploadfile/scottlysle/pdfgenerator_cs06162007023347am/pdfgenerator_cs.aspx // http://blog.codecentric.de/en/2010/08/pdf-generation-with-itext/ public string SetFields(string PathSource, string PathTarget, System.Object myFields) { try { GeneXus.Utils.GXProperties Fields = (GeneXus.Utils.GXProperties)myFields; // create a new PDF reader based on the PDF template document iTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(PathSource); iTextSharp.text.pdf.PdfStamper pdfStamper = new iTextSharp.text.pdf.PdfStamper(pdfReader, new System.IO.FileStream(PathTarget, System.IO.FileMode.Create)); GeneXus.Utils.GxKeyValuePair item = Fields.GetFirst(); while (item != null) { pdfStamper.AcroFields.SetField(item.Key, item.Value); item = Fields.GetNext(); } // flatten the form to remove editting options, set it to false to leave the form open to subsequent manual edits pdfStamper.FormFlattening = false; // close the pdf pdfStamper.Close(); pdfReader.Close(); return(""); } catch (Exception e) { return(e.Message); } }
public GeneXus.Utils.GXProperties GetFields(string PathSource) { GeneXus.Utils.GXProperties allFields = null; try { iTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(PathSource); allFields = new GeneXus.Utils.GXProperties(); foreach (KeyValuePair <string, iTextSharp.text.pdf.AcroFields.Item> de in pdfReader.AcroFields.Fields) { allFields.Add(de.Key.ToString(), de.Value.ToString()); } } catch (Exception) { // Do nothing } return(allFields); }