原文:http://freesky-zh.iteye.com/blog/509594
1。画无边框的table,比如对格式有要求的数据,需要左对齐或右对齐。
- PdfPTable table = new PdfPTable(2);
- //无边框
- table.getDefaultCell().setBorder(0);
- // table.getDefaultCell().setBorderWidth(0);
需要注意的是,table中的cell必须是String或Paragraph,这样上面的cell宽度设为0才起作用,对于PdfPCell,setBorder=0是不起作用的。对齐也是如此。
- //以下单元格右对齐,对String和Paragraph有效,对PdfPCell无效。
- table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
2。分割线,对于一个段落或一句话需要分割线以提示用户的情况。可以通过变通的方式来实现,就是运用table的四个边框都是可选的这一特性,可以设置top或bottom划线来实现。
- //only add bottom line for table
- PdfPTable tt = new PdfPTable(2);
- tt.setWidthPercentage(100f);
- tt.getDefaultCell().setBorderWidthLeft(0);
- tt.getDefaultCell().setBorderWidthRight(0);
- tt.getDefaultCell().setBorderWidthTop(0);
- tt.addCell("column1");
- tt.addCell("column2");