Reputation: 562
I need to replace a check box in existing pdf with new check box using ItextSharp.
While reading the Pdf how do I know the location of form field which I am reading.
rectangle measures and page information (If the form field I am reading now is in page number 6).
Precisely what I want to know is how to know existing form field location while reading? Can anyone provide some sample code on finding location and page.
Why am I trying to replace existing pdf? you can find the reason here..
Unable to print Check Boxes in pdf
Thanks
Upvotes: 0
Views: 449
Reputation: 96064
Once you have a PdfReader, you can easily access the AcroFields of the reader which hold the coordinates of all fields:
PdfReader pdfReader = new PdfReader(inputFilename);
AcroFields acroFields = pdfReader.AcroFields;
IList<FieldPosition> positions = acroFields.GetFieldPositions(fieldName);
You get a list of FieldPosition elements (each containing a page number and a rectangle) because a PDF form field may have multiple visualizations. In your case the list most likely contains but one element.
The method documentation of GetFieldPositions is a bit out of date, though. ;)
Upvotes: 1