Saturday 15 September 2012

xml - How to fill XFA form using iText? -



xml - How to fill XFA form using iText? -

code:

using (filestream pdf = new filestream("c:/test.pdf", filemode.open)) using (filestream xml = new filestream("c:/test.xml", filemode.open)) using (filestream filledpdf = new filestream("c:/test_f.pdf", filemode.create)) { pdfreader.unethicalreading = true; pdfreader pdfreader = new pdfreader(pdf); pdfstamper stamper = new pdfstamper(pdfreader, filledpdf); stamper.acrofields.xfa.fillxfaform(xml); stamper.close(); pdfreader.close(); }

this code throws no exception , seems ok, if open filled pdf, adobe reader says that:

this document enabled extended features. document changed since created , using extended features isn't possible anymore.

some fields filled properly, can't edit it. fields empty. if take xml manually clicking 'import data' adobe reader, form filled properly, guess there no error in xml.

you not creating pdfstamper object correctly. use:

pdfstamper stamper = new pdfstamper(pdfreader, filledpdf, '\0', true)

in code, not using pdfstamper in append mode. means itext reorganize different objects in pdf. isn't problem.

however: pdf reader-enabled, means pdf digitally signed using private key owned adobe. reorganizing objects within pdf, signature broken. made clear message mentioned:

this document enabled extended features. document changed since created , using extended features isn't possible anymore.

you changed document in way isn't allowed (see section 8.7 of book entitled "preserving usage rights of reader-enabled forms").

to avoid breaking signature, need utilize pdfstamper in append mode. instead of reorganizing original content, itext maintain original file intact , append new content after end of original file.

xml pdf itext xfa

No comments:

Post a Comment