Share with others

Creating a PDF file using Java code

 

We will use the iText API for creating a pdf file using java code. Its a open source java API for creating pdf files, But if you are planning to use this iText API for commercial purpose you need to buy a licence for it. You can download this iText API from below link.

Download iText API

You can create pdf documents, XML files, HTML as well as RTF documents using this API. Lots of customization are there in this iText API which allows users create paragraphs, applying different fonts, adding images to pdf files, adding watermarks to pdf documents etc.

Steps to be followed for creating a PDF Document

  • Create a document using com.itextpdf.text.Document class of iText API.
  • Now create a PdfWriter using com.itextpdf.text.pdf.PdfWriter.
  • Open the document and start writing text to it.
  • After writing content to it, close the document as well as writer.

Below is the Snapshots for Application using Java swings:

create a pdf using java

Here user will enter the details on the UI form of member application. We have one button also which will be used to create pdf file in the location we have provided.

create a pdf file

In this snapshots you can see the user has entered all the details. [Note] We are considering date field as the string only.


 

Now moving on to source code of this small application:

 

Download the Source Code
Creating a PDF file using Java Code


Share with others