Greetings, I am using itext 5.2.1 and attempting to read the data from the xfa_enabled.pdf (included in the iText in Action tutorial book) PDF containing an XFA form. Below is the sample code:
public void readData(String src, String dest) throws IOException, ParserConfigurationException, SAXException, TransformerFactoryConfigurationError, TransformerException { FileOutputStream os = new FileOutputStream(dest); PdfReader reader = new PdfReader(sr http://itext-general.2136553.n4.nabble.com/file/n4647963/xfa_enabled.pdf xfa_enabled.pdf c); XfaForm xfa = new XfaForm(reader); Node node = xfa.getDatasetsNode(); NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if("data".equals(list.item(i).getLocalName())) { node = list.item(i); break; } } list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if("movies".equals(list.item(i).getLocalName())) { node = list.item(i); break; } } Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); tf.setOutputProperty(OutputKeys.INDENT, "yes"); tf.transform(new DOMSource(node), new StreamResult(os)); reader.close(); } This works correctly. I then manually change some of the values in the generated xml and attempt to fill in a pdf with the updated data using the below code: public static void fillData3(String src, String xml, String dest) throws IOException, DocumentException, ParserConfigurationException, SAXException { boolean preserve = true; PdfReader reader = new PdfReader(src); PdfStamper stamper = null; try { // preserve the reader enabling by creating a PDF in append mode (or not) if (preserve) { stamper = new PdfStamper(reader, new FileOutputStream(dest), '\0', true); } else { stamper = new PdfStamper(reader, new FileOutputStream(dest)); } AcroFields form = stamper.getAcroFields(); XfaForm xfa = form.getXfa(); xfa.fillXfaForm(new FileInputStream(xml)); } finally { if (stamper != null) { try { stamper.close(); } catch (Exception e) { e.printStackTrace(); } } } } This also seems to work correctly and I can open the generated PDF with the updated fields with Adobe Reader 10.1.3 However, when I attempt to read the data from the generated pdf using the readData method, I get the below error: Exception in thread "main" ExceptionConverter: java.io.EOFException at com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:292) at com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:284) at com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2297) at com.itextpdf.text.pdf.PdfReader.getStreamBytes(PdfReader.java:2263) at com.itextpdf.text.pdf.PdfReader.getStreamBytes(PdfReader.java:2276) at com.itextpdf.text.pdf.XfaForm.<init>(XfaForm.java:132) at com.itextpdf.text.pdf.AcroFields.<init>(AcroFields.java:146) at com.itextpdf.text.pdf.PdfStamperImp.getAcroFields(PdfStamperImp.java:806) at com.itextpdf.text.pdf.PdfStamper.getAcroFields(PdfStamper.java:383) Any ideas on what could be the cause as this seems to be occuring even for other XFA PDF's that I am working on. I have attached the xfa_enabled.pdf file. Kind Regards, Dee -- View this message in context: http://itext-general.2136553.n4.nabble.com/ExceptionConverter-java-io-EOFException-when-reading-XFA-data-tp4647963.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php