title: Generate scaled image from off-screen NSView
body: <p>I have a sequence of off screen NSViews in a Cocoa application, which are used to compose a PDF for printing. The views are not in an NSWindow, or visible in any way.</p>
  
  <p>I'd like to be able to generate thumbnail images of that view, exactly as the PDF would look, but scaled down to fit a certain pixel size (constrained to a width or height). This needs to be as fast as possible, so I'd like to avoid rendering to PDF, then converting to raster and scaling - I'd like to go direct to the raster.</p>
  
  <p>At the moment I'm doing:</p>
  
  <pre><code>NSBitmapImageRep *bitmapImageRep = [pageView bitmapImageRepForCachingDisplayInRect:pageView.bounds];
  [pageView cacheDisplayInRect:pageView.bounds toBitmapImageRep:bitmapImageRep];
  NSImage *image = [[NSImage alloc] initWithSize:bitmapImageRep.size];
  [image addRepresentation:bitmapImageRep];
  </code></pre>
  
  <p>This approach is working well, but I can't work out how to apply a scaling to the NSView before rendering the bitmapImageRep. I want to avoid using <code>scaleUnitSquareToSize</code>, because as I understand it, that only changes the bounds, not the frame of the NSView.</p>
  
  <p>Any suggestions on the best way of doing this?</p>