show a pdf file inside an app

Is possible to insert in android app a pdf file and show it inside the app when the user press a button?

In ipad app I show the pdf file inside the app with

       kwksust_ficha = native.newWebView( 900, 700, 2468, 1536 ) 

       kwksust_ficha:request( “fl_suelos1.pdf”, system.ResourceDirectory ) 

       kwksust_ficha.oriX = kwksust_ficha.x; kwksust_ficha.oriY = kwksust_ficha.y 

       kwksust_ficha.alpha = 1; kwksust_ficha.oldAlpha = 1 

       kwksust_ficha.name = “kwksust_ficha” 

       sceneGroup:insert(kwksust_ficha); sceneGroup.kwksust_ficha = kwksust_ficha

 

 

If whith WebView is not possible, is any way to do it?

(I would like that the pdf file is inside the app on the device but if it’s not possible, is possible to show it if the pdf file is on my own server and require an online connection?

 

There isn’t a good way to do PDF’s in Android. Even Chrome wants to download them and then launch some PDF viewer app. You might be able to open that app and pass it the PDF, but I’m not sure of that.

Rob

I have been looking for and if I understand well it’s possible to show pdf files inside an android app with some librarys:

pdfrenderer

https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html

or 

android-pdfview

https://github.com/JoanZapata/android-pdfview

but I do not know if it’s possible to use them with corona sdk and I don’t understant how to implement them

You might be able to do this with Corona Enterprise, but not Corona SDK.

Rob

On Android, you can use the system.openURL() function.  That’ll display your local PDF file via the default PDF viewer 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!

thanks a lot Joshua. it’s ok the answer you say. 

I’ve tested and it work.

It open the pdf when the page is loading

Now I go to try making a buttton to open the pdf when the user press a button and a message if the user’s device have not installed a pdf viewer.

Thanks a lot.

Great!  And I also recommend using system.openURL() for Windows Phone 8 and OSX/Win32 desktop apps too if you plan on porting your app onto those platforms in the future.

For iOS, we have a QuickLook plugin that’ll display your PDF within your own app without suspending it if you want to use it.  That’ll open the PDF more the Apple iOS way.  Information about this plugin can be found here…

   https://docs.coronalabs.com/plugin/CoronaProvider_native_popup_quickLook/index.html

Thanks Joshua.

Until now, I have not problems showing pdf files on ipad (ios).

I used …

kwksust_ficha = native.newWebView( 900, 700, 2468, 1536 ) 

       kwksust_ficha:request( “fl_suelos1.pdf”, system.ResourceDirectory ) 

       kwksust_ficha.oriX = kwksust_ficha.x; kwksust_ficha.oriY = kwksust_ficha.y 

       kwksust_ficha.alpha = 1; kwksust_ficha.oldAlpha = 1 

       kwksust_ficha.name = “kwksust_ficha” 

       sceneGroup:insert(kwksust_ficha); sceneGroup.kwksust_ficha = kwksust_ficha

 

and it show the pdf file and the user do not go out of my app.

I think it woks also now if apple developers have not changed nothing

There isn’t a good way to do PDF’s in Android. Even Chrome wants to download them and then launch some PDF viewer app. You might be able to open that app and pass it the PDF, but I’m not sure of that.

Rob

I have been looking for and if I understand well it’s possible to show pdf files inside an android app with some librarys:

pdfrenderer

https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html

or 

android-pdfview

https://github.com/JoanZapata/android-pdfview

but I do not know if it’s possible to use them with corona sdk and I don’t understant how to implement them

You might be able to do this with Corona Enterprise, but not Corona SDK.

Rob

On Android, you can use the system.openURL() function.  That’ll display your local PDF file via the default PDF viewer 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!

thanks a lot Joshua. it’s ok the answer you say. 

I’ve tested and it work.

It open the pdf when the page is loading

Now I go to try making a buttton to open the pdf when the user press a button and a message if the user’s device have not installed a pdf viewer.

Thanks a lot.

Great!  And I also recommend using system.openURL() for Windows Phone 8 and OSX/Win32 desktop apps too if you plan on porting your app onto those platforms in the future.

For iOS, we have a QuickLook plugin that’ll display your PDF within your own app without suspending it if you want to use it.  That’ll open the PDF more the Apple iOS way.  Information about this plugin can be found here…

   https://docs.coronalabs.com/plugin/CoronaProvider_native_popup_quickLook/index.html

Thanks Joshua.

Until now, I have not problems showing pdf files on ipad (ios).

I used …

kwksust_ficha = native.newWebView( 900, 700, 2468, 1536 ) 

       kwksust_ficha:request( “fl_suelos1.pdf”, system.ResourceDirectory ) 

       kwksust_ficha.oriX = kwksust_ficha.x; kwksust_ficha.oriY = kwksust_ficha.y 

       kwksust_ficha.alpha = 1; kwksust_ficha.oldAlpha = 1 

       kwksust_ficha.name = “kwksust_ficha” 

       sceneGroup:insert(kwksust_ficha); sceneGroup.kwksust_ficha = kwksust_ficha

 

and it show the pdf file and the user do not go out of my app.

I think it woks also now if apple developers have not changed nothing