objective-ccocoansprintoperation

Hide window that show when we use NSPrintOperation


I use below code for print view1 and when i run it, a window open and i should select settings and click on print button then the view will print.how to do it (settings) in code (means window doesn't open and directly print view1 with settings that we set in code)

NSPrintOperation *printOperation= [NSPrintOperation 

printOperationWithView:view1];
[printOperation runOperation];

Solution

  • You can suppress the display of the NSPrintPanel object by sending setShowsPrintPanel: with a NO argument to the NSPrintOperation object before running the operation.

    Just like this:

    NSPrintOperation *printOperation= [NSPrintOperation printOperationWithView:view1];
    
    [printOperation setShowsPrintPanel:NO];
    [printOperation runOperation];