我尝试用 C# 填写 PDF 表单。但不知何故,它不起作用。问题:fields
对象(在行中:fields.SetField("Name", "Peter");
)似乎是null
.
这是我的代码:
public static void FillForm()
{
String pdfTemplate = @"c:\Users\Hagen\Desktop\formular.pdf";
String newFile = @"c:\Users\Hagen\Desktop\formular_fertig.pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields fields = pdfStamper.AcroFields;
fields.SetField("Name", "Peter");
pdfStamper.Close();
}