Page 1 of 1

copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 4:29 am
by FireWorx
I have been successful copying PDF's to the standalone using the standalone builder and then viewing them in a browser using the following code:

put "file:///" & specialfolderpath("engine") & tDeptPreifx & tMapPageSelected & ".pdf" into tLocalPDF
replace " " with "%20" in tLocalPDF
  iphoneControlSet sBrowserId, "rect" , the rect of group "Browser"
   iphoneControlSet sBrowserId, "visible" , "true"
   iphoneControlSet sBrowserId, "autoFit", "true"
  iphoneControlSet sBrowserId, "url", tLocalPDF ## Then set the iOS browser to that URL

Now I would like to nest a couple folders filled with PDF's in the specialfolderpath("documents") folder and then access them in the same way as above substituting ("documents' ) for ("engine") and have them updated by ITunes when needed. Can anyone give me some sample code that would create say folder FD1 and FD2 within the specialfolderpath("documents") folder and copy say 50 existing PDF's from each of those folders on my HD to the folders that we create?

I don't know if an entire folder can be script copied, or one file at a time, or if I will be required to select and copy each PDF manualy via the standalone builder to the (engine) folder and then move them to the documents folder. I read all the posts and the documentation and i'm still unclear on this. Thanks for your help. Dave

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 5:08 am
by Dixie
fireworx...

One way to do it would be to check if the .pdf document exists in the 'documents' folder and if it doesn't then copy it from the app bundle to the 'documents' folder. It does mean though that now you have just duplicated the files within the app....

Code: Select all

   put specialFolderPath("documents") & "/myDoc.pdf" into documentFilePath
   if there is not a file documentFilePath then
      put URL("file:" & specialFolderPath("engine") & "/myDoc.pdf") into URL("file:" & specialFolderPath("documents") & "/myDoc.pdf")
   end if
With you having such a large number of .pdf files, you could drop them into the 'documents' folder manually... the path to that should be something like... users/username/Library/Application Support/iPhone Simulator... and then dig down a little further to find your app and its documents folder.... At least that way you won't have duplicates of the .pdf docs within your app...

be well

Dixie

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 6:20 am
by Jellicle
Dave, I'm confused. Are you wanting a way to have 2 folders of PDFs available to the user from inside the Documents folder on an iOS device, and have those folders exposed so that iTunes can be used to change their contents? And are you wanting to put a bunch of PDFs into those folders when the app is installed, but avoid having to copy them from the engine?

Gerry

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 7:15 am
by FireWorx
Yes Gerry,
If possible I would like to have at least 1 or 2 folders and if performance is OK add up to a total of 5 folders each containing about 40 PDF's. Then show them in a browser window on an IPAD. The situation is a small county with 5 fire departments. The idea is to have 5 folders one for each departments PDF maps and have the 40 or so PDF's available for viewing. The primary idea is to get our own maps up on the screen while responding to calls but we also respond into the other fire districts so that would be a nicety.
The map pages are updated once a year and at that time I would do an update through iTunes. We are experimenting with using Ibooks but I wanted to build a more custom user interface and include google maps, target hazards info, etc.

SO in other words
Documents/FD1/FD1Map1.PDF
FD1Map2.PDF
Documents/FD2/FD2Map1.PDF
FD2Map2.PDF

ANy ideas about best way to get this done? Appreciate it! Dave

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 8:18 am
by Jellicle
Ok, so you have control over all the devices this will be installed on, at least once a year? But to start with, you need to install the 200 PDFs when you install the app, and you want to know what the most efficient way of doing that is? I think that a manual copy will be the way to go - I can't see how bundling 200 PDFs in the engine, and copying them to the device, would be better. And while it'd possible to download the files to the Documents folder over the internet via wifi, it'll be faster to do it manually, while the iPads are connected to a computer.

As for displaying the PDFs from nested folders - no problem.

Gerry

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 9:59 am
by Dixie
Gerry...

err..isn't that what I said ?...:-)

Dixie

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 10:20 am
by Jellicle
Dixie wrote:err..isn't that what I said ?...:-)
Dixie
Sort of, but you seemed (in the second part of your post) to be referring to files in the simulator - I was wondering what that was about and so sought clarification from the OP :) And I was also confused until the OP revealed this was an in-house thing, and not for distribution to the public - if it was the latter then I wouldn't recommend a method that depended on the user knowing how to use iTunes to add the files.

Now, fix my code signing problem for me :)

Gerry

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 4:04 pm
by FireWorx
Thanks to all of you. Because a combination of your posts I am starting to understand. I will have an IPad to work with next week and I am currently developing and testing on a Mac. So for now I guess I should copy a few files into the engine folder via the standalone and move them into the documents folder on PreOpenStack just to make sure I have my code correct. Then build out the standalone and when I get the IPad test it on the devise.

Perhaps a er code snipet to advise the users that if the folder is not providing the PDF (in the event of a corruption etc) to alert the admin that a Itunes update is needed.

As far as manualy moving the PDF's via Itunes. I understand I need to select the file sharing box in the standalone builder but is there any other code or boxes or procedures that I need to pay atention to? Is there another way to add the files manualy besides ITunes? Dixie n Jel you say a manual add is best but are you recomending manual via Itunes?

Thanks,
Dave

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 5:09 pm
by Dixie
Dave...

This is what I understand you want to do :-

1. You want to have 'X' number of .pdf files that your app will be able to display.
2. These .pdf's will need to be changed over time...

