Take the 2-minute tour ×

I am trying to create a PDF file by inserting some text into it with a proper structure in Android.

Document doc = new Document();
PdfWriter.getInstance(doc, new FileOutputStream("urgentz.pdf"));
Image image = Image.getInstance ("urgentzImageahslkdhaosd.jpg");
doc.add(new Paragraph("Your text blah bleh"));

The above code does not work.

share|improve this question
Here is a tutorial of how to Convert Text to PDF in Java. Hope this helps. roseindia.net/java/java-conversion/TextToPDF.shtml –  iKiar Aug 17 '12 at 14:01
– iKiar Its not working for android. It gives error in importing PDF Reader –  Sumit Aug 17 '12 at 14:06
Did you properly add all of the .jar files to your project? (Check your Java Build Path) –  iKiar Aug 17 '12 at 14:15
What is the error? Can you edit your question and add the stacktrace? –  Alexis Pigeon Aug 17 '12 at 14:19

1 Answer 1

Without seeing stacktrace I can only guess what's wrong. You might find these questions useful:

Some ideas:

  1. Check File paths. You have specified only filenames to pdf and image without any paths. Use something like /mnt/sdcard/<YourFolderHere>/somefile.pdf and make sure you have defined android.permission.WRITE_EXTERNAL_STORAGE in AndroidManifest.xml
  2. Use droidText instead of iText
  3. Try another PDF Writer library http://coderesearchlabs.com/androidpdfwriter/
share|improve this answer

Your Answer


