PDF File Upload

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

PDF File Upload

Post by bsouthuk » Wed Oct 14, 2009 9:49 am

Hi wonder if someone can help me.

I have created an application in studio 3.5 and wanted to upload a PDF file so that users are able to open the PDF when they click on a button.

Is this easily done on revolution?

Cheers

Daniel

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Oct 14, 2009 1:16 pm

Assuming that you're uploading to an FTP server, it can be a one-liner like

Code: Select all

 put URL("binfile:" & tLocalPath) into URL("ftp://user:password@example.org/" & tRemotePath)
It's always safest to read files to upload as binary files.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Post by bsouthuk » Wed Oct 14, 2009 2:31 pm

Thanks Jan

Is there not a way of uploading my PDF file to my stack in RunRev like I would do my website and then for a user to click a button for the PDF to open?

Just not too sure about this FTP server. I have a linux based hosted website. Going by your code if my

username is bsouthuk
password is manutd07
domain is porrima-qg.com
file name that i have uploaded to my site is QG.PDF

Then should the exact code be:

Code: Select all

put URL("binfile:" & tLocalPath) into URL("ftp://bsouthuk:manutd07@porrima-qg.co.uk/qg.pdf" & tRemotePath)
Is this right?

And when you click on the button, the PDF file will show in a browser?

Cheers

Dan

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Wed Oct 14, 2009 3:23 pm

I really hope these are not real login credentials... If they are, I advise to edit your post and REMOVE THEM IMMEDIATELY!!!

Maybe you meant not "upload" (which is always to a server) but "store" (for example within a stack)

you can do that:

Code: Select all

set the storedPDF of this stack to url ("binfile:" & "somefile.pdf")
put the storedPDF of this stack into url ("binfile:" & "someotherfile.pdf")
launch "someotherfile.pdf"
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Post by bsouthuk » Wed Oct 14, 2009 4:12 pm

Ha no they are not real!

Thanks very much for this now all I need to know is how do I store my PDF in my stack?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Oct 14, 2009 4:50 pm

Hi bsouthuk,

BvG already answered your question:

Code: Select all

set the storedPDF of this stack to url ("binfile:" & "somefile.pdf") 
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Post by bsouthuk » Wed Oct 14, 2009 4:58 pm

I think i'm having a blonde moment hear.

The name of my pdf file is "o2.pdf"

Therefore am I right in saying that I type the following code in a button and it will store the PDF that I have saved on my desktop and open the PDF file when I click the button?

The code I have is:

Code: Select all


set the storedPDF of this stack to url ("binfile:" & "o2.pdf") 
put the storedPDF of this stack into url ("binfile:" & "o2.pdf") 
launch "o2.pdf"
Is this right?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Oct 14, 2009 5:08 pm

bsouthuk,

Set the storedPDF property from the message box, using the first line. Make sure that the path to the PDF is correct. Probably it should be something like "C:/folder/folder/o2.pdf" instead of simply "o2.pdf".

In your button, you can use the remaining two lines. Again, make sure that you use a correct path, e.g. to the temp directory or to the desktop. The launch command needs a correct file path too.

If you try your code and get errors, post the errors in this forum.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Post by bsouthuk » Wed Oct 14, 2009 6:55 pm

Thanks Mark though having some problems - when i click on the button, nothing actually happens.

In the button I have the following code:

Code: Select all


on mouseUp
put the storedPDF of this stack into url ("binfile:" & "C:/Users/Daniel Shapiro/Desktop/Daniel/Commercials/O2/Business tariff and bundle Pricing.pdf") 
launch "C:/Users/Daniel Shapiro/Desktop/Daniel/Commercials/O2/Business tariff and bundle Pricing.pdf"
end mouseUp
In the stack property inspector under 'custom properties' it says 'StoredPDF" then underneath this in the'properties context' box it has the following some crazy lines of code which looks chinese or something. Thousands of lines!

Then in the 'External references' the following:

C:/Users/Daniel Shapiro/Desktop/Daniel/Commercials/O2/Business tariff and bundle Pricing.pdf

What am I doing wrong?

Cheers

Dan
[/code]

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Oct 14, 2009 7:00 pm

Hi Dan,

Do you use Mac OS X or Windows?

Normally, you should not hardcode the filepath. You should create the filepath using a system-dependent component and a file-dependent component. For example:

specialfolderpath("temp") & "/someuniquefilename.pdf"
specialfolderpath("desktop") & "/yourpdf.pdf"
item 1 to -2 of the effective filename of this stack & "/yourpdf.pdf"

et cetera...

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Post by bsouthuk » Wed Oct 14, 2009 7:08 pm

Hey Mark

I use windows.

In the filepath section under 'external references' I add the file path. Are you saying to delete this?

Is everything I have done correct.

Sorry but when you say to create the filepath using a system-dependand component and give some examples it makes no sense to me!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed Oct 14, 2009 7:33 pm

Hi Daniel,
shouldn't that be

Code: Select all

launch document "C:/Users/Daniel Shapiro/Desktop/Daniel/Commercials/O2/Business tariff and bundle Pricing.pdf" 
instead of

Code: Select all

launch "C:/Users/Daniel Shapiro/Desktop/Daniel/Commercials/O2/Business tariff and bundle Pricing.pdf" 
? Could you try this? You might want to look up 'launch' and 'launch dokument' in the dictionary.
regards
Bernd

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Post by bsouthuk » Wed Oct 14, 2009 8:45 pm

Thanks Bernd now Acrobat opens but I get the following error message:

Adobe reader could not open 'QG.pdf' because it is either not a supported file type or because the file ahas been damaged.

I have tried this with 3 other PDF files so can you spot where I am giong wrong?

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Post by bsouthuk » Wed Oct 14, 2009 8:54 pm

...And strangely enough I cant open the PDF files but double clicking them on my desktop now - the same error message is displayed.

What on earth am i doing wrong here?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Oct 14, 2009 8:58 pm

bsouthuk,

The launch document command should work. I have had, hwoever, quite a few problems with it on Windows XP and Vista.

Try something like this:

Code: Select all

put specialfolderpath(desktop) & "/Commercials/O2/Business tariff and bundle Pricing.pdf" into myFilePath
if there is a file myFilePath then
  set the hideConsoleWindows to true
  put "start" && quote & quote && quote & myFilePath & quote into myShell
  get shell(myShell)
else
  beep
  answer "Can't find file" && myFilePath
end if
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply