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.

Thu Dec 26, 2019 8:11 am

hi,

Dim field As PdfField = nothing
Dim fieldName As String = nothing
Dim PageNr as iteger = -1

For i As Integer = 0 To formWidget.FieldsWidget.List.Count - 1
Field = TryCast(formWidget.FieldsWidget.List(i), PdfField)
FieldName = Field.Name

PageNr= ??????

Next

lg GH

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Thu Dec 26, 2019 10:26 am

Hi,

Thanks for your inquiry.
Please try the code below to get the page number of each form field in PDF file.
Code: Select all
        Dim doc As PdfDocument = New PdfDocument
        doc.LoadFromFile("..\sample.pdf")
        Dim formWidget As PdfFormWidget = CType(doc.Form, PdfFormWidget)
        Dim PageNr As Integer = -1
        Dim i As Integer = 0
        Do While (i < formWidget.FieldsWidget.List.Count)
            Dim field As PdfField = CType(formWidget.FieldsWidget.List(i), PdfField)
            Dim page As PdfPageBase = field.Page
            PageNr = doc.Pages.IndexOf(page) + 1
            Console.WriteLine(PageNr)
            i = (i + 1)
        Loop
        Console.Read()

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Thu Dec 26, 2019 8:29 pm

Thank you for your fast help.

GH

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Fri Dec 27, 2019 1:12 am

Hi,

Thanks for your reply.
Any question, welcome to contact us. Have a nice day.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Aug 18, 2021 3:16 pm

Hi! When I use the code you posted, I get an error in VB.NET, "PDFFormWidget is not defined" on this line: Dim formWidget As PdfFormWidget = CType(doc.Form, PdfFormWidget).
Thanks in advance!
These are my Imports-
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Graphics.Fonts
Imports Spire.Pdf.Actions
Imports Spire.Pdf.Fields

NicoleMaak
 
Posts: 1
Joined: Thu Jun 23, 2016 5:22 pm

Thu Aug 19, 2021 7:09 am

Hello Nicole,

Thank you for your inquiry.
Kindly note that the namespace of "PDFFormWidget" is "Spire.Pdf.Widget", but I didn't find it in your imports. Please import the "Spire.Pdf.Widget" namespace in your project to try again. If there is any question, please feel free to write back.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF