Currently, I am using iText to convert my jTable data to pdf.
private void print() {
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("jTable.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
Graphics2D g2 = cb.createGraphicsShapes(800, 500);
Shape oldClip = g2.getClip();
g2.clipRect(0, 0, 800, 500);
jTable.print(g2);
g2.setClip(oldClip);
g2.dispose();
cb.restoreState();
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
The problem i got was that there is no table header, and let say if the data display in table cell is not complete due to the space is not enough, in pdf the data isn't showing completely as well. is there any other API can convert the jTable model data to pdf?