0

How can an NSView be set up for printing? For example, say I have a view in which I've overridden layout() to lay things out just as text does, flowing from one line to the next according to the width of the view. Nothing should scale, and the view needs to get taller (possibly requiring more pages) as it becomes more narrow.

What steps would I need to take in order to make print preview work and then actually print such a document? For example, I need to size the view to fit the page. At what point would I set the bounds, and where would I get the information on the size of the page? Do I print the view that's currently on screen, or should I create a new view with the same data?

I've read Customizing Content for the Printed Page, Not the Display, but I think drawRect is a later step than what I want.

arsenius
  • 12,090
  • 7
  • 58
  • 76
  • Do you want to print what's on the screen or do you want to reformat for printing? Which printing methods of `NSView` do you override? – Willeke May 23 '17 at 09:15
  • Currently I override none of them. Not sure where to start. I *guess* I want to reformat for printing. Basically I just want to know 1. how to choose which view gets printed (currently it does the whole window) and 2. when and where to set the frame for that view to match the selected printer settings (Letter, A4, custom, etc...) – arsenius May 26 '17 at 15:18
  • 1. Implement an action method `print:` in the view or viewcontroller. 2. It's probably easier to use an offscreen view for printing. See [Creating an autoresizing printout](https://stackoverflow.com/q/32582043/4244136). – Willeke May 26 '17 at 22:22

0 Answers0