Represent data in tabular form without using PdfPTable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Represent data in tabular form without using PdfPTable

avchavan
Hi,
Is there a way to represent data in tabular format without using PdfPTable?
The problem is i have a Table but i am not using table header and one of the PDF guideline says:
"SC 1.3.1: The table in the document does not have table headers. If adding table headers does not make sense, then maybe the table should not be used to show these data and it should just be text."
I tried assigning the DIV role to PdfPTable but it didnt work.
Assigning TEXT role gives Exception.
What can i do different here?
Here's a sample code using PdfPTable.

public class TableData{

        public static void main(String[] args) throws IOException, DocumentException, XMPException {
                Document document = new Document();
                PdfAWriter writer = PdfAWriter.getInstance(document, new FileOutputStream("list.pdf"), PdfAConformanceLevel.PDF_A_1A);
                writer.setViewerPreferences(PdfAWriter.PageModeUseOutlines);
                writer.setViewerPreferences(PdfAWriter.DisplayDocTitle);
                writer.setRunDirection(PdfAWriter.RUN_DIRECTION_LTR);
                writer.setTagged(PdfAWriter.markAll);
                writer.createXmpMetadata();
                XmpWriter xmp = writer.getXmpWriter();

                DublinCoreProperties.addSubject(xmp.getXmpMeta(), "Subject");
                DublinCoreProperties.setTitle(xmp.getXmpMeta(), "Title", "en_US", "en_US");
                DublinCoreProperties.setDescription(xmp.getXmpMeta(), "Description", "en_US", "en_US");
                PdfProperties.setKeywords(xmp.getXmpMeta(), "Keywords");
                PdfProperties.setVersion(xmp.getXmpMeta(), "1.4");
                document.addTitle("Title");
                document.addLanguage("en_US");
                document.open();
                Font font1 = FontFactory.getFont("ROsanswebtextregular.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
                Font fontBullet = FontFactory.getFont("ZapfDingbats.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 8);
                ICC_Profile icc = ICC_Profile.getInstance(new FileInputStream("sRGB Color Space Profile.icm"));
                writer.setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

                PdfPTable table = new PdfPTable(2);
                table.setWidthPercentage(75);
                table.setWidths(new float[]{0.7f, 1.3f});
                table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
                table.setSpacingBefore(10);
                table.setSpacingAfter(15);

                Paragraph p13 = new Paragraph("List indicator: ", font1);
                List p14 = new List(10);
                Chunk bullet = new Chunk(String.valueOf((char)110), fontBullet);
                p14.setListSymbol(bullet);
               
                for(int i = 0; i < 5; i++){
                        ListItem li = new ListItem("asd"+i, font1);
                        p14.add(li);
                }
               
                PdfPCell cell13 = new PdfPCell(p13);
                PdfPCell cell14 = new PdfPCell();
                cell14.addElement(p14);
                cell14.setUseAscender(true);
                table.addCell(cell13);
                table.addCell(cell14);
                table.setRunDirection(PdfAWriter.RUN_DIRECTION_LTR);
                table.setRole(PdfName.TEXT);
                document.add(table);
                document.close();
        }
}

Loading...