Search code examples
objective-cnsprintoperation

How can I change page orientation within a multi page NSPrintOperation?


Let's say that I have a three page report that I want to print out, first page is portrait orientation, second page is landscape, and third page is again portrait.

I've subclassed a special NSView to be my printing operation, but what I get is three pages, all oriented portrait, cutting off the landscape orientation. I have been able to work around it, by separating each of the pages into a separate print job, but that's not acceptable, because it ignores the settings from the

NSPrintOperation *printOperation = [NSPrintOperation printOperationWithView: printView printInfo: printInfo];

[printView setCurrentForm: [formSet objectAtIndex: 0]];

[printOperation setShowsPrintPanel:YES];
[printOperation runOperationModalForWindow: [self window] delegate: nil didRunSelector: nil contextInfo: nil];
[printOperation cleanUpOperation];
[NSPrintOperation setCurrentOperation: nil];

call from the first page (if, for example, they selected "PDF Open in Preview" from that dialog, I want the three pages to be joined as one job, which opens as a PDF in Preview.)

What do I need to do in the code that has the printer version of the NSView rendered, to force the NSPrintOperation to change the orientation?


Solution

  • Set the orientation in rectForPage:

    NSPrintOperation.currentOperation.printInfo.orientation = NSPaperOrientationLandscape;
    

    or

    NSPrintOperation.currentOperation.printInfo.orientation = NSPaperOrientationPortrait;