XFA Form conversion to PDFA-1B - pdf

We have a requirement to convert XFA Form (Adobe LiveCycle Form) to PDF/A-1B.
We're attempting to use iText 5.4.0 to parse the PDF, populate the XFA fields and then save the modified PDF back out.
All the examples I can find with iText talk about populating XFA fields into PDF.
Can I convert an XFA form ( static / dynamic and generated using LiveCycle) to PDFA 1b directly?
As need PDFA for sure and can’t live with plain PDFs. So as workaround we were thinking about converting the PDF to PDFA. Is that the right approach or we are missing something here.

You can also use Adobe LiveCycle Forms Server or PDF Generator for this purpose. It supports conversion of XFA-based forms (either static or dynamic) to either PDF/A-1b or PDF/A-1a.

Yes, you can convert XFA forms to PDF/A using iText in combination with XFA Worker. However, XFA Worker is a closed source product. So you need to be an iText customer if you want to achieve what you want.
Note that we've done exactly what you need in a project for the Ministry of Justice in Belgium. I've written the following blog post about this project: : http://lowagie.com/xfabpm
Disclaimer: I'm the CEO of the iText Software Group. This answer isn't meant to promote the product. It's a genuine answer to this question.

I was also looking for the same problem and I reached an easy solution, you can try this out:
Drag and drop it xfa format PDF into chrome, it will open in chrome browser.
You will find three options at right corner:
Rotate clockwise
Download
Print
Click on "Print"
Change destination "save as PDF" and save.
Saved PDF is flat PDF(Acroform) and can be edited easily

Related

Dynamic XFA PDF issue with chrome ("Please wait...")

I am having issue to view XFA PDF in Google chrome. I am able to open the same PDF in Acrobat reader but when I view in chrome I get “Please wait...” message.
Can you please let me know if there is any solution to fix this issue?
The XML Forms Architecture is deprecated in ISO 32000-2 (released in 2017). One of the reasons for deprecation was the fact that adoption of XFA was poor. This wasn't a problem when Adobe Reader had a high penetration, but it became problematic with the advent of pdf.js, Chrome's PDF viewer, Microsoft's PDF viewer, etc. None of those viewers supported XFA. Instead of rendering the XML stream, they just render the single (static) PDF page that is usually stored inside an XFA document. PDF renders much quicker than XML, and the static PDF page saying "Please wait..." was there to bridge the gap between opening the document and rendering the XML in Adobe Reader. It's also the page that is shown by PDF viewers who don't support XFA. Those viewers know how to render the PDF part of the form, but they don't know how to parse the XFA stream.
To make a long story short: there is no fix for your issue. Google Chrome doesn't support XFA, and as XFA is deprecated, Google Chrome won't support XFA in the future either.
There might be a workaround if you are allowed to flatten the form. For instance: XFA is often used as a templating format.
The template defines what a final document has to look like.
XML data is merged into the template.
The XFA template with the data is flattened to an ordinary PDF document.
Once an XFA form is flattened to an ordinary PDF document, the document is no longer interactive. No data can be entered; all interactivity is gone. There is no XFA XML stream inside the document anymore.
There are two products that can flatten an XFA form: Adobe LC Enterprise Suite, and iText's pdfXFA add-on. Both of these products are closed source, commercial products.

Can form field data be saved in PDF?

I am learning the basics of form pdfs now. After entering the field values, I can save the pdf with data as a pdf file. With Acrobat pro, I am able to export data in FDF and XFDF files. we need to develop a website that will allow users to fill a few form pdfs in browser and download it preferably as pdf forms filled with data. The PDFTron is a good solution, but it looks like I can download FDF file or XFDF file or the flattened pdf from it. The user should be able to modify the downloaded forms. Is this possible with PDFTron?
If it is not PDFTron, Is there any other way I could do this?
Yes, PDFTron fully supports online form filling and the export/import of XFDF data. In particular the WebViewer technology sounds like the best fit for you. It comes with out of the box form field filling, and XFDF is uses as the data interchange. A simple call in javascript to AnnotationManager.exportAnnotations() will give you all the form field data that you can use with any XFDF compliant PDF SDK.
This is the online sample for form filling. It will work on any modern browser/device.
https://www.pdftron.com/webviewer/demo/samples/forms/index.html?doctype=xod
This presentation explains WebViewer technology at a high level.
https://prezi.com/view/Aug5ft1twZNNKfBXfTIQ/
Finally, this page shows the basics of form field data interchange.
https://www.pdftron.com/webviewer/demo/tutorials/getting-started-annotations.html
I really like PDFTK and the PHP library php-pdftk. It will do everything that you want and more, they are really powerful tools, and free if you open-source your code!
PDFTK: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
php-pdftk: https://github.com/mikehaertl/php-pdftk

pdf prepare form modular

