1

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"));
doc.open();
Image image = Image.getInstance ("urgentzImageahslkdhaosd.jpg");
doc.add(new Paragraph("Your text blah bleh"));
doc.add(image);               
doc.close();

The above code does not work.

JJD
  • 50,076
  • 60
  • 203
  • 339
Sumit
  • 928
  • 2
  • 15
  • 34

1 Answers1

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/
Community
  • 1
  • 1
Kuitsi
  • 1,675
  • 2
  • 28
  • 48