文本 5.5.3。 508 遵守 JAWS 16

IText 5.5.3. 508 Compliance with JAWS 16

我在打印包含表格的 508 兼容标记 PDF 文件时遇到问题。出于某种原因,JAWS 不读取 PdfPTable 的辅助功能文本。

在下面的代码片段中,JAWS 读取块的 ALT 文本,但不读取 PdfPCell 和 PdfPTable。请帮忙!

    /**
 * Creates a PDF with information about the movies
 * @param    filename the name of the PDF file that will be created.
 * @throws    DocumentException 
 * @throws    IOException
 */
public void createPdf(String filename)
    throws IOException, DocumentException {
    // step 1
    Document document = new Document();
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    writer.setPdfVersion(PdfWriter.VERSION_1_7);
    writer.setTagged();
    writer.setViewerPreferences(PdfWriter.DisplayDocTitle);
    document.addLanguage("en-US");
    document.addTitle("Some title");
    writer.createXmpMetadata();
    // step 3
    document.open();
    // step 4
    Paragraph p1 = new Paragraph();
    p1.setFont(FontFactory.getFont(
            FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 20));
    Chunk c1 = new Chunk("What is this?");
    c1.setAccessibleAttribute(PdfName.ALT, new PdfString(" Q1. What is this?"));

    p1.add(c1);
    document.add(p1);
    document.add(createFirstTable());
    // step 5
    document.close();
}

/**
 * Creates our first table
 * @return our first table
 */
public static PdfPTable createFirstTable() {
    // a table with three columns
    PdfPTable table = new PdfPTable(3);
    table.setAccessibleAttribute(PdfName.ALT, new PdfString("My Table"));
    // the cell object
    PdfPCell cell;
    // we add a cell with colspan 3
    cell = new PdfPCell(new Phrase("Cell with colspan 3"));
    cell.setAccessibleAttribute(PdfName.TD, new PdfString("Cell 1"));
    cell.setColspan(3);
    table.addCell(cell);
    // now we add a cell with rowspan 2
    cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
            cell.setRowspan(2);
    table.addCell(cell);
    // we add the four remaining cells with addCell()
    table.addCell("row 1; caa*");
    table.addCell("row 1; c+");
    table.addCell("row 2; c-");
    table.addCell("row 2; c/");
    return table;
}

哇! 508 真的很令人沮丧。几天后,我想出了一个出路。我偶然发现了这个方法:createTaggedPDF17()。我为第一行创建了一个 PdfPHeaderSet,并为 table body 中的每个单元格添加了一个 header。

效果很好! JAWS 以我想要的方式阅读替代文本。

我不知道为什么它以前不起作用。但这解决了我的问题。

public static PdfPTable createFirstTable() {
    // a table with three columns
    PdfPTable table = new PdfPTable(3);

    // the cell object
    PdfPCell cell;
    // we add a cell with colspan 3
    //create header cell for first row
    PdfPHeaderCell headerCell = new PdfPHeaderCell();
    headerCell.setScope(PdfPHeaderCell.ROW);
    headerCell.setPhrase(new Phrase("Cell with colspan 3"));
    headerCell.setName("header Cell");
    headerCell.setAccessibleAttribute(PdfName.TD, new PdfString("Cell 1"));
    headerCell.setColspan(3);
    table.addCell(headerCell);
    // now we add a cell with rowspan 2
    cell = new PdfPCell(new Phrase("Cell with rowspan 2"));

    //add metadata for each cell in the body.
    cell.addHeader(headerCell);

    cell.setRowspan(2);
    table.addCell(cell);
    // we add the four remaining cells with addCell()
    table.addCell("row 1; caa*");
    table.addCell("row 1; c+");
    table.addCell("row 2; c-");
    table.addCell("row 2; c/");

    //set header row for the table
    table.setHeaderRows(1);

    return table;
}