Nick Nick - 2 months ago 22
Objective-C Question

NSPrintInfo changed in macOS Sierra

I have an application derived from the Xcode Cocoa Application template that prints properly on El Capitan, but introduces a centimetre margin all round with a shadow box on Sierra. Changing the margin values (in the shared instance in viewDidLoad of the viewController) to larger positive values makes the margins bigger, but reducing them to zero still leaves the margin and shadow box. The image is a screen-shot of the print preview. I would like to go back to having the PDF take up the whole printed page. Looking at the menu for the File/Print shows it executes firstResponder print:. Should I try to override this function? But if the code below is being executed to no effect, what good will this do?

NSPrintInfo *PageDefaults = [NSPrintInfo sharedPrintInfo];
[PageDefaults setBottomMargin:0];
[PageDefaults setLeftMargin:0];
[PageDefaults setRightMargin:0];
[PageDefaults setTopMargin:1];


enter image description here

If I increase the top and left margins in the code above to 120, the print changes to:
enter image description here

The storyboard shows that I am only using a PDF View control that fills the entire viewController scene
enter image description here

And finally, the viewController on screen shows it looks as it should:
enter image description here

Answer

-[PDFView print:] in 10.10 calls printWithInfo:autoRotate:pageScaling:. In 10.12 -[PDFView print:] calls printOperationWithView: and prints the background. Solution: create a subclass of PDFView, override print: and call printWithInfo:autoRotate:pageScaling:.

- (void)print:(id)sender {
    [self printWithInfo:[NSPrintInfo sharedPrintInfo] autoRotate:YES pageScaling:kPDFPrintPageScaleToFit];
}