Adam - I'm confused!! You are directly writing XFA form information (via fillXfaForm) _BUT_ then you use the acroFields APIs to change the lock state - you can NOT mix these two! Either you are working with XFA _OR_ you are working with AcroForms. It's like cross the streams....
Leonard -----Original Message----- From: Adam Carless [mailto:adam.carl...@hansard.com] Sent: Monday, May 17, 2010 7:04 AM To: itext-questions@lists.sourceforge.net Subject: Re: [iText-questions] Encryption and XFA Forms Big thanks to Mark and Leonard for all your help, I've finally got my head around the problem now and sorted out the solution. In case it's useful to anyone else, here's the core code I've ended up with to fill in and lock an XFA form (ignoring any AcroForm parts). This code doesn't include any exception handling, checks, or other PDF manipulation, it's just to show the form filling & securing part... InputSource is = new InputSource(new StringReader(passedXfaData)); is.setEncoding("UTF-8"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(passedPdfReader, baos); // must have ALLOW_FILL_IN otherwise fillXfaForm() silently fails stamper.getWriter().setEncryption(PdfWriter.ENCRYPTION_AES_128, "", "", PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_FILL_IN); // mergeXfaData() ignores an XFA form if there is also an AcroForm in the PDF // So get the XfaForm explicitly and fill that, so no AcroForm stuff happens. AcroFields acroFields = stamper.getAcroFields(); XfaForm xfaForm = acroFields.getXfa(); xfaForm.fillXfaForm(is); // once the form is filled in, we have to mark each of the fields as readonly // so the users can't edit the values in the final PDF. HashMap<String, AcroFields.Item> fieldMap = acroFields.getFields(); for (String fieldName : fieldMap.keySet()) { acroFields.setFieldProperty(fieldName, "setfflags", PdfFormField.FF_READ_ONLY, null); } stamper.setFullCompression(); stamper.close(); return baos.toByteArray(); Thanks again to Mark and Leonard for all the help, it's much appreciated. Adam Carless The contents of this message and any attachments are confidential and are intended for the use of the persons to whom it is addressed. If you are not the intended recipient, you should not copy, forward, use or alter the message in any way, nor disclose its contents to any other person. Please notify the sender immediately and delete the e-mail from your system, if you so wish you can contact us on +44 1624 688000. The sender is not responsible for any alterations that may have occurred without authorisation. Any files attached to this email will have been checked by us with virus detection software before transmission. You should carry out your own virus checks before opening any attachments, as we do not accept any liability for loss or damage which may be caused by viruses. For information regarding company registration please visit the contact page at www.hansard.com ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/