6

I have the following table created with fixed column width as follows,

 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));

But when I see the output format in my PDF file , the column width is uneven. enter image description here

Am I missing something in that code snippet ?

Am Novice
  • 325
  • 2
  • 9
  • 21

2 Answers2

11

To fix column width we can use setFixedLayout(), in iText7. And it worked for me

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

Please upgrade to the latest version of iText - 7.1.x line - and use the code below to create a table with columns of even width:

Table headerTable = new Table(UnitValue.createPercentArray(new float[]{5,5,5}));
headerTable.setWidth(UnitValue.createPercentValue(100));
Alexey Subach
  • 11,903
  • 7
  • 34
  • 60