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

Free Support Forum - aspose.com

Issue with deleting form fields

Dear Support,

I want to scan the document and obtain all the adobe fillable fields (step 1), get their information and then remove them from the document (step 2) as seen below:

//Step 1: Get all Adobe fields.
Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(copy_filename);

//get all field names
String[] allfields = form.FieldNames;
Aspose.Pdf.Facades.FormFieldFacade fieldfacade = null;

foreach (string mFieldName in allfields)
{

fieldfacade = form.GetFieldFacade(mFieldName);

//Step 2: remove the Adobe fields.
Aspose.Pdf.Facades.FormEditor formEditor = new Aspose.Pdf.Facades.FormEditor();
formEditor.BindPdf(root + “/” + id + “.pdf”);

//delete field

formEditor.RemoveField(mFieldName);
formEditor.Save(filename); // save this to filename which is original.
formEditor.Close();
}

For the attached example documents, Paycheck.pdf seems to work fine with no problem or errors.

However, for the document AdobeApplication2014.pdf, I get an error at the following line:
formEditor.RemoveField(mFieldName);

Message:
{“Message”:“An error has occurred.”,“ExceptionMessage”:“Object reference not set to an instance of an object.”,“ExceptionType”:“System.NullReferenceException”,“StackTrace”:" at Aspose.Pdf.InteractiveFeatures.Forms.Field.\u0019\u0003(String )\r\n at Aspose.Pdf.InteractiveFeatures.Forms.Form.\u0019\u0003(String )\r\n at Aspose.Pdf.InteractiveFeatures.Forms.Form.Delete(String fieldName)\r\n at Aspose.Pdf.InteractiveFeatures.Forms.Form.Delete(Field field)\r\n at Aspose.Pdf.Facades.FormEditor.RemoveField(String fieldName)\r\n at FieldGeneratorSystem.Controllers.DocumentController.GetAdobeFields() in c:\Users\Jonathan\Documents\GitHub\SNAsposeNet\FieldGeneratorSystem\Controllers\DocumentController.cs:line 203\r\n at FieldGeneratorSystem.Controllers.DocumentController.GetDocumentFields(String filename, String userDefinedTags) in c:\Users\Jonathan\Documents\GitHub\SNAsposeNet\FieldGeneratorSystem\Controllers\DocumentController.cs:line 132\r\n at FieldGeneratorSystem.Controllers.DocumentController.<>c__DisplayClass37.b__36(Task1 t) in c:\\Users\\Jonathan\\Documents\\GitHub\\SNAsposeNet\\FieldGeneratorSystem\\Controllers\\DocumentController.cs:line 348\r\n at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()\r\n at System.Threading.Tasks.Task.Execute()"}

What could be the problem with the second document? Is the formEditor null? If yes, why? How can I solve it?

Thank you,
Sireesha

Hi Sireesha,


<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””>Thanks
for using our API’s.<o:p></o:p>

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-37812. We will investigate this issue in details and will keep you updated on the status of a correction.

We apologize for your inconvenience.