Skip navigation.
 
mlprinting in Cocoa
FROM : Victor Bovio
DATE : Wed Apr 16 18:03:39 2008

Hi,

Does anyone knows a good book or tutorial that covers printing (in-
depth) in Cocoa apps ??, I have Hillegass book but just covers the 
minimal steps for printing..

I'll write below the problems I have with my app in case anyone can 
help, Thanks!


----------------------


I have a document-based Cocoa application, in which I display quartz 
routines directly to the context of my NSView.
Following the documentation I added this methods to enable printing in 
my application:


on NSDocument:

- (void)printDocumentWithSettings:(NSDictionary *)printSettings 
showPrintPanel:(BOOL)showPrintPanel
                delegate:(id)delegate didPrintSelector:
(SEL)didPrintSelector contextInfo:(void *)contextInfo
{
    NSView *view = [self myDocumentView];
    NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
    NSPrintOperation *printOp = [NSPrintOperation 
printOperationWithView:view printInfo:printInfo];
    [printOp setShowPanels:showPrintPanel];
    [self runModalPrintOperation:printOp delegate:delegate
                  didRunSelector:didPrintSelector 
contextInfo:contextInfo];
}


on NSView:

- (void)drawRect:(NSRect)rect
{
    NSGraphicsContext *nsctx = [NSGraphicsContext currentContext];
    CGContextRef context = (CGContextRef)[nsctx graphicsPort];
    // draw quartz routines to the context
}

- (BOOL)knowsPageRange:(NSRangePointer)aRange
{
    aRange->location = 1;
    aRange->length = 1;
    return YES;
}

- (NSRect)rectForPage:(NSInteger)pageNumber
{
    return NSMakeRect(0, 0, 8.5*72, 11*72);
}


It works and I can print, but I have two problems:

1) the preview image that is displayed in the print panel does not 
show correctly the contents of my view, it looks like it was blured (a 
lot)

2) if I select a different page size and/or orientation in the page 
setup panel, it is ignored when I print.


Any ideas what I'm missing ??

Related mailsAuthorDate
mlprinting in Cocoa Victor Bovio Apr 16, 18:03
mlRe: printing in Cocoa Chris Hanson Apr 17, 21:10