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.<PostDocument>b__36(Task`1 t) in c:\\Users\\Jonathan\\Documents\\GitHub\\SNAsposeNet\\FieldGeneratorSystem\\Controllers\\DocumentController.cs:line 348\r\n at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.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
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.<PostDocument>b__36(Task`1 t) in c:\\Users\\Jonathan\\Documents\\GitHub\\SNAsposeNet\\FieldGeneratorSystem\\Controllers\\DocumentController.cs:line 348\r\n at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.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