How can I set XFA data in a static XFA form in iTextSharp and get it to save?

后端 未结 2 1715
余生分开走
余生分开走 2020-12-11 10:32

I\'m having a very strange issue with XFA Forms in iText / iTextSharp (iTextSharp 5.3.3 via NuGet). I am trying to fill out a static XFA styled form, however my changes are

相关标签:
2条回答
  • 2020-12-11 10:57

    I found the issue. The replacement DomDocument needs to be the entire merged XML of the new document, not just the data or datasets portion.

    0 讨论(0)
  • 2020-12-11 10:59

    I upvoted your answer, because it's not incorrect (I'm happy my reference to the demo led you to have another look at your code), but now that I have a second look at your original code, I think it's better to use the book example:

    public byte[] ManipulatePdf(String src, String xml) {
      PdfReader reader = new PdfReader(src);
      using (MemoryStream ms = new MemoryStream()) {
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          AcroFields form = stamper.AcroFields;
          XfaForm xfa = form.Xfa;
          xfa.FillXfaForm(XmlReader.Create(new StringReader(xml)));
        }
        return ms.ToArray();
      }
    }
    

    As you can see, it's not necessary to replace the whole XFA XML. If you use the FillXfaForm method, the data is sufficient.

    Note: for the C# version of the examples, see http://tinyurl.com/iiacsCH08 (change the 08 into a number from 01 to 16 for the examples of the other chapters).

    0 讨论(0)
提交回复
热议问题