Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best strategy for creating, displaying and printing pdf documents in android

I plan to use the built-in android pdf library. In my app I need to display a pdf report that may consist of several pages. Users should be able to print those pages. Printing with the PrintDocumentAdapter seems pretty straight forward, but what's unclear to me is what is the best way to create the pdf. I know that you can generate a PdfDocument with simply a View/canvas and or take more "low-level" approach where you draw lines,text, paint, etc.

I see three possibilities:

  1. Create a view for each page. The user can navigate between the views as needed and print. However it's unclear to me how to generate a pdf for each page/view. What I mean by this is if I'm viewing page/view 1, yes I can easily create a pdf from this, but what about the other pages? Yes I can have this in memory, but what I've found is if they aren't actively being displayed on screen, they create empty pdfs. I don't want to have the user print each page individually.

  2. Create the pdf documents (low-level approach), integrate a pdf reader and just display/print the pdf from there.

  3. Create a view for each page that the user can navigate through. When the print option is invoked, generate the pdf documents again (low-level approach)

Obviously option 1 is the preferred approach, but I'm not clear on how I can do that. Of course, I could be missing something here so any help would be appreciated!

like image 696
bmurmistro Avatar asked Nov 01 '22 07:11

bmurmistro


1 Answers

Android didn't have built in pdf genaration library, but in API19 android provided an api https://developer.android.com/reference/android/graphics/pdf/PdfDocument.html

But as @Ivan Wooll said itext is a nice pdf generation library if you want to use.

like image 112
Raghavendra Avatar answered Nov 12 '22 19:11

Raghavendra