pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jammy Dodger" <onejammydod...@gmail.com>
Subject Re: Fill data into pdf xfa forms by PdfBox
Date Fri, 17 Jan 2014 22:45:52 GMT
Many thanks to Maruan Sahyoun for his great work on PDFBox + XFA.
This code only works when you remove all security on the PDDocument.
It also assumes the COS object in PDXFA is a COSStream. The simplistic example below reads
the xml stream and writes it back into the PDF.

PDDocument doc = PDDocument.load("filename");

PDDocumentCatalog docCatalog = doc.getDocumentCatalog();
PDAcroForm form = docCatalog.getAcroForm();

PDXFA xfa = form.getXFA();
COSBase cos = xfa.getCOSObject();
COSStream coss = (COSStream) cos;
InputStream cosin = coss.getUnfilteredStream();
Document document = documentBuilder.parse(cosin);

COSStream cosout = new COSStream(new RandomAccessBuffer());
OutputStream out = cosout.createUnfilteredStream();

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(xmlDoc);
StreamResult result = new StreamResult(out);
transformer.transform(source, result);

PDXFA xfaout = new PDXFA(cosout);

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message