Reputation: 832
I am using the opensource http://itextpdf.com/ , to create some pdf .
I could create a table , but width of all column are same , I need to change the width of the particular column .
PdfPTable table = new PdfPTable(6);
Phrase tablePhrse = new Phrase("Sl n0", normalFontBold);
PdfPCell c1 = new PdfPCell(tablePhrse);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
I could not find any method to set the width of the column , pls suggest some way to do achieve this ..
Upvotes: 13
Views: 52430
Reputation: 21
Make sure to set table total width
// Set Column Number
PdfPTable table = new PdfPTable(2);
// Set Table Total Width
table.setTotalWidth(500);
// Set Each Column Width - Make Sure Array is the same number specified in constructor
table.setWidths(new int[]{50, 450});
Upvotes: 1
Reputation: 1942
Try this.
float[] columnWidths = new float[]{10f, 20f, 30f, 10f};
table.setWidths(columnWidths);
Upvotes: 5
Reputation: 192
float[] columnWidths = {1, 5, 5};
// columnWidths = {column1, column2, column3...}
PdfPTable table = new PdfPTable(columnWidths)
Upvotes: 1
Reputation: 31
Here is the corrected one if table.setWidths(new int[]{200,50});
does not work.
innertable.setWidthPercentage(50);
Upvotes: 1
Reputation: 4715
You can make use of setWidths() method.
table.setWidths(new int[]{200,50});
public void setWidths(int[] relativeWidths)
Upvotes: 23