We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Error when clicking submit button if all radio buttons not checked/reclicked

Hoping someone can help as i have seen similar posts but no-one has got a final answer.


Basically if i create a new pdf as outlined in the code below (However has multiple sections which has multiple sections and radio buttons) if you click the submit button which is added at the end you get an error.

The error goes away and the submit button works as expected if you go through every radio button on the generated pdf and manually reclick it even if it already has a value selected. It dosent seem to make a difference if you set a selected value in the code or not.

I am using the latest version of aspose with this.

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Add a section in the Pdf document
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

//Create a table, set its column widths and add it to paragraphs collection
//of the section
Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
tab1.ColumnWidths = “120 120”;
sec1.Paragraphs.Add(tab1);
//create rows
for (int r = 0; r < 3; r++)
{
//Add a row to the table
Aspose.Pdf.Generator.Row r1 = tab1.Rows.Add();
Aspose.Pdf.Generator.FormField radio = new Aspose.Pdf.Generator.FormField();

//Create a form field of RadioButton type. Set its field name and button color.
//Then set the index of the radio button value to be checked
radio.FormFieldType = Aspose.Pdf.Generator.FormFieldType.RadioButton;
radio.FieldName = “ARadio” + r;
radio.ButtonColor = System.Drawing.Color.FromName(“Red”);
radio.RadioButtonCheckedIndex = 0;
radio.IsBordered = true;
radio.BorderColor = System.Drawing.Color.FromName(“Yellow”);
// create cells
for (int c = 0; c < 2; c++)
{ //Add 1st cell to the row, set its padding and set the ID of the first paragraph
//in the cell to “text1”
Aspose.Pdf.Generator.Cell c1 = r1.Cells.Add(“item1” + r + c);
c1.Padding.Left = 30;
c1.Paragraphs[0].ID = “text1” + r + c;
//Create radio button instance and add it to above created radio form field.
//Set its width and height. The position of the radio button is set to be
//relative to the paragraph. Link this radio button with the paragraph with ID
//equal to cell text
Aspose.Pdf.Generator.RadioButton bt1 = radio.RadioButtons.Add();
bt1.ButtonHeight = 12;
bt1.ButtonWidth = 12;
bt1.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
bt1.ReferenceParagraphID = “text1” + r + c;
bt1.Left = -20;
bt1.Top = 0;


}
//Add the radio form field to the paragraphs collection of the section
sec1.Paragraphs.Add(radio);
}


MemoryStream stream = new MemoryStream();
pdf1.Save(stream);

FormEditor fe = new FormEditor(stream, stream);
fe.AddSubmitBtn(“Submit”, pdf.PageCount , “Save”, string.Format(@"{0}/en/Submit/Render/SaveOfflineDocument?applicationformid={1}",Settings.General.PortalURL, applicationForm.ID.ToString()), 500, 400, 550, 425);
fe.Save(stream);


return stream;

Hi Graeme,


Thanks for your inquiry, I've managed to reproduce the issue at my end and logged it as PDFNEWNET-34897 in our issue tracking system for further investigation and resolution. We will keep you updated regarding issue status via this thread.


Sorry for the inconvenience faced.


Best Regards,

Is there an ETA for this yet as it is becoming quite urgenmt?


Graeme

Is there an ETA for this yet as it is becoming quite urgent?


Graeme

Hi Graeme,


Sorry for
the inconvenience faced. I’m afraid, the reported issue is still not resolved
due to some other priority tasks and it’s pending in the queue for analysis. I’ve recorded your concerns regarding the urgency of the matter and requested
the development team to share the ETA at their earliest and as soon as I get a
feedback I’ll update you via this forum thread.

Thanks for
your patience and understanding.

Best Regards

Hi Graeme,


Thanks for your patience. It is recommended to use new generator( Aspose.Pdf) instead old generator (Aspose.Pdf.Generator). New generator is more improved and efficient, it can be used for both creating a new PDF from scratch or edit existing PDF document. Please check following code snippet for your scenario.

Document doc = new
Document();<o:p></o:p>

Aspose.Pdf.Page page = doc.Pages.Add();

//Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Add a section in the Pdf document

//Create a table, set its column widths and add it to paragraphs collection

//of the section

Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();

tab1.ColumnWidths = "120 120";

page.Paragraphs.Add(tab1);

//create rows

for (int r = 0; r < 3; r++)

{

//Add a row to the table

Aspose.Pdf.Row r1 = tab1.Rows.Add();

//Aspose.Pdf.FormField radio = new Aspose.Pdf.Generator.FormField();

//Create a form field of RadioButton type. Set its field name and button color.

//Then set the index of the radio button value to be checked

RadioButtonField radio = new RadioButtonField(doc);

radio.PartialName = "ARadio" + r;

for (int c = 0; c < 2; c++)

{ //Add 1st cell to the row, set its padding and set the ID of the first paragraph

Aspose.Pdf.Cell c1 = r1.Cells.Add("");

RadioButtonOptionField bt1 = new RadioButtonOptionField();

bt1.Width = 12;

bt1.Height = 12;

bt1.OptionName = "text1" + r + c;

radio.Add(bt1);

bt1.Border = new Border(bt1);

bt1.Border.Width = 1;

bt1.Border.Style = Aspose.Pdf.InteractiveFeatures.Annotations.BorderStyle.Solid;

bt1.Characteristics.Border = System.Drawing.Color.Black;

bt1.DefaultAppearance.TextColor = System.Drawing.Color.Red;

bt1.Caption = new TextFragment("Item " + c + " " + r);

c1.Paragraphs.Add(bt1);

}

//Add the radio form field to the paragraphs collection of the section

page.Paragraphs.Add(radio);

}

MemoryStream stream = new MemoryStream();

doc.Save(stream);

FormEditor fe = new FormEditor();

fe.BindPdf(stream);

fe.AddSubmitBtn("submitbutton", 1, "Submit", "http://localhost/PDFGeneration/PostData.asmx/SubmitData", 100, 450, 150, 475);

fe.Save("34897-1.pdf");


Please feel free to contact us for any further assistance.


Best Regards,