Trouble getting PDF to display on device
Posted: 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
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