iTextSharp PdfStamper.PartialFormFlatte仅展平部分而非全部字段

时间:2016-08-30 20:13:20

标签: itext

以下代码正确分配值" foo"到指定的字段,但字段没有被压扁"。我必须忽略一步,但我不知道它是什么。请指教。感谢。

public byte[] FlattenSpecifiedFormFields(byte[] b, List<string> fieldNames2Flatten)
    {
        PdfReader reader = new PdfReader(b);
        using (var ms = new MemoryStream())
        {
            var stamper = new iTextSharp.text.pdf.PdfStamper(reader, ms);               
            foreach (string name in fieldNames2Flatten)
            {

                stamper.AcroFields.SetField(name, "foo");
                stamper.PartialFormFlattening(name);
            }

            stamper.Close();
            return ms.ToArray();
        };
    }

1 个答案:

答案 0 :(得分:3)

即使部分展平表单,FormFlattening true属性也必须设置为var stamper = new PdfStamper(reader, ms); stamper.FormFlattening = true; foreach (string name in fieldNames2Flatten) { stamper.AcroFields.SetField(name, "foo"); stamper.PartialFormFlattening(name); } 。即:

SKNode