【发布时间】:2016-12-20 13:06:21
【问题描述】:
我将 TextFields 替换为签名字段,但无法在生成的 PDF 中看到这些空白签名字段。 客户在后期需要这些空白字段进行数字签名。
/// <summary>
/// Adds a text field to the report that the user can update signatures to the specified location.
/// </summary>
/// <param name="writer">pdfwriter of document.</param>
/// <param name="xPosition">The lower left x position of the text field.</param>
/// <param name="yPosition">The lower left y position of the text field.</param>
/// <param name="width">The width of the text field.</param>
/// <param name="height">The height of the text field.</param>
/// <param name="fieldId"></param>
protected virtual void AddTextField(iTextSharp.text.pdf.PdfWriter writer, String fieldId, float xPosition, float yPosition, float width, float height)
{
Rectangle position = new Rectangle(xPosition, yPosition, xPosition + width, Math.Max(yPosition - height, 0));
iTextSharp.text.pdf.TextField field = new iTextSharp.text.pdf.TextField(writer, position, fieldId);
// Requirement is to change existing textFields to blank Signature fields
// In the method, memoryStream, reader and stamper are not available.
// Below is the textField I need to transform into Signature field.
// field.Text = String.Empty;
// field.Font = FontFactory.GetFont("Arial Narrow").BaseFont;
// field.TextColor = Color.WHITE;
// field.FontSize = 9;
// Not seeing the signature field appear on the pdf.
// Don't know exactly the reason
PdfFormField sig = PdfFormField.CreateSignature(writer);
sig.SetWidget(position, null);
sig.Flags = PdfAnnotation.FLAGS_PRINT;
sig.Put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g"));
sig.FieldName = fieldId;
sig.SetPage();
writer.AddAnnotation(sig);
//Also tried below code
//PdfFormField pfield = PdfFormField.CreateSignature(writer);
//pfield.FieldName = fieldId;
//pfield.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
//pfield.SetWidget(position, null);
//pfield.SetPage();
//pfield.MKBorderColor = Color.BLACK;
//pfield.MKBackgroundColor = Color.BLUE;
//PdfAppearance tp = PdfAppearance.CreateAppearance(writer, width, height);
//tp.Rectangle(position);
//tp.Stroke();
//pfield.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
//writer.AddAnnotation(pfield);
}
第二个任务: *如果 - 客户将在稍后阶段将签名文本添加到这些字段(使用像 DocuSign 之类的第 3 方工具),我真的需要一个签名字段吗?还是简单的 PDFTextFields 真的有用?
在查询中添加上述问题,因为这可能有助于关联我的场景。
提前感谢您的帮助。
【问题讨论】:
标签: itext