public void CrearPDF(W9 obj) { string root = new FileInfo(Assembly.GetExecutingAssembly().Location).FullName; //Instacia para leer PDF //LLenar campos del form PDF PdfDocument pdf = new PdfDocument(new PdfReader("../../../assets/fw9.pdf"), new PdfWriter("outputw9.pdf")); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true); IDictionary <string, PdfFormField> fields = form.GetFormFields(); fields["topmostSubform[0].Page1[0].f1_1[0]"].SetValue(obj.Nombre); fields["topmostSubform[0].Page1[0].f1_2[0]"].SetValue(obj.NombreNegocio); fields["topmostSubform[0].Page1[0].FederalClassification[0].c1_1[0]"].SetValue("0"); fields["topmostSubform[0].Page1[0].Address[0].f1_7[0]"].SetValue(obj.Domicilio); fields["topmostSubform[0].Page1[0].Address[0].f1_8[0]"].SetValue($"{obj.Ciudad} {obj.Estado} {obj.CodigoPostal}"); fields["topmostSubform[0].Page1[0].f1_10[0]"].SetValue(obj.Tel); pdf.Close(); }
static void Main(string[] args) { W9 w9 = new W9() { Nombre = "JUAN PEREZ PEREZ", Ciudad = "LEON", Domicilio = "CALLE ALFARO 313C", Estado = "GUANAJUATO", Tel = "477171234", TipoNegocio = 1, CodigoPostal = "37000", NombreNegocio = "CASTORES SA DE CV", Domicilio2 = String.Empty }; PdfCreador creador = new PdfCreador(); creador.CrearPDF(w9); }