CONVERT JTable DATA TO PDF FILE

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);
}
}









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 data from pdf to text file - Java Beginners
convert data from pdf to text file   how to read the data from pdf file and put it into text file(.txt
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
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
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
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
Java insert file data to JTable
Java insert file data to JTable In this section, you will learn how to insert text file data into JTable. Swing has provide useful and sophisticated set...(); frame.setVisible(true); } }  Through the above code, you can insert the file data
Extract File data into JTable
Extract File data into JTable In this section, you will learn how to read the data from the text file and insert it into JTable. For this, we have created... the BufferedReader class, we have read the data of the file. This data is then broken
Convert pdf to rtf file using Java
Convert pdf to rtf file using Java In this section, you will learn how to convert .pdf file to .rtf file in java programming language. We have used itext api for this purpose. To read resume.pdf  file, we have used PDFReader class
Convert pdf to text file using Java
How to Convert pdf to text file in Java In this section, you will learn how to convert pdf file to text file in Java Programming. We have used itext api for this purpose. To read resume.pdf  file, we have used PDFReader class
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
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 excel into pdf
convert excel into pdf  How to convert excel into pdf files
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 PDF to XML in Java
Convert PDF to XML File in Java In this Java tutorial section, you will learn how to convert pdf file to xml using java program. We have used itext api for this purpose. To read hello.pdf file, we have used PDFReader class. The data
Download PDF file
Download PDF file  How to download PDF file with JSF
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
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
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
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
How to Make a Pdf and inserting data
make a pdf file and how we can insert a data into the pdf file. This all... How to Make a Pdf and inserting data  ...* and com.lowagie.text.pdf.* package which will help us to make a pdf file. ADS_TO_REPLACE_1
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 ZIP To PDF
Convert ZIP To PDF       Lets discuss the conversion of a zipped file into pdf file... into the string by using the string class constructor.Generate a pdf file
Convert pdf to rtf and txt - XML
Convert pdf to rtf and txt  Can we convert PDF to RTF and TXT, and how?  Hi Friend, Try the following codes: 1)Convert PDF to RTF...) {} } } 2)Convert PDF to TEXT import java.io.*; import java.util.
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
converting html file into pdf - Struts
converting html file into pdf  i want to convert html file into pdf file using java code please help me
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
Read PDF file
Read PDF file Java provides itext api to perform read and write operations with pdf file. Here we are going to read a pdf file. For this, we have used PDFReader class. The data is first converted into bytes and then with the use
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text.*; import...()); } } } pdf given to code is in marathi it gives following output
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text...."+e.getStackTrace()); } } } pdf given to code
Retrieve Data into JTable and export it to Excel File
Java Retrieve Data into JTable and export it to Excel File... it into Vector which is then added to table. To export the table data to excel file, we...;= new JTable(data, columnNames); JScrollPane scrollPane 
ModuleNotFoundError: No module named 'data-pdf'
ModuleNotFoundError: No module named 'data-pdf'  Hi, My Python... 'data-pdf' How to remove the ModuleNotFoundError: No module named 'data-pdf... to install padas library. You can install data-pdf python with following
to convert html to pdf in java - Java Beginners
to convert html to pdf in java  HI all, i want to convert html to pdf using java. actually i dont need as the tags in the html. but the tags should be removed and i need only the text in that. Thanks in advance
To convert Html to pdf in java - Java Beginners
To convert Html to pdf in java  Hi all, I want to convert html file to pdf file using java. can any one help me out. Thanks & Regards... static void main(String[]args){ try{ File file = new File("applet.html
how to dispaly pdf file on browser
how to dispaly pdf file on browser  In my project i have created one pdf file(by pdfwriter) into my local mechine . after that it need to display in browser as a pdf file . but in jsp i can't display by tag can anyone give me
upload the pdf file only - Struts
upload the pdf file only  plz tell me,in my web application i want to upload only pdf file.but i m getting the problem when anyone change the extesion of EXE or TEXT with .pdf its also upload.plz give me response ASAP plz
upload only pdf file - Struts
upload only pdf file  in web application,i want to attach only pdf file but if i change the extension of EXE or TXT files with PDF Extension its also upload ,but i want to upload only pdf file not only the extesion but also
Generate pdf file - JSP-Servlet
Generate pdf file   Hi Friends, How to generate the pdf file for the jsp page or in servets  Hi Friend, You need to download itext api. After that set the classpath and try the following code
how to display pdf file on browser
how to display pdf file on browser   In my project i have created one pdf file(by pdfwriter) into my local mechine . after that it need to display in browser as a pdf file . but in jsp i can't display by iframe tag can anyone
Display both image and data into Swing JTable
Display both image and data into Swing JTable  How To Display both image and data into Swing JTable which is retrieved from MySQL database
convert data format sql
convert data format sql  convert data format sql
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
form field mapping with pdf file using java
form field mapping with pdf file using java   Hai all, I have one... file. means, if click on text field according that perticular field .the data related to the field in pdf file should marked with a color. can any one give
how to generate pdf file in struts
how to generate pdf file in struts  I am developing a struts application.I am having one registration form when i am submitting the form the values... be shown as pdf or excel format

Ads