【发布时间】:2014-03-05 10:23:23
【问题描述】:
我正在尝试使用适用于 C# 的 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 });
}
}
writer 和 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 });
}
}
【问题讨论】: