CONVERT JTable DATA TO PDF FILE

Ads
 

CONVERT JTable DATA TO PDF FILE

HOW TO CONVERT JTable DATA TO .PDF FILE??PLEASE GIVE ME CODE FOR THAT.

View Answers

August 11, 2012 at 12:04 PM

Here is an example that reads the jtable data from the jframe and stored the data into the pdf file in the form of table.

import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class JTableToPDF{
JTable table;
JButton button;
public static void main(String[] args) {
new JTableToPDF();
}

public JTableToPDF(){
JFrame frame = new JFrame("Getting Cell Values in JTable");
JPanel panel = new JPanel();
String data[][] = {{"Angelina","Mumbai"},{"Martina","Delhi"}};

String col[] = {"Name","Address"};
DefaultTableModel model = new DefaultTableModel(data, col);
table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
button=new JButton("Save to pdf");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
    try{
int count=table.getRowCount();
Document document=new Document();
       PdfWriter.getInstance(document,new FileOutputStream("C:/data.pdf"));
       document.open();
       PdfPTable tab=new PdfPTable(2);
       tab.addCell("Name");
       tab.addCell("Address");
for(int i=0;i<count;i++){
Object obj1 = GetData(table, i, 0);
Object obj2 = GetData(table, i, 1);
String value1=obj1.toString();
String value2=obj2.toString();

tab.addCell(value1);
tab.addCell(value2);
}
document.add(tab);
document.close();
    }
    catch(Exception e){}
}
});
panel.add(pane);
panel.add(button);
frame.add(panel);
frame.setSize(500,500);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public Object GetData(JTable table, int row_index, int col_index){
return table.getModel().getValueAt(row_index, col_index);
}
}

Ads









Related Tutorials/Questions & Answers:
CONVERT JTable DATA TO PDF FILE
CONVERT JTable DATA TO PDF FILE  HOW TO CONVERT JTable DATA TO .PDF... the jtable data from the jframe and stored the data into the pdf file in the form...(data, col); table = new JTable(model); JScrollPane pane = new JScrollPane(table
Java convert jtable data to pdf file
Java convert jtable data to pdf file In this tutorial, you will learn how to convert jtable data to pdf file. Here is an example where we have created... have fetched the data from the jtable and save the data to pdf file. Example
Advertisements
convert an pdf file to html in Java
convert an pdf file to html in Java  Hi all, How to convert an pdf file to html in Java? Currently all my data is generated into a report in pdf and i want to be able to generate it to html page as well. How to go about
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
Convert Text File to PDF file
Convert Text File to PDF file  import java.io.BufferedReader; import...); System.out.println("Text is inserted into pdf file"); document.close... FileReader( Input File)); String inLine = null
How to Convert PDF into rtf File Java
How to Convert PDF into rtf File Java  Hi, How could in covert the PDF file to rtf file in Java Programming. Please suggest any online example... the online example of Java Convert PDF into rtf File. Thanks
How to convert a swing form to PDF
How to convert a swing form to PDF  Sir, I want to know about how convert a swing form containing textbox,JTable,JPanel,JLabel, Seperator etc swing menus to a PDF file using java code
convert excel into pdf
convert excel into pdf  How to convert excel into pdf files
convert excel file data into different locales while converting exclile file to csv file
convert excel file data into different locales while converting exclile file to csv file   can any one provide the code for how to convert excel file data into different locales while converting exclile file to csv file
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import... to the libraries.the pdf file are not opened when i execute the program.please send the code to open the pdf file when i execute the jsp page
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import... to the libraries.the pdf file are not opened when i execute the program.please send the code to open the pdf file when i execute the jsp page
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import... to the libraries.the pdf file are not opened when i execute the program.please send the code to open the pdf file when i execute the jsp page
write data to a pdf file when i run jsp page
write data to a pdf file when i run jsp page  Hi, <%@page import... to the libraries.the pdf file are not opened when i execute the program.please send the code to open the pdf file when i execute the jsp page
convert word document to pdf
convert word document to pdf  Hi, Could you please help me write a java code that converts the word docuemnt into PDF? I have to save the generated...? import officetools.OfficeFile; fis = new FileInputStream(new File("test.doc
Convert BLOB to PDF and save it to a location
Convert BLOB to PDF and save it to a location  I have a requirement to convert blob(stored in a DB table) back to .pdf in the UI(for the users... it has to convert each blob to a pdf and zip it, which the user should be able
Download PDF file
Download PDF file  How to download PDF file with JSF
jTable data problem
jTable data problem  Hello. I have a code that read file and store in arraylist and then convert to array(To use for table model) My class extends... that read file and store in arraylist and then convert to array(To use for table
about pdf file handeling
about pdf file handeling  can i apend something in pdf file using... to handle pdf files. You can find the related examples from the given link: Handling PDF files
pdf file in jsp
pdf file in jsp  i have a pdf, which has to be displayed in a jsp page along with some html tags, the pdf which is to be displayed shold be readonly and wont allow the uer to save too
Java swing: Export excel sheet data to JTable
Java swing: Export excel sheet data to JTable In this tutorial, you will learn how to read data from excel file and export it to JTable. In swing applications, sometimes, it is required to display the excel file data into the jtable
about pdf file handeling
about pdf file handeling  i have downloaded a jar file containing packages for writing in pdf files . in which folder i should copy it ? i'm using windowsXP os.pls give whole path
convert data format sql
convert data format sql  convert data format sql
Java convert file to byte array
Java convert file to byte array  How to convert file to byte array in Java? Thanks   Hi, To convert file to byte array in Java you have...) Use the insputStream.read(bytes); of the class to read the data into byte array
how to convert .xml file to csv file
how to convert .xml file to csv file  how to convert .xml file to csv file
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
How to convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
how to convert a jar file into .exe file
how to convert a jar file into .exe file  hi, I want convert my jar file into executable file,urgently please help me
convert zip file to byte array
convert zip file to byte array  Hi,How to convert zip file to byte array,can you please provide program?? Thanks, Ramanuja
how to convert image file to text file?
how to convert image file to text file?  hi, can anybody tell how to convert image file to text file? plz help me
Remove JTable row that read txt file records
Remove JTable row that read txt file records  Hi every one. i have a jtable that correctly read data frome file and show them in own. I want to add... AbstractTableModel{ Vector data; Vector columns; public

Ads