IText 7表中的列宽问题

时间:2018-03-20 15:08:06

标签: itext itext7

我使用固定列宽创建了下表,如下所示,

 Table headerTable = new Table(new float[]{5,5,5});
 headerTable.setWidthPercent(100);

 headerTable.addCell(new Cell().add(new Paragraph("Student Name : Michel John(xxxx-xxx-xxx-xxx)")).setFontSize(10).setTextAlignment(TextAlignment.LEFT));
 headerTable.addCell(new Cell().add(new Paragraph("Admission Date : 2012-05-01")).setFontSize(10).setTextAlignment(TextAlignment.CENTER));
 headerTable.addCell(new Cell().add(new Paragraph("Current Standard : Eigth Standard - 'B' Section")).setFontSize(10).setTextAlignment(TextAlignment.RIGHT));

但是当我在PDF文件中看到输出格式时,列宽不均匀。 enter image description here

我是否遗漏了该代码段中的内容?

2 个答案:

答案 0 :(得分:2)

请升级到最新版本的iText - 7.1.x行 - 并使用以下代码创建一个包含均匀宽度列的表格:

Table headerTable = new Table(UnitValue.createPercentArray(new float[]{5,5,5}));
headerTable.setWidth(UnitValue.createPercentValue(100));

答案 1 :(得分:0)

要固定列宽,我们可以在iText7中使用setFixedLayout()。它对我有用

    Table content = new Table(UnitValue.createPercentArray(new float[]{3,5,10}));
    content.setWidth(UnitValue.createPercentValue(100));
    content.setFixedLayout();