multiple-page print support in NSView
multiple-page print support in NSView
- Subject: multiple-page print support in NSView
- From: Rua Haszard Morris <email@hidden>
- Date: Wed, 7 Apr 2010 16:11:29 +1200
I am trying to write an NSView subclass to render a multi-page printout. What I would like is to use the page/paper size in calculating the dimensions of each page; for example, if the printout is made up of N rows of items, each item rendering as 60-point-tall row.
So, assuming 10 rows of items, the rendered view needs to be 10 * 60 pt high, and the page boundaries need to be set appropriately - if the usable paper area is 120 points high, then we need 5 pages of 2 rows, and if the user specifies much larger paper, e.g. 240 points, then we need 3 pages, each with up to 4 rows (the last page only having two rows).
How do I implement knowsPageRange, rectForPage, and locationOfPrintRect to achieve this?
I have tried implementing these methods to set up arbitrary rectangles for each page, and I find that the rendering I do in drawRect is scaled weirdly in the printout, with a huge (half the page) right margin and an even huger (more than half the page, proportional to the total number of pages) top margin.
A possibly related issue is that the view doesn't know it's actual size (i.e. frame) until it has rendered itself, because of the number of items, and the possibility of large items that take up more than a single row. There may be an interaction between a size given to the view at init time (if it isn't given a size then it doesn't render anything in the printout) and the actual size of the complete printout.
In general my problems involve the relationship between "page coordinates" and view coordinates - if I can relate these two sizes appropriately then I might be able to get somewhere.
Is there sample code or a tutorial somewhere that explains how to set up custom page coordinates? I have read through "Printing Programming Topics for Cocoa", and it seems I'm missing something critical here.
Thanks
Rua HM._______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden