Java JTable export to PDF
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 p开发者_开发技巧df?
Yes, another API would be Docmosis. You would put your model data into a DataProvider instance and use that to populate a template. The template would control how your table looks and Docmosis would populate it to produce the PDF. You could do it as an image, but using the template to design the table look and feel is better.
精彩评论