iOS Air print for UIwebview

siva picture siva · Jul 1, 2011 · Viewed 12.1k times · Source

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

Answer

Hafthor picture Hafthor · Jul 11, 2013
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.