I am trying to add a ComboBox to a cell in my printed PDF using iTextSharp, however it is not appearing in the generated PDF. Instead what prints out is just a blank cell with no drop down.
I am not entirely sure what is causing this but I am now pretty stumped. I have followed other examples online like in this one here, however I could not replicate it.
One thing I should note, the version of iTextSharp we are using is 1.4.3 which is a port of iTextSharp 4.1.6 which made it .net core compatible so not sure if an older version would be the cause of this.
This is my current code. What am I doing incorrectly?
if (_dropDownCol)
{
PdfFormField selectGroup = PdfFormField.CreateEmpty(_Writer);
String[] options = { "Choose first option", "Choose second option", "Choose third option" };
String[] exports = { "option1", "option2", "option3" };
var comboBox = new PdfPCell();
comboBox.CellEvent = new SelectCellEvent(GetTaskDropDownValueID(task, digitalDocument), selectGroup, Orientation, "combo1", exports, options);
comboBox.MinimumHeight = 20;
taskArea.AddCell(comboBox);
}
and the SelectedCellEvent
public class SelectCellEvent : IPdfPCellEvent
{
private string _ID { get; set; }
protected PdfFormField selectGroup;
protected String name;
protected String[] exports;
protected String[] options;
protected BaseFont font;
private int _Rotation { get; set; }
public SelectCellEvent(string id, PdfFormField selectGroup, PDFOrientation orientation, string name, string[] exports, string[] options)
{
_ID = id;
this.selectGroup = selectGroup;
this.name = name;
this.exports = exports;
this.options = options;
font = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
_Rotation = orientation == PDFOrientation.Portrait ? 0 : 90;
}
public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
{
position.Left = position.Left + cell.PaddingLeft;
PdfWriter writer = canvases[0].PdfWriter;
TextField tf = new TextField(writer, position, _ID);
tf.BorderStyle = PdfBorderDictionary.STYLE_BEVELED;
tf.BorderColor = BaseColor.Gray;
tf.ChoiceExports = exports;
tf.Choices = options;
tf.Alignment = Element.ALIGN_CENTER;
selectGroup.AddKid(tf.GetComboField());
}
}