Delete fields functionality doesn't work

Hello,

Could you please help me to delete radio button options? It seems like field remove functionality doesn’t work in appropriate way. I have three radio buttons on my file. Here is my code sample:

using (Aspose.Pdf.Document document = new Aspose.Pdf.Document(@"C://result.pdf"))
{
    var fields = document.Form.Fields.ToList();
    var editor = new FormEditor();
    editor.BindPdf(document);

    foreach (var field in fields)
    {
        document.Form.Delete(field);
        editor.RemoveField(field.Name);
        editor.DelListItem(field.Name, field.ToString());
    }
    document.Save(@"C://without_fields.pdf");
}

Am I doing something wrong? Cause none of these methods work for me…

files.zip (13.0 KB)
result.png (36.2 KB)

@vitaliy1924

We were able to notice that API was unable to delete the form fields from the PDF when we tested the scenario using 21.7 version of the API at our end. Hence, we have logged an issue as PDFNET-50268 in our issue tracking system for further investigation. We will look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

@vitaliy1924

To delete sub-fields of RadioButtonField you can use the following code:

Document doc = new Document(pdf_input);
RadioButtonField radio = doc.Form[1] as RadioButtonField;
foreach (var subfield in radio)
{
   doc.Form.Delete(subfield as Field);
}
doc.Save(pdf_output);

Just replace pdf_input and pdf_output with your file paths. Also, you can remove subfields by the index as doc.Form.Delete(radio[1…n] as Field);