Hello,

Some days ago I posted a question about how to add tags (Table, TR,
TH, TD) to tables created using PdfPTables.I need to add these tags in
order to get accesible PDF/A1a.
After some research in the lists, it seems that the way to go should
be use the MarkObject element but the code is not yet completed.In
fact, it seems that this part is in a dead line for now.

I do not know if this could help anybody but here is a workaround.
This is a sample of what I am doing to get accesible tables. It is
based on the writeSelectRows method, writing the table cell by cell.

PdfPTable table = new PdfPTable(3);
//Fill the table here
....

table.setTotalWidth(300f);
float yPos = 500f;

PdfStructureElement mytable = new PdfStructureElement(eTop, new
PdfName("MyTable"));
root.mapRole(new PdfName("MyTable"), new PdfName("Table"));

float widths[] = table.getAbsoluteWidths();
PdfContentByte canvases[] = table.beginWritingRows(writer.getDirectContent());

for(int i=0; i < table.size(); i++) {
        float xPos = 10f;
        float rowHheight = table.getRowHeight(i);

        PdfStructureElement tr = new PdfStructureElement(mytable, new
PdfName("MyRow"));
        root.mapRole(new PdfName("MyRow"), new PdfName("TR"));

        for(int j = 0; j < table.getNumberOfColumns(); j++) {
                PdfStructureElement td = new PdfStructureElement(tr, new 
PdfName("MyColumn"));
                root.mapRole(new PdfName("MyColumn"), new PdfName("TD"));

                PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
                cb.beginMarkedContentSequence(td);
                if((j+1) == table.getNumberOfColumns()) {
                        yPos = table.writeSelectedRows(j, j + 1, i, i+1, xPos, 
yPos, canvases);
                } else {
                        table.writeSelectedRows(j, j + 1, i, i+1, xPos , yPos, 
canvases);
                        xPos += widths[j];
                }
                cb.endMarkedContentSequence();
        }
}
table.endWritingRows(canvases);

Hope this helps to somebody. If there is a simpler way please let me know it.

Jose

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to