1

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.

uliwitness
  • 8,532
  • 36
  • 58
  • When and how do you create the view? Which properties of `printInfo` do you set and to what? Which printing methods of `NSView` are implemented? – Willeke Mar 27 '18 at 11:23
  • I've updated the question with the info. – uliwitness Mar 29 '18 at 14:54
  • Is `-beginDocument` not called or is the print info incorrect in `-beginDocument`? – Willeke Mar 29 '18 at 23:25
  • `-beginDocument` is called, and the print info looks right. When I check out the page count my calculations are working with, it is right. It's simply that the print panel's preview seems to have already updated its page count and therefore uses the old page count from the previous time I made it update (the drawing is right, it's just cut off/contains empty pages depending on whether the page count went up or down) – uliwitness Apr 02 '18 at 19:01
  • `-beginDocument` works in my test app, but only if I use `NSPrintOperation.currentOperation.printInfo` instead of `NSPrintInfo.sharedPrintInfo`. If `-beginDocument` doesn't work, try `-knowsPageRange:`, you can return `NO`. – Willeke Apr 04 '18 at 09:28

0 Answers0