1

使用 iText 填充和展平 XFA PDF 创建 PDF/A 1a 时,如何保留阅读顺序?

预展平 PDF 的阅读顺序存储在 和 元素中,但此信息未在展平标记的 PDF/A 1a 文档中表示。

具体来说,我的两列表单(在展平之前由 JAWS 正确读取)在两列中从上到下一直错误地从左到右读取,而不是向下读取一列然后继续到开头第二列。

iText Java 代码如下所示:

public void manipulatePdf(String src, String xml, File dest)
        throws IOException, DocumentException, InterruptedException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfReader reader = new PdfReader(src);
    PdfStamper stamper = new PdfStamper(reader, baos);
    AcroFields form = stamper.getAcroFields();

    XfaForm xfa = form.getXfa();
    stamper.close();

    Document document = new Document();
    PdfAWriter writer = PdfAWriter.getInstance(document,
            new FileOutputStream(dest), PdfAConformanceLevel.PDF_A_1A);

    writer.setTagged();
    document.addLanguage("en-us");
    document.open();

    ICC_Profile iccProfile = ICC_Profile.getInstance(new FileInputStream(
            colorProfile));
    writer.setOutputIntents("Custom", "", "http://www.color.org",
            "sRGB IEC61966-2.1", iccProfile);
    PdfICCBased iccBased = new PdfICCBased(iccProfile);
    iccBased.remove(PdfName.ALTERNATE);
    PdfDictionary outputIntent = new PdfDictionary(PdfName.OUTPUTINTENT);
    outputIntent.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(
            "sRGB IEC61966-2.1"));
    outputIntent.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
    outputIntent.put(PdfName.S, PdfName.GTS_PDFA1);
    outputIntent.put(PdfName.DESTOUTPUTPROFILE, writer.addToBody(iccBased)
            .getIndirectReference());
    writer.getExtraCatalog().put(PdfName.OUTPUTINTENTS,
            new PdfArray(outputIntent));

    PdfDictionary markInfo = new PdfDictionary(PdfName.MARKINFO);
    markInfo.put(PdfName.MARKED, new PdfBoolean(true));
    writer.getExtraCatalog().put(PdfName.MARKINFO, markInfo);

    XFAFlattener xfaf = new XFAFlattener(document, writer);
    xfaf.flatten(new PdfReader(baos.toByteArray()), false);
    document.close();

    System.out.println("The form is flattened");
}
4

0 回答 0