简体   繁体   中英

Converting dynamic XFA to static PDF

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM