Open Printing to PDF

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Open Printing to PDF

Post by maxs » Thu Nov 24, 2016 3:29 am

I'm using the Open Printing to PDF "MyPDF" command, yet nothing seems to happen and the rest of the script stops working.

Does it make a PDF of the card?

How does this work? Does if create a pdf the can be accessed by a printer?

Max

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

Re: Open Printing to PDF

Post by Klaus » Thu Nov 24, 2016 12:24 pm

Hi Max,

especially on iOS you need to open printing to a PDF file where you have write permissions!
...
Open Printing to PDF "MyPDF.pdf"
...
will try to save the PDF in the current folder which maybe the ENGINE folder where you do not have write permissions!
Try something like this:
...
put specialfolderpath("documents") & "/Yourpdf.pdf" into tPDFFile
open printing to PDF tPDFFile
...

Best

Klaus

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open Printing to PDF

Post by maxs » Wed Jan 04, 2017 10:55 am

Thank you Klaus,

Thanks for the help. How do I access or find the file on the Ipad after it's created? Max

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

Re: Open Printing to PDF

Post by Klaus » Wed Jan 04, 2017 11:17 am

Hi Max,

been busy? :D

Not sure I understand your question, you created the file so you know where it is, not?

Code: Select all

...
put specialfolderpath("documents") & "/Yourpdf.pdf" into tPDFFile
## Creates the pathname to the PDF file
## Now do what you want with tPDFFile now.
...
Best

Klaus

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open Printing to PDF

Post by maxs » Wed Jan 04, 2017 8:24 pm

Hi Klaus,

The documentation says
Starts a print loop that outputs directly to pdf rather that the currently configured printer.

It seems that I can print a card to a PDF file that is in a special "documents" folder. NO?
So where is the documents folder on the Ipad?

I seem to be completely misunderstanding this command.

Max

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

Re: Open Printing to PDF

Post by Klaus » Wed Jan 04, 2017 8:51 pm

Hi Max,
maxs wrote:It seems that I can print a card to a PDF file that is in a special "documents" folder.
yes, exactly! And logical, since you need to supplay a valid filename.
maxs wrote:So where is the documents folder on the Ipad?
Inside of your application package.
Due to "sandboxing" every app has its own "documents" folder.

Sorry, cannot provide more info since I don't develop for mobile nor do I own any mobile device.
Yes, no cell phone, that's me! :D


Best

Klaus

Batninja
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 33
Joined: Sat Oct 15, 2011 9:43 am

Re: Open Printing to PDF

Post by Batninja » Thu Jan 05, 2017 12:58 am

Hi here is my button script in an iPhone app that prints a sub stack as a pdf and then displays in the mergReader external

Code: Select all

on mouseUp
   --lock the screen as it seems you have to go to sub stack at least once to print it, I got glitches otherwise
   lock screen
   -- go to the stack to print
   go to stack "a4paper"
   --default margins are 72 points = 1 inch so reset to zero
   set the printMargins to 0, 0, 0, 0
   -- set the print path to the app documents folder
   put specialFolderPath("documents") & "/frame.pdf" into tFilePath
   --prepare the PDF document to the file path
   open printing to PDF tFilePath
   --specify the card to print and the area of the card (divide by 72 to get size)
   print card "pdfprint" of stack "a4paper" from 0,0 to 595,841
   --do the printing
   close printing
   --return to the main stack
   go to stack "PDFPrinter"
   -- all done
   unlock screen
   --use the mergReader external to display the pdf and offer printing email etc.
   mergReader tFilePath
end mouseUp
Notes:

1. PDF print by default only prints the visible potion of the card, so if using an A4 or US sized card you need to specify the print area (i.e. 595x841 px for A4) since the iPhone shows a smaller screen area

2. Best to use a sub stack because of 1.

3. The mergReader extension is great, remember to include both it and the PDF printer in the IOS application inclusions

4. The "documents" app file location is the only place you can save files to (you can include pdf's when building but they end up in the "engine" folder and as far as i can tell its best to leave that alone - this is set as tFilePath with a file name of "frame.pdf"

5. I seem only able to output US letter sized PDF's not A4 size (see previous post) - if this is the case then the solution is to specify a pdf size of 8.27 inches (A4 width) by 11 inches (US letter height) i.e. 595 px x 792 px

6. I'm not sure if specifying say a double sized PDF would result in a higher quality photo output when scaled down to actual page size.

Hope this helps

Roger

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open Printing to PDF

Post by maxs » Thu Jan 05, 2017 9:21 am

ROger,

Thank you so much for this additional information.

Max

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2376
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Open Printing to PDF

Post by jmburnod » Thu Jan 05, 2017 11:32 am

Hi Max,
where is the documents folder on the Ipad?
As Klaus said every app has its own "documents" folder.
You can see it with iTunes if you set "file sharing" of your app to true in the standalone application setting.
Best regards
Jean-Marc

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open Printing to PDF

Post by maxs » Thu Jan 05, 2017 5:27 pm

Thanks. This is very good to know. Max

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

Re: Open Printing to PDF

Post by quailcreek » Fri Jan 27, 2017 5:43 am

This is a thread that I went thru when I was doing something similar. It might give you some ideas.

http://forums.livecode.com/viewtopic.php?f=49&t=24391
Tom
MacBook Pro OS Mojave 10.14

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open Printing to PDF

Post by maxs » Sun Jan 29, 2017 7:07 pm

Thanks Tom, there is alot of good stuff here.

Post Reply

Return to “iOS Deployment”