Print to PDF

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Print to PDF

Post by bsouthuk » Tue Apr 24, 2012 7:43 pm

Hi

I wonder if someone can help me.

I am trying to print to pdf using my iPad. My app works perfectly on my iPad apart from printing to pdf. I am trying the following code:

Code: Select all

on mouseUp
   open printing to PDF "myPDF.pdf"
print this card
close printing
launch document "myPDF.pdf"
end mouseUp
this works fine when trying on the MAC. But not when testing directly on my iPad. When i click the button with the script, nothing happens, no pdf is launched, nothing.

Is there something I am doing wrong here?

Thanks

Daniel

JosepM
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 344
Joined: Tue Jul 20, 2010 12:40 pm

Re: Print to PDF

Post by JosepM » Tue Apr 24, 2012 10:16 pm

Hi,

Check this post...

http://forums.runrev.com/viewtopic.php? ... pdf#p54123

Salut,
Josep M

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

Re: Print to PDF

Post by bsouthuk » Tue Apr 24, 2012 10:33 pm

Hi

I already checked this post and tried all the different code but the PDF never opens on my iPad. I'm not even sure if the PDF actually saves to the iPad. And if it does save then where?

Very confused on this one!

Klaus
Posts: 14235
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Print to PDF

Post by Klaus » Wed Apr 25, 2012 12:27 pm

Hi Daniel,
And if it does save then where?
well, you are the developer and if you can answer this, who can?
Come on!

And this is exactly is the problem:
"myPDF.pdf" is a valid filename on the desktop/IDE.
This will be in the current "defautlfolder", whereever that may be!
It is up to you to know this!

But "the defaultfolder" on iOS is obviopusly the folder inside of the
application package***, where you do NOT have write permissions!
*** specialfolderpath("engine")

So at this point the script silently fails and does not continue!

If you pass a VALID filename to the print command, it sure will work!
...
## We are allowed to write to the users docs folder!
put specialfolderpath("documents") & "/yourPDF.pdf" into tPdfFile
open printing to PDF tPdfFile
print this card
close printing
launch document tPdfFile
...

Best

Klaus

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

Re: Print to PDF

Post by bsouthuk » Wed Apr 25, 2012 1:42 pm

Thank you for your email Klaus but I have already tried this code and still the PDF does not open when using my iPad. Nothing happens when i click on the button that obtains the code.

I have checked the box in the standalone settings for print to pdf but still nothing. I presume that the pdf will open on top of the app that is running? And if you close the pdf that opens then the app will then be displayed?

Klaus
Posts: 14235
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Print to PDF

Post by Klaus » Wed Apr 25, 2012 1:53 pm

Hi Daniel,

hmmm...?

Please add this right after the print command to check, if the PDF has really been created:
...
put specialfolderpath("documents") & "/yourPDF.pdf" into tPdfFile
open printing to PDF tPdfFile
print this card
close printing
answer (thre is a file tPFDFile)
## Should be true on success
## if this displays in fact TRUE then you could try to add a little wait
## 10 = 10 ticks = 60 ticks = 1 second
wait 10
launch document tPdfFile
...
And yes the app that opens the PDF should open on top of your app,
which should appear again after the user closed the PDF.
But since I do not own an iOS license I am not sure.


Best

Klaus

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

Re: Print to PDF

Post by bsouthuk » Wed Apr 25, 2012 2:05 pm

Hi Klaus

I tested this in my MAC, the message that appears is true and the pdf opens straight away. However, when testing the IPAD, the message also appears as true but no pdf is launched.

In the Sandbox, documents folder in Xcode on the mac, the pdf file is displayed. Though I still have no idea in how to find the pdf file on the iPad itself as I cannot find a Documents folder on it!

Klaus
Posts: 14235
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Print to PDF

Post by Klaus » Wed Apr 25, 2012 2:37 pm

Hi daneil,

sorry, no idea..

But you could add another answer which may give you a hint:
...
launch document tPdfFile
answer the result
## should not be empty, if the PDF will not launch
...

Best

Klaus

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

Re: Print to PDF

Post by bsouthuk » Wed Apr 25, 2012 3:19 pm

I get:

/var/mobile/Applications/C36456456456456456546/Documents/yourPDF.pdf

I have tested my iPad to see if it can open pdfs from emails which is can. I cannot understand why the pdfs are not being launched as I have done everything that is required!

Klaus
Posts: 14235
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Print to PDF

Post by Klaus » Wed Apr 25, 2012 3:36 pm

"the result" returns the FILEPATH? :shock:
Sorry, no more ideas...

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

Re: Print to PDF

Post by bsouthuk » Tue May 01, 2012 1:14 pm

Thanks for your help Klaus

I have been told by the guys at LC that the Launch Document command does not work for mobile deployment. The following external I have been told should help: http://mergext.com/

Or displaying the pdf within a browser object.

Klaus
Posts: 14235
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Print to PDF

Post by Klaus » Tue May 01, 2012 1:42 pm

bsouthuk wrote:I have been told by the guys at LC that the Launch Document command does not work for mobile deployment.
Ah, did not know this, thanks for the info!

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Print to PDF

Post by monte » Tue May 01, 2012 9:31 pm

Theres a few advantages to using mergDoc for displaying the PDF. One line of code and you get the standard modal preview and from there your user can print or send to another app without any extra code from you. You can still get mergExt + MobGUI for half price using the MERGUI code on the runrev store. The offer ends if a few days.

Cheers

Monte
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

CALL-151
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 206
Joined: Wed Oct 20, 2010 11:00 am

Re: Print to PDF

Post by CALL-151 » Thu May 03, 2012 10:22 pm

Bsouthuk,

Just to make sure you're clear about what your issue was, your code was printing to pdf, you just couldn't find it because of the way iOS sandboxing restricts access. The fact that other apps on your iOS device can open PDFs is irrelevant. The iOS release notes are a must in order to understand how to write to and read from various locations within your app's sandbox and the significant differences between those different locations. In addition, the dictionary is the most reliable guide to what works and what doesn't on iOS.

If you want to code your own PDF viewer inside your app, read about iphoneControlCreate "browser", but if you're serious about iOS app development with LC, I'd highly recommend grabbing MobGUI and the MergExt externals while they're on sale.

Post Reply