Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kaydell.leavitt

macrumors regular
Original poster
Apr 19, 2010
100
0
I have the following code as my controller to try to print a view. The print job dialog displays, but nothing prints:

Code:
//
//  PrintTestAppDelegate.m
//  PrintTest
//
//  Created by kaydell on 4/27/10.
//  Copyright 2010 LevSolve.com. All rights reserved.
//

#import "PrintTestAppDelegate.h"

@implementation PrintTestAppDelegate

@synthesize window;
@synthesize printTestView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
	// Insert code here to initialize your application 
}

- (IBAction) print: (id) sender {
	NSLog(@"print:");
	NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
	NSPrintOperation *printOp = [NSPrintOperation printOperationWithView:printTestView printInfo:printInfo];
	[printOp runOperation]; // <<<<<<<<<<< this displays a print job dialog <<<<<<<<<<<<<<<
}

@end


//
//  PrintTestView.m
//  PrintTest
//
//  Created by kaydell on 4/27/10.
//  Copyright 2010 LevSolve.com. All rights reserved.
//

#import "PrintTestView.h"


@implementation PrintTestView

- (void)drawString:(NSString *)string centeredInRect:(NSRect)r withAttributes:(NSDictionary *)theAttribute
{
	NSPoint stringOrigin;
	NSSize stringSize;
	stringSize = [string sizeWithAttributes:theAttribute];
	stringOrigin.x = r.origin.x + (r.size.width - stringSize.width)/2;
	stringOrigin.y = r.origin.y  + (r.size.height - stringSize.height)/2;
	[string drawAtPoint:stringOrigin withAttributes:theAttribute];
}

- (void) drawHeaderRect: (NSRect) dirtyRect {
	NSRect bounds = [self bounds];
	[self drawString:@"Header" centeredInRect:bounds withAttributes:nil];	
}

- (void) drawBodyRect: (NSRect) rect {
	NSRect bounds = [self bounds];
	[self drawString:@"Body" centeredInRect:bounds withAttributes:nil];	
}

- (void) drawFooterRect: (NSRect) rect {
	NSRect bounds = [self bounds];
	[self drawString:@"Footer" centeredInRect:bounds withAttributes:nil];	
}

- (void) drawRect: (NSRect) rect { <<<<<<<<< this is never called <<<<<<<<<<<<<<<<<<<
	if (![NSGraphicsContext currentContextDrawingToScreen]) {
		[self drawHeaderRect:rect];
		[self drawBodyRect:rect];
		[self drawFooterRect:rect];
	}
}

@end

-- Kaydell
 
Where do you create printTestView? If you only have the code posted then this variable is nil. Declaring a property is just declaring a variable. Synthensizing a property creates methods to set/get the variable. Neither of these create an object to store in the variable.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.