Display PDF in android device

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

terryho
Posts: 89
Joined: Mon Nov 05, 2012 2:53 pm

Display PDF in android device

Post by terryho » Sun Mar 24, 2013 1:39 pm

Hi all

Can anyone help me to view a preloaded PDF file in android device?

I use the following example code, which can view PDF file in iOS device, but it cannot work in android device.

On preOpenCard
# create the browser
MobileControlCreate "browser"
put the result into sBrowserId
put "file://" & specialfolderpath("engine") & "/sample.pdf" into tLocalPDF

# set up the basic defaults
MobileControlSet sBrowserId, "rect" , the rect of group "Browser"
MobileControlSet sBrowserId, "visible" , "true"
## Then set the iOS browser to that URL
MobileControlSet sBrowserId, "url", tLocalPDF
end preOpenCard

Does it need special command for android device?

Regards

Terry Ho

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Display PDF in android device

Post by Simon » Sun Mar 24, 2013 9:28 pm

Hello Terry,
Android browser does not support .pdf viewing.
...it cannot work in android device
You have it right :D

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

juanjo
Posts: 35
Joined: Wed Jul 31, 2013 10:31 am

Re: Display PDF in android device

Post by juanjo » Wed Oct 30, 2013 12:47 pm

Any other way to display a PDF in Android?

Klaus
Posts: 11313
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Display PDF in android device

Post by Klaus » Thu Oct 31, 2013 2:21 pm

Hi Terry,

I read this one on the mailing list, maybe this will help:
http://stackoverflow.com/questions/7437 ... ding-first

Use it like this:
...
put (the path to the PDF on the device) into tURL
put "http://docs.google.com/gview?embedded=true&url=" before tURL
mobileControlSet "webPage","URL",tURL
...
I do not develop for ANDROID (yet) so I cannot test this.


Best

Klaus

JackD
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 28
Joined: Sat Mar 14, 2009 3:17 am
Location: Olympia, WA USA

Re: Display PDF in android device

Post by JackD » Wed Dec 04, 2013 4:28 am

Thanks Klaus,

"put "http://docs.google.com/gview?embedded=true&url=" before tURL" really does work. It's a bit clunky but the pdf opens and you can zoom in to read it.

How did we ever make progress before we had the internet and forums like this?
27" iMac, OS X 10.13
iPad 3, iPad Pro, iPhone 4s, iPhone 6, LG Optimus L9 phone, Samsung Galaxy Camera
LiveCode 8.1.9

Klaus
Posts: 11313
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Display PDF in android device

Post by Klaus » Wed Dec 04, 2013 12:48 pm

Hi Jack,
JackD wrote:How did we ever make progress before we had the internet and forums like this?
well, I did!
Maybe thats why I am so "fit" in Livecode, I had to learn it the hard way with try an error in my early days without internet! 8)

That's why I really get angry about people posting here but don't bother to take a short look into the dictionary but start to waste our time right way!
Not you, don't get me wrong! :)


Best

Klaus

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Display PDF in android device

Post by joel.epsteinBUS31vi » Thu Mar 06, 2014 4:33 am

Hi all -

Once again, I'm sure I'm missing something fundamentally obvious and simple. Unfortunately, I'm not seeing where I've gone astray and I'd appreciate any advice you may have.

I am trying to display a PDF in a browser on an Android device. I've made sure to put the appropriate file in the "copy files" pane of the standalone settings. But when I use this code:

Code: Select all

mobileControlCreate "browser"
put the result into browserID
mobileControlSet browserID, "rect", the rect of graphic "pdfRect"
mobileControlSet browserID, "visible", "true"
         
put specialFolderPath("engine") & "/pdfs/side-effects.pdf" into theURL
put "http://docs.google.com/gview?embedded=true&url=" before theURL
replace space with "%20" in theURL
         
mobileControlSet browserID, "url", theURL
the browser window appears, but is blank. If I change the last line with an actual URL, the URL appears correctly. So I'm fairly sure I have the control set up correctly.

When I add the line: answer theURL, I get this as a result:

Code: Select all

http://docs.google.com/gview?embedded=true&url=/data/app/com.projectiveart.sgd-1.apk/pdfs/side-effects.pdf
I'm not sure what that "-1" before the .apk is doing there. When I intentionally remove the "-1", the browser window is still blank.

So... That's where I'm at. I think I may be close. Sure would appreciate a final nudge in the right direction.

Thanks so much.

Joel

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Display PDF in android device

Post by Simon » Thu Mar 06, 2014 6:29 am

Hi Joel,
In reading the google docs, I don't think it can be a local file.
You will have to upload the file to a server and use it's URL.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

joel.epsteinBUS31vi
Posts: 135
Joined: Thu Sep 13, 2012 10:25 pm

Re: Display PDF in android device

Post by joel.epsteinBUS31vi » Thu Mar 06, 2014 2:03 pm

Hi Simon -

Thanks so much for the speedy response.

So is it correct to say that - given the limitations of the Android platform - there is no way to display an on-board PDF directly within LiveCode?

I appreciate your help.

Joel

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Display PDF in android device

Post by Simon » Thu Mar 06, 2014 11:25 pm

Hi Joel,
I can't say for sure that you can't, but I haven't seen a way.
You could export the pdf to images, if you had Adobe Acrobat.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SparkOut
Posts: 2030
Joined: Sun Sep 23, 2007 4:58 pm

Re: Display PDF in android device

Post by SparkOut » Thu May 07, 2015 7:21 pm

Is this still the case? Does anyone know how to open a pdf that has been stored as a local file on the android device?

josepxavier
Posts: 6
Joined: Wed Oct 08, 2014 6:12 pm

Re: Display PDF in android device

Post by josepxavier » Fri May 08, 2015 5:15 am

I hope you do well

launch URL "file:/mnt/sdcard/formularios/preciario.pdf"

You need a viewer like Adobe Reader

SparkOut
Posts: 2030
Joined: Sun Sep 23, 2007 4:58 pm

Re: Display PDF in android device

Post by SparkOut » Fri May 08, 2015 7:50 am

This doesn't work though, when the file is bundled with the standalone app, the specialFolderPath("documents") is not accessible by the Adobe or 3rd party application. Is there a consistent location that we can copy the file to on different devices, which can be accessed by the 3rd party reader?

MaxV
Posts: 1574
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Display PDF in android device

Post by MaxV » Tue May 12, 2015 1:39 am

As josepxavier said /mnt/sdcard/ is a public folder where any app can access.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Display PDF in android device

Post by Simon » Tue May 12, 2015 2:00 am

As josepxavier said /mnt/sdcard/ is a public folder where any app can access.
Well I had always hoped that would be a constant but looking at my Galaxy S4 it's now
/storage/extSdCard/

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply

Return to “Android Deployment”