Thursday, 13 August 2015

How to Create PDF File Using Java Code

package com.anand;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;

public class GeneratePDF {

    public static void main(String[] args) {
        try {
            OutputStream file = new FileOutputStream(new File("/home/ananddw/test.pdf"));
            Document document = new Document();
            PdfWriter.getInstance(document, file);
            document.open();
            document.add(new Paragraph("welcome Anand in the World of PDF "));
          
            document.close();
            file.close();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }
}

===============================================
Attach Some Require Jar else you will get error 

Thanks 
Anand Dwivedi

No comments:

Post a Comment

Map class field to map

 import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class AutogeneratedClassMapper {     public static M...