Creating Tagged PDF Document in Seam iText

2019-06-10 17:37发布

问题:

I am trying to create an accessible PDF using Seam and their iText implementation. I cannot find any references to whether or not this is possible. It seems that iText itself can handle it; the PDF on this example is tagged. But all of the PDFs that we create aren't and I can't seem to figure out how to add it.

Here's some sample code from one of our documents:

<?xml version="1.0" encoding="UTF-8"?>
<p:document xmlns:p="http://jboss.com/products/seam/pdf" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:h="http://java.sun.com/jsf/html" type="PDF" pageSize="letter" title="Letter" margins="15.0 40.0 20.0 10.0">


    <f:facet name="header">
        <p:font size="10" name="TIMES-ROMAN" style="bold">
            <p:header borderWidth="0"/>
            <p:footer borderWidthTop="0" borderWidthBottom="0" alignment="center">
FY #{handler.form.year}<p:text value=" #{handler.form.name}"/><p:text value="     "/>CAN #{handler.form.number}<p:text value="     "/>Object Class #{handler.form.class}<p:text value="     "/>#{handler.form.time} 
            </p:footer>
        </p:font>
    </f:facet>

    <p:font size="10" name="TIMES-ROMAN">
        <p:table columns="3" widthPercentage="100" widths="1 2 1">
        <p:cell borderWidth="0">
                <p:image alignment="left" value="/assets/img/logo.PNG" scalePercent="5"/>
        </p:cell>
        <p:cell borderWidth="0" horizontalAlignment="center" paddingTop="30">
            <p:paragraph>

                WORKSHEET
            </p:paragraph>
        </p:cell>
... snip ...

I realize that's not the best code (I'm just pulling from a document I'll need to clean up). Still, any ideas on if Seam can actually put in PDF tags?

回答1:

Out-of-the-box tagged PDF is supported since iText 5.4.0 (which is the most recent version).

When you use the high-level objects such as Paragraph, PdfPTable, etc... and you use PdfWriter.setTagged(), then you get good quality Tagged PDF. You can even choose your own roles.

It would surprise me if jBoss/SEAM would be using such a recent version of iText. I've reached out to them to upgrade and the SEAM team never responded. (Who am I? I'm the CEO of iText Software.)