Trouble getting PDF to display on device

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jstarkman
Posts: 47
Joined: Wed Mar 16, 2011 4:39 am

Trouble getting PDF to display on device

Post by jstarkman » Thu Dec 27, 2012 8:16 pm

Hi all,

Very much a newbie here, so please excuse the stupid question (if deemed so...)

I have successfully been able to get a local file to display in a browser object, but am having trouble getting the file to display on my iOS device. The local file is at the root of the HDD, /7Plans.pdf.

In my Standalone Application Settings, I am using the Copy Files pane to copy this local file. Then I create a copy of the file into the application's Documents folder (although for my current purposes, I'm not sure I need to do this if I'm only reading the file, and therefore maybe it can remain in the engine folder).

This line works when using the iOS simulator:
iphoneControlSet sMenuBrowserId, "url", "file:///7Plans.pdf"

This line does NOT work when using the device:
iphoneControlSet sMenuBrowserId, "url", "binfile:7Plans.pdf"

Neither does this:
iphoneControlSet sMenuBrowserId, "url", "binfile:/Documents/7Plans.pdf"

My preOpenCard script is below. What am I doing wrong? Is there a neat way to set up the code so that the same script will work for either the simulator or the device, or must they always be different?
Thanks,
Joel

____________________________________________________________
// declare the local id of the browser we are creating
global sMenuBrowserId

on preOpenCard
global sMenuBrowserId
local tPathToEngineFile, tPathToDocFile, tTempFile

// quit if we are not on a mobile device
if the environment is not "mobile" then
answer "Not mobile environment, so exiting preOpenCard"
exit preOpenCard
end if

// set up the basic defaults
// set up the size of the graphic "MenuBrowserRect" to represent the size of remaining card space
// taking into account the presence of NavBar and TabBar, e.g. in MenuState
local tCardLeft, tNavBarBottom, tCardRight, tTabBarTop
put the left of this Card into tCardLeft
put the bottom of group "NavBar" into tNavBarBottom
put the right of this Card into tCardRight
put the top of group "TabBar" into tTabBarTop
set the rect of graphic "MenuBrowserRect" to tCardLeft, tNavBarBottom, tCardRight, tTabBarTop
set the visible of graphic "MenuBrowserRect" to false

// create the browser
iphoneControlCreate "browser"
put the result into sMenuBrowserId

// set up the Browser rect based on the size of the graphic "MenuBrowserRect"
set the rect of group "Browser" to the rect of the graphic "MenuBrowserRect"

// set up the Browser parameters
iphoneControlSet sMenuBrowserId, "rect", the rect of group "Browser"
iphoneControlSet sMenuBrowserId, "visible", "true"
iphoneControlSet sMenuBrowserId, "autoFit", "true" // allows UiWebView content (in Browser control) to be scaled/zoomed

put (specialFolderPath("engine") & "/7Plans.pdf") into tPathToEngineFile // this is where I expect file to reside by using the 'Copy Files' pane of the Standalone App settings
if there is a file tPathToEngineFile then answer "The file" && tPathToEngineFile && "exists" else answer "The file" && tPathToEngineFile && "does not exist"

put (specialFolderPath("Documents") & "/7Plans.pdf") into tPathToDocFile // this is where I want to copy the file to.
if there is a file tPathToDocFile then answer "Prior to copying, the file" && tPathToDocFile && "exists" else answer "Prior to copying, the file" && tPathToDocFile && "does not exist"

try
if not (there is a file tPathToDocFile) then
put url ("binfile:" & tPathToEngineFile) into url ("binfile:" & tPathToDocFile)
if there is a file tPathToDocFile then answer "After copying, the file" && tPathToDocFile && "exists" else answer "After copying, the file" && tPathToDocFile && "does not exist"
wait 5 milliseconds with messages
end if
catch pErr
put pErr into field 1
end try

set the defaultFolder to specialFolderPath("Documents")
// answer "Default folder is" && defaultFolder
// answer "tPathToDocFile is" && tPathToDocFile
// answer "Files in default folder are" && (defaultFolder & slash & the files)
// answer "binfile: & tPathToDocFile =" && "binfile:" & tPathToDocFile

//------------------------------------------------------------------
iphoneControlSet sMenuBrowserId, "url", "binfile:7Plans.pdf"
// iphoneControlSet sMenuBrowserId, "url", "file:///7Plans.pdf"
//------------------------------------------------------------------

end preOpenCard

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

Re: Trouble getting PDF to display on device

Post by Simon » Thu Dec 27, 2012 8:35 pm

Just to beat Klaus to the punchline:
(specialFolderPath("Documents") & "/7Plans.pdf")
should be (specialFolderPath("documents") & "/7Plans.pdf") case sensitive, all the paths are I believe.

That's a start.

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Trouble getting PDF to display on device

Post by sturgis » Thu Dec 27, 2012 8:56 pm

Since you're using the browser instance (at least it seems so to me) you have to designate the file using the browsers expected scheme. Since its a file, a browser expects it to be in the form of
file://path/to/file. Since you're most likely starting at the root (on desktop) its the file:///path/to/file.pdf

You also have to allow for any possible issues with spaces in the path name. You can replace space with "%20" in the url string to get over that hump.

Since all you are doing is reading the file then yes you can most likely just leave it in the engine package. Not sure what the apple rule of the day is regarding that though.

The "url" form of accessing files won't work correctly with browser objects.

jstarkman
Posts: 47
Joined: Wed Mar 16, 2011 4:39 am

Re: Trouble getting PDF to display on device

Post by jstarkman » Thu Dec 27, 2012 11:35 pm

Simon & Sturgis,

Thank you for your replies. This is a problem I've been working on for hours, and have tried many versions of the file in an attempt to get it to work (brute force method).

I finally found the solution:

iphoneControlSet sMenuBrowserId, "url", tPathToDocFile

does the job. Should have used my head instead of my arms the first time I suppose.

Joel

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Trouble getting PDF to display on device

Post by sturgis » Thu Dec 27, 2012 11:43 pm

DOH, my apologies for steering you wrong. My brain forgot you were on IOS.
jstarkman wrote:Simon & Sturgis,

Thank you for your replies. This is a problem I've been working on for hours, and have tried many versions of the file in an attempt to get it to work (brute force method).

I finally found the solution:

iphoneControlSet sMenuBrowserId, "url", tPathToDocFile

does the job. Should have used my head instead of my arms the first time I suppose.

Joel

Post Reply