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!