我无法使用以下服务在 Cocoa 中打印:[[NSPrintOperation printOperationWithView:self] runOperation]; 打印对话框启动,但预览为空白。请让我知道可能是什么问题?
我有一个要打印的 CGImage (iImageRef)。以下是我尝试的方法:
1.
NSImage* image = [[NSImage alloc] initWithCGImage:iImageRef size:size];
NSView* printView = [[NSView alloc] initWithFrame:rect];
[printView setWantsLayer:YES];
printView.layer = [CALayer layer];
printView.layer.contents = image;
NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:printView];
[printOperation setShowsPrintPanel:YES];
[printOperation runOperation];
NSImage* image = [[NSImage alloc] initWithCGImage:iImageRef size:size];
NSView* printView = [[NSView alloc] initWithFrame:rect];
[printView setWantsLayer:YES];
printView.layer = [CALayer layer];
printView.layer.contents = image;
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
[printInfo setTopMargin:0.0];
[printInfo setBottomMargin:0.0];
[printInfo setLeftMargin:0.0];
[printInfo setRightMargin:0.0];
[printInfo setHorizontalPagination:NSFitPagination];
[printInfo setVerticalPagination:NSAutoPagination];
[printInfo setVerticallyCentered:NO];
[printInfo setHorizontallyCentered:YES];
NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:printView printInfo:printInfo];
[printOperation setShowsPrintPanel:YES];
[printOperation runOperation];