我正在从iTextSharp创建PdfTable,但包含此表的pdf不允许在其单元格中进行编辑。
如何确保在生成的pdf中可以编辑单元格内容?
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(columnsToAdd);
table.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
Font headerFont = new Font(Font.HELVETICA, 8f, Font.BOLD, Color.BLACK);
Font bodyFont = new Font(Font.HELVETICA, 6f, Font.NORMAL, Color.BLACK);
PdfPCell cEmpId = new PdfPCell(new Phrase("Emp ID", headerFont));
PdfPCell cEmpAge = new PdfPCell(new Phrase("Emp Age", headerFont));
table.AddCell(cEmpId);
table.AddCell(cEmpAge);
foreach(Child child in childData)
{
PdfPCell cellEmpID = new PdfPCell {FixedHeight = 10f};
cellEmpID.Phrase = (new Phrase(child.Emp_ID.ToString(CultureInfo.InvariantCulture),
bodyFont));
PdfPCell cellEmpAge = new PdfPCell {Phrase = (new Phrase(child.Emp_Age, bodyFont))};
table.AddCell(cellEmpID);
table.AddCell(cellEmpAge);
}
编辑1: 根据Chris的回答,我将尝试以下代码,但目前还不确定。
//WITHIN THE LOOP IN MY CODE ABOVE ADD THESE LINES FOR EVERY PDF CELL
//Create our textfield, the rectangle that we're passing in is ignored and doesn't matter
var tfEmpID = new TextField(writer, new iTextSharp.text.Rectangle(0, 0), child.Emp_ID);
//Set the cell event to our custom IPdfPCellEvent implementation
cellEmpID.CellEvent = new ChildFieldEvent(root, tfEmpID.GetTextField(), 1);
//THEN OUTSIDE THE LOOP
//IMPORTANT! Add the root annotation to the writer which also adds all of the child annotations
writer.AddAnnotation(root);