UIwebview 的 iOS Air 打印

发布于 2024-11-18 06:55:55 字数 129 浏览 3 评论 0原文

任何人都可以指导我如何打印 UIWebview 的内容,

例如: - 我想从 UIWebview 打印我的 doc、xls、ppt 文件以打印内容。

请获取一些链接或示例代码来解决此问题

提前致谢

Can any one guide me how to print the contents of my UIWebview,

FOR EX : - i would like to print my doc,xls,ppt file from UIWebview to print the contents.

Please get some links or sample code to solve this problem

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安穩 2024-11-25 06:55:55
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = webView.viewPrintFormatter;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
    // indicate done or error
}];

更广泛的示例苹果的开发网站。

UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = webView.viewPrintFormatter;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
    // indicate done or error
}];

A more extensive sample on Apple's dev site.

抱猫软卧 2024-11-25 06:55:55

要打印 UIWebview 的内容,需要视图格式化程序。
我已经粘贴了下面的代码。

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];

To print contents of UIWebview, view formatters are required.
I have pasted the code below.

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文