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();
}
}
}
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
Post a Comment