在我的 Mac 应用程序中,我有一个显示一些 html 内容的 web 视图。我从该 web 视图创建了一个 PDFDocument,然后我想打印该文档。所以我从文档中创建了一个 PDFView,然后我调用了 NSPrintOperation printOperationWithView。当显示打印面板时,除了显示为空白的页面预览之外,所有显示都是正确的,但是如果我按下详细信息按钮,面板会刷新并且页面预览会正确显示。
我该如何解决这个问题?请需要帮助。提前致谢。
这是我的问题的一个例子:
1- 打印面板显示空白页预览。接下来我按显示详细信息。
2-刷新面板后,页面预览正确显示。
这是我的代码:
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];
NSData *pdfFinal = [[[[webView mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[webView mainFrame] frameView] documentView].frame];
PDFDocument *doc = [[PDFDocument alloc] initWithData:pdfFinal];
PDFView *pdfView = [[PDFView alloc] init];
[pdfView setDocument:doc];
NSPrintOperation *op;
op = [NSPrintOperation printOperationWithView:pdfView.documentView printInfo:printInfo];
[op setShowsProgressPanel:YES];
[op setShowsPrintPanel:YES];
[op runOperation];