New approach for offline viewing PDF inside Android browser

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Re: New approach for offline viewing PDF inside Android brow

Postby rmuzzini » Mon Sep 04, 2017 8:56 am

jim1001 wrote:I'd be grateful for any answers to some basic questions about this solution.


hi, jim.

jim1001 wrote:[*]Does this allow for PDF viewing inside a LiveCode app or does it jump out of the LiveCode app?

you open the pdf inside your LC app. in someway, you can write your pdf viewer app using LC.

jim1001 wrote:[*]Does it use the following LiveCode?
Code: Select all
mobileControlCreate “browser”


in my case, yes. as i previously said, the browser widget was not reliable in my context. then i used the good old way. i.e.:
Code: Select all
local sBrowserID
on openMobileBrowser pURL //for mobile environment
   if sBrowserID is a number then mobileControlDelete sBrowserID
   mobileControlCreate "browser"
   put the result into sBrowserID
   mobileControlSet sBrowserId, "rect", (the rect of grc "browserRect")
   mobileControlSet sBrowserID, "visible", "true"
   mobileControlSet sBrowserID, "autoFit", "true"
   mobileControlSet sBrowserID, "scrollingEnabled", "true"
   mobileControlSet sBrowserID, "url", pURL
end openMobileBrowser

on openMacBrowser pURL //CEF browser has bugs on mac
   put revBrowserOpen(the windowid of this stack, "") into tBrowserId
   if tBrowserId is not an integer then doAlert "Error on opening browser:" && tBrowserId
   put tBrowserId into sBrowserId
   revBrowserSet sBrowserId, "showborder", true
   revBrowserSet sBrowserId, "rect", (the rect of grc "browserRect")
   revBrowserSet sBrowserId, "url", pURL
end openMacBrowser

on openCEFBrowser pURL //for windows, and linux - probably…
   put revBrowserOpenCef(the windowid of this stack, "") into tBrowserId
   if tBrowserId is not an integer then doAlert "Error on opening browser:" && tBrowserId
   put tBrowserId into sBrowserId
   revBrowserSet sBrowserId, "showborder", true
   revBrowserSet sBrowserId, "rect", (the rect of grc "browserRect")
   revBrowserSet sBrowserId, "url", pURL
end openCEFBrowser

on doAlert pMessage
   answer warning pMessage
   exit to top
end doAlert


jim1001 wrote:[*]Will it work with LiveCode Community current stable release (8.1.6)?


i'm still using LC 8.1.0., indy edition, and concering that version the answer is "yes". you have just to do your own tests using the version your need to.

jim1001 wrote:...and now having had a quick look at the LiveCode Dictionary for widget

[*]What is the list of all things you need to do for the solution? eg. do you have to build your own widget from a Builder extension? (something I know nothing about)
[*]Assuming widgets are important in all this, where is the best place to find out more about them in general (including their URL property)?[/list]

Thanks!


i don't like widgets, i can't give you any info on this.

regards.
rmuzzini
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 49
Joined: Mon Oct 08, 2012 11:30 am

Re: New approach for offline viewing PDF inside Android brow

Postby MaxV » Mon Sep 04, 2017 12:50 pm

Here my answers:
jim1001 wrote:Does this allow for PDF viewing inside a LiveCode app or does it jump out of the LiveCode app?

It works inside livecode, it just use the integrated browser capabilities with javascript.
jim1001 wrote:Does it use the following LiveCode?
Code: Select all
mobileControlCreate “browser”


You can use the browser widget or the code to show the browser.
jim1001 wrote:Will it work with LiveCode Community current stable release (8.1.6)?

Yes, it works with any version.
jim1001 wrote:What is the list of all things you need to do for the solution? eg. do you have to build your own widget from a Builder extension?

No, you dind't need to build. Just unpack the HTML/Javascipts files of the previous link: https://github.com/mozilla/pdf.js/relea ... 0-dist.zip . It's the javascript PDF reader of firefox and works with any browser.
jim1001 wrote:Assuming widgets are important in all this, where is the best place to find out more about them in general (including their URL property)?

No widgets.
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w
MaxV
 
Posts: 1282
Joined: Tue May 28, 2013 2:20 pm
Location: Italy

Re: New approach for offline viewing PDF inside Android brow

Postby jim1001 » Mon Sep 04, 2017 4:54 pm

rmuzzini & MaxV,

Thank you for taking the time to answer my questions. Having read you answers, re-read previous posts and the original article I understand it much better. I could ask more questions as a lot of this is new to me but think maybe I'll have a go with getting it to work first & maybe ask later if I get any problems.

Thanks again for sharing your work.

All the best,
Jim
jim1001
 
Posts: 116
Joined: Fri Jan 29, 2016 6:25 pm

Re: New approach for offline viewing PDF inside Android brow

Postby jim1001 » Wed Sep 06, 2017 11:57 am

I can get the PDF viewer to show on the Android tablet but I can't get any PDF to display in it.

I've tried lots of combinations, too many to list, but for example this one

Browser URL
Code: Select all
"file:/sdcard/.../pdfjs/web/viewer.html"

with viewer.js as supplied gives me a blank PDF viewer

I would really like to set the PDF file in LiveCode so I tried the setting rmuzzini advised. But this combination

Browser URL
Code: Select all
"file:/sdcard/.../pdfjs/web/viewer.html?filepath='/sdcard/.../test.pdf'"

with viewer.js
Code: Select all
var DEFAULT_URL = decodeURIComponent...

also gave me a blank PDF viewer.

Any idea how to get the PDF to show? Thanks!
jim1001
 
Posts: 116
Joined: Fri Jan 29, 2016 6:25 pm

Re: New approach for offline viewing PDF inside Android brow

Postby jim1001 » Wed Sep 06, 2017 4:56 pm

If I type the following address directly into the address bar of a Chrome browser on the tablet I also see the PDF viewer. The PDF is still not visible although the tab shows the filename (test.pdf) I set as the DEFAULT_URL in viewer.js

Code: Select all
file:///sdcard/.../pdfjs/web/viewer.html

viewer.js
Code: Select all
var DEFAULT_URL = "file:///sdcard/.../PDFs/test.pdf";


ps: I did read that https://mozilla.github.io/pdf.js/getting_started/ says
Note: the worker is not enabled for file:// urls, so use a server.

Any help appreciated - thanks.
jim1001
 
Posts: 116
Joined: Fri Jan 29, 2016 6:25 pm

Re: New approach for offline viewing PDF inside Android brow

Postby MaxV » Thu Sep 07, 2017 12:11 pm

Code: Select all
    var DEFAULT_URL = 'test.pdf';

works.

Best regards
Max
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w
MaxV
 
Posts: 1282
Joined: Tue May 28, 2013 2:20 pm
Location: Italy

Re: New approach for offline viewing PDF inside Android brow

Postby jim1001 » Thu Sep 07, 2017 7:05 pm

Hi MaxV,

Thanks for your suggestion. I wish it would work for me but it doesn't! Before my last post I had tried similar to your suggestion with the supplied default PDF and another one in the web folder and changing DEFAULT_URL to point at them. The result is always the same - a blank PDF viewer but with the correct PDF filename on the tab.

I've tried on two different Android tablets, a Samsung and a Lenovo and get the same result.

Downloading the PDF using the PDF viewer controls does work.

https://github.com/mozilla/pdf.js/issues/7157 is the closest I've seen to what I get, although the Document Properties are always empty for me.

I haven't looked into the CSS yet - need to look into how to do that on a tablet.

And any idea why a GitHub contributor says "the worker is not enabled for file:// urls"?

Cheers,
Jim
jim1001
 
Posts: 116
Joined: Fri Jan 29, 2016 6:25 pm

Re: New approach for offline viewing PDF inside Android brow

Postby MaxV » Sun Sep 10, 2017 7:56 pm

I'll try to send you my results as soon as I'll touch the PC with my work, this week I'm travelling a lot and I hope, I I'll remember to do it when I'll be back home. Just in case send me a private message near the end of the week to remember it. :mrgreen:
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w
MaxV
 
Posts: 1282
Joined: Tue May 28, 2013 2:20 pm
Location: Italy

Re: New approach for offline viewing PDF inside Android brow

Postby jim1001 » Sun Sep 10, 2017 9:19 pm

Thank you MaxV. Look forward to seeing your results.

All the best,
Jim
jim1001
 
Posts: 116
Joined: Fri Jan 29, 2016 6:25 pm

Re: New approach for offline viewing PDF inside Android brow

Postby MaxV » Mon Sep 11, 2017 5:53 pm

Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w
MaxV
 
Posts: 1282
Joined: Tue May 28, 2013 2:20 pm
Location: Italy

Re: New approach for offline viewing PDF inside Android brow

Postby mrcoollion » Tue Sep 12, 2017 9:39 am

Thanks :D
I can really use this in my mobile apps!
mrcoollion
 
Posts: 237
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: New approach for offline viewing PDF inside Android brow

Postby jim1001 » Tue Sep 12, 2017 5:37 pm



Thanks MaxV - your code worked for me. And now I understand what you meant by the browser widget - I thought on mobile you had to use mobileControlCreate “browser”.

However to be useful in the app I'm developing I really need to pass the PDF file in my LiveCode as rmuzzini said he had done:
<path-to-viewer-folder>/viewer.html?filepath=<path-to-your-local-or-remote-pdf-file>


MaxV - have you tried this?

I couldn't get it to work. I tried with the pdfjs folder & PDFs already copied to the Android device before installing the app. Also tried copying over the pdfjs folder & PDFs on installation with "Copy files" of the app.

rmuzzini - I noticed your PDF file was stored under specialFolderPath("Documents") - is this essential for your code to work or can you display a PDF stored in another place?

If we do have to use specialFolderPath("Documents") is it possible to manually copy files outside LiveCode to it? I read at http://livecode.wikia.com/wiki/Saving_files_on_Android that it's a virtual folder but can't find it in the Android filesystem...

Best wishes,
Jim
jim1001
 
Posts: 116
Joined: Fri Jan 29, 2016 6:25 pm

Re: New approach for offline viewing PDF inside Android brow

Postby MaxV » Wed Sep 13, 2017 10:08 am

jim1001 wrote:Thanks MaxV - your code worked for me. And now I understand what you meant by the browser widget - I thought on mobile you had to use mobileControlCreate “browser”.

However to be useful in the app I'm developing I really need to pass the PDF file in my LiveCode

rmuzzini - I noticed your PDF file was stored under specialFolderPath("Documents") - is this essential for your code to work or can you display a PDF stored in another place?

If we do have to use specialFolderPath("Documents") is it possible to manually copy files outside LiveCode to it? I read at http://livecode.wikia.com/wiki/Saving_files_on_Android that it's a virtual folder but can't find it in the Android filesystem...

On mobile all the files selected to include in your app, from the Standalone application settings, are copied in specialFolderPath("Engine"). This virtual folder is a read only folder, so you can't modify it.
You have to:
  • copy all files and folder in specialFolderPath("Documents"),
  • overwrite the test.pdf with your file,
  • use this code: set the URL of widget 1 to (specialFolderPath("Documents") & "/pdfjs/web/viewer.html")
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w
MaxV
 
Posts: 1282
Joined: Tue May 28, 2013 2:20 pm
Location: Italy

Re: New approach for offline viewing PDF inside Android brow

Postby jim1001 » Mon Sep 18, 2017 8:12 pm

MaxV,

Thanks for your last post & sorry for the delay.

On mobile all the files selected to include in your app, from the Standalone application settings, are copied in specialFolderPath("Engine").


Well my case is special in that I will be personally installing my app on the few devices that will be using it. The app I’m developing has a lot of media files, eg videos, PDFs, that I don’t want to copy over each time I build & install the app. I will be able to copy these media files to the devices outside LiveCode and reference them by absolute path name from LiveCode.

Anyhow I would still like to understand your suggestion.

copy all files and folder in specialFolderPath("Documents"),

Can you explain this please? What files and folders do you mean? Where, when and how do you do this?

overwrite the test.pdf with your file,

Do you mean in viewer.js keep
Code: Select all
var DEFAULT_URL = 'test.pdf'
but swap different files into test.pdf?
Can you do this inside LiveCode? My app needs to view lots of different PDFs on user demand.

rmuzzini apparently found an easier way where he could display a PDF anywhere on the target filesystem. However I couldn’t get his code to work.

Thanks,
Jim
jim1001
 
Posts: 116
Joined: Fri Jan 29, 2016 6:25 pm

Previous

Return to Android Deployment

Who is online

Users browsing this forum: No registered users and 0 guests