Sometimes we need to create PDF reports as we do crystal reports in .Net. Same thing can be
achieved through iText library. Following program creates a PDF file and adds a text into it. In order to achieve this you need to download the iText library and import it's jar file into your
program.
Here is the link to download:
iText JAR
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class iTextPDFDemo {
public void iTextPDF() throws Exception{
String FILE = "D:/MyiText.pdf";
Document document = new Document();
PdfWriter.getInstance(document,
new FileOutputStream(FILE));
document.open();
document.add(new Paragraph("Now I can be able to write into the world of PDF "));
document.close();
}
public static void main(String args[]){
iTextPDFDemo get = new iTextPDFDemo();
try {
get.iTextPDF();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Comments
Post a Comment