Sumit
Sumit

Reputation: 928

Convert text to PDF

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.

Upvotes: 1

Views: 4162

Answers (1)

Kuitsi
Kuitsi

Reputation: 1675

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/

Upvotes: 1

Related Questions