Để in nội dung của UIWebview, xem trình định dạng được yêu cầu. Tôi đã dán mã bên dưới.
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
//pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"google.com";
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
// Webvied print
NSData *mydata=[NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://www.google.com"]];
// Use this webview if your content is not loaded into webview, if webview already exists then give its reference here
UIWebView *webview = [[UIWebView alloc] initWithFrame: CGRectZero];
[webview loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: @"http://www.google.com"]]];
[webview loadData:mydata MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL: [NSURL URLWithString: @"http://www.google.com"]];
UIViewPrintFormatter *formatter = [webview viewPrintFormatter];
pic.printFormatter = formatter;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not complete because of error: %@", error);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
Nguồn
2014-05-21 08:05:13
Tôi sẽ rất ngạc nhiên nếu UIWebView có thể hiển thị các tệp Word, Excel hoặc Powerpoint, điều gì khiến bạn nghĩ rằng nó có thể? – DarkDust
@DarkDust http://developer.apple.com/library/ios/#qa/qa1630/_index.html – Dolbz
@Dolbz: Cảm ơn, không biết. – DarkDust