JTable to PDF converter

做~自己de王妃 提交于 2019-12-20 07:05:05

问题


I have a problem in Java code to convert JTable to PDF. It throws NullPointerException and same code works in another page no difference at all in both.

The code

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);
    table.print(g2);
    g2.setClip(oldClip);
    g2.dispose();
    cb.restoreState();
    } catch (Exception e) {
    e.printStackTrace();
    }

    document.close();
}

来源:https://stackoverflow.com/questions/10222354/jtable-to-pdf-converter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!