Fitting a printout to the page

This lesson demonstrates how to fit a printout to a given page size.

The printThisCard command

The printThisCard handler takes two parameters, the paper size in points and the margin width in points. There are 72 points in an inch. The syntax of the command is

printThisCard pPaperSize, pMargin

The command is called with a statement such as:

printThisCard
printThisCard empty, 144 ## 2-inch margin
printThisCard "576,720", 72 ## 8x10" paper, 1" margin

Checking the parameters

You can call the handler with just one parameter, or with none. It's possible to do this because the first part of the handler checks to see whether a value was passed for both the parameters. If not, the handler assigns the value currently chosen for the user's printer. In other words, if you don't specify pPaperSize when you use the handler, it reads the size from the current paper size set by the system. If you don't specify pMargin, it assumes you want one-inch (72-point) margins.

if pPaperSize is empty then 
	put the printPaperSize into pPaperSize
end if
   
if pMargin is empty then 
	put 72 into pMargin
end if

You can use this method with any handler to assign a default value to one or more of the parameters. Just check whether the parameter is empty. If it is, then no value has been passed, and you set the default value by simply putting the desired default into the parameter.

Calculating the print area

Next, the handler sets up a rectangle for the page size less the margins. Finally, the card is printed into this rectangle. When you use the print...into form of the print command, the card is scaled up or down to fit the destination rectangle. In this case, it is scaled to fit the printable area of the page, since that's the destination rectangle that we put into the tDestinationRect variable.

set the printMargins to pMargin,pMargin,pMargin,pMargin
put pMargin,pMargin, \
	item 1 of pPaperSize - pMargin, \
	item 2 of pPaperSize - pMargin \
	into tDestinationRect
   
print this card into tDestinationRect

The printThisCard command code

on printThisCard pPaperSize, pMargin
	local tDestinationRect
   
	## set up defaults if no size and margin provided
	if pPaperSize is empty then 
		put the printPaperSize into pPaperSize
	end if
   
	if pMargin is empty then 
		put 72 into pMargin
	end if
   
	## get the page area
	set the printMargins to pMargin,pMargin,pMargin,pMargin
	put pMargin,pMargin, \
		item 1 of pPaperSize - pMargin, \
		item 2 of pPaperSize - pMargin \
		into tDestinationRect
   
	## print into that rectangle
	print this card into tDestinationRect
end printThisCard

Magnifying or reducing the card size

Suppose you want to approach the problem from the opposite direction, and specify that cards should be printed at, say, half size regardless of how many cards fit on a page. In this case, instead of using the print...into form, set the printScale property to specify how much the card should be magnified or reduced:

set the printScale to 0.5 ## half
print this card

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.