带有表格的模板pdf,填写表格,然后将填写的pdf放入另一个pdf中?
我尝试按照以下步骤使用itext 7:
PdfDocument pdfDoc = new PdfDocument(new PdfReader(templateFilePath));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
form.GetField("form_field1").SetValue("value1");
PdfDocument pdfOutputDoc = new PdfDocument(new PdfReader(filePath), new Writer(outputFilePath))
PdfFormXObject pdfDocXObject = pdfDoc.GetFirstPage().CopyAsFormXObject(pdfOutputDoc)
Rectangle location = new Rectangle(0,0,10,10);
PdfStampAnnotation annotation = new PdfStampAnnotation(location);
annotation.SetStampName(new PdfName("itext7"));
annotation.SetNormalAppearance(pdfDocXObject.GetPdfObject());
pdfOutputDoc.GetFirstPage().AddAnnotation(annotation);
但是问题是插入的文件不包含填充的单词,字段“form_field1”的位置是空白而不是“value1”?
上面的代码有什么问题?