我正在使用opensource http://itextpdf.com/来创建一些pdf。
我可以创建一个表,但所有列的宽度都相同,我需要更改特定列的宽度。
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);
我找不到任何方法来设置列的宽度,请提示一些方法来实现这一点..
试试这个。
float[] columnWidths = new float[]{10f, 20f, 30f, 10f};
table.setWidths(columnWidths);
如果table.setWidths(new int[]{200,50});
不起作用,这是更正的。
innertable.setWidthPercentage(50);
float[] columnWidths = {1, 5, 5};
// columnWidths = {column1, column2, column3...}
PdfPTable table = new PdfPTable(columnWidths)
确保设置表格总宽度
// 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});