Generate PDF in Java using iText

import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Date; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; public class GeneratePDF { public static void main(String[] args) { try { OutputStream file = new FileOutputStream(new File("C:\\Test.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("Hello Kiran")); document.add(new Paragraph(new Date().toString())); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } } }
Generate PDF in Java using iText


#java #code #snippet #pdf

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.