Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to export jTable model data to PDF file

843807Jul 3 2010 — edited Jul 3 2010
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 31 2010
Added on Jul 3 2010
1 comment
992 views