Enable printing current webview (#196)
Sometimes when doing complex rendering you want to print the current
webview rather than another page or link. This enables you to call
.print('') and it will print the current webview rather than a blank
page on both ios and android.
This commit is contained in:
committed by
Sebastián Katzer
parent
675b3f5962
commit
6e44eb9cde
@@ -382,29 +382,39 @@
|
||||
*/
|
||||
- (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller
|
||||
{
|
||||
UIWebView* page = [[UIWebView alloc] init];
|
||||
UIPrintPageRenderer* renderer = [[UIPrintPageRenderer alloc] init];
|
||||
UIViewPrintFormatter* formatter = [page viewPrintFormatter];
|
||||
UIViewPrintFormatter* formatter;
|
||||
|
||||
if([content length] == 0) {
|
||||
formatter = [self.webView viewPrintFormatter];
|
||||
} else {
|
||||
UIWebView* page = [[UIWebView alloc] init];
|
||||
formatter = [page viewPrintFormatter];
|
||||
|
||||
page.delegate = self;
|
||||
|
||||
if([content length] == 0) {
|
||||
// do nothing, already loaded
|
||||
} else if ([NSURL URLWithString:content]) {
|
||||
NSURL *url = [NSURL URLWithString:content];
|
||||
|
||||
[page loadRequest:[NSURLRequest requestWithURL:url]];
|
||||
} else {
|
||||
NSString* wwwFilePath = [[NSBundle mainBundle] pathForResource:@"www"
|
||||
ofType:nil];
|
||||
NSURL* baseURL = [NSURL fileURLWithPath:wwwFilePath];
|
||||
|
||||
|
||||
[page loadHTMLString:content baseURL:baseURL];
|
||||
}
|
||||
}
|
||||
|
||||
[renderer addPrintFormatter:formatter startingAtPageAtIndex:0];
|
||||
|
||||
page.delegate = self;
|
||||
|
||||
if ([NSURL URLWithString:content]) {
|
||||
NSURL *url = [NSURL URLWithString:content];
|
||||
|
||||
[page loadRequest:[NSURLRequest requestWithURL:url]];
|
||||
}
|
||||
else {
|
||||
NSString* wwwFilePath = [[NSBundle mainBundle] pathForResource:@"www"
|
||||
ofType:nil];
|
||||
NSURL* baseURL = [NSURL fileURLWithPath:wwwFilePath];
|
||||
|
||||
|
||||
[page loadHTMLString:content baseURL:baseURL];
|
||||
}
|
||||
|
||||
controller.printPageRenderer = renderer;
|
||||
|
||||
// just trigger the finish load fn straight off if using current webView
|
||||
if([content length] == 0)
|
||||
[self webViewDidFinishLoad:(UIWebView *)self.webView];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user