Product: PDFTron.NET.x64
Product Version: 11.2
Hi, how can I delete a RadioButtonGroup, the RadioButtonWidgets in this group and the fields in the acroform?
I tried this: How to delete a specific digital signature field? but this code does not work for RadioButtons. (Works for TextBoxWidget, etc, but not for RadioButtons)
Thank you.
1 Like
Hi Gergely,
I’m sorry to hear that you’re facing an issue in removing a RadioButtonGroup
& similar objects. In order to support you further, I would ask that you answer the following questions:
- What .NET framework & version are you working in (.NET Core 6.0+, .NET Framework)?
- Can you specify what you are trying to remove these objects from?
- Can you provide the specific document or file that is being manipulated?
- Any additional information regarding your use case (screenshots are welcomed).
Thank you,
Kaden Rettig
Associate Technical Support Engineer
Apryse Support Team
1 Like
Hi, I am using .NET Core 8. Here is my (sample) code:
using (PDFDoc doc = new())
{
Page blank_page = doc.PageCreate();
doc.PagePushBack(blank_page);
RadioButtonGroup radio_group = RadioButtonGroup.Create(doc, "RadioGroup");
RadioButtonWidget radiobutton1 = radio_group.Add(new Rect(140, 410, 190, 460));
RadioButtonWidget radiobutton2 = radio_group.Add(new Rect(310, 410, 360, 460));
RadioButtonWidget radiobutton3 = radio_group.Add(new Rect(480, 410, 530, 460));
radiobutton3.EnableButton();
radio_group.AddGroupButtonsToPage(blank_page);
int numFields = 0;
FieldIterator itr = doc.GetFieldIterator();
for (itr = doc.GetFieldIterator(); itr.HasNext(); itr.Next())
{
++numFields;
}
Console.WriteLine("Number of fields in the document: " + numFields);
// Remove the radio buttons
blank_page.AnnotRemove(radiobutton1);
blank_page.AnnotRemove(radiobutton2);
blank_page.AnnotRemove(radiobutton3);
numFields = 0;
itr = doc.GetFieldIterator();
for (itr = doc.GetFieldIterator(); itr.HasNext(); itr.Next())
{
++numFields;
}
Console.WriteLine("Number of fields in the document after removing the radiobuttons: " + numFields);
}
It removes the widgets only but there remains 3 fields in the document. I would like to remove the fields as well.
Thank you.
Hello Gergely,
Thank you for providing your environment details & a code snippet of your current implementation. While Radio Button Groups may be added as RadioButtonGroup objects to documents, these unfortunately cannot currently be removed as easily. Is flattening an option for you, or is complete removal necessary?
If your goal is to completely remove these RBG objects from the document, you would need to use the PDFNet SDK’s SDF API to navigate the PDF at a low-level and remove the objects. We have a variety of documentation for observation in regard to the use of our low-level PDF API. I would recommend you start here, observe the SDF Object Model if you’re unfamiliar, and also take a look at our SDF sample.
Please let me know if you have any further questions.
Thank you,
Kaden Rettig
Associate Technical Support Engineer
Apryse Support Team
Hey,
If you want to get rid of the fields for good, you’re going to have to use the SDF API.
You’ll need to go through the PDF objects and remove the associated fields.
Here’s some sample code to help you out:
var field = doc.GetField("RadioGroup");
if (field != null)
{
field.Destroy();
}
If you need more info about working with the SDF API, check out https://www.pdftron.com/documentation/sdk/overview/
1 Like