write pdf file using java with itext

Make a pdf file through itext jar in java

write pdf file using java with itext

import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;

/**
  * @Manoj Shakya
 */
public class Test {

    public static void main(String [] aa){
        try{
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        PdfWriter.getInstance(document, new FileOutputStream("C:\\test.pdf"));
        document.open();
        PdfPTable bodytable = new PdfPTable(6);
       

        for(int i=0; i<5; i++){

            bodytable.addCell("first");
            bodytable.addCell("second");
            bodytable.addCell("third");
            bodytable.addCell("fourth");
            bodytable.addCell("fifth");
            bodytable.addCell("sixth");
        }
        document.add(bodytable);
        document.close();
        }catch(Exception e){
        e.printStackTrace();
    }
    }

}

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

How to capture finger prints in java

Shallow Copy Deep Copy Java example