1) First download the following jar file itext-5.0.2.jar
package com.atech.prac;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import com.atech.internalCertification.CertificationBean;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
public class Practicse {
public static void main(String args[]){
try {
System.out
.println("InternalCertificationCalculation.generatePdfForUser()");
OutputStream file = new FileOutputStream(new File("D:\\"+ "prac" + ".pdf"));
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
// header table
PdfPTable table = new PdfPTable(3);
table.setTotalWidth(new float[]{ 144, 72, 72 });
table.setLockedWidth(true);
PdfPCell cell;
cell = new PdfPCell(new Phrase("Table 5"));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
cell.setRowspan(2);
table.addCell(cell);
table.addCell("row 1; cell 1");
table.addCell("row 1; cell 2");
table.addCell("row 2; cell 1");
table.addCell("row 2; cell 2");
document.add(table);
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.atech.prac;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import com.atech.internalCertification.CertificationBean;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
public class Practicse {
public static void main(String args[]){
try {
System.out
.println("InternalCertificationCalculation.generatePdfForUser()");
OutputStream file = new FileOutputStream(new File("D:\\"+ "prac" + ".pdf"));
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
// header table
PdfPTable table = new PdfPTable(3);
table.setTotalWidth(new float[]{ 144, 72, 72 });
table.setLockedWidth(true);
PdfPCell cell;
cell = new PdfPCell(new Phrase("Table 5"));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
cell.setRowspan(2);
table.addCell(cell);
table.addCell("row 1; cell 1");
table.addCell("row 1; cell 2");
table.addCell("row 2; cell 1");
table.addCell("row 2; cell 2");
document.add(table);
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment