Print 2 pages from customview
Print 2 pages from customview
- Subject: Print 2 pages from customview
- From: Ivan Myrvold <email@hidden>
- Date: Mon, 29 Dec 2003 15:35:42 +0100
I have problems with printing of a custom view. I must have
misunderstood some fundamental things about printing in Cocoa.
Here is what I tries to do:
In IB a have made a custom view in a window, with the size of the
custom view being w 595 and h 1520. That should be about two A4 pages
high.
My window size is only of height 760, so I can only see the first page.
Running the application, the first page shows up nicely in the window.
I have no need to see the second page.
But when I print out the two pages, the second page is supposed to
start with the line with the (200, 800), but in fact the first line I
can see is the line with (200, 1200) Where have the other lines
disappeared. And the last line printed is about in the middle of the
page with (200, 1500). The first page is OK. Can anyone see what is
wrong here? I have been scratching my head all day over this, and can't
see what's wrong:
In my subclassed custom view, I have these routines:
- (void)drawRect:(NSRect)rect {
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
NSRect myBounds;
myBounds = NSMakeRect(0.0, 0.0, 595.0, 1520);
[@"NSMakePoint(200, 10)" drawAtPoint:NSMakePoint(200, 10)
withAttributes:attributes];
[@"NSMakePoint(200, 100)" drawAtPoint:NSMakePoint(200, 100)
withAttributes:attributes];
[@"NSMakePoint(200, 200)" drawAtPoint:NSMakePoint(200, 200)
withAttributes:attributes];
[@"NSMakePoint(200, 300)" drawAtPoint:NSMakePoint(200, 300)
withAttributes:attributes];
[@"NSMakePoint(200, 400)" drawAtPoint:NSMakePoint(200, 400)
withAttributes:attributes];
[@"NSMakePoint(200, 500)" drawAtPoint:NSMakePoint(200, 500)
withAttributes:attributes];
[@"NSMakePoint(200, 600)" drawAtPoint:NSMakePoint(200, 600)
withAttributes:attributes];
[@"NSMakePoint(200, 700)" drawAtPoint:NSMakePoint(200, 700)
withAttributes:attributes];
// here the second page is to begin
[@"NSMakePoint(200, 800)" drawAtPoint:NSMakePoint(200, 800)
withAttributes:attributes];
[@"NSMakePoint(200, 900)" drawAtPoint:NSMakePoint(200, 900)
withAttributes:attributes];
[@"NSMakePoint(200, 1000)" drawAtPoint:NSMakePoint(200, 1000)
withAttributes:attributes];
[@"NSMakePoint(200, 1100)" drawAtPoint:NSMakePoint(200, 1100)
withAttributes:attributes];
[@"NSMakePoint(200, 1200)" drawAtPoint:NSMakePoint(200, 1200)
withAttributes:attributes];
[@"NSMakePoint(200, 1300)" drawAtPoint:NSMakePoint(200, 1300)
withAttributes:attributes];
[@"NSMakePoint(200, 1400)" drawAtPoint:NSMakePoint(200, 1400)
withAttributes:attributes];
[@"NSMakePoint(200, 1500)" drawAtPoint:NSMakePoint(200, 1500)
withAttributes:attributes];
[@"NSMakePoint(200, 1600)" drawAtPoint:NSMakePoint(200, 1600)
withAttributes:attributes];
}
- (BOOL)knowsPageRange:(NSRange *)rptr {
rptr->location = 1;
rptr->length = 2;
return YES;
}
- (NSRect)rectForPage:(int)pageNum {
NSRect frontRect = NSMakeRect([self bounds].origin.x, [self
bounds].origin.y, [self bounds].size.width, [self
bounds].size.height/2.0);
NSRect backRect = NSMakeRect([self bounds].origin.x, [self
bounds].size.height/2.0, [self bounds].size.width, [self
bounds].size.height);
if (pageNum == 1)
return frontRect;
else
return backRect;
}
- (IBAction)print:(id)sender {
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
[printInfo setLeftMargin:1.0];
[printInfo setRightMargin:1.0];
[printInfo setTopMargin:1.0];
[printInfo setBottomMargin:1.0];
NSPrintOperation *printOp = [NSPrintOperation
printOperationWithView:self printInfo:printInfo];
[printOp setShowPanels:YES];
[printOp runOperation];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.