[webkit-dev] Printing a WebView in ObjectiveC command-line
application fails in OS X 10.5
Plessl Christian
christian at plesslweb.ch
Tue Dec 4 10:53:06 PST 2007
I'm developing an open-source command line tool named wkpdf (http://wkpdf.plesslweb.ch
) that uses WebKit to generate a PDF for a URL. Due to some unknown
changes, wkpdf is not compatible with the recently released Mac OS X
10.5 (Leopard).
When running wkpdf, NSView is raising the following assertion, when
the WebView is printed:
wkpdf --source http://wkpdf.plesslweb.ch --output wkpdf.pdf
2007-12-04 19:24:45.585 wkpdf[1902:10b] *** Assertion failure in -
[WebHTMLView lockFocusIfCanDraw],
/SourceCache/AppKit/AppKit-949/AppKit.subproj/NSView.m:4776
2007-12-04 19:24:45.586 wkpdf[1902:10b] lockFocus sent to a view
which is not in a window
The same problem was also mentioned by Scott Garner on the cocoa-dev
mailinglist (http://www.cocoabuilder.com/archive/message/cocoa/2007/11/2/192061
) for his Automator action that converts URLs to PDFs.
I couldn't find a solution in Apple's documentation or on the web. I
suppose the problem is related to the fact, that wkpdf doesn't have a
user interface, i.e. the WebView is not visible. Here are some code
snippets, the full source code can be browsed at http://wkpdf.plesslweb.ch/browser/trunk
The WebView is created like this:
WebView * webView = [[WebView alloc]
initWithFrame:NSMakeRect(0,0,800,600)
frameName:@"myFrame"
groupName:@"myGroup"];
[webView setFrameLoadDelegate: controller];
NSURLRequest * request = ...
[[webView mainFrame] loadRequest:request];
And later printed in the didFinishLoadForFrame callback:
(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame
*)frame
...
NSView *viewToPrint = [[[sender mainFrame] frameView] documentView];
printOp = [NSPrintOperation printOperationWithView:viewToPrint
printInfo:printInfo];
[printOp setShowPanels:NO];
[printOp runOperation];
The assertion is caused by [printOp runOperation].
Does anyone have an idea how to solve this problem? Is this the
appropriate mailing list for this question, or would cocoa-dev be more
appropriate?
Best regards,
Christian
More information about the webkit-dev
mailing list