PDF Viewer

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

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

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

PDF Viewer

Post by Jamie37 » Sun Jan 31, 2016 1:30 am

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: 11197
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: PDF Viewer

Post by Klaus » Sun Jan 31, 2016 10:51 am

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 » Sun Jan 31, 2016 1:18 pm

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: 11197
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: PDF Viewer

Post by Klaus » Sun Jan 31, 2016 1:27 pm

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 » Sun Jan 31, 2016 6:49 pm

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
Location: McKenna, WA

Re: PDF Viewer

Post by quailcreek » Sun Jan 31, 2016 7:24 pm

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: 11197
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: PDF Viewer

Post by Klaus » Mon Feb 01, 2016 12:13 pm

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 » Mon Feb 01, 2016 11:50 pm

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 » Tue Feb 02, 2016 12:42 am

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
Location: McKenna, WA

Re: PDF Viewer

Post by quailcreek » Tue Feb 02, 2016 1:39 am

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: 11197
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: PDF Viewer

Post by Klaus » Tue Feb 02, 2016 9:58 am

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 » Mon Feb 15, 2016 9:45 pm

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
Screen Shot 2016-02-15 at 20.44.39.png
Screenshot showing standalone settings

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: PDF Viewer

Post by quailcreek » Mon Feb 15, 2016 10:47 pm

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 » Mon Feb 15, 2016 10:51 pm

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
Location: McKenna, WA

Re: PDF Viewer

Post by quailcreek » Mon Feb 15, 2016 11:04 pm

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

Post Reply

Return to “Talking LiveCode”