IText 7 表中的列宽问题
Issue with Column Width in IText 7 Tables
我创建了以下具有固定列宽的 table,
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 文件中看到输出格式时,列宽不均匀。
我是否遗漏了该代码片段中的某些内容?
请升级到最新版本的 iText
- 7.1.x 行 - 并使用下面的代码创建一个 table 具有均匀宽度的列:
Table headerTable = new Table(UnitValue.createPercentArray(new float[]{5,5,5}));
headerTable.setWidth(UnitValue.createPercentValue(100));
要固定列宽,我们可以在 iText7 中使用 setFixedLayout()
。它对我有用
Table content = new Table(UnitValue.createPercentArray(new float[]{3,5,10}));
content.setWidth(UnitValue.createPercentValue(100));
content.setFixedLayout();
我创建了以下具有固定列宽的 table,
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 文件中看到输出格式时,列宽不均匀。
我是否遗漏了该代码片段中的某些内容?
请升级到最新版本的 iText
- 7.1.x 行 - 并使用下面的代码创建一个 table 具有均匀宽度的列:
Table headerTable = new Table(UnitValue.createPercentArray(new float[]{5,5,5}));
headerTable.setWidth(UnitValue.createPercentValue(100));
要固定列宽,我们可以在 iText7 中使用 setFixedLayout()
。它对我有用
Table content = new Table(UnitValue.createPercentArray(new float[]{3,5,10}));
content.setWidth(UnitValue.createPercentValue(100));
content.setFixedLayout();