सबसे पहले, UIPrintInteractionControllerDelegate जोड़ सकते हैं और सभी छवियों को मुद्रित करने के लिए
UIPrintInteractionController *printController;
कोड नीचे चर बनाने दस्तावेजों, एक्सेल, पावरपॉइंट, पीडीएफ फाइलों मेरे लिए काम करता है:
[self printItem:SomeData withFilePath:YourFilePath];
उपर्युक्त कोड में आप अपने दस्तावेज़/छवि औरके NSData प्रदान करते हैं और यूआरएल (filepath) और printItem के आगे नीचे दिए गए कोड: withFilePath: विधि
-(void)printItem :(NSData*)data withFilePath:(NSString*)filePath{
printController = [UIPrintInteractionController sharedPrintController];
printController.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [NSString stringWithFormat:@""];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
//If NSData contains data of image/PDF
if(printController && [UIPrintInteractionController canPrintData:data]) {
printController.printingItem = data;
}else{
UIWebView* webView = [UIWebView new];
printInfo.jobName = webView.request.URL.absoluteString;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
printController.printFormatter = webView.viewPrintFormatter;
}
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
//NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
// Check wether device is iPad/iPhone , because UIPrintInteractionControllerDelegate has different methods for both devices
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[printController presentFromRect:self.view.frame inView:self.view animated:YES completionHandler:completionHandler];
}
else {
[printController presentAnimated:YES completionHandler:completionHandler];
}
}
मुझे आशा है कि यह मदद मिलेगी। धन्यवाद
स्रोत
2016-06-15 09:40:50
मैंने सादे पाठ को मुद्रित करने के लिए नमूना कोड शामिल करने के लिए अपना उत्तर अपडेट किया। –