PDF Viewer

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

PDF Viewer

Post by Jamie37 »

Hopefully somebody will be able to help. I want to have a list field in my livecode card which will give the name of different PDF files. The idea being that when one of the names is clicked, it will open a local PDF. I ideally do not want it to be a web browsing option when you use a URL of a PDF. I want to store my PDF locally and open the file on the card. The problem I am having is I am using mobile and have o idea on how to store files with the app and how to access them in the code.

Again hopefully somebody can help and I am relatively new to livecode so bare with me if I do not understand.

Thanks
Jamie
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF Viewer

Post by Klaus »

Hi Jamie,

take a look here: http://forums.livecode.com/viewtopic.php?f=6&t=25220
Fact is, you can currently only display PDF files in the above mentioned way,
if they are outside of the stack, means separate files.


Best

Klaus
Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: PDF Viewer

Post by Jamie37 »

Hi Klaus

Thank you for your reply. I would like to do it so I do not have to open a booster Window. So where would I need to place files I. The mobile app for them to be opened.

Thanks
Jamie
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF Viewer

Post by Klaus »

Hi Jamie,

add the files via the "Copy files" tab in the standalone builder settings and
find them in your standalone in -> specialfolderpath("resources")


Best

Klaus
Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: PDF Viewer

Post by Jamie37 »

Im sorry for not understanding and am really happy with your help. However I just cannot seem to work out how to access the files I have put into the copied files section. All the tutorials just seem to be how to access files in the documents folder on a pc or mac?

Would you be able to give me some very basic code that will allow me to open a pdf. Im learning as I go along as it is for a college project.

Thanks
Jamie
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: PDF Viewer

Post by quailcreek »

Hi Jamie,
The files and folders set up in Copy Files, will be placed into the engine folder of the iSO apps sandbox. You will need to copy the data to the apps documents folder so you can access them. The code below should get you stated. Once you get the list into your fld you will need to figure out how you want to pull the PDF related to the clickText or you might want to look up textStyle > linkText in the dictionary.

Code: Select all

put specialFolderPath("documents") & "/PdfFolder" into tListofPDFs
if there is not a file tListofPDFs then
   put url("binfile:" & specialFolderPath("engine") & "/PdfFolder") into url("binfile:" & specialFolderPath("documents") & "/PdfFolder")
else
   --      answer "There is a folder PdfFolder"
end if

set the defaultFolder to tListofPDFs
put the files into thePdfList
put thePdfList into fld “myField”
Tom
MacBook Pro OS Mojave 10.14
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF Viewer

Post by Klaus »

Hi Jamie,
Jamie37 wrote:All the tutorials just seem to be how to access files in the documents folder on a pc or mac?
if you use -> specialfolderpath("resources") then this will work on a Mac, PC, Android and iOS like this:
I am using the browser example from the mentioned Livecode lesson in the link above:

Code: Select all

...
### I use -> example.pdf here, of course you need to supply you filenames 8) 
put specialfolderpath("resources") & "/example.pdf" into tPDFFile
revbrowserset tBrowserId, "url", ("file://" & tPDFFile)
...
Please look up the different specialfolderpath("XXX") in the dictionary, they are meant to make accessing files easier on the different platforms!

Hint:
If you are not editing/modifying any file like only displaying your PDF files, you can keep them in the resources folder.
Otherwise you need to copy them first to -> specialfolderpath("documents") for mobile,
or any other folder on Mac/PC, where you have write permissions!


Best

Klaus
Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: PDF Viewer

Post by Jamie37 »

Hi Klaus,

Very grateful for your help so far. I replaced the tutorial code with yours and I keep getting the error 'Unknown browser id'. The tutorial works fine with the same id so can figure out why it is not working. SO you aware, the tutorial im using is this one: http://lessons.livecode.com/m/2592/l/27 ... n-your-app

Thanks
Jamie
Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: PDF Viewer

Post by Jamie37 »

Ok I seem to have sorted the error but I do not think what I have done is right because nothing seems to be displaying?

This is my code for the button:

Code: Select all

global sBrowserId

on mouseUp
   put specialfolderpath("resources") & "/TEST.pdf" into tPDFFile
   browserSetURL tPDFFile
end mouseUp

the browserSetURL handler is implemented in the card script

on browserSetURL 
    ## Set the url to be displayed to the given url
    revbrowserset sBrowserId, "url", ("file://" & tPDFFile)
end browserSetURL
Thanks
Jamie
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: PDF Viewer

Post by quailcreek »

I'm not sure if this is the only problem but you need to pass the variable to your handler.

Code: Select all

on browserSetURL pPDFFile
    ## Set the url to be displayed to the given url
    revbrowserset sBrowserId, "url", ("file://" & pPDFFile)
end browserSetURL
Tom
MacBook Pro OS Mojave 10.14
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: PDF Viewer

Post by Klaus »

Yes, you forgot to add the parameter to your "browserSetUrl" handler.
Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: PDF Viewer

Post by Jamie37 »

Hello,

Sorry for the late reply, I have been away. I tried adding the variable to pass but again it still is not working If it helps, I have attached an image of my standalone settings with the file in to make sure I have done it right. A quick question, does it have to be made into a stand alone for it to work rather than just testing it in livecode.

Sorry for being a pain, I just cannot seem to get it to work.

Thanks
Jamie
Attachments
Screenshot showing standalone settings
Screenshot showing standalone settings
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: PDF Viewer

Post by quailcreek »

Are you copying the file to the documents folder and then reading it from there?
Tom
MacBook Pro OS Mojave 10.14
Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: PDF Viewer

Post by Jamie37 »

Hi quailcreek,

I'm just putting them into the non-stack file option.... if thats what you mean

Thanks
Jamie
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: PDF Viewer

Post by quailcreek »

Sorry, I keep thinking this is an iOS app.
Tom
MacBook Pro OS Mojave 10.14
Post Reply