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

Free Support Forum - aspose.com

Extract Form Fields from PDF document using Aspose.PDF in C# - All forms fields are not being identified

All form fields are not identified from the pdf, I can share the pdf that I am using in a private email, not sure whether I can share the pdf in public forum as it is related to insurance industry.
we use currently iTextSharp on production.
//iTextSharp code to get all the acrofields is below:

temppdfReader = new PdfReader(pdfTemplate);
tempStamper = new PdfStamper(temppdfReader, new FileStream(pdfNew, FileMode.Create));

AcroFields fields = tempStamper.AcroFields;

Am trying same using aspose, but its retrieving only 4 out of 16 fields on the pdf.
Approach 1 using Aspose:

        var dataDir = GetDataDir_Data();
        var pdfDocument = new Document(dataDir + "sample-doc.pdf");
        return pdfDocument.Form.Fields;

As suggested on this forum I also tried below code:
Approach 2:
var dataDir = GetDataDir_Data();
var pdfDocument = new Document(dataDir + “sample-doc.pdf”);
pdfDocument.Form.XFA.FieldNames;

Approach 3:
fs = new FileStream(dataDir + “sample-doc.pdf”, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var pdfDocument = new Document(fs);
formFields = pdfDocument.Form.XFA.FieldNames;

@bnjaspose

You can share the PDF in a private message by clicking over username and pressing Blue Message Button. We will test the scenario in our environment and address it accordingly.

you mean by clicking on your username to sent a private message to you? When I clicked on your username “asad.ali”, I dont see blue message button actually.

@bnjaspose

I have sent you a private message. You can now reply to it and share the file in your reply.

i have sent the pdf, please check it.

@bnjaspose

We have tested the scenario in our environment and did not notice any issue. The API was giving count of total 16 form fields:

using (var pdf = new Document(dataDir + "C-622-NJ.pdf"))
{
  // Approach 1
  var totalFields = pdf.Form.Fields.Length;
  // Approach 2
  var form = new Aspose.Pdf.Facades.Form(pdf);
  var count = form.FieldNames.Count();
}

It seems like you are using the API without any valid license. It is a trial version limitation that API can process only 4 elements of any collections e.g. Annotations, Paragraphs, Form Fields, etc. Would you please try using a 30-days free temporary license in order to use the API without any restriction. In case you still face any issue, please let us know.

1 Like

i will check it, thank you

1 Like