User Guide
Example: Multiple-page printing 495
Printing for landscape or portrait orientation
Because Flash Player can detect the settings for orientation, you can build logic into your
ActionScript to adjust the content size or rotation in response to the printer settings, as the
following example illustrates:
if (myPrintJob.orientation == PrintJobOrientation.LANDSCAPE)
{
mySprite.rotation = 90;
}
Responding to page height and width
Using a strategy that is similar to handling printer orientation settings, you can read the page
height and width settings and respond to them by embedding some logic into an
if
statement. The following code shows an example:
if (mySprite.height > myPrintJob.pageHeight)
{
mySprite.scaleY = .75;
}
In addition, a page’s margin settings can be determined by comparing the page and paper
dimensions, as the following example illustrates:
margin_height = (myPrintJob.paperHeight - myPrintJob.pageHeight) / 2;
margin_width = (myPrintJob.paperWidth - myPrintJob.pageWidth) / 2;
Example: Multiple-page printing
When printing more than one page of content, you can associate each page of content with a
different sprite (in this case,
sheet1 and sheet2), and then use PrintJob.addPage() for
each sprite. The following code illustrates this technique:
package
{
import flash.display.MovieClip;
import flash.printing.PrintJob;
import flash.printing.PrintJobOrientation;
import flash.display.Stage;
import flash.display.Sprite;
import flash.text.TextField;
NOTE
If you plan to read the system setting for content orientation on the paper, remember to
import the PrintJobOrientation class by using the following:
import flash.printing.PrintJobOrientation;
The PrintJobOrientation class provides constant values that define the content
orientation on the page.