How to open a PDF file that's linked in a data grid?

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
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 5:07 am

I have a datagrid that has a linked pdf file. I'd like to be able to open the pdf file when the file is clicked on in the data grid. I see the open file "etc.txt" in the dictionary. But don't think that's actually what I'm looking for. Any help is appreciated.

I have this (using DBlib):

Code: Select all

   put field "fldFile" into myRecord["fldFile"]


Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to open a PDF file that's linked in a data grid?

Post by Klaus » Tue Dec 25, 2012 12:43 pm

Hi Shawn,

to open a document just like doubleclicked in the desktop/Finder, do this:
...
launch document "path/to/your doc.pdf"
...


Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 2:10 pm

I appreciate it Klaus.

Still can't get it working, but it's probably because I didn't accurately describe what I'm trying to accomplish.

I have a dgData grid with 3 columns. One of those columns have the column title of fldFile. I'd like to launch the file when a fldFile row is hilited. All the files are pdf files.

Right now on my dgData grid I have this

Code: Select all

on mouseUp
   launch the selectedText of field "fldFile"
end mouseUp

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to open a PDF file that's linked in a data grid?

Post by Klaus » Tue Dec 25, 2012 2:28 pm

Hi Shawn,

hmm, where's the problem, just do it accordingly:

Code: Select all

on mouseUp
   put the selectedText of field "fldFile" into tFile
   launch document tFile
end mouseUp
Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 2:35 pm

Hmmm.

This is what I changed it to.

Code: Select all

on mouseUp
   launch document field "fldFile"
end mouseUp
Then changed to your code above. I get the same result, which isn't opening the PDF file, but no error, it's opening the folder where my LC project is saved. I'm still working on it ;) and reading.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to open a PDF file that's linked in a data grid?

Post by Klaus » Tue Dec 25, 2012 3:00 pm

Hi Shawn,
shawnblc wrote:

Code: Select all

on mouseUp
   launch document field "fldFile"
end mouseUp
Then changed to your code above. I get the same result, which isn't opening the PDF file, but no error,
it's opening the folder where my LC project is saved. I'm still working on it ;) and reading.
OK, you should check the result to get a hint on what might go wrong:

Code: Select all

...
launch document (field "fldFile")
if the result <> EMPTY then
  answer "Error:" && the result
end if
...
Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 3:07 pm

Thanks. I think I'll be able to figure it out with what help you've given me. I appreciate it. I'll update this thread. Thank you Klaus.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 3:55 pm

When I do this ----> it works.

Code: Select all

on mouseUp
   launch document "/Users/Shawn/Dropbox/myPDF.pdf"
end mouseUp
when I do this it does not work. hmmmm.

Code: Select all

on mouseUp
   put the selectedText of field "fldFile" into tFile
   launch document tFIle

end mouseUp


OR 

on mouseUp
   launch document field "fldFile"
end mouseUp

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to open a PDF file that's linked in a data grid?

Post by Klaus » Tue Dec 25, 2012 4:23 pm

Hi Shawn,

hmmmm, are you sure that in tFile is really a valid path to your PDF document -> "/Users/Shawn/Dropbox/myPDF.pdf"?
...
## Do something like this:
answer tFile
answer (there is a file tFile)
...
What does "the result" tell you?


Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 4:36 pm

I get fldFile and False

Here's a snap of my data grid. The URL to the PDF file is valid and will open as described above but not when referenced with fldFile or tFile.

This works. In fact I can reference any PDF file like below and it will work.

Code: Select all

on mouseUp
   launch document "/Users/Shawn/Dropbox/Apple Store.pdf"
end mouseUp
Last edited by shawnblc on Mon Jun 03, 2013 12:20 am, edited 1 time in total.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to open a PDF file that's linked in a data grid?

Post by Klaus » Tue Dec 25, 2012 5:22 pm

AHA, Datagrid! :D

OK, we are getting nearer:
I get fldFile and False
So this is in fact a problem of pulling the correct data out of your datagrid!
Where did you put the "mouseup" script? In the group script?

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 5:25 pm

Klaus wrote:AHA, Datagrid! :D

OK, we are getting nearer:
I get fldFile and False
So this is in fact a problem of pulling the correct data out of your datagrid!
Where did you put the "mouseup" script? In the group script?
In the data grid on mouseUp. I have hilited box ticked in the properties.

What I'm trying to accomplish is basically like a HTML table where the file would be hyperlinked to the file and open in your pdf viewer. This has me stumped. I must've tried a hundred variations.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to open a PDF file that's linked in a data grid?

Post by Klaus » Tue Dec 25, 2012 5:52 pm

OK, datagrids are highly cool but complex beasts, so you need to do someting like this in the "mouseup" script.
Datagrids hold their content in a multidimensional Array (the dgData of grp "your datagrid") ,
which makes it easy to address your "fields" directly, see below:

Code: Select all

on mouseup

  ## Get the selected index/line:
   put the dgHilitedindex of me into pHilitedIndex

  ## Get the array for the selected "row":
   put the dgDataOfIndex[pHilitedIndex] of me into theDataA
 
   ## get the key assocciated with your field "fldFile":
   put theDataA["fldFile"] into tFile

  if there is a file tFile then
     launch document tFile
  else
    answer "File missing:" & CR & tFile 
  end if
end mouseup
Best and merry cristmas :D

Klaus

P.S.
Load the complete docs (PDF) for datagrids here, not really easy to handle, but powerful! :)
http://lessons.runrev.com/m/datagrid

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: How to open a PDF file that's linked in a data grid?

Post by shawnblc » Tue Dec 25, 2012 5:58 pm

Wow Klaus. Thank you! That worked! I have a lot to learn, but I'm having a lot of fun! I'll have to make sure I save all of the snippets of code that you've provided. I'm sure that they'll come in handy on this LC journey. Thank you and have a great day!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”