2

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

  • 由于 Adob​​e 移动阅读器不支持 XFA,因此我将 XFA 展平为静态 PDF。我尝试过,但动态 XFA 无法使用 iText 转换为静态 PDF。
  • 后来我尝试使用“Adobe PDF”作为打印服务来打印 XFA 表格。这在手动执行时可以按预期工作,但在通过代码执行时会以某种方式清除表单数据。

下面是打印任务的示例代码。Adobe Acrobat DC 安装用于“Adobe PDF”打印服务。

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

有人请提出一种解决方法来实现预期。谢谢!

4

1 回答 1

1

我使用免费的 PDF Creator 打印机解决了它,配置为将文件存储到某个目录。然后我创建了一个 REST API 来打印 XFA PDF 并将 PDF 1.4 返回给 API 客户端。它工作,但工作缓慢。应该说生成的 PDF 的质量非常好。

还通过 Ghostscript 尝试了 Adob​​e PDF 和 Microsoft Print to PDF 打印机,但它只打印“请稍候...”页面。

于 2020-09-29T13:27:24.683 回答