我写一个程序,生成一个pdf或rtf文件与其中的表,使用iText。我使用iText类表和单元格,而不是更具体的RtfTable或pdfTable,以便任何一个文件可以在最后生成。我需要将单元格的填充值设置为-1,否则打印页上的每行数据之间的空间太大。但是,我现在正在尝试添加边框(具体到pdf文件),并且单元格没有排队的文本。每个单元格的底部边框直接切割文本。当单元格填充设置为2或更高时,它实际上只包围文本。下面是我所做的一个例子:
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?