Android PDF - Any native options yet?

Hi Peeps,

Like many others I’m still looking for a slick option to display PDF’s on android. It amazes me that the platform still can’t display PDF’s natively.

To date the only solution I’ve had is to JPG all the pages/slides of a PDF and use a webView to display them in HTML. Simple but no-where as slick as the iOS offering.

Are there any tricks or libraries that could be used to display PDF’s without the need for an internet connection.

Many thanks and sorry to bring this old subject back up again!

Chris.

On Android, you can use the system.openURL() function. That’ll display your local PDF file via the default PDF viewer app installed on the device. This is more of the Android way of doing it because when the end-user is done looking at the PDF file, pressing the Back key will take them back to your app.

local wasOpened = system.openURL(system.pathForFile("fl\_suelos1.pdf")) if (wasOpened) then -- PDF was opened successfully by the default PDF viewer. -- Note that your app will be suspended when this happens. else -- A PDF viewer is not available on the device. -- You can ask the user nicely to install one in order to view PDF files. end

I hope this help!

Great work. I’ll give it a test. Thankfully I control the software on the device so I can ensure there is a PDF viewer on there. 

Any suggestion on the best PDF viewer? Adobe I presume?

Recommending Adobe’s “Acrobat Reader” makes the most sense, except it’s currently only supported on Android 4.0.3 and newer OS versions.
   https://play.google.com/store/apps/details?id=com.adobe.reader&hl=en
 
Corona currently supports Android 2.3 and higher.  So, you might want to recommend a 3rd party version on older OS versions.
 
If you want to alert the user to download a different PDF app viewer based on the Android OS version that they’re running, then the newest daily builds can make this easier via a new system.getInfo(“androidApiLevel”) API.
   https://docs.coronalabs.com/daily/api/library/system/getInfo.html#androidapilevel
 
This allows you to do something like this…

local androidApiLevel = system.getInfo("androidApiLevel") if (androidApiLevel \>= 15) then -- Recommend Adobe's PDF viewer app. else -- Recommend a 3rd party PDF viewer app for older OS versions. end

Great tip, thanks  :slight_smile:

On Android, you can use the system.openURL() function. That’ll display your local PDF file via the default PDF viewer app installed on the device. This is more of the Android way of doing it because when the end-user is done looking at the PDF file, pressing the Back key will take them back to your app.

local wasOpened = system.openURL(system.pathForFile("fl\_suelos1.pdf")) if (wasOpened) then -- PDF was opened successfully by the default PDF viewer. -- Note that your app will be suspended when this happens. else -- A PDF viewer is not available on the device. -- You can ask the user nicely to install one in order to view PDF files. end

I hope this help!

Great work. I’ll give it a test. Thankfully I control the software on the device so I can ensure there is a PDF viewer on there. 

Any suggestion on the best PDF viewer? Adobe I presume?

Recommending Adobe’s “Acrobat Reader” makes the most sense, except it’s currently only supported on Android 4.0.3 and newer OS versions.
   https://play.google.com/store/apps/details?id=com.adobe.reader&hl=en
 
Corona currently supports Android 2.3 and higher.  So, you might want to recommend a 3rd party version on older OS versions.
 
If you want to alert the user to download a different PDF app viewer based on the Android OS version that they’re running, then the newest daily builds can make this easier via a new system.getInfo(“androidApiLevel”) API.
   https://docs.coronalabs.com/daily/api/library/system/getInfo.html#androidapilevel
 
This allows you to do something like this…

local androidApiLevel = system.getInfo("androidApiLevel") if (androidApiLevel \>= 15) then -- Recommend Adobe's PDF viewer app. else -- Recommend a 3rd party PDF viewer app for older OS versions. end

Great tip, thanks  :slight_smile: