Deleting All Buttons on Document Before Flattening

My document has 11 buttons on it. I am using the following code to loop through all the fields and remove the buttons before flattening the document.

For Each formField As Field In pdfDocument.Form
If formField.GetType().Name = "ButtonField" Then
pdfDocument.Form.Delete(formField.PartialName)
End If
Next (formField)
For Each formField As Field In pdfDocument.Form
If formField.GetType().Name = "ButtonField" Then
pdfDocument.Form.Delete(formField.PartialName)
End If
Next (formField)

The first loop through the document finds btnOverflowOperators, btnOverflowRVs, btnOverflowPolicy, btnFinish, and btnSave.

It is missing btnOverflowWatercraft, btnClear, and btnOverflowVehicles.

A second pass through the same loop removes btnOverflowWatercraft and btnClear.

And I have to make a third pass to find and remove btnOverflowVehicles.

Why isn't my code recognizing all the buttons on the first pass?

Hi Diane,


Thanks for your inquiry. I am afraid while testing the scenario with Aspose.Pdf for .NET 9.2.0, we are unable to notice the issue. If you are using some old API version then please download and try latest version, It will fix the issue. Otherwise, if issue persist then please share your environment details so we will try to replicate issue for further investigation.

Dim pdfDocument As New
Document(myDir + “UMPF2752MO.pdf”)<o:p></o:p>

'Get the PDF form

Dim form As Aspose.Pdf.InteractiveFeatures.Forms.Form = pdfDocument.Form

'get fields in the rectangular area

Dim fields As Aspose.Pdf.InteractiveFeatures.Forms.Field() = form.Fields

For Each formField As Field In fields

If formField.[GetType]().Name = "ButtonField" Then

'Console.WriteLine("Field Name : {0} ", formField.PartialName);

pdfDocument.Form.Delete(formField.PartialName)

End If

Next

pdfDocument.Save(myDir + "UMPF2752MO_out.pdf")

We are sorry for the inconvenience caused.


Best Regards,




Thank you.

I upgraded to 9.2 and the problem went away.

Thanks, Diane

Hi Diane,


Thanks for your feedback. It is good to know that you have managed to accomplish your requirements.

Please feel free to contact us for any further assistance, we will be more than happy to extend our support.

Best Regards,