java如何画出表格_Java利用iText7画个性化表格
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畫個性化表格相關教程
總結
以上是生活随笔為你收集整理的java如何画出表格_Java利用iText7画个性化表格的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java remove removeat
- 下一篇: 二战美国另类的M10坦克歼击车