Using iTextPdf to generation PDF files in Android 2

In this tutorial, we will learn how to generate PDF files in Android Application using iTextPdf library.

iTextpdf is open source library for PDF generation, under the copyright law:

Copyright law allows an author to prohibit others from reproducing, adapting, or distributing copies of the author’s work.

According to the copyright law, you do not have the right to use software that you didn’t write yourself.

However, iText is distributed using a copyleft license:

Copyleft gives every person who receives a copy of a work permission to reproduce, adapt or distribute the work as long as any resulting copies or adaptations are also bound by the same copyleft licensing scheme.

This means that anyone can use iText for free as long as the conditions for its use are met.

To know more about the conditions, you need to take a look at the license. In this case: the AGPL. This means that:

  • You can not distribute a closed source application that is based on iText without distributing the full source code of your own application.
  • You can not use iText in a web application without making the full source code of your web application available through that web application.


Step 1:

Library Dependency:

Step 2:

Create new FileOutputStream and give name to this output file to store your Pdf content.

Step 3:

Create instance of Document class. getInstance() of PdfWriter is used to write every element of this Document into the outputstream file.

Step 4:

Add some document header attributes.

Step 5:

Add some document footer.


To add a Paragraph to the document.

To insert an image into the document.

To create a table in a document.

To create a list in a document.

To create an anchor and a new chapter.


To create a PDF from HTML file.

XML Worker uses HTML TagProcessors in the HtmlPipeline to convert HTML to PDF.

  • XML Worker will look for CSS styles in the head tag (external or internal), and for styles in individual tags.
  • XML Worker will automatically create bookmarks for header tags h1 to h6.
  • XML Worker will only add pictures to the document if they are defined using a fully qualified URL.

Library Dependency:




generate_pdf1 generate_pdf2 generate_pdf3 generate_pdf4 generate_pdf5 generate_pdf6

Complete Source Code available at here.


About Durga Chiranjeevi

I’m a normal guy, engineer by education who is passionate about Programming and Internet. An android enthusiast, now moving for cross platforms and game development.