目前,我正在使用 iText 将我的 jTable 数据转换为 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();
}
我遇到的问题是没有表格标题,如果表格单元格中的数据显示不完整,因为空间不够,在 pdf 中数据也没有完全显示。是否有任何其他 API 可以将 jTable 模型数据转换为 pdf?