我正在尝试使用ComboBox
将iTextSharp
添加到打印的PDF的单元格中,但是它没有出现在生成的PDF中。相反,打印出来的只是一个没有下拉菜单的空白单元格。
我不确定是什么原因造成的,但是现在我很沮丧。我在网上也遵循了其他示例,例如this one here,但是我无法复制它。
我应该注意的一件事是,我们使用的iTextSharp
的版本是1.4.3,它是iTextSharp
4.1.6的端口,这使其与.net内核兼容,因此不确定是否较旧版本可能是造成这种情况的原因。
这是我当前的代码。我在做什么错?
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);
}
和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());
}
}