Exporting PDF files in Java

user2399013 picture user2399013 · May 21, 2013 · Viewed 35.5k times · Source

I have a table that gets it's data from a SQL DB. I'm trying to find the easiest way to export that table, as it is, into a PDF file. Nothing fancy, just a title and the table with it's content. I've searched around here and also checked into external packages (docmosis and such), but did not make up my mind. I am fairly new in Java and I'm looking for the easiest way to export a table to a pdf.

Trying to answer possible questions, here's how I populate the table:

try {
   result = DBConnection.getTableContent("customers", attributes, where, null, null);
   DefaultTableModel model = (DefaultTableModel) searchTable.getModel();
   model.setRowCount(0);
   for (int i = 0; i < result.size(); i++) {                        
      model.addRow(result.get(i).toArray());
   }
}

Thanks

Answer

Adarsh picture Adarsh · May 21, 2013

You can use iText PDF Api. It is pretty easy to use. You just have to download the jar, import the class and you are good to go. Check out this tutorial on how to use the classes