IOS Print to PDF

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

IOS Print to PDF

Post by Nakia » Wed Jan 09, 2013 6:47 am

Hi,

I am working with printing to PDF on IOS and am using the "open printing to pdf tFilename" syntax.
It mostly seems to work well but it does not print the entire card (meaning it only prints about 3/4 of the card)

It seems to chop the botton 1/4 off when it prints the Card.

Any idea's what may be casuing this.

My stack is at standard Iphone Resolution and scaling is taken care of by tmControls..

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Wed Jan 09, 2013 7:06 am

Further to this, is there a way to print all the content on the card?
Meaning, I have an IOS Scroller that scolls more information on the Card that really needs to be there when its printed to the PDF...

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Fri Jan 11, 2013 2:20 am

No replies, seems I have everyone stumped!!!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS Print to PDF

Post by jacque » Fri Jan 11, 2013 7:00 pm

It's more likely that no one had the time to write a full explanation, since printing can be complex depending on what you want to do. If you post your printing code, we can take a look.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Mon Jan 14, 2013 12:23 am

Thanks for th reply Jacque.

So basically I have a card that I wish to PDF print but there are a few things to consider though.
The Card has an IOS Scroller on it that can have different anounts of data in it (which varies its content rect)

Looking through the Dictionary there is little to no information on the open printing to PDF function so I haven't got far at all but what I have learned so far.
It seems that I need to print into a Rect to get any luck what so ever (in terms of getting it to fit to one page).. and Im not sure how to go about printing the contents of the iOS Scroller.

any assistance anyone could provide would be great.

Code: Select all

on saveInspection
   put specialFolderPath("documents") & "/test.pdf" into tFilePath
   put "Info" into tCardsToPrint
   open printing to pdf tFilePath
   if the result is "Cancel" then exit saveInspection
   repeat with x = 1 to the number of lines of tCardsToPrint
      print card (line x of tCardsToPrint) into 0,0,640,800
   end repeat
   close printing -- send group of cards to printer
   wait 2 seconds
   mergReader tFilePath
   
end saveInspection


jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS Print to PDF

Post by jacque » Mon Jan 14, 2013 7:54 pm

Thanks for posting the code. The "print card" command only prints the visible area, so you need to designate what part of the card to print if it isn't currently showing.

On the desktop you would reset the card size so that everything could be seen and then do something like this:

Code: Select all

print card (line x of tCardsToPrint) from 0,0,the width of this cd,the height of this cd  into 0,0,640,800
That will print everything on the entire card and scale the content to fit into a 640x800 pixel rectangle on the pdf. But on mobile you can't change the size of the card, it is fixed to the screen size. The only way to print everything is to move your objects so that they fit inside of the screen area.

There's another glitch though. If your scrolling field or iOS scroller has more text than is currently displayed, only the displayed part will print. The text that is scrolled out of view will not print. To accomodate that you need to adjust the size of the field or the scroller to display the entire content.

If that isn't practical, you can move the text to a special printing card and print that card instead. The card does not need to be visible, so you could just have a designated printing card that you print over and over after repeatedly filling the field with new content. This is actually a more standard way to do it when there is lots of text to print. You can set up the card with any images, objects, or anything else that should always print, and only change the text as needed.

If your text is so lengthy that it won't fit on a single card then you need to start dealing with pagination. I'll leave that alone for now unless you think you'll need it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Wed Jan 23, 2013 3:12 am

Thanks for your reply Jacque!