If you use the 'copy files' pane in the 'Standalone Application Settings' then the .pdf's will be copied to the 'engine' folder of your app. As I understand from the iOS release notes you are not able to change or add any files within the application bundle as the bundle is digitally signed when it is built and any changes to it after this point would invalidate the signature and prevent it from launching... So, if you use the 'copy files' pane to bring the .pdf's into your app and then copy them to the documents folder, you would have a collection of .pdf's in the 'engine' folder and a copy of the collection of the .pdf's in the 'documents' folder.

I would 'manually' place the .pdf's in the documents folder as you are creating your app... that way you will only have 1 set of the .pdf's in your app. Then in time, when these .pdf's become obsolete and need changing, then you could change them out by downloading a new set from, say, your server to the 'documents' folder of your app...or I guess if you wish change them out for the newer ones using iTunes... You see, the way I see it is as soon as the .pdf's you are starting with become outdated, then you will still have a copy of the 'original' .pdf's within the app bundle that you can do nothing about !

You will just have to come up with a method by which you tell your app when to look for the updated .pdf's and change then out with the ones in the 'documents' folder.

be well

Dixie

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 5:54 pm
by FireWorx
Thanks Dixie,
You raise some good points. I thank you for taking the extra time to explain things so clearly. It looks like the way to go forward is with your original recommendation to:

"With you having such a large number of .pdf files, you could drop them into the 'documents' folder manually... the path to that should be something like... users/username/Library/Application Support/iPhone Simulator... and then dig down a little further to find your app and its documents folder.... At least that way you won't have duplicates of the .pdf docs within your app..."

Can you help me out with an example of code that would help me "drop" them in as you suggest above? And in:
"I would 'manually' place the .pdf's in the documents folder as you are creating your app...

My question surrounds the code required to "drop" and "place" the files from my PC to the documents folder in the directory of the ap. Also not clear on your comment "as you are creating the ap. Is there a documents folder within the stack that can be populated with the PDF's before building it out to a standalone? Or does that code need to be written to the standalone OnPreOpenStack handler to look for the folders n files n if they exist then exit the handler and if they don't look on Daves Hard drive direct path to the PDF folders and copy them to the specialfolderpath("documents") folder.

Either way dropping, placing, or if on PreOpenStack method copying the folder n files is the recommended ticket a snippet of code would be so welcome to point me in the right direction.

Thanks for bearing with me and helping me while I struggle through trying to wrap my head around this.
Dave

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 6:18 pm
by Dixie
Dave...

This could become a little drawn out...:-) If you contact me off-list, I can send you a couple of stacks that should point you in the right direction.
dixonja@hotmail.co.uk

be well,

Dixie

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Fri Sep 16, 2011 7:16 pm
by FireWorx
Thanks Dixie !
I just sent you an e-mail with some code that I am hoping will get me close to getting the job done.
Dave

Re: copying PDF's to the specialfolderpath("documents") folder

Posted: Tue Sep 20, 2011 6:48 pm
by FireWorx
Hi,
Thanks to Dixie for giving me enough correct code and an example stack to get me started in the right direction. The idea being worked on is to have 5 folders located in the specialfolderpath("documents") folder filled with say 50 PDF's each that will be opened in a browser window and updated from time to time via iTunes.

The procedure being:
1) copy the 5 folders to the specialfolderpath("engine") folder via the "copy files" pane in the standalone settings.
2) Script a button to copy each of the 5 folders and contained PDF files over to the specialfolderpath("documents") folder.
3) Verify that the copy process worked and check the links to the specialfolderpath("documents") folder.
4) Go back into the "copy files" pane and delete the folders from the specialfolderpath("engine") folder.

Working within these folders is difficult because you can't see the contents of them and error checking is limited on the IOS tester. SO its difficult to check your work. What I ended up doing is modifying a stack I found here in the forum called "List files and Folders" to shed some light on the folders and files i was working on and constructed a button to copy over all the folders and files. Perhaps there is a much easier way and if you know of one speak up. Now I would like some more info on using iTunes to update those PDF's when they get stale. Script below and modified stack attached. I just called it MySplash because once you have all the files located where you want them you can delete all the buttons and field controls off the card and and use it as your standalone.

on mouseup
put specialFolderPath("engine") into tpath
put specialFolderPath("documents") into tpath2
set the defaultfolder to tpath ##set default folder to the parent folder to list folders
set itemdelimiter to "/"
put the folders into NestedFolderList ## a list of the folder names that we will copy
put the number lines of NestedFolderList into tFolderLineNum ## the total number of folders - 1 The first line has some machine data in it
-------
repeat with y= 2 to tFolderLineNum
put line y of NestedFolderList into tFolderName
set the defaultfolder to tpath & "/" & tFolderName ## Set the default folder to the child folder to list the files of that folder
put the files into tFileList
put the number lines of tFileList into tLineNum
create folder tpath2 & "/" & tFolderName & "/" ## copy a folder over even if its empty. Itunes can populate it later
repeat with x = 2 to tLineNum ## repeat for the number of lines - 1. The first line holds machine data
put line x of tFileList into tFileName
put tpath & "/" & tFolderName &"/" & tFileName into OldFilePath ## the engine folder and file path
put tpath2 & "/" & tFolderName & "/" & tFileName into NewFilePath ## new path to folder n files in the documents folder

if there is not a file NewFilePath then ## The file doesnt exist in the folder where you want it so make the copy
put URL ("binfile:/" & OldFilePath) into URL ("binfile:/" & NewFilePath)
if there is not a file NewFilePath then ## checks to see new file got created where you want it or gives sad msg.
answer "sorry didn't seem to work."
exit mouseup
end if
end if
put empty into OldFilePath
put empty into NewFilePath
end repeat
put empty into tFolderName
end repeat
end mouseup