add field to exist PDF

add field to exist PDF

Forum member · Mar 30, 2007
I am trying to use c#(.net 2.0) to add an field to an exist pdf. using ceTe.DynamicPDF; using ceTe.DynamicPDF.Merger; using ceTe.DynamicPDF.Merger.Forms; using ceTe.DynamicPDF.PageElements; C# code as below ceTe.DynamicPDF.Forms.FormField _formField = new ceTe.DynamicPDF.Forms.FormField("Description1"); _formField.IsReadOnly = true; _formField.Value = "add form"; page.Elements.Add(_formField); document.Form.Fields.Add(_formField); however I could not see it in pdf page. I believe there should have a way to set field's coordinate, but I did not find it. besides, when I read the examples in this forum I find there has a way to get a coordinate such as _formField.GetX why I cannot see it in the element of form field. Anybody can help me.

Re: add field to exist PDF

Support · Apr 2, 2007
Hello, This is not a correct way of creating the form fields using our product. You can refer to the Form Fields on our help documentation to create the Form fields. Following is the sample code to create a form field and adding it to an exisitng PDF. MergeDocument merDoc = new MergeDocument(@"C:\Temp\DocA.pdf"); TextField textField = new TextField( "txt", 50, 75, 150, 100 ); merDoc.Pages[1].Elements.Add( textField]; merDoc.DrawToWeb(); In order to know the X and Y positions of an existing form field you can use the GetX, GetY methods of the PdfFormField class. Following is the sample code. PdfDocument pdfDocument = new PdfDocument(@"C:\Temp\DocA.pdf"); MergeDocument merDoc = new MergeDocument(pdfDocument); PdfFormField field = pdfDocument.Form.Fields["txt"]; float x = field.GetX(merDoc.Pages[field.GetOriginalPageNumber()-1]); float y = field.GetY(merDoc.Pages[field.GetOriginalPageNumber()-1]); Thanks, ceTe Software Support Team.