Re: multiple-page print support in NSView
Re: multiple-page print support in NSView
- Subject: Re: multiple-page print support in NSView
- From: Keary Suska <email@hidden>
- Date: Wed, 7 Apr 2010 09:01:05 -0600
On Apr 6, 2010, at 10:11 PM, Rua Haszard Morris wrote:
> 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.
Without any code, we can't tell you what you are doing wrong.
> 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.
If you want to use -knowsPageRange then you *must* know ahead of time. You don't have to know ahead of time if you can keep pages from page breaking at inconvenient places, but that can be tricky.
> 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.
Printing doesn't use a different coordinate system. 0,0 is always lower left. Vertical/horizontal centering may change the position of the view on the page.
> 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.
That is pretty much it other than sample code. Are you aware of the sample code listings that come with each class reference document? Other than that, the only difficult-to-find documentation that is a real hiney-biter is that text is always rendered in a flipped coordinate system.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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