Showing posts with label Using itext to generate pdfs. Show all posts
Showing posts with label Using itext to generate pdfs. Show all posts

Friday, 25 January 2013

Using itext to generate pdfs

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


Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...