iText生成PDF时 table的单元格边框怎么设置为虚线

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iText生成PDF时 table的单元格边框怎么设置为虚线相关的知识,希望对你有一定的参考价值。

参考技术A class CustomCell implements PdfPCellEvent
/*public void cellLayout(PdfPCell cell, Rectangle rect,
PdfContentByte[] canvas)
PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
cb.setLineDash(new float[] 3.0f, 3.0f , 0);
cb.stroke();
*/

public void cellLayout(PdfPCell cell, Rectangle position,
PdfContentByte[] canvases)

// TODO Auto-generated method stub
PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
cb.saveState();
//cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
//cb.setLineDash(0, 1, 1);
cb.setLineWidth(0.5f);
cb.setLineDash(new float[] 5.0f, 5.0f , 0);
cb.moveTo(position.getLeft(), position.getBottom());
cb.lineTo(position.getRight(), position.getBottom());
cb.stroke();
cb.restoreState();




public class DottedLineCell2
public static void main(String[] args) throws IOException, DocumentException
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
CustomCell border = new CustomCell();
PdfPTable table = new PdfPTable(6);
PdfPCell cell;
for (int i = 1; i <= 6; i++)
cell = new PdfPCell(new Phrase("test"));

cell.setBorder(Rectangle.NO_BORDER);

cell.setCellEvent(border);
table.addCell(cell);

document.add(table);
document.close();


本回答被提问者采纳
参考技术B 右击设置单元格格式

itext的单元格怎么设置宽度

  设置表格的宽度有两种方法,分别如下
table.setTotalWidth(float totalWidth);//设置表格的总宽度
table.setTotalWidth(float[] columnWidth);//设置表格的各列宽度
使用以上两个函数,必须使用以下函数,将宽度锁定。
table.setLockedWidth(true);
参考技术A 使用table或是pdftable时,需要开始就是指定整个table的宽度、列数以及各列宽度的比例关系,通过这样的方式就可以设置或是确定单元格的宽度了。
不知道这样说是不是对你有帮助。本回答被提问者采纳

以上是关于iText生成PDF时 table的单元格边框怎么设置为虚线的主要内容,如果未能解决你的问题,请参考以下文章

itext的单元格怎么设置宽度

如何将条件数据添加到itext表单元格中

iText 7 PDF 可访问性:“表格标题单元格没有关联的子单元格”

使用 XMLWorker 和 itext 解析 html 时,如何将单元格间距添加到 pdftable

PHPWordPHPWord动态生成表格table | 单元格横向合并单元格纵向合并单元格边框样式单元格垂直水平居中

IText 生成pdf 怎么设置其大小