2017-08-10 28 views
0

我有一个使用java(itext)生成的pdf表。在这里我有一个名为'税'的专栏。现在我想此列拆分为2即使用pdf itext将单元拆分为两个

这是当前税收领域:

|----------| 
| Tax  | 
|----------| 
|   | 
|   | 
|----------| 

我想拆分此定义如下:

|----------| 
| Tax | 
|----------| 
|Name| % | 
|----|---- | 
| |  | 
| |  | 
| |  | 
|----------| 

请帮助我。

+0

使用的两列一个完整的教程到开始和使用'colspan'在第一个标题行。 – mkl

+0

@mkl如果你可以解释,这将是有帮助的。我是新来的java和itext。 – Fida

+0

参考乔里斯的回答。 – mkl

回答

4

此代码应该做的伎俩:

PdfDocument pdfDocument = new PdfDocument(new PdfWriter(getOutputFile())); 
Document layoutDocument = new Document(pdfDocument); 

// build table 
Table table = new Table(UnitValue.createPercentArray(new float[]{0.5f, 0.5f})); 

// add "Tax" header 
Cell headerCell = new Cell(1,2);  // rowspan = 1, colspan = 2 
headerCell.add(new Paragraph("Tax")); 
table.addCell(headerCell); 

// add "Name" and "%" header 
table.addCell(new Cell().add(new Paragraph("Name"))); 
table.addCell(new Cell().add(new Paragraph("%"))); 

// add arbitrary data 
table.addCell(new Cell().add(new Paragraph("The java cookbook"))); 
table.addCell(new Cell().add(new Paragraph("6"))); 

layoutDocument.add(table); 
layoutDocument.close(); 

欲了解更多有关利用iText生成表,还有在http://developers.itextpdf.com/content/itext-7-examples/itext-7-tables