I have a few documents that all look the same initially, but then have different content in the middle of the document.
Is there a way to make a base template pdf, and then tell a pdf to use it as the base and then add additional template data to the result.
i.e. like a modular class system.
I am using pdf, adobe acrobat pro DC, and its Prepare Form component.
and I am usign Itext to read the template and then populate the data into a final pdf.
please remove tag if this is not related to itext, but i wondered if there was an option within itext to pull a template and then add the contents from another template.
the answer seems to be use livecycle designer for dynamic tempaltes.
or wait for itexts new dynamic forms.

Can I watermark XFA PDF using iText (commercial or not)?

Well, after spending quite some time playing with this, I think I may have found a solution soon after I posted the question. Bit embarrassing but hey, it seems to work now.
I don't want to delete the question yet, in case someone wants the details. Basically, I tried again point (c) but in the XML I put back I used an embedded image. So, it seems I can change the XFA template master page using iText. More testing to follow ...
=========================
The problem: Apply watermark to a PDF XFA (dynamic or not). At the end the PDF should still be an XFA and should have all its security settings intact. I don't have control over the PDFs coming in.
The question: Can I use iText 5 to do that? If yes, is it via PdfStamper.getUnderContent() or via XfaForm.setXfa() or something else ? The first 2 didn't work for me yet.
I wonder if it's some XFA detail that I am missing (i.e. when I try to replace the XML), not sure how the XFA is actually protected from changes. Do I need to generate some UUID, encrypt some things, something about signatures ...
Btw, if I take the PDF generated by iText after replacing the XML, then open and save in LC, the watermark shows
thanks,
Cristian
========================
Anyway, that's the short version of my question. If you think you can help and/or are interested in more details ...
I know this or similar questions came up before but what I have tried so far didn't work for me. I also admit I am not a IText, XFA or PDF Standard expert. I browsed a number of forums posts, the Itext book, browsed the specs, no luck yet.
The PDF input has no regular usage rights, no security. When opened in Acrobat it will show the restrictions on Changing Document/Document Assembly/Adding templates but I have a feeling all XFAs have that. Nothing comes back from the following ...
System.out.println(" permissions " + reader.getPermissions());
System.out.println(" usage rights " + reader.hasUsageRights());
System.out.println(" viewer pref" + reader.getSimpleViewerPreferences());
Here are some of the things I have been through:
a) doing in it LC (https://forums.adobe.com/thread/496558)
This works. If I try to place an image on the master page, then it shows as watermark on all pages when saved from LC.
b) trying to write under using iText (https://sourceforge.net/p/itext/mailman/message/17225398/)
I found a post from '07 suggesting using pdfStamper.getUnderContent(). The thread does not seem to conclude if it did work eventually for the person asking
For me, the code works for a simple PDF, but not for XFA
PdfContentByte under = pdfStamper.getUnderContent(1);
under.beginText();
BaseFont FONT = BaseFont.createFont("c:/windows/fonts/times.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
under.setFontAndSize(FONT, 40);
under.showTextAligned(Element.ALIGN_CENTER, "TEST_TEXT", 200, 600, 45);
under.endText();
c) generate the XML and replace it using iText (Some pdf file watermark does not show using iText)
After reading the post above and section 8.6 from itext in action, it seemed this is the correct path, so:
I create a simple XFA using LiveCycle
Save as xfa1.pdf and extract xml (using iText) to xfa1.xml
in LC add an image to the masterpage and save as xfa2.pdf
open xfa2.pdf and notice the watermark is present
extract XML from xfa2 to xfa2.xml and compare to xfa1.xml - notice the image element
either place the image element in original XML or use xfa2.xml and replace the XFA in original xfa1.pdf using iText, let's call it xfa3_itext;
Relevant code:
XfaForm xfa = new XfaForm(reader);
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
fact.setNamespaceAware(true);
DocumentBuilder db = fact.newDocumentBuilder();
Document doc = db.parse(new FileInputStream(xml));
xfa.setDomDocument(doc);
xfa.setChanged(true);
XfaForm.setXfa(xfa, stamper.getReader(), stamper.getWriter());
I have tried with a sample PDF that was provided by a customer and with a simple XFA form created in LiveCycle Designer, no luck. If I open xfa3_itext in LiveCycle it does the watermark and if I save it again from LiveCycle as dynamic XFA PDF, the new PDF shows the watermark.
phew, that is a long post ... sorry.
thanks for reading and for any feedback

Converting PDF to WMF

Can someone suggest the best way to convert a PDF file to WMF?
I currently make Dynamic XML Form PDFs with Adobe LiveCycle Designer, but a client requires the file in WMF format for printing. Instead of filling out the form directly, they have their users answer the questions within their own UI, then print the fields to the form.
I've tried converting the PDF to PNG within Acrobat then converting it to WMF, but our client is having issues with them indicating these WMFs "appear to be graphics renamed as WMFs".
Thanks
Try writing a script that prints your PDF files into a WMF/EMF virtual printer.
There a few out there, for example:
EMF Printer (GPL, not free for commercial use).
Amyuni EMF Printer Freeware, but a bit outdated (Disclaimer: I work for Amyuni Technologies).
I believe there is another one (as source code) in the Windows Driver Kit source code samples, but I cannot find the link now.