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

Free Support Forum - aspose.com

Can't Modify Text in Form Fields on specific pdf

Typically, I am able to access form fields on a PDF using something like the following


Aspose.PDF.Document doc;
//document initialization code here
var field = doc.Form[fieldName]

However, on a new pdf I’m using I get the following message:

Unable to cast object of type ‘Aspose.Pdf.InteractiveFeatures.Annotations.WidgetAnnotation’ to type ‘Aspose.Pdf.InteractiveFeatures.Forms.Field’.

Furthermore, when I inspect the doc.Count property I get 55 (which is the correct number), but when I query the lenth of the fields array with doc.Fields.length, I get just 25.

Seemingly, half the form fields are “WidgetAnnotations” and I’ve been unable to modify their value.

I tried a few workarounds, like trying to access the WidgetAnnotations collection via documenet.pages[index].annotations - but wasn’t able to modify text in the underlying text box.

Any help would be appreciated.

Hi Nathan,


Thanks for your inquiry. Please share your sample document. We will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Sorry for the late reply - here’s a link to the form I’m having an issue with:

http://www.state.nj.us/treasury/taxation/pdf/current/njw3m.pdf

Hi Nathan,


Thanks for sharing the resource file.

I have tested the scenario using Aspose.Pdf for .NET 9.7.0 where I have used the following code snippet and I am unable to notice any problem. The filed names are properly being returned.

[C#]

Aspose.Pdf.Document doc= new Aspose.Pdf.Document(“c:/pdftest/njw3m.pdf”); <o:p></o:p>

Console.WriteLine("Total Number of Fields = "+ doc.Form.Fields.Length);

int counter=1;

//document initialization code here

foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field field in doc.Form.Fields)

{

Console.WriteLine(counter+":- "+ field.FullName) ;

counter+=1;

}

var field2 = doc.Form["dateoftpsig2"];


Can you please try using the latest release and in case the problem still persists, please share the code snippet which can help us in replicating this issue at our end. We are sorry for your inconvenience.

Hi Nathan,


Thanks for sharing your source PDF form. I have tested the scenario with Aspose.Pdf for .NET 9.7.0 and unable to replicate the issue. Please check following code for reference.

//open document<o:p></o:p>

Document pdfDocument = new Document(myDir + "njw3m.pdf");

FormType formType = pdfDocument.Form.Type;

//Get the PDF form

Aspose.Pdf.InteractiveFeatures.Forms.Form form = pdfDocument.Form;

//get the form fields in Field array

Aspose.Pdf.InteractiveFeatures.Forms.Field[] fields = form.Fields;

//Display Field names and values

foreach (Field field in fields)

{

field.Value = "testvalue-" + field.FullName;

}

//Flatten the PDF form

pdfDocument.Flatten();

pdfDocument.Save(myDir + "Fillablefields_out.pdf");

Please feel free to contact us for any further assistance.


Best Regards,