chipp at chipp.com
Thu Mar 31 20:08:56 CST 2005
Recently, I bit the bullet and created my own print routines which print
a field of htmlText of any size. It also has a nifty feature in that it
creates preview imgs on the fly.
Basically, it's pretty simple. Here's how I did it.
I create two separate stacks: Print and OffScreenPrint
The Print stack has a substack called "Preview"
The reason for the 2 stacks, is that you need to be able to 'save' the
offscreen stack after you set the "formatForPrinting" property (Windows
Forgetting for a moment the print preview mode, the guts look like this:
Call the PageSetup function (answer printer) and from this you get the
printPaperSize (tPageHeight and tPageWidth). You can use these to setup
your offscreen imaging stack. You also get the printMargins as well. Use
these also to setup your offscreen print stack.
Before calling the print routine, you'll want to 'render' all your text
to the offscreen stack. Basically, you copy it to the main field of the
offscreen stack (or set the htmlText of the field) then check to see if
the formattedheight is too great for the field. Remove words (or
paragraphs, your choice) from the end until the field fits on the card
w/out overflowing. Then create a new card and continue. Do this until
all your text/htmltext is gone. Now you have a bunch of cards in your
offscreen stack to print from.
You can easily use shared groups (backgrounds) for adding headers and
Before printing, set the formatForPrinting prop to true and save (you
don't want to copy/paste stuff while it's set to true because it may
cause problems). Now close the stack (delete stack will remove it from
memory, which is what you want to do) and open it back up offscreen.
Oh, btw, you want to set the margins of your fields on the offscreen
stack to something high (I use 10) to keep it from 'cutting off letters.'
Now, the guts of the printing goes something like this:
open printing with dialog
put item 1 of printPaperSize into tW
put item 2 of printPaperSize into tH
--> DO PAGE CREATION STUFF HERE
--> COPY THE TEXT TO STACK "offscreenPrint"
--> CREATING A NEW CARD FOR OVERFLOW UNTIL NO MORE OVERFLOW
--> SET formatForPrinting to True AND SAVE STACK THEN CLOSE/OPEN
put the number of cds in stack "offscreenPrint" into tNumPages
set the defaultStack to "offscreenPrint"
repeat with x = 1 to tNumPages
go cd x
print card into 0,0,tW,tH
if x <> tNumPages then print break
That's pretty much all there is to it. If you want, you can even create
bitmaps from the offScreen stack which act as *very accurate* print
previews. I dump them into the Preview stack and set the preview img to
1/2 the size with resizeQuality set to best. Works beautifully, both on
Mac and PC.
More information about the use-livecode