>  > Sounds like you have a form with an XFA form that has an AcroForm
>  > counter-part. In that case, iText ignores the XFA and fill out the
>  > AcroForm fields which have a slightly different alignment, scaling, etc.

I think I've found a way around this problem, but unfortunately I seem to have 
uncovered another problem at the same time.

Firstly, my workaround for mergeXfaData() not actually merging XFA data if an 
FDF form is also present. The solution was to upgrade to version 5.0.2, then I 
could get the XFA form and explicitly fill it in - with code like this:

InputSource is = new InputSource(new StringReader(passedXfaDataString));
is.setEncoding("UTF-8");

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(passedPdfReader, baos);

XfaForm xfaForm = stamper.getAcroFields().getXfa();
xfaForm.fillXfaForm(is);
stamper.close();

return baos.toByteArray();


However, the next step I need to do is encrypt the final PDF. From reading 
Paulo's replies when this question pops up, I know the encryption needs to be 
done as soon as the stamper is created. so the code should look like:

...
PdfStamper stamper = new PdfStamper(passedPdfReader, baos);
stamper.setEncryption(PdfWriter.ENCRYPTION_AES_128, "", "", 
PdfWriter.ALLOW_PRINTING);

XfaForm xfaForm = stamper.getAcroFields().getXfa();
xfaForm.fillXfaForm(is);
...

However, this doesn't do what I'd expect. Instead it ignores all the filled XFA 
values leaving blank fields in the final PDF. I've tried all 4 of the various 
similar setEncryption() methods on PdfStamper, but they all do the same thing - 
they cause the filled XFA data values to not appear in the final PDF.

If setEncryption() is commented out, final PDF comes out fine, but unsecured. 
If 
setEncryption() (in any of the 4 similar variants) is enabled, the final PDF 
comes out secured, but with no XFA data filled in.

I've also tried using stamper.getWriter().setEncryption(byte[], byte[], int, 
int), using null byte arrays rather than empty strings for the passwords. But 
that also did the same.

The variant of setEncryption() which takes a Certificate array hasn't been 
tried, since I don't have any public certificates to use.

Has anyone got any suggestions to get around encryption causing all the form 
data to be thrown away?

Thanks for your help,
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/

Reply via email to