I have went the way of setting up a seperate printing card as you suggested and it seems to be working well now :)
Are you able to explain to me about pagination as I may be in situation where what I need to print (to 1 PDF Files) is not going to fit onto 1 Printing Card :(

Maybe I am looking in the incorrect area in the dictionary but there doesn't seem to be much infomation on printing available..

Thannks
Nakia

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS Print to PDF

Post by jacque » Wed Jan 23, 2013 5:40 am

The left-side "Printing" section label doesn't seem to be linked correctly and only shows a few entries. Try setting the category to "All" and searching for "print" instead and then follow all the "See also" links. Most of the capabilities are there. The one you need is missing though, it's the pageHeights property.

For each field that needs to paginate, you put the text into it and then get the pageHeights of the field. That gives you a list of integers representing the scroll amount for each "page" of text. So you print one page, then set the scroll of the field to the next integer, print another page, add the next integer to the scroll, etc. Do that for each field that needs to print multiple pages.

You can use "print break" to start a new page without closing the print job.

See "pageHeights" in the dictionary. It warns that the pageHeights calculation is based on a field with zero-width borders and a 6 pixel margin. For a printing card that's fine, no one will ever see it.

Another thing about creating a printing card -- the printmargins indicate where on the printed page the edge of the card will be. If your objects are not at left-side 0 on the card, they will not appear where the printmargin is set. The left side of the card will be at the left printmargin, the field itself will be offset as much from there as it is on the card. If you need exact margins, your field's topleft should be set at 0,0 on the card.

Also, every printer has a "dead" area where nothing will print, and it varies by manufacturer. Generally a quarter inch per side can't be printed on, and often a half inch at the top, so the printer's "0" point is often a quarter to half inch or so in from the edge. After that quarter inch, your printmargins take effect, which means a left printmargin of 72 (1 inch) will actually print on the page at 1.25 inches. If your field isn't at the extreme left edge of the card, it will add that much more to the left margin.

Well, that's a start anyway. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS Print to PDF

Post by jacque » Wed Jan 23, 2013 5:44 am

By the way, if you are printing to PDF, there aren't any "dead" areas of the page where ink can't print, so you don't have to worry about those paper restrictions.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Wed Jan 23, 2013 10:14 am

Thanks so much !!
That helps more than you could imagine..

So if I need to print multiple cards on one PDF
I simply apply a print break after the first card in the printing loop?

Thanks again

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS Print to PDF

Post by jacque » Wed Jan 23, 2013 7:32 pm

Right, "print break" starts a new page. But whether or not you need to use it depends on the size of your printing card. If the card is sized the same as a piece of paper, then LiveCode will start a new page automatically when the paper size is exceeded. If the card is smaller than a piece of paper, LiveCode will print as much as will fit and then do the rest on the second page. That can result in half a card at the bottom of one page and the other half on the second page.

You can deal with this two ways. Usually I just make sure my printing stack is the same size in pixels as a normal piece of paper. Alternately you can set the printPaperSize so that LiveCode knows when to break. There are still times when you may want to issue a "print break" command; for example, if your field text has sections with chapter headings and you want a new page to start at each chapter, no matter how much of the current page is filled.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Wed Jan 23, 2013 10:35 pm

Thanks Jacque,

As previoulsy noted I am working on iOS so my printing card size is limited to my stack size (320x480).
In my case I have just made 2 printing cards and all my content will fit on each page with out running over onto the next ,so I really just need to tell my printing loop to print both cards..

Thanks again.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Wed Jan 30, 2013 11:56 pm

Righto,

Seems I have this working beside the fact that the printing routine seems to resize the Card after the first print which is messing up the size of the card on the next print.
(The card is built at Stardard Res, I am using tmControls) but obvioulsy on the second print the contents of the card are all messed up.

Any idea's on how to get around this?

EDIT - tried placing in the openCard/ preOpenCard of the printing Card "iphoneUseDeviceResolution false, false" but to no avail.
Is there a way I can force that Card only not to resize when it receives the resizeStack message..

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: IOS Print to PDF

Post by Nakia » Thu Jan 31, 2013 6:01 am

Okay,

So what I ended up doing was creating a substack of my mainstack to house these printing cards in.
Thanks Monte :)

But, for some reason now my print loop won't complete ?
I have made BOLD the only part of the printing loop I changed after moving the printing cards into a substack.

any ideas?

Code: Select all

on printPDF
   
   -- PDF Printing
   put specialFolderPath("documents") & "/Inspection.pdf" into tFilePath
   put ("Print" & return & "Print2" & return) into tCardsToPrint
   lock screen
   open printing to pdf tFilePath
   if the result is "Cancel" then exit printPDF
   repeat with x = 1 to the number of lines of tCardsToPrint
      print card (line x of tCardsToPrint)[b]of stack "Printing"[/b] into 110,50,500,700
      print break
   end repeat
   close printing
   wait 2 seconds
   unlock screen
   mergReader tFilePath
end printPDF


jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: IOS Print to PDF

Post by jacque » Thu Jan 31, 2013 6:52 am

You can block the resizestack message by putting an empty handler into that card:

on resizeStack
end resizeStack

That will prevent the message from going through to the main handler, provided that card is current when the message is received.

The most likely reason the repeat is failing is that you're on a substack now and the list is referencing the main stack. What's in tCardsToPrint? Does your printing stack have the same number of cards and content as the list? The script is indicating it does.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply