In my Mac app, I have a webview that shows some html content. I am creating a PDFDocument from this web view and then I want to print this document. So I create a PDFView from the document, and then I call NSPrintOperation printOperationWithView. When the print panel is displayed, everything is displayed correctly, except for the preview of the page, which appears blank, but if I click the Details button, the panel will be updated and the page preview will be displayed correctly.
How can i solve this? Need help please. Thanks in advance.
This is an example of my problem:
1- A blank page view is displayed on the print panel. Then click on Details.

2- After updating the panel, the page preview is displayed correctly.

This is my code:
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];
source
share