Hello!
We’re trying to build a PDF in .NET and are in need of a broad range of form inputs. While working through the examples provided in the documentation, we’ve come across an issue with the RadioButtonField. Specifically, this issue seems to arise while using Kofax Power PDF as the PDF viewer. When multiple form inputs are added to a document, any added after the RadioButtonField with options, is not showing in Power PDF.
The code we are using is as follows:
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
Document doc = new Document();
Page page = doc.Pages.Add();
// Create a field
TextBoxField textBoxField = new TextBoxField(doc.Pages[1], Rectangle.Trivial)
{
Name = "text box",
PartialName = "text box",
MappingName = "text box",
AlternateName = "text box",
Width = 150,
Height = 12,
IsInLineParagraph = true
};
page.Paragraphs.Add(new TextFragment("This is a textbox") { IsKeptWithNext = true });
page.Paragraphs.Add(textBoxField);
// Add field to the document
doc.Form.Add(textBoxField, 1);
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = "120 120 120";
page.Paragraphs.Add(table);
Row r1 = table.Rows.Add();
Cell c1 = r1.Cells.Add();
Cell c2 = r1.Cells.Add();
Cell c3 = r1.Cells.Add();
RadioButtonField rf = new RadioButtonField(page);
rf.PartialName = "radio";
RadioButtonOptionField opt1 = new RadioButtonOptionField(page, Rectangle.Trivial);
RadioButtonOptionField opt2 = new RadioButtonOptionField(page, Rectangle.Trivial);
RadioButtonOptionField opt3 = new RadioButtonOptionField(page, Rectangle.Trivial);
opt1.OptionName = "Item1";
opt2.OptionName = "Item2";
opt3.OptionName = "Item3";
opt1.Caption = new TextFragment("Item1");
opt2.Caption = new TextFragment("Item2");
opt3.Caption = new TextFragment("Item3");
opt1.Width = 15;
opt1.Height = 15;
opt2.Width = 15;
opt2.Height = 15;
opt3.Width = 15;
opt3.Height = 15;
rf.Add(opt1);
rf.Add(opt2);
rf.Add(opt3);
opt1.Border = new Border(opt1);
opt1.Border.Width = 1;
opt1.Border.Style = BorderStyle.Solid;
opt1.Characteristics.Border = System.Drawing.Color.Black;
opt1.DefaultAppearance.TextColor = System.Drawing.Color.Red;
opt1.Caption = new TextFragment("Item1");
opt2.Border = new Border(opt1);
opt2.Border.Width = 1;
opt2.Border.Style = BorderStyle.Solid;
opt2.Characteristics.Border = System.Drawing.Color.Black;
opt2.DefaultAppearance.TextColor = System.Drawing.Color.Red;
opt2.Caption = new TextFragment("Item2");
opt3.Border = new Border(opt1);
opt3.Border.Width = 1;
opt3.Border.Style = BorderStyle.Solid;
opt3.Characteristics.Border = System.Drawing.Color.Black;
opt3.DefaultAppearance.TextColor = System.Drawing.Color.Red;
opt3.Caption = new TextFragment("Item3");
c1.Paragraphs.Add(opt1);
c2.Paragraphs.Add(opt2);
c3.Paragraphs.Add(opt3);
doc.Form.Add(rf, 1);
TextBoxField textAreaField = new TextBoxField(doc.Pages[1], Rectangle.Trivial)
{
Name = "text area",
PartialName = "text area",
MappingName = "text area",
AlternateName = "text area",
Width = 50,
Height = 50,
Multiline = true,
IsInLineParagraph = false
};
page.Paragraphs.Add(new TextFragment("This is a textarea") { IsKeptWithNext = true });
page.Paragraphs.Add(textAreaField);
// Add field to the document
doc.Form.Add(textAreaField, 1);
dataDir = dataDir + "RadioButtonWithOptions_out.pdf";
// Save the PDF file
doc.Save(dataDir);
// ExEnd:RadioButtonWithOptions
Console.WriteLine("\nFields added successfully.\nFile saved at " + dataDir);
There’s also a change needed to the RadioButtonOptionFields, we had to call the constructor that accepted page and rectangle objects, or the radio buttons themselves would not show in Power PDF either.
Other than the RadioButtonField class not accepting a Rectangle as a constructor argument like many of the other Fields, there isn’t much difference in them that we can tell.
Is this a known issue? Or, is there something wrong with using these fields in conjunction in the way we are attempting to do it?
We’ve also updated to the most recent nuget package version (23.8.0).
Thanks!