Hi,

my recent works could help. I have been trying using the iText
acroFields.mergeXfaData(...), but I faced a bug with duplicated subforms
assigned to different datas (same structure)...
That seems to happen because of a corrupted mapping between short and long
names in AcroFieldSearch class... I tried to fix it, but I lost myself in
the depth of code ;-) !

So, I did it my own way, merging XFA dataset with a classic XML merging
approach... sounds trivial, but  works fine.

Here is my code, if that can help (form is an instance of an home-made class
defining a set of pdf form, datas to merge aso...):

PdfReader pdfReader = new PdfReader(form.getFormTemplate().getURI());

XfaForm xfaForm = new XfaForm(pdfReader);
if (!xfaForm.isXfaPresent()) {
        form.setState(IForm.STATE_FAILED);
        throw new Exception("Not an XFA Form !!");
}

FileOutputStream pdfOutputStream = new
FileOutputStream(form.getMergedPath());
PdfStamper pdfStamper = new PdfStamper(pdfReader, pdfOutputStream);
                        
Document dataSetDocument =
XmlDomHelper.loadDomDocument(form.getDataFlow().getURI());
Node dataSetsNode =
XPathAPI.selectSingleNode(dataSetDocument.getDocumentElement(),
"//xfa:data", dataSetDocument);
                        
// Get data definitions from xfa structure (link to an xfa form file through
form instance)
Document xfaDocument = xfaForm.getDomDocument();

Node newXfaDataSetsNode =
xfaDocument.importNode(dataSetsNode.cloneNode(true), true);
Node xfaDataSetsNode =
XPathAPI.selectSingleNode(xfaDocument.getDocumentElement(), "//xfa:data",
dataSetDocument);

// Replacement of the dataset definition in xfa-form with the filled dataset
from the xml business datas:
xfaDataSetsNode.getParentNode().replaceChild(newXfaDataSetsNode,
xfaDataSetsNode);
xfaForm.setDomDocument(xfaDocument);
                        
xfaForm.setChanged(true);
XfaForm.setXfa(XfaForm.serializeDoc(xfaForm.getDomDocument()),
pdfStamper.getReader(), pdfStamper.getWriter());
                        
pdfStamper.close();
pdfReader.close();

form.setState(IForm.STATE_MERGED);


-- 
View this message in context: 
http://www.nabble.com/Pre-Populating-fields-in-an-XFA-form-tp14409379p14597628.html
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to