Java利用iText7画个性化表格
Java利用iText7画个性化表格
有时PDF中会出现非传统等行等列表格,下面介绍如何画个性化表格
(需要安装iText7插件哦)(官网http://developers.itextpdf.com/)
public class Test {
private static final String PICPersonF = "E:\\project\\BMIs1.png";
public static final String DEST2 = "E:\\project\\test4.pdf";// 文件路径
public static void test(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
PdfFont sysFont = PdfFontFactory.createFont("STSongStd-Light",
"UniGB-UCS2-H", false);
//创建总表形式(一行四格)
Table table = new Table(new float[] { 55, 13, 14, 13 })
.setWidthPercent(95);
//表头
for(int i=0;i<4;i++){
table.addCell(new Cell().add(new Paragraph(""+(i+1))));
}
//表格行合并"2"代表合并2行单元格
Cell cell=new Cell(2,1).add(new Paragraph("one"));
table.addCell(cell);
//表格列合并"3"代表合并3列
cell=new Cell(1,3).add(new Paragraph("two"));
table.addCell(cell);
//将剩余格补齐
cell=new Cell().add(new Paragraph("three"));
table.addCell(cell);
cell=new Cell().add(new Paragraph("three"));
table.addCell(cell);
cell=new Cell().add(new Paragraph("three"));
table.addCell(cell);
doc.add(table);
doc.close();
}
public static void main(String[] args) throws Exception {
test(DEST2);
}
}效果如下
Java利用iText7画个性化表格相关教程