As WKWebView
contents can finally be printed out in macOS 11+, I'm trying to replace my old WebView
dependencies.
However, with the HTML correctly loaded in WKWebView
, creating PDF files using NSPrintJobDisposition: NSPrintSaveJob
produces blank, empty documents. They have the correct page count and sizing, but remain empty. Using the same code without NSPrintSaveJob
works just fine.
This is how I'm printing the contents:
NSPrintInfo *printInfo = NSPrintInfo.sharedPrintInfo;
[printInfo.dictionary addEntriesFromDictionary:@{
NSPrintJobDisposition: NSPrintSaveJob,
NSPrintJobSavingURL: url
}];
NSPrintOperation *printOperation =[(WKWebView*)_webView printOperationWithPrintInfo:printInfo];
printOperation.view.frame = NSMakeRect(0,0, printInfo.paperSize.width, printInfo.paperSize.height);
printOperation.showsPrintPanel = NO;
printOperation.showsProgressPanel = YES;
[printOperation runOperation];
Setting showsPrintPanel
as true
and uncommenting the dictionary produces traditional prints, and the results look completely normal. In both cases, I'm calling the runOperation
only after navigation has actually finished.
I'm confused about what I am doing wrong, or is printing from WKWebView
still this buggy?