Am Novice
Am Novice

Reputation: 325

Issue with Column Width in IText 7 Tables

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 ?

Upvotes: 6

Views: 11254

Answers (2)

Yahini priya Raja
Yahini priya Raja

Reputation: 341

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

Upvotes: 11

Alexey Subach
Alexey Subach

Reputation: 12312

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

Upvotes: 10

Related Questions