Page 2 of 3

Re: New approach for offline viewing PDF inside Android brow

Posted: Mon Sep 04, 2017 8:56 am
by rmuzzini
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.

Re: New approach for offline viewing PDF inside Android brow

Posted: Mon Sep 04, 2017 12:50 pm
by MaxV
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.

Re: New approach for offline viewing PDF inside Android brow

Posted: Mon Sep 04, 2017 4:54 pm
by jim1001
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

Re: New approach for offline viewing PDF inside Android brow

Posted: Wed Sep 06, 2017 11:57 am
by jim1001
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!

Re: New approach for offline viewing PDF inside Android brow

Posted: Wed Sep 06, 2017 4:56 pm
by jim1001
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.

Re: New approach for offline viewing PDF inside Android brow

Posted: Thu Sep 07, 2017 12:11 pm
by MaxV

Code: Select all

    var DEFAULT_URL = 'test.pdf';
works.

Best regards
Max

Re: New approach for offline viewing PDF inside Android brow

Posted: Thu Sep 07, 2017 7:05 pm
by jim1001
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

Re: New approach for offline viewing PDF inside Android brow

Posted: Sun Sep 10, 2017 7:56 pm
by MaxV
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:

Re: New approach for offline viewing PDF inside Android brow

Posted: Sun Sep 10, 2017 9:19 pm
by jim1001
Thank you MaxV. Look forward to seeing your results.

All the best,
Jim

Re: New approach for offline viewing PDF inside Android brow

Posted: Mon Sep 11, 2017 5:53 pm
by MaxV

Re: New approach for offline viewing PDF inside Android brow

Posted: Tue Sep 12, 2017 9:39 am
by mrcoollion
Thanks :D
I can really use this in my mobile apps!

Re: New approach for offline viewing PDF inside Android brow

Posted: Tue Sep 12, 2017 5:37 pm
by jim1001
Try this: https://mega.nz/#!pJwhgCQR!8RJRc6k79p-_ ... 9zYgU44rsg
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

Re: New approach for offline viewing PDF inside Android brow

Posted: Wed Sep 13, 2017 10:08 am
by MaxV
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")

Re: New approach for offline viewing PDF inside Android brow

Posted: Mon Sep 18, 2017 8:12 pm
by jim1001
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

Re: New approach for offline viewing PDF inside Android brow

Posted: Tue Sep 19, 2017 8:16 pm
by jacque
On mobile all the files selected to include in your app, from the Standalone application settings, are copied in specialFolderPath("Engine").
That was the original location some time ago, but it was changed when Apple revised their app requirements. Inclusions are now placed in specialFolderPath("resources"). To maintain backward compatibility, LC redirects specialFolderPath("engine") so it looks in "resources" instead. There are some good reasons for using specialFolderPath("resources") in scripts because during development it allows you to use the same specialFolderPath as the app will use. You don't have to branch when in development mode.

In the IDE, specialFolderPath("resources") points to the folder that contains the mainstack. In a standalone, it points to a "resources" folder that the standalone builder creates (you don't need to create it yourself.) This means if your resources are in a folder inside the mainstack folder, your scripts will work the same way in the IDE as they do in a standalone when you use specialFolderPath("resources").

That isn't true if you use specialFolderPath("engine") which in the IDE will point to the location of the LC app.