In the Adobe's ISO 32000 spec for PDF/A it states that XFA data can be stored in a special place in the PDF/A-2 confirming PDF. Here is the text of that section.
Incorporation of XFA Datasets into a PDF/A-2 Conforming File To support PDF/A-2 conforming files, ExtensionLevel 3 adds support for XML form data (XFA datasets) through the XFAResources name tree, which is part of the name dictionary of the document catalog.
(See “TABLE 3.28 Entries in the name dictionary” on page 23.) While Acrobat forms (and form data) are permitted in a PDF/A-2 conforming file, XML forms are not. Such XML forms are specified as XDP streams referenced from interactive form dictionaries. XDP streams can contain XFA datasets.
For applications that convert PDF documents to PDF/A-2, the XFAResources name tree supports relocation of XML form data from XDP streams in a PDF document into the XFAResources name tree.
The XFAResources name tree consists of a string name and an indirect reference to a stream. The string name is created at the time the document is converted to a PDF/A-2 conforming file. The stream contains the element of the XFA, comprised of elements.
In addition to data values for XML form fields, the elements enable the storage and retrieval of other types of information that may be useful for other workflows, including data that is not bound to form fields, and one or more XML signature(s).
See the XML Architecture, XML Forms Architecture (XFA) Specification, version 2.6 in the Bibliography
We have an XFA Form that we pass xml to and now need to convert that document to PDF/A-2.
We are currently testing out XFA Worker to see if that will allow us to do this, I have been unable to find a sample of XFA Worker that will do this for us.
I first tried to flatten with XFA Worker but that removes the data completely and is no longer able to be extracted.
How do you get the XFA xml data into the place that Adobe says to put it in with XFA Worker?
UPDATE: Thanks Bruno, my code isn't allowing me to convert the XFA Form to PDF/A-2. Here is the code I used.
xfa.fillXfaForm(new ByteArrayInputStream(xmlSchemaStream.toByteArray()));
stamper.close();
reader.close();
try (ByteArrayOutputStream outputStreamDest = new ByteArrayOutputStream()) {
PdfReader pdfAReader = new PdfReader(output.toByteArray());
PdfAStamper pdfAStamper = new PdfAStamper(pdfAReader, outputStreamDest, PdfAConformanceLevel.PDF_A_2A);
....
and I get an error com.itextpdf.text.pdf.PdfAConformanceException: Only PDF/A documents can be opened in PdfAStamper.
So I am now assuming the new PdfAStamper isn't a converter but just reading in the byte array of the XFA PDF.
PdfAStamper
is not a converter. It's a class that allows you to stamp extra content (watermarks, page numbers, fill out forms) to an existing PDF/A document. You can't "feed" it an XFA form.PdfAStamper
expects a PDF/A document. – Bruno LowagiePdfAStamper
. That is very confusing. I assumed that you were using XSLT on the XML embedding in the XFA form to convert the XFA data to HTML. I assumed that you were converting that HTML to PDF using XML Worker. Now I'm not so sure anymore. – Bruno Lowagiexfa.fillXfaForm(new ByteArrayInputStream(xmlSchemaStream.toByteArray()));
then you are not using XML Worker. You are using core iText functionality. Maybe you're not using XML Worker at all. In that case, please don't confuse the Stack Overflow visitor into thinking that you are. That's confusing. Bottom line: once you have filled out the form like thisxfa.fillXfaForm(new ByteArrayInputStream(xmlSchemaStream.toByteArray()));
you need XFA Worker to flatten that form. – Bruno Lowagie