我在写一个程序,它使用iText生成一个带有表格的pdf或rtf文件。我使用了iText类的表格和单元格,而不是更具体的RtfTable或pdfTable,这样可以在最后生成任何文件。我需要将单元格填充值设置为-1,否则打印页面上每行数据之间的空间太大。但是,我现在试图添加边框(特别是pdf文件),并且单元格不与文本排列在一起。每个单元格的底部边框直接切入文本。当单元格填充设置为2或更高时,它仅实际包围文本。下面是我在做什么的样本:iText细胞边界切割文本
Document document = new Document();
Paragraph paragraph = new Paragraph();
Font iTextFont = new Font(Font.TIMES_ROMAN, 9, Font.NORMAL);
try{
PdfWriter.getInstance(document, new FileOutputStream("C:/datafiles/TestiText.pdf"));
document.open();
Table table = new Table(3);
table.setPadding(-1);
table.setWidth(90);
Cell cell1 = new Cell();
cell1.setBorder(Rectangle.BOX);
cell1.setVerticalAlignment(ElementTags.ALIGN_TOP);
table.setDefaultCell(cell1);
paragraph = new Paragraph("header", iTextFont);
Cell cell = new Cell(paragraph);
cell.setHeader(true);
cell.setColspan(3);
table.addCell(cell);
paragraph = new Paragraph("example cell", iTextFont);
table.addCell(paragraph);
paragraph = new Paragraph("one", iTextFont);
table.addCell(cell);
paragraph = new Paragraph("two", iTextFont);
cell = new Cell(paragraph);
table.addCell(paragraph);
paragraph = new Paragraph("Does this start a new row?", iTextFont);
table.addCell(paragraph);
paragraph = new Paragraph("Four", iTextFont);
table.addCell(paragraph);
paragraph = new Paragraph("Five", iTextFont);
table.addCell(paragraph);
document.add(table);
} catch (Exception e) {
//handle exception
}
document.close();
}
是否有通过移动整个边境下来的下降(但不影响文字位置)来解决这个问题,还是要得到之间摆脱了空间的方式每行(间距似乎只是文本上方的问题,而不是下面),而不将单元格填充设置为-1?
您是否找到解决方案?我有同样的问题。我希望我的单元格不太高,这似乎是由填充引起的,但是当我减少填充时,文本将穿过底部边框。 – 2009-09-08 08:43:36