我尝试打印 pdfUIPrintInteractionController
它加载在UIWevView
。好消息是我可以打印,坏消息是打印输出太小。
any help would be appreciated :)
- (IBACTION) printPDF {
if ((!_webView)) return;
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %ld",
error.domain, (long)error.code);
}
};
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.duplex = UIPrintInfoDuplexLongEdge;
controller.printInfo = printInfo;
controller.showsPageRange = YES;
_webView.scalesPageToFit = NO;
UIViewPrintFormatter *viewFormatter = [_webView viewPrintFormatter];
viewFormatter.startPage = 0;
controller.printFormatter = viewFormatter;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
/* [controller presentFromBarButtonItem:printButton animated:YES completionHandler:completionHandler]; */
}else
[controller presentAnimated:YES completionHandler:completionHandler];
}
输出:
除了 @crescendolls 响应之外,这里还有一段完整的代码,用于将 Web 视图中的 PDF 转换为数据,并相应地打印它。
-(void)printReport {
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;
//does not display PDF appropriately
//pic.printFormatter = webView.viewPrintFormatter;
//does display PDF appropriately
NSCachedURLResponse* webResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:[webView request]];
NSData* webData = [webResponse data];
pic.printingItem = webData;
[pic presentFromBarButtonItem:self.printBarButton animated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
// indicate done or error
}];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)