Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Mon Oct 16, 2023 5:39 am
Hi, I am working for getting Form Fields from PDF files. I have got the Form fields details but I need the PDF page number where the field was Identified. How can I get the page number. In addition to this I am also in search of Positions for both the Field Name and Field Value. Kindly help on this.
-

moorthys
-
- Posts: 3
- Joined: Fri Oct 13, 2023 6:45 am
Mon Oct 16, 2023 6:05 am
Hi,
Thanks for your your inquiry.
Please refer to the following code for reference.
- Code: Select all
//Load a pdf document
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"xxxx.pdf");
//Get pdf forms
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
//Find pdf form fields
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
// get the page index
PdfPageBase page = field.Page;
int pageindex = doc.Pages.IndexOf(page);
Console.WriteLine(pageindex);
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
// get the bounds of the field
RectangleF bounds = textBoxField.Bounds;
Console.WriteLine(bounds.X);
Console.WriteLine(bounds.Y);
}
if (field is PdfListBoxWidgetFieldWidget)
{
// your code here
}
if (field is PdfComboBoxWidgetFieldWidget)
{
// your code here
}
if (field is PdfRadioButtonListFieldWidget)
{
// your code here
}
if (field is PdfCheckBoxWidgetFieldWidget)
{
// your code here
}
}
If you have any other questions, just feel free to contact us. We are here to assist you.
Best regadrs,
Triste
E-iceblue support team
-


Triste.Dai
-
- Posts: 1000
- Joined: Tue Nov 15, 2022 3:59 am