PdfPageEventHelper
classを拡張してテーブルのヘッダーを追加しようとしていました。だから私は試していまし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 が出力されます。