< Previous PageNext Page > Hide TOC

Customizing a View’s Drawing for Printing

A view gets drawn for the printer the same way as for drawing to the screen. drawRect: messages are sent to the view identifying what region should be drawn. Core Graphics then translates the drawing operations performed by the view into the appropriate representations for displaying on the screen or rendering on a printer.

In some cases you need to behave differently when drawing to the screen versus to a printer. For example, a selected object on screen may have handles or a highlight that should not be drawn when printing. To test whether you are drawing to the screen, send the message currentContextDrawingToScreen to NSGraphicsContext, as shown here:

- (void)drawRect:(NSRect)r {
    if ( [NSGraphicsContext currentContextDrawingToScreen] ) {
        // Draw screen-only elements here
    } else {
        // Draw printer-only elements here
    }
    // Draw common elements here
}

You may also need to adjust your drawing based on an attribute in the print operation’s NSPrintInfo object. You can get the current print operation with the NSPrintOperation class method currentOperation and then get its NSPrintInfo object from the printInfo method.

NSPrintOperation *op = [NSPrintOperation currentOperation];
NSPrintInfo *pInfo = [op printInfo];


< Previous PageNext Page > Hide TOC


© 2002, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-06-28)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.