你可以运行一个 NSPrintPanel 显示系统打印对话框。为此,您还需要设置一个 NSPrintInfo 宾语:
NSPrintPanel
NSPrintInfo
NSPrintInfo* printInfo = [NSPrintInfo new]; // set printInfo.printer if you want to override the default PMPrintSettings printSettings = printInfo.PMPrintSettings; // configure printSettings [printInfo updateFromPMPrintSettings]; PMPageFormat pageFormat = printInfo.PMPageFormat; // configure pageFormat [printInfo updateFromPMPageFormat];
创建面板并使用该信息对象运行它:
NSPrintPanel* panel = [NSPrintPanel printPanel]; // configure panel; for example, set its options property NSInteger result = [panel runModalWithPrintInfo:printInfo];
使用信息作为打印会话的基础:
if (result == NSOKButton) { PMPrintSession session = printInfo.PMPrintSession; printSettings = printInfo.PMPrintSettings; pageFormat = printInfo.PMPageFormat; PMSessionBeginCGDocumentNoDialog(session, printSettings, pageFormat); PMSessionBeginPageNoDialog(session, pageFormat, NULL); CGContextRef lGraphics; PMSessionGetCGGraphicsContext(session, &lGraphics); ... PMSessionEndPageNoDialog(session); PMSessionEndDocumentNoDialog(session); }