Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jan 10, 2022 1:55 pm

Hello!

For several hours I have been trying to set the selected index/value on a comboBoxField, so it can show up as default when opening the PDF generated, but to no avail. I can see that while debugging my SelectedIndex, SelectedItem, and SelectedValue are populated with the value I want as default, but when the PDF is generated, the dropdown is blank (but the options are available to be selected). I dont have any problems with PdfTextBoxField, those are being populated just fine. My code for the ComboboxField is the following (I'm trying to hardcode the first option as selected index to test):

Code: Select all
PdfComboBoxField comboBoxField = new PdfComboBoxField(page, fieldId);
                        comboBoxField.Bounds = new RectangleF(fieldX + fieldMaxWidth + 2, fieldY, fieldMaxWidth, fieldHeight);
                        comboBoxField.BorderWidth = 0.75f;
                        comboBoxField.BackColor = Color.LightSkyBlue;
                        comboBoxField.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);
                        comboBoxField.Editable = true;
foreach (XPathNavigator itemNode in itemNodes)
                        {
                            String text = itemNode.SelectSingleNode("text()").Value;
                            comboBoxField.Items.Add(new PdfListFieldItem(text, text));
                        }
comboBoxField.SelectedIndex = 0;
form.Fields.Add(comboBoxField);


Everything works except for this selected index. Please let me know your thoughts on this code.

Best,

Diego

diegomzal
 
Posts: 2
Joined: Mon Jan 10, 2022 1:42 pm

Tue Jan 11, 2022 2:03 am

Hello,

Thank you for your inquiry.
I did an initial test with your code, but didn't reproduce the issue you mentioned. The version I used is the latest version(Spire.PDF Pack Version:8.1). If you were not using the latest version, please first give it a try. If the issue still exists after trying, please provide the following information for our reference. You could attach them here or send them to us via email ([email protected]). Thanks in advance.
1) Your input PDF file (if any).
2) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
3) Your application type, such as Console app (. Net Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Tue Jan 11, 2022 1:35 pm

Hello

thanks for your kind reply!

Please note that Im using FreeSpirePdf v7.8.9. Im not using an input PDF; since Im completely generating it from code. Im currently using Windows 10 64bits and my region setting is English, United States. My application type would be Web App, using .Net Framework 4.7.2.

Best,

Diego

diegomzal
 
Posts: 2
Joined: Mon Jan 10, 2022 1:42 pm

Wed Jan 12, 2022 3:55 am

Hello,

Thank you for your sharing.
I tested your code in the same environment with the same settings as you, but still did not reproduce your issue. I have attached my result file. I view PDFs using Adobe Acrobat Reader DC (version 2021.007.20099). Are you using this PDF reader? If not, I suggest that you use it first to see the result file I provided.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF