0

I am trying to print an NSImage but am having trouble getting it to be to proper size. I want the NSImage to be printed as a 4"x6" photo on any paper large enough. Here's the code I have now.

var printView = NSImageView(frame: NSRect(x: 0, y: 0, width: 72*4, height: 72*6))
var printInfo = NSPrintInfo()

printInfo.paperSize = NSSize(width: 72*4, height: 72*6)
printInfo.bottomMargin = 10
printInfo.topMargin = 10
printInfo.leftMargin = 10
printInfo.rightMargin = 10

printView.image = generateImage()
let printOp = NSPrintOperation(view: printView, printInfo: printInfo)
printOp.run()
  • 1
    Unless you spell it, nobody knows what your 'trouble' is. – El Tomato Jun 20 '18 at 00:11
  • It appears to be printing the image scaled to whatever size the paper is instead of being a fixed size –  Jun 20 '18 at 01:24
  • What settings are you using in the print dialog? There is a setting that scales the output to the page size. Is that set by any chance? – user1118321 Jun 20 '18 at 05:07
  • You can't change the size of the paper in code. The size of the paper in the printer won't change. What are `printInfo.horizontalPagination` and `printInfo.verticalPagination`? – Willeke Jun 20 '18 at 09:08

1 Answers1

3

This seems to fix my problem

var printView = NSImageView(frame: NSRect(x: 0, y: 0, width: 72*4, height: 72*6))
var printInfo = NSPrintInfo()

printInfo.bottomMargin = 0
printInfo.topMargin = 0
printInfo.leftMargin = 0
printInfo.rightMargin = 0

printView.image = generateImage()
let printOp = NSPrintOperation(view: printView, printInfo: printInfo)
printOp.run()