Setting values for Grouped Radio-Button fields

Posted by: pramod.gurshaney on 24 April 2020, 1:30 am EST

  • Posted 24 April 2020, 1:30 am EST

    I am using the following code to open a ParForm.pdf, set field values and then return the updated pdf as test.pdf. I am able to successfully set the values in the Text fields (“Date”, “Date Received”, “From”, “Position Location”) but I am unable to set the values for 3 RadioButtons grouped with a common name of “Group1”. Please let me know how to set the grouped radio button values. Thanks.

    
    public FileResult HandleFormDataSubmit()
            {
                var fields = new Dictionary<string, StringValues>
                {
                    { "Date", "02/03/2020" },
                    { "Date Received", "02/04/2020" },
                    { "Group1", new StringValues(new string[] { "Off", "Off", "On" }) },
                    { "From", "First Last" },
                    { "Position Location", "MyCity" }
                };
    
                var values = fields.ToList();
                var fieldValues = values.Select(kvp_ => new KeyValuePair<string, IList<string>>(kvp_.Key, kvp_.Value.ToArray())).ToArray();
                var ms = ImportFormData(fieldValues);
                var result = new FileStreamResult(ms, "application/pdf")
                {
                    FileDownloadName = "Test.pdf"
                };
                return result;
            }
    
            public static Stream ImportFormData(KeyValuePair<string, IList<string>>[] fieldValues)
            {
                GcPdfDocument pdf = new GcPdfDocument();
                var pdfFile = Path.Combine("Resources", "PDFs", "ParForm.pdf");
                using var fs = new FileStream(pdfFile, FileMode.Open, FileAccess.Read);
                pdf.Load(fs);
                pdf.ImportFormDataFromCollection(fieldValues);
                var outMs = new MemoryStream();
                pdf.Save(outMs);
                outMs.Seek(0, SeekOrigin.Begin);
                return outMs;
            }
    
    
  • Posted 24 April 2020, 2:37 am EST

  • Posted 27 April 2020, 1:04 pm EST

    Hello,

    It’s good to hear that the issue has been fixed at your end.

    If you need any other help, please let us know.

    Regards,

    Prabhat

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels