This is my first post to the list, so apologies if this has been covered before (I've searched the archives but couldn't find anything).
I have a PDF which has been created using Adobe Acrobat Pro (not sure which version). This PDF contains a single XFA form with various form fields, some of which are inline with static text. When the PDF is opened in Acrobat Reader, and the form fields are filled in by hand, the values appear correctly aligned with the surrounding text. It all works as expected. However, when I fill the fields using PdfStamper.getAcroFields().mergeXfaData(Document) the values appear to be dropped slightly, so they appear approximately 1.5mm low on the page. Also the whole page alignment seems to be altered slightly, with the top and bottom margins becoming wider. I've tried this both using and not using encryption, compression, and form flattening, and the results are the same. Also, when I check the various "boxes" of the reader object before and after the merge, the rectangle values all seem to be the same. So I don't think the box sizes are being manipulated by the merging process. Initially I was using version 2.1.4 of iText, but I have now also tried it with versions 2.1.7 and 5.0.2, but I still see the same mis-alignment. This mis-alignment is visible in the on-screen version of the PDF as well as the printed version, so I don't think it's a printer driver issue (unless printer config can affect the on-screen layout too?) I've included a code fragment at the end of this which I think shows the relevant parts of what I'm trying to do, but I can provide full code if necessary. I can also provide sample PDFs showing the problem (didn't want to attach PDFs to this initial post), both the initial template PDF and the version after doing the XFA merge. I've searched the iText documentation but couldn't find anything which seemed relevant to this problem. Any help with realigning the form fields is gratefully received. If the problem is that I'm missing something in the API please feel free to just tell me where to look. Thanks for any help, Adam Carless PS: Here's a code fragment to show what I'm doing. The real code has more comments and error handling, but this is the main XFA handling part: static byte[] merge(byte[] template, String xfaData) throws PdfMergeException { try { PdfReader reader = new PdfReader(template); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Set name-space awareness as xfa is defined within its own // (remove this and you will get NPE's from the mergeXfaData call // when it's parsing the incoming DOM). dbf.setNamespaceAware(true); // xfaData is a constructed XML fragment with a root element of // "<topmostSubform>" holding a set of "<name>value</name>" elements InputSource is = new InputSource(new StringReader(xfaData)); is.setEncoding("UTF-8"); Document doc = dbf.newDocumentBuilder().parse(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, baos); stamper.getAcroFields().mergeXfaData(doc); stamper.close(); return baos.toByteArray(); } catch (Exception e) { throw new PdfMergeException("PDF merging problem", e); } } 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/