Posted by a ceTe Software moderator
Hi Robert,
There is no direct option to modify or add a new item to an existing combo box in a PDF. You can remove the existing combo box and add a new one in that place by adding required items.
Here is a code sample to get items, dimensions and positions of an existing combo box and add new one by modifying the items.
PdfDocument pdf = new PdfDocument(@"Source PDF file path");
MergeDocument document = new MergeDocument(pdf);
PdfChoiceField field = (PdfChoiceField)pdf.Form.Fields["cmbox1"];// cmbox1 is existing combo box form field name
string[] arrItems = field.GetItems();
//Modicy the items in the list as per yur requirements.
arrItems[0] = "New item";
//Get the postions of existing Combobox and add new one using retrived values.
int pageNumber = pdf.Form.Fields["cmbox1"].GetOriginalPageNumber() - 1;
Page page = document.Pages[pageNumber];
float xPos = pdf.Form.Fields["cmbox1"].GetX(page);
float yPos = pdf.Form.Fields["cmbox1"].GetY(page);
float width = pdf.Form.Fields["cmbox1"].Width;
float height = pdf.Form.Fields["cmbox1"].Height;
//Remove existing combo box and add a new one.
document.Form.Fields["cmbox1"].Output = FormFieldOutput.Remove;
ComboBox comboBoxObj = new ComboBox("cmbox2", xPos, yPos, width, height);
for (int i = 0; i < arrItems.Length; i++)
{
comboBoxObj.Items.Add(arrItems[i]);
}
page.Elements.Add(comboBoxObj);
document.Draw(@"C:\Temp\Mydocument.pdf");
Thanks,
ceTe DynamicPDF Support Team