0
我想在PDF文件中打印兩個JTable
,這裏是我試過但打印的只是列的標題,請如何添加表格的內容。使用itext在PDF中打印多個JTable
try{
Document document = new Document();
PdfWriter.getInstance(document,new FileOutputStream("transcript.pdf"));
document.open();
document.add(new Paragraph("UNIVERSITY OF MAIDUGURI"));
document.add(new Paragraph("======================================================================="));
PdfPTable table1 = new PdfPTable(partITable.getColumnCount());
PdfPTable table2 = new PdfPTable(partITable2.getColumnCount());
table1.setSpacingAfter(10);
table1.setSpacingBefore(5);
for(int i=0;i<partITable.getColumnCount();i++){
table1.addCell(partITable.getColumnName(i));
}
for(int rows=0;rows<partITable.getRowCount()-1;rows++){
for(int cols=0;cols<partITable.getColumnCount();cols++){
table1.addCell(partITable.getModel().getValueAt(rows,cols).toString());
}
}
for(int i=0;i<partITable2.getColumnCount();i++){
table2.addCell(partITable2.getColumnName(i));
}
for(int rows=0;rows<partITable2.getRowCount()-1;rows++){
for(int cols=0;cols<partITable2.getColumnCount();cols++){
table2.addCell(partITable2.getModel().getValueAt(rows,cols).toString());
}
}
document.add(table1);
document.add(table2);
document.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
感謝Ayuba,它的工作原理 –