We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Not all PDF Form Fields Being Returned

I am trying to use Aspose.Pdf to enumerate the form fields in a PDF.


I am using Aspose.Pdf version 2016.08.02 (11.9.0.0). I start by opening the PDF:

Dim document As New Aspose.Pdf.Document(Server.MapPath("~/App_Data/88.pdf"))


I then enumerate the fields in document.Form. For each field, I call a method that displays the information:

For Each fld As Aspose.Pdf.Forms.Field In document.Form
DisplayField(fld)
Next


In the DisplayField method I see if it’s a group and, if so, recurse into the children of the group. Otherwise I just display the form field details (this is an ASP.NET application).

Private Sub DisplayField(fld As Aspose.Pdf.Forms.Field)
If fld.IsGroup Then
For Each childFld As Aspose.Pdf.Forms.Field In fld
DisplayField(childFld)
Next
Else
lblOutput.Text &= String.Format(“

Name={0}, PartialName={1}, FullName={2}, Required={3}, ReadOnly={4}, Value={5}

”,
fld.Name,
fld.PartialName,
fld.FullName,
fld.Required,
fld.ReadOnly,
fld.Value)
End If
End Sub


The issue, though, is that it only enumerates through a small number of the form fields in the PDF. There are many other (on the same page and other pages) that aren’t getting displayed. For instance, the attached PDF has 32 form fields. But when I use the above code, Aspose.Pdf returns only 4 form fields.

Here’s the output displayed in the web page. You can see I only get 4 form fields:

Name=, PartialName=box1 pg1, FullName=box1 pg1, Required=False, ReadOnly=False, Value=Yes

Name=, PartialName=box2 pg1, FullName=box2 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=box3 pg1, FullName=box3 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=fname1 pg1, FullName=fname1 pg1, Required=False, ReadOnly=False, Value=The Village Family Services


How do I get ALL form fields?

What’s interesting, it that if I debug and view in the Immediate Window the following:

document.Form.Count

I get back 32 (as to be expected).

But if I do:

document.Form.Fields.Count

I get back 4, which would explain why it only shows four form fields. When I step through the code I see that the loop is only iterated through 4 times. So what gives? How do I loop through all 32 form fields?

Hi Scott,


Thank you for contacting support. We have tested your scenario in our environment with the latest version 17.5 of Aspose.Pdf for .NET API and it returns 32 form fields as below:

[.NET, VB.NET]
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Dim<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> document <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>As<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>New<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Aspose.Pdf.Document(“c:\pdf\test76\88.pdf”)<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>For<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Each<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> fld <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>As<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Aspose.Pdf.Forms.Field <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>In<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> document.Form<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
DisplayField(fld)<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
Next
<span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>’…<br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Private<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Sub<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> DisplayField(fld <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>As<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Aspose.Pdf.Forms.Field)<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”> If<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> fld.IsGroup <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Then<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>For<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Each<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> childFld <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>As<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Aspose.Pdf.Forms.Field <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>In<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> fld<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
DisplayField(childFld)<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>Next<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”> Else
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Console.WriteLine(<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>String<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>.Format(“

Name={0}, PartialName={1}, FullName={2}, Required={3}, <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>ReadOnly<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>={4}, Value={5}

”,<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
fld.Name,<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
fld.PartialName,<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
fld.FullName,<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
fld.Required,<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
fld.<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>ReadOnly<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>,<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
fld.Value))<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”> End<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>If<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>End<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Sub

Results:

Name=, PartialName=box1 pg1, FullName=box1 pg1, Required=False, ReadOnly=False, Value=Yes

Name=, PartialName=box2 pg1, FullName=box2 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=box3 pg1, FullName=box3 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=fname1 pg1, FullName=fname1 pg1, Required=False, ReadOnly=False, Value=The Village Family Services

Name=, PartialName=fmumber1 pg1, FullName=fmumber1 pg1, Required=False, ReadOnly=False, Value=197806197

Name=, PartialName=name1 pg1, FullName=name1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=address1 pg1, FullName=address1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=city1 pg1, FullName=city1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=zip1 pg1, FullName=zip1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=ssa1 pg1, FullName=ssa1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=dob1 pg1, FullName=dob1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=cdl1 pg1, FullName=cdl1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=date1 pg1, FullName=date1 pg1, Required=False, ReadOnly=False, Value=

Name=, PartialName=offense1 pg2, FullName=offense1 pg2, Required=False, ReadOnly=False, Value=This is a test

Name=, PartialName=offense2 pg2, FullName=offense2 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=offense3 pg2, FullName=offense3 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=offense5 pg2, FullName=offense5 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=occur1 pg2, FullName=occur1 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=offense6 pg2, FullName=offense6 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=occur2 pg2, FullName=occur2 pg2, Required=False, ReadOnly=False, Value=5/1/2017

Name=, PartialName=offense4 pg2, FullName=offense4 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=whappened1 pg2, FullName=whappened1 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=occur3 pg2, FullName=occur3 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=whappened2 pg2, FullName=whappened2 pg2, Required=False, ReadOnly=False, Value=I don’t know what happened.

Name=, PartialName=whappened3 pg2, FullName=whappened3 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=whappened4 pg2, FullName=whappened4 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=whappened5 pg2, FullName=whappened5 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=whappened6 pg2, FullName=whappened6 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=whappened7 pg2, FullName=whappened7 pg2, Required=False, ReadOnly=False, Value=

Name=, PartialName=box4 pg1, FullName=box4 pg1, Required=False, ReadOnly=False, Value=Yes

Name=, PartialName=date 1 pg 2, FullName=date 1 pg 2, Required=False, ReadOnly=False, Value=

Name=, PartialName=AuthCode, FullName=AuthCode, Required=False, ReadOnly=False, Value=a589f775-8ba5-4696-a9d1-67903070db8f


The issue, I found out, was due to the license. I hadn’t applied the license. Rather than throw an exception or give any error, it just limits things to reading 4 form fields.


This thread highlights the issue:
Form Fields only return 4 items

Once I correctly applied the license, it worked as expected.

Hi Scott,


Thank you for the confirmation. We have documented all evaluation limitations as well as various ways to apply a license. Please note, you need to set license once per application or process for each Aspose library. When you have applied a license as per application or process level, then you do not need to apply license again till the lifespan of the application. Please refer to this help topic: Apply License to Aspose.Diagram for .NET API