1
我想添加一个复选框,使用C#的iTextSharp库。我跟着一些例子,并试图修改它们,因为它们展示了如何创建一组复选框。我如何创建一个?用iTextSharp添加一个复选框
private static void WriteFooter(Document doc, int page, int maxPages, bool lastPage, PdfWriter writer, PdfAppearance[] checkBoxAppearance)
{
if(!lastPage)
{
doc.Add(new Paragraph("\nMA-2028.1-F2(Portrait) Page " + page + " of " + maxPages, Fonts.ExtraSmall));
doc.NewPage();
} else
{
PdfContentByte cb = writer.DirectContent;
PdfFormField _checkGroup = PdfFormField.CreateRadioButton(writer, true);
RadioCheckField _radioG;
PdfFormField _radioField1;
_radioG = new RadioCheckField(writer, new Rectangle(20, 20), null, "Yes");
_radioG.CheckType = RadioCheckField.TYPE_CHECK;
_radioField1 = _radioG.RadioField;
_checkGroup.AddKid(_radioField1);
ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, new Phrase("No Users Require Deletion"), 20, 20, 0);
writer.AddAnnotation(_checkGroup);
cb = writer.DirectContent;
doc.Add(
new Paragraph(
"Operations Management:\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER });
doc.Add(
new Paragraph(
"Automation Manager or Designee: \n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER });
}
}
写入器和checkBoxAppearance从另一个函数传入。以前在我的代码中,我创建了一个带有复选框的表格,但我需要在此表格之外添加一个表格。我遵循http://simpledotnetsolutions.wordpress.com/2012/11/01/itextsharp-creating-form-fields/的代码
checkBoxAppearance是一个数组,它定义了复选框的行为。
并试图修改它只有一个复选框。我也试图让文本显示在旁边。
编辑: 我也想这样:
private static void WriteFooter(Document doc, int page, int maxPages, bool lastPage, PdfWriter writer, PdfFormField checkboxField, PdfAppearance[] checkbox, PdfContentByte cb)
{
if(!lastPage)
{
doc.Add(new Paragraph("\nMA-2028.1-F2(Portrait) Page " + page + " of " + maxPages, Fonts.ExtraSmall));
doc.NewPage();
} else
{
PdfFormField field;
RadioCheckField checkBox;
for (int i = 0; i < 1; i++)
{
checkBox = new RadioCheckField(writer, new Rectangle(20, 20), "noDelete", "Yes");
field = checkBox.CheckField;
field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", checkbox[0]);
field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", checkbox[1]);
writer.AddAnnotation(field);
//ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, new Phrase("No Users Need Deletion"), 210, 790, 0);
}
doc.Add(
new Paragraph(
"Operations Management:\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER });
doc.Add(
new Paragraph(
"Automation Manager or Designee:\n\n", Fonts.Small) { Alignment = Element.ALIGN_CENTER });
}
}
这是一个绝对的耻辱,这不适用于iTextSharp v5.5.11 – CarneyCode