How to create PDFs in an Android app? [closed]

Solution 1:

If anyone wants to generate PDFs on Android device, here is how to do it:

  • http://sourceforge.net/projects/itext/ (library)
  • http://www.vogella.de/articles/JavaPDF/article.html (tutorial)
  • http://tutorials.jenkov.com/java-itext/image.html (images tutorial)

Solution 2:

If you are developing for devices with API level 19 or higher you can use the built in PrintedPdfDocument: http://developer.android.com/reference/android/print/pdf/PrintedPdfDocument.html

// open a new document
PrintedPdfDocument document = new PrintedPdfDocument(context,
     printAttributes);

// start a page
Page page = document.startPage(0);

// draw something on the page
View content = getContentView();
content.draw(page.getCanvas());

// finish the page
document.finishPage(page);
. . .
// add more pages
. . .
// write the document content
document.writeTo(getOutputStream());

//close the document
document.close();