Java利用iText7画个性化表格

来源:互联网 发布:php经典书籍推荐 编辑:程序博客网 时间:2024/05/20 09:21

有时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);}}
效果如下





原创粉丝点击