我正在使用以下方法在新页面上将签名字段添加到PDF / A文档(具有PDF / A-3A符合级别)。一切似乎都正常...
public void AddCertifiedSignature(string srcPath, string destPath)
{
var reader = new PdfReader(srcPath);
var writer = new PdfWriter(destPath);
var pdfDoc = new PdfADocument(reader, writer);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
var ps = new PageSize(PageSize.A4);
var newPage = pdfDoc.AddNewPage(ps);
var signatureRectangle = new Rectangle(36, 648, 200, 100);
var signatureAnnotation = new PdfWidgetAnnotation(signatureRectangle);
var signatureField = PdfFormField.CreateSignature(pdfDoc, signatureRectangle, PdfAConformanceLevel.PDF_A_3A);
signatureField.SetFieldName("SignField1");
form.AddField(signatureField, newPage);
pdfDoc.Close();
}
但是,在最后一行,我得到一个例外:
Additional information: Every annotation shall have at least one appearance dictionary
有人知道如何添加请求的字典(或更好的实现)吗?我当前正在使用iText 7.1.2.0(.NET)。
答案 0 :(得分:1)
我不是专家,但是,我使用了您的代码(并在工作中将其转换为Java)并通过添加使它起作用
PdfAnnotation annotation = pdfDoc.getLastPage().getAnnotations().get(0);
PdfFormXObject appearObj = new PdfFormXObject(signatureRectangle);
PdfAnnotationAppearance appearance = new PdfAnnotationAppearance(appearObj.getPdfObject());
annotation.setNormalAppearance(appearance);
与
所在的行之前pdfDoc.Close();
不是最干净的解决方案,但我希望它会有所帮助;)