Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to generate a pdf file for which am using itext but am not using any ide..
I want to make in simple notepad using commmand prompt..
Is there any other way of generating pdf file......
please help..........
Posted
Comments
[no name] 17-Mar-15 20:14pm    
Alright - you want to generate a pdf file with java and itext. And for whatever reason you want to write your java code in notepad instead of an IDE - fine. But why would not using an IDE stop you from being able to use itext to generate a pdf?
Member 11520467 17-Mar-15 20:28pm    
thanks a lot brother but I dont know how to do it....
can you please help me out with this.....
[no name] 17-Mar-15 20:35pm    
I don't understand what exactly the problem is.
Member 11520467 17-Mar-15 20:38pm    
i dont know how to convert jtable to pdf....
[no name] 17-Mar-15 20:41pm    
take a look here:
http://istime4j.blogspot.de/2014/01/export-jtable-data-to-pdf-file-in-java.html

Please see my comments to the question.

You really can develop Java code using just some text editor and just command-line tool. The main one is javac:
https://www.google.com/?gws_rd=ssl[^].

See also: http://www.cs.swarthmore.edu/~newhall/unixhelp/debuggingtips_Java.html[^].

—SA
 
Share this answer
 
v2
import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

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

public PDFTest(){
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("d:/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);
}
}




am getting these errors:::::::::::::::::::
C:\Users\Tushar\Desktop\login\report to pdf>javac PDFTest.java
PDFTest.java:6: error: package com.itextpdf.text does not exist
import com.itextpdf.text.Document;
^
PDFTest.java:7: error: package com.itextpdf.text.pdf does not exist
import com.itextpdf.text.pdf.PdfPTable;
^
PDFTest.java:8: error: package com.itextpdf.text.pdf does not exist
import com.itextpdf.text.pdf.PdfWriter;
^
PDFTest.java:31: error: cannot find symbol
Document document=new Document();
^
symbol: class Document
PDFTest.java:31: error: cannot find symbol
Document document=new Document();
^
symbol: class Document
PDFTest.java:32: error: cannot find symbol
PdfWriter.getInstance(document,new FileOutputStream("d:/data.pdf"));
^
symbol: variable PdfWriter
PDFTest.java:34: error: cannot find symbol
PdfPTable tab=new PdfPTable(2);
^
symbol: class PdfPTable
PDFTest.java:34: error: cannot find symbol
PdfPTable tab=new PdfPTable(2);
^
symbol: class PdfPTable
8 errors
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900