1

目前,我正在使用 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?

4

1 回答 1

1

是的,另一个 API 是Docmosis。您可以将模型数据放入 DataProvider 实例并使用它来填充模板。该模板将控制您的表格的外观,Docmosis 将填充它以生成 PDF。您可以将其作为图像进行,但使用模板来设计表格的外观和感觉会更好。

于 2010-07-03T02:40:46.923 回答