2
votes

Requirement: View XFA based PDFs on mobile devices.
Options I've tried:

  • Since XFA aren't supported on Adobe mobile reader, I get to flatten an XFA as a static PDF. I tried but dynamic XFAs can't be converted to static PDFs using iText.
  • Later I tried printing XFA forms using 'Adobe PDF' as print service. That works expectedly while performed manually, but somehow clears form data while performed through code.

Below is the sample code for print task. Adobe Acrobat DC is installed for 'Adobe PDF' print service.

import java.awt.print.PrinterJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;

...
private static void writePDF(long uid, Path path) throws Exception {
        final String inFile = path.toString();
        PDDocument pdfdoc = PDDocument.load(inFile);
        PrinterJob printJob = PrinterJob.getPrinterJob();

        printJob.setPageable(new PDPageable(pdfdoc));
        // printJob.setPrintable(new PDPageable(pdfdoc));
        printJob.setPrintService(getSystemPrinter("Adobe PDF"));

        printJob.setJobName(path.getFileName().toString());
        pdfdoc.silentPrint(printJob);
    }

private static PrintService getSystemPrinter(final String printerName) {
        PrintService desiredPrinter = null;
        for (PrintService printer : PrintServiceLookup.lookupPrintServices(null, null)) {
            if (printerName.equalsIgnoreCase(printer.getName())) {
                desiredPrinter = printer;
                break;
            }
        }
        return desiredPrinter;
    }

Someone please suggest a workaround to achieve the desired. Thanks!

1
Using Adobe DC in a server environment isn't allowed (read the EULA). iText can flatten XFA forms using XFAWorker. Did you get a trial license to experiment with it? XFAWorker and Adobe LC are probably your only options and XFAWorker is the least expensive one. - Bruno Lowagie
Or you do what Adobe is expecting you to do in such a situation… get the LiveCycle Forms $erver … - Max Wyss
I tried developers.itextpdf.com/examples/form-examples/flattening-form, but same doesn't seem to work for dynamic XFA. Another link youtube.com/watch?v=h0wzj84tnmw require an additional dependency. - masT
I don't have provision to add an additional proprietary software. Please suggest something with existing toolset. - masT
In that case do not use XFA forms. - mkl

1 Answers

1
votes

I solved it using free PDF Creator printer, configured to store files to some directory. Then I created a REST API to print XFA PDF and return PDF 1.4 to the API client. It worked, but worked slow. Should say quality of resulted PDF is very well.

Also tried Adobe PDF and Microsoft Print to PDF printers through Ghostscript, but it prints only"Please wait..." page.