java itext 不要边框_java – iText单元格边框通过文本

在编程中,作者遇到一个挑战:使用iText库生成PDF和RTF文件时,设置单元格填充为-1以减小行间距,但这导致边框切割了文本。当填充值大于等于2时,边框才正确包围文本。作者寻求解决方案,希望能调整边框位置而不影响文本,或者消除行间的多余空间而不改变填充设置。
摘要由CSDN通过智能技术生成

我写一个程序,生成一个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?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值