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

Java Interview question and answer

  Java Backend Interview Prep — Q&A Guide Java Backend Interview Prep 24 topics · 287 questions Expand all Collap...