When to resize my NSView for printing?

297 views Asked by At

I have an NSView subclass specifically for printing. I want it to fit the width to the page and the height to the number of records.

But I haven't really found a good spot to size the view. I'm currently sizing the view in -beginDocument (because I need to get the paper size from the -printInfo to be able to do that), but sometimes the page count under the print panel preview is wrong, so it looks like this is happening too late.

Is there a recommended way to make the printed output view dependent on the page size?

The view is created right in the -print: method and given a model object to print, before creating the NSPrintOperation with -printOperationWithView: and calling -runModal on it (where the user then sets all the properties they like). It implements -beginDocument (for aforementioned reasons) and -drawRect: and that's pretty much it.

I also give the print operation an accessory view controller which changes a few properties on the view of my own (colors and font sizes), which then trigger a redraw of the preview because I give out their keys from -keyPathsForValuesAffectingPreview.

0

There are 0 answers