@Override public void process(int level, Node node, InvocationContext context) { TableNode tableNode = (TableNode) node; List<TableColumnNode> tableNodeColumns = tableNode.getColumns(); PdfPTable table = new PdfPTable(tableNodeColumns.size()); for (PdfPTableEvent tableEvent : tableEvents) { table.setTableEvent(tableEvent); } context.pushTable(new TableInfos(table, tableNodeColumns)); context.processChildren(level, node); context.popTable(); KeyValues kvs = context.iTextContext().keyValues(); Float spacingBefore = kvs.<Float>getNullable(TABLE_SPACING_BEFORE).or(5f); Float spacingAfter = kvs.<Float>getNullable(TABLE_SPACING_AFTER).or(5f); table.setSpacingBefore(spacingBefore); table.setSpacingAfter(spacingAfter); applyAttributes(context, table); context.append(table); }
public static void createPdf(String filename, String dbTable) throws SQLException, DocumentException, IOException { // step 1 Document document = new Document(PageSize.A4); // System.out.println(Tax.class.getResource("fonts/arial.ttf").getPath()); BaseFont bf = BaseFont.createFont("etc/Arial.ttf", "Cp1253", BaseFont.EMBEDDED); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 PdfPTableEvent event = new Printer(); PdfPTable table = getTable(dbTable, bf); table.setTableEvent(event); document.add(table); document.newPage(); // step 5 document.close(); }
public TableNodeProcessor(PdfPTableEvent... tableEvents) { this.tableEvents = tableEvents; }