You can create view that that displays what you want to print. Then you use it to create print operation.
You would typically created a view that displays your image. You implement an algorithm to figure out what image you want to display on which page. Then you return number of pages available to print and implement method to print specific page.
- If you have 10 images and you want to
print one per page that's easy.
- If you want to print records per page
and you have 100 records then you
calculate how many records you can
fit on a page (using current font
size and number of lines per record).
- Then you figure out from records per
page how many pages you need to
display all records - this is your
number of pages (range of pages).
- When requested to print specific
range of pages you select the records
that should be show on given page and
display them.
- See references below on how to
implement these steps. See the
custom pagination info for
example how to implement these steps, it's not difficult.
See Print Programming Topics, or the full example I reference bellow from the book has pagination which I did not included here. Have a look at the custom pagination for more hints.
If you have Document Based application and a view that you want to dump to printer, then in our MyDocument
(or whatever you call it) that extends NSDocument
you would implement:
- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)ps
error:(NSError **)e
The view then uses standard drawRect:
for drawing.
Example, here PeopleView
just draws a table
of people details, it takes a NSDictonary
of people employees
here:
- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)ps
error:(NSError **)e
{
PeopleView * view = [[PeopleView alloc] initWithPeople:employees];
NSPrintInfo * printInfo = [self printInfo];
NSPrintOperation * printOp
= [NSPrintOperation printOperationWithView:view
printInfo:printInfo];
[view release];
return printOp;
}
You can look for more details in chapter 27, Printing, in Hillegass' Cocoa Programming For Mac OS X.