0
如果您看到下表,我已將兩個單元格分開,將一個單元格添加爲左側單元格(名稱),並將另外一個單元格添加爲表格。通過刪除左側單元格重新設計輸出
我曾嘗試下面的代碼:
我用包作爲進口com.lowagie.text.pdf *;
PdfWriter.getInstance(document,
new FileOutputStream("C:/Temp/TableWidthAlignment.pdf"));
document.open();
//Main table
PdfPTable mainTable = new PdfPTable(2);
mainTable.setWidths(new int[] { 10,90 });
//cell one is Name cell
PdfPCell innerCellKeyName = new PdfPCell(new Phrase("Name", boldFont));
//innerCellKeyName.setBorder(Rectangle.NO_BORDER);
mainTable.addCell(innerCellKeyName);
PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
cell.setColspan(3);
table.addCell(cell);
table.addCell("1.1");
table.addCell("2.1");
table.addCell("3.1");
table.addCell("1.2");
table.addCell("2.2");
table.addCell("3.2");
table.addCell("4.1");
table.addCell("4.2");
table.addCell("4.3");
//cell two is as table
PdfPCell cell2 = new PdfPCell(table);
mainTable.addCell(cell2);
document.add(mainTable);
輸出是:
預期輸出是:交叉箱需要被移除形式盒在左單元。
你知道你使用的是舊版本的iText的,自2009年12月,7年前已壽命結束? –
是的,這是真的,這是舊的應用程序,這是我們必須遵循舊規則的原因。 – Arun
我們現在已經7年了。也許是時候升級了。使用行跨度是行之有效的方法,但在您過時的iText版本中,「PdfPTable」不支持行跨度。 –