0

Using itextsharp v5.5.5.0 in VS2010 Setting the stamper FormFlattening = true no filed data is written to the output pdf. If set false the data is all present & correct but still editable (which I don't want)

PdfReader pdfTemplate = new PdfReader("..\\..\\pdf\\BFC-Template.pdf");
FileStream fileOutputStream = new FileStream("..\\..\\pdf\\BFC.pdf", FileMode.Create);
PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream);

stamper.AcroFields.SetField("FitID", "1234");
stamper.AcroFields.SetField("FitBy", "Fred Flintstone");
stamper.AcroFields.SetField("FitDate", "03/11/2015");
stamper.AcroFields.SetField("FitLocation", "Bedrock");

stamper.FormFlattening = true;
stamper.Close();
pdfTemplate.Close();
fileOutputStream.Close();
4

2 回答 2

2

Try adding :

stamper.AcroFields.GenerateAppearances = true;

EDIT:

If your form is a Dynamic Form. you might need to change

stamper.AcroFields.SetField("FitID", "1234");

to:

stamper.AcroFields.Xfa.DatasetsSom.Name2Node["FitID"].InnerText = "1234"
于 2015-03-06T21:50:01.320 回答
0

没关系,但您可以尝试从 pdfStamper 字段实例化 AcroFields 对象。

PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream);
AcroFields pdfFields = pdfStamper.AcroFields;

然后您可以使用 pdfFields 设置每个字段:

pdfFields.SetField("FitID", "1234");
pdfFields.SetField("FitBy", "Fred Flintstone");
pdfFields.SetField("FitDate", "03/11/2015");
pdfFields.SetField("FitLocation", "Bedrock");
stamper.FormFlattening = true;
stamper.Close();

我有这个确切的设置,它对我有用。

于 2015-03-06T21:59:43.287 回答