How to create PDF file using iText or some other library on android?

Khushwant picture Khushwant · Dec 8, 2011 · Viewed 36.3k times · Source

How to create PDF file using iText or some other library on android?

Is there any tutorial on iText for android?

Thanks

Answer

arTsmarT picture arTsmarT · Jan 21, 2012

You can use iText to create PDFs. Use the latest version (5.1.3) and include only the itextpdf-5.1.3.jar in the build path. You can use something like this to accomplish the pdf creation.

Document document = new Document();
file = Environment.getExternalStorageDirectory().getPath() + "/Hello.pdf"
PdfWriter.getInstance(document,new FileOutputStream(file));
document.open();
Paragraph p = new Paragraph("Hello PDF");
document.add(p);
document.close();

Also, don't forget to use the permission to write to external storage in the manifest.xml.