我试图通过扩展PdfPageEventHelper
类来添加表的标题。所以我在尝试onEndPage()
。我得到了正确的标题,但该rowspan
属性不适用于表格。
我正在尝试使用下面的代码,
PdfPTable table1 = new PdfPTable(3);
try{
table1.setWidths(new int[]{15,20,20});
table1.setLockedWidth(true);
table1.setTotalWidth(700);
Image image = Image.getInstance("images.png");
PdfPCell cell = new PdfPCell(new Paragraph("{Month}", font3));
PdfPCell cell2 = new PdfPCell(image, false);
cell.setColspan(2);
cell.setBorder(PdfPCell.NO_BORDER);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell2.setBorder(PdfPCell.NO_BORDER);
cell2.setRowspan(2);
PdfPCell cell3 = new PdfPCell(new Paragraph("Mr Fname Lname", font3));
cell3.setColspan(2);
cell3.setBorder(PdfPCell.NO_BORDER);
cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
table1.addCell(cell);
table1.addCell(cell2);
table1.addCell(cell3);
table1.writeSelectedRows(0, -1, 20 , 820, writer.getDirectContent());
}
更新:
当我运行您在示例中提供给我的相同代码时,它会打印如下所示的 pdf,