当我在等待某人创建可填写的PDF供我在我的项目中使用时,我在编写代码时用可填写的税表代替。以下代码填写了税务PDF表格,但是当我用可填写的PDF表格替换税表时,它不再有效。我已经验证了字段名称是正确的(通过检查acroFields中的字段)。为什么我的表格不会填写? (模板是可填写的表格)
try
{
if (!string.IsNullOrWhiteSpace(template))
{
pdfMemoryReader = new PdfReader(template);
pdfMemoryReader.RemoveUsageRights(); // prevents the "This document enabled extended features in Adobe Reader...." message
PdfStamper pdfMemoryStamper = null;
try
{
pdfMemoryStamper = new PdfStamper(pdfMemoryReader, memoryStream);
AcroFields acroMemoryFields = pdfMemoryStamper.AcroFields;
acroMemoryFields = PopulatePDF(studentId, termId, acroMemoryFields, PDFFields);
pdfMemoryStamper.FormFlattening = true;
pdfMemoryStamper.Writer.CloseStream = false;
if (pdfMemoryStamper != null)
{
pdfMemoryStamper.Close();
}
memoryStream.Position = 0;
}
finally
{
pdfMemoryReader.Close(); //this supposedly closes the underlying stream
}
}
}
catch
{ }
return memoryStream;
和PopulatePDF(我还验证了PDFFields.StudentLName有一个值):
public AcroFields PopulatePDF(Guid studentId, Guid termId, AcroFields acroFields, PDFViewModel PDFFields)
{
SharedInfo(studentId, termId, PDFFields);
acroFields.SetField("[StudentLName]", PDFFields.StudentLName);
acroFields.SetField("[StudentFName]", PDFFields.StudentFName);
acroFields.SetField("[Grade]", PDFFields.StudentFName);
}
为什么这个新表格不会填写?表格需要一些属性才能使用iTextSharp吗? iTextSharp是版本4.1.2.0
答案 0 :(得分:2)
答案是删除括号。这是在观察窗口“添加”。