I'm creating "labels" and textboxes and checkboxes using iTextSharp, but my attempts to derive from that code to create buttons has not yet been successful.
Here is how I'm creating textBoxes:
PdfPCell cellRequesterNameTextBox = new PdfPCell()
{
CellEvent = new DynamicTextbox("textBoxRequesterName")
};
tblFirstRow.AddCell(cellRequesterNameTextBox);
. . .
public class DynamicTextbox : IPdfPCellEvent
{
private string fieldname;
public DynamicTextbox(string name)
{
fieldname = name;
}
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].PdfWriter;
float textboxheight = 11f;
Rectangle rect = rectangle;
rect.Bottom = rect.Top - textboxheight;
TextField text = new TextField(writer, rect, fieldname);
PdfFormField field = text.GetTextField();
writer.AddAnnotation(field);
}
}
And here is how I'm creating checkboxes:
PdfPCell cell204Submitted = new PdfPCell()
{
CellEvent = new DynamicCheckbox("checkbox204Submitted")
};
tblLastRow.AddCell(cell204Submitted);
. . .
public class DynamicCheckbox : IPdfPCellEvent
{
private string fieldname;
public DynamicCheckbox(string name)
{
fieldname = name;
}
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].PdfWriter;
RadioCheckField ckbx = new RadioCheckField(writer, rectangle, fieldname, "Yes");
ckbx.CheckType = RadioCheckField.TYPE_CHECK;
ckbx.BackgroundColor = new BaseColor(255, 197, 0);
ckbx.FontSize = 6;
ckbx.TextColor = BaseColor.WHITE;
PdfFormField field = ckbx.CheckField;
writer.AddAnnotation(field);
}
}
And here is how I'm attempting to create buttons:
PdfPCell cellButton1 = new PdfPCell()
{
CellEvent = new DynamicButton("button1")
};
tblButtonRow.AddCell(cellButton1);
. . .
public class DynamicButton : IPdfPCellEvent
{
private string fieldname;
public DynamicButton(string name)
{
fieldname = name;
}
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].PdfWriter;
float buttonheight = 24f;
Rectangle rect = rectangle;
PushbuttonField btn = new PushbuttonField(writer, rect, fieldname);
PdfFormField field = btn.Field; // <= what should this be?
writer.AddAnnotation(field);
}
}
What's missing or wrong in the last (button) code? I'm thinking my assignment to "field" in DynamicButton.CellLayout() must be wrong, but what should it be?
Here is how the "buttons" look (the long skinny lines at the bottom, beneath the checkbox and its associated text/label):
How can I plump up/hydrate those twiggified "buttons"?