Reputation: 41
I tried this code using iTextSharp 5.5.13 in C#:
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filename,FileMode.Create, FileAccess.Write));
document.Open();
document.Add(new Paragraph("Hello World!"));
PdfFormField field = PdfFormField.CreateSignature(writer);
field.setFieldName(SIGNAME);
field.SetPage();
field.SetWidget(new iTextSharp.text.Rectangle(72, 732, 144, 780), PdfAnnotation.HIGHLIGHT_INVERT);
field.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
writer.AddAnnotation(field);
PdfAppearance tp = PdfAppearance.CreateAppearance(writer, 72, 48);
tp.SetColorStroke(BaseColor.BLUE);
tp.SetColorFill(BaseColor.LIGHT_GRAY);
tp.Rectangle(0.5f, 0.5f, 71.5f, 47.5f);
tp.FillStroke();
tp.SetColorFill(BaseColor.BLUE);
ColumnText.ShowTextAligned(tp, Element.ALIGN_CENTER,
new Phrase("SIGN HERE"), 36, 24, 25);
field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
document.Close();
Everthing was perfect except setFieldName
.
At setFieldName
there was an error shown:
Error CS1061 'PdfFormField' does not contain a definition for '
setFieldName
' and no extension method 'setFieldName
' accepting a first argument of type 'PdfFormField
' could be found (are you missing a using directive or an assembly reference?)
And how to set font size of
ColumnText.ShowTextAligned(tp, Element.ALIGN_CENTER, new Phrase("SIGN HERE"), 36, 24, 25);
Upvotes: 1
Views: 2031
Reputation: 8104
Try to write instad of setFieldName
:
field.FieldName = SIGNAME;
Upvotes: 1