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.
Wed Jul 27, 2016 8:14 pm
I'm able to get a list of fields on a form. But I would like to be able to determine which page each of those fields are on. Is there a way to get that information?
Alternatively, I'd be ok with just getting all the fields on a given page. That's pretty much the same thing for me.
thanks in advance!
-

rja
-
- Posts: 5
- Joined: Wed Jul 27, 2016 8:11 pm
Thu Jul 28, 2016 7:10 am
Hi,
Thanks for your inquiry.
Spire.PDF supports to find the page the field is on at present. Please try to use the method field.Page() to get the page. Here is sample code for your reference:
- Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(FilePath + "FormField.pdf");
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
PdfPageBase page = field.Page;
...
}
If there is any question, welcome to get it back to us.
Sincerely,
Betsy
E-iceblue support team
-


Betsy
-
- Posts: 802
- Joined: Mon Jan 19, 2015 6:14 am
Thu Jul 28, 2016 3:27 pm
Thanks for the reply. I don't think there's a Page method, just the Page property, which returns a PdfPageBase object. However I don't believe that the PdfPageBase has a page number property (I apologize if that wasn't clear in my inquiry). Is it possible to get the form fields that are only on page 1 of the PDF, for example?
-

rja
-
- Posts: 5
- Joined: Wed Jul 27, 2016 8:11 pm
Fri Jul 29, 2016 6:23 am
Hi,
Thanks for your reply.
Here is sample code for your reference:
- Code: Select all
PdfDocument pdf = new PdfDocument(FilePath + "sample.pdf");
PdfFormWidget widget = pdf.Form as PdfFormWidget;
Dictionary<int, List<PdfField>> allXOB = new Dictionary<int, List<PdfField>>();
for (int i = 0; i < pdf.Pages.Count; i++)
{
allXOB.Add(i, new List<PdfField>());
}
int pageCount = allXOB.Count;
if (widget != null)
{
for (int i = 0; i < widget.FieldsWidget.Count; i++)
{
PdfField field = widget.FieldsWidget[i];
PdfPageBase page = field.Page;
for (int j = 0; j < pageCount; j++)
{
if (pdf.Pages[j].Equals(page))
{
allXOB[j].Add(field);
break;
}
}
}
}
If there is any question, welcome to get it back to us.
Sincerely,
Betsy
E-iceblue support team
-


Betsy
-
- Posts: 802
- Joined: Mon Jan 19, 2015 6:14 am
Tue Aug 02, 2016 8:51 am
Hi,
Did you try the code I provided ? Did it help you?
Sincerely
Betsy
E-iceblue support team
-


Betsy
-
- Posts: 802
- Joined: Mon Jan 19, 2015 6:14 am
Tue Aug 02, 2016 1:46 pm
Hi Betsy,
Thank you for the code. Yes, this solved my problem.
-

rja
-
- Posts: 5
- Joined: Wed Jul 27, 2016 8:11 pm
Wed Aug 03, 2016 1:19 am
Hi,
Thanks for your feedback.
Please feel free to contact us if there is any further question. We are here for help.
Sincerely,
Betsy
E-iceblue support team
-


Betsy
-
- Posts: 802
- Joined: Mon Jan 19, 2015 6:14 am