Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting PDF files in Java

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

like image 266
user2399013 Avatar asked May 21 '13 17:05

user2399013


1 Answers

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

like image 58
Adarsh Avatar answered Oct 08 '22 19:10

Adarsh