简体   繁体   English

将动态 XFA 转换为静态 PDF

[英]Converting dynamic XFA to static PDF

Requirement: View XFA based PDFs on mobile devices.要求:在移动设备上查看基于 XFA 的 PDF。
Options I've tried:我试过的选项:

  • Since XFA aren't supported on Adobe mobile reader, I get to flatten an XFA as a static PDF.由于 Adob​​e 移动阅读器不支持 XFA,我可以将 XFA 展平为静态 PDF。 I tried but dynamic XFAs can't be converted to static PDFs using iText.我尝试过,但无法使用 iText 将动态 XFA 转换为静态 PDF。
  • Later I tried printing XFA forms using 'Adobe PDF' as print service.后来我尝试使用“Adobe PDF”作为打印服务来打印 XFA 表单。 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.为“Adobe PDF”打印服务安装了 Adob​​e 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;
    }

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.我使用免费的 PDF Creator 打印机解决了这个问题,该打印机配置为将文件存储到某个目录。 Then I created a REST API to print XFA PDF and return PDF 1.4 to the API client.然后我创建了一个 REST API 来打印 XFA PDF 并将 PDF 1.4 返回给 API 客户端。 It worked, but worked slow.它有效,但工作缓慢。 Should say quality of resulted PDF is very well.应该说结果 PDF 的质量非常好。

Also tried Adobe PDF and Microsoft Print to PDF printers through Ghostscript, but it prints only"Please wait..." page.还尝试通过 Ghostscript 将 Adob​​e PDF 和 Microsoft Print 打印到 PDF 打印机,但它只打印“请稍候...”页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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