将动态XFA转换为静态PDF

要求:在移动设备上查看基于XFA的PDF .
我试过的选项:

  • 由于XFA不能使用iText转换为静态PDF .

  • 后来我尝试使用'Adobe PDF'作为打印服务打印XFA表单 . 这可以在手动执行时工作,但在通过代码执行时以某种方式清除表单数据 .

以下是打印任务的示例代码 . 为“Adobe PDF”打印服务安装了Adobe Acrobat DC .

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;
    }

有人请建议一个解决方法来实现所需 . 谢谢!

回答(0)