我使用固定列宽创建了下表,如下所示,
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));
Run Code Online (Sandbox Code Playgroud)
但是当我在我的 PDF 文件中看到输出格式时,列宽是不均匀的。

我在那个代码片段中遗漏了什么吗?
请升级到最新版本iText- 7.1.x 行 - 并使用下面的代码创建一个具有均匀宽度列的表格:
Table headerTable = new Table(UnitValue.createPercentArray(new float[]{5,5,5}));
headerTable.setWidth(UnitValue.createPercentValue(100));
Run Code Online (Sandbox Code Playgroud)
小智 6
要修复列宽,我们可以setFixedLayout()在 iText7 中使用,。它对我有用
Table content = new Table(UnitValue.createPercentArray(new float[]{3,5,10}));
content.setWidth(UnitValue.createPercentValue(100));
content.setFixedLayout();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3805 次 |
| 最近记录: |