iTextSharp CheckBox进入PdfPCell

时间:2015-04-20 14:57:32

标签: c# itextsharp

我想创建一个PDF文档。我创建了一个包含2列的表。我曾经使用PdfPCell将我的数据放入表中。

PDFWriterEvents epm = new PDFWriterEvents();

writer.PageEvent = epm;

document.Open();

cb = writer.DirectContent;

PdfPTable tableau = new PdfPTable(2);

tableau.WidthPercentage = 100;
BaseFont f = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
int iTailleEcriture = 10;
int r, v, b, a;
r = 205;
v = 32;
b = 101;
a = 64;
BaseColor c = new BaseColor(r, v, b, a);
BaseColor couleurEcriture = new BaseColor(255, 255, 255);
PdfPCell cell1 = new PdfPCell(new Phrase("Droit", new Font(f, iTailleEcriture, Font.BOLD, couleurEcriture)));
PdfPCell cell2 = new PdfPCell(new Phrase("Oui / Non", new Font(f, iTailleEcriture, Font.BOLD, couleurEcriture)));
cell1.BackgroundColor = c;
cell2.BackgroundColor = c;
tableau.SetWidths(widths);
cell1.HorizontalAlignment = Element.ALIGN_CENTER;
cell2.HorizontalAlignment = Element.ALIGN_CENTER;
cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
tableau.AddCell(cell1);
tableau.AddCell(cell2);
cell1 = new PdfPCell(new Phrase(acces.DESCRIPTION, new Font(f, iTailleEcriture)));

RadioCheckField _radioG;
cell2 = new PdfPCell();
_radioG = new RadioCheckField(writer, new iTextSharp.text.Rectangle(0, 0), "", "Yes");
_radioG.CheckType = RadioCheckField.TYPE_CHECK;
_radioG.Checked = d.OUI_NON;
cell2.FixedHeight = 22;
cell2.Border = PdfPCell.RIGHT_BORDER;
iTextSharp.text.pdf.events.FieldPositioningEvents kid = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer, _radioG.CheckField, "checks");
kid.Padding = 0.5F;
cell2.CellEvent = kid;

cell1.HorizontalAlignment = Element.ALIGN_LEFT;
cell2.HorizontalAlignment = Element.ALIGN_CENTER;
cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
tableau.AddCell(cell1);
tableau.AddCell(cell2);
document.Add(tableau);

cb = writer.DirectContent;

但是这段代码无法正常工作。我有我的所有文字但不是我的复选框。为什么?

0 个答案:

没有答案