1
votes

I am creating a PDF using iText 5.5.6. I wanted to tag table, row and cell as a DIV. I have written the following code but only the table gets marked as a DIV and not the row and cell.

PdfPTable table = new PdfPTable(2);
table.setRunDirection(PdfAWriter.RUN_DIRECTION_LTR);
table.setRole(PdfName.DIV);
table.setWidthPercentage(80);
table.setWidths(new float[] { 0.8f, 1.2f });
table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
table.setSpacingBefore(10);
table.setSpacingAfter(15);
Paragraph p3 = new Paragraph("Name:", font12);
Paragraph p4 = new Paragraph("FirstName LastName", font12);
Paragraph p5 = new Paragraph("DOB: ", font12);
Paragraph p6 = new Paragraph("00-00-0000", font12);
PdfPCell cellp3 = new PdfPCell(p3);
cellp3.setBorder(0);
PdfPCell cellp4 = new PdfPCell(p4);
cellp4.setBorder(0);
cellp3.setRole(PdfName.DIV);
cellp4.setRole(PdfName.DIV);
table.addCell(cellp3);
table.addCell(cellp4);
PdfPCell cellp5 = new PdfPCell(p5);
cellp5.setBorder(0);
PdfPCell cellp6 = new PdfPCell(p6);
cellp6.setBorder(0);
cellp5.setRole(PdfName.DIV);
cellp6.setRole(PdfName.DIV);
table.addCell(cellp5);
table.addCell(cellp6);

How to solve this?

1
@BrunoLowagie in setAccessibleAttribute() key would be PdfName.DIV and what would be the value? new PdfString() - avinash chavan
Please disregard my comment. I've checked the iText code and I was wrong. Changing a PdfPTable's semantic meaning isn't trivial... - Bruno Lowagie
@BrunoLowagie so, how do i get around this? - avinash chavan
I don't know, but I'm sure that somebody at iText Support knows (that is: if it's possible). - Bruno Lowagie

1 Answers

3
votes

If I test your code the table and all the cells are tagged as DIV. The rows are indeed not.

In iText the classes PdfPTable, PdfPRow and PdfPCell are responsible for table functionality. PdfPRow is typically only used in the iText implementation internally, because a PdfPTable instance accepts PdfPCells directly.

But you are able to retrieve the table rows to set their role. After you have added all the cells to the table, do this:

for (PdfPRow row : table.getRows())
    row.setRole(PdfName.DIV);