8

The program I'm writing runs under OS X 10.5 Leopard. My target has its Base SDK and Deployment Target both set to Mac OS X 10.5. When I initiate printing, my print dialog doesn't show the Page Attributes option in which the user can select page size and orientation.

No Page Attributes

Other programs running under Leopard do show this option:

Yes Page Attributes

Here's the code that initiates printing:

-(void)print {
    NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
    TemperaturePressurePrintView *printView = [[TemperaturePressurePrintView alloc] initWithFrequencies:frequencies];
    if (printView) {
        [[NSPrintOperation printOperationWithView:printView printInfo:printInfo] runOperation];
        [printView release];
    }
}

What do I need to do to get Page Attributes to show up in my print dialog?

SSteve
  • 10,550
  • 5
  • 46
  • 72

2 Answers2

17

This was a tough thing to search for because the results were mostly about using the print panel, not programming one. I finally found a clue on Cocoabuilder where it mentions NSPrintPanelOptions and NSPrintPanel's -setOptions: method.

This code accomplishes what I need:

-(void)print {
    NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
    TemperaturePressurePrintView *printView = [[TemperaturePressurePrintView alloc] initWithFrequencies:frequencies];
    if (printView) {
        NSPrintOperation *op = [NSPrintOperation printOperationWithView:printView printInfo:printInfo];
        [[op printPanel] setOptions:[[op printPanel] options] | NSPrintPanelShowsPageSetupAccessory];
        [op runOperation];
        [printView release];
    }
}
SSteve
  • 10,550
  • 5
  • 46
  • 72
  • important to note that this snippet is a drop-in replacement for the standard [myView print:nil]; operation, except that it lets you customize the print dialog first. Great, clear solution. Thanks! – ecume des jours Jan 06 '13 at 17:44
0

It's a few years after the original answer and macOS Sierra seems to have introduced a bug into the behaviour of panels that have the 'NSPrintPanelShowsPageSetupAccessory' option set. Invalid values, such as a ridiculously large scale, cause crashes instead of displaying an alert sheet.

Fortunately there is a workaround. Using

NSPrintPanelShowsPaperSize | NSPrintPanelShowsOrientation | NSPrintPanelShowsScaling

instead seems to result in a panel that works fine.

Chuck
  • 96
  • 1
  • 3