Creating / Printing WebViews programmatically
Creating / Printing WebViews programmatically
- Subject: Creating / Printing WebViews programmatically
- From: Rob Chahin <email@hidden>
- Date: Thu, 14 Sep 2006 12:51:32 +0100
Gah..
I'm trying to print the contents of an NSTableView by exporting its
contents to HTML, sending it to a WebView and then printing out the
WebView.
At the moment I'm doing this by subclassing the print method of
NSTableView like so:
(webView is an outlet to an IB webView)
- (void)print:(id)sender {
WebView *printView =[[WebView alloc] initWithFrame:NSMakeRect
(0,0,640,480) frameName:nil groupName:nil];
[printView setHostWindow:[self window]];
[[printView mainFrame] loadHTMLString:@"<html><body><p>This is some
text.</p></body></html>" baseURL:nil];
[[webView mainFrame] loadHTMLString:@"<html><body><p>This is some
text.</p></body></html>" baseURL:nil];
NSLog(@"classes: %@, %@", printView, [[[printView mainFrame]
frameView] documentView]);
NSLog(@"classes: %@, %@", webView, [[[webView mainFrame] frameView]
documentView]);
[[NSPrintOperation printOperationWithView:webView] runOperation];
}
My log output reads:
2006-09-14 11:52:02.231 app[11710] classes: <WebView: 0x35bf10>, (null)
2006-09-14 11:52:09.512 app[11710] classes: <WebView: 0x35bf10>,
<WebHTMLView: 0xc9b7a70>
(Sometimes I need to print, cancel, and then print to give the views
time to draw the content, but that's another issue)
The setHostWindow: is in there because the Apple docs mention
attaching a WebView to a window, but don't go into detail about when
you need to do it. The result is the same regardless.
The problem seems to be that I'm creating my webView incorrectly,
since it more or less works with the IB webView. I tried printView =
[WebView new]; but that didn't work either.
Some of you have undoubtledly done this before, so any help would be
appreciated.
–––––––––
Rob Chahin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden