[英]set the table cell width in iText java pdf
I am using the opensource http://itextpdf.com/ , to create some pdf .我正在使用开源http://itextpdf.com/来创建一些 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 ..我找不到任何设置列宽的方法,请建议一些方法来实现这一点..
You can make use of setWidths() method.您可以使用 setWidths() 方法。
table.setWidths(new int[]{200,50});
public void setWidths(int[] relativeWidths) public void setWidths(int[] relativeWidths)
Try this.试试这个。
float[] columnWidths = new float[]{10f, 20f, 30f, 10f};
table.setWidths(columnWidths);
Here is the corrected one if table.setWidths(new int[]{200,50});
这是更正的 if
table.setWidths(new int[]{200,50});
does not work.不起作用。
innertable.setWidthPercentage(50);
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});
float[] columnWidths = {1, 5, 5};
// columnWidths = {column1, column2, column3...}
PdfPTable table = new PdfPTable(columnWidths)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.