// Get the UIWebView content and convert to UIImage
UIViewPrintFormatter* printFormatter = [_webView viewPrintFormatter];
UIGraphicsBeginImageContext(_webView.frame.size);
[printFormatter.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// For Testing check the view layer size
//[UIImagePNGRepresentation(newImage) writeToFile:@"/Users/kito/Desktop/testfile.png" atomically:TRUE];
// Assign the AirPrint Job
UIPrintInteractionController* printController = [UIPrintInteractionController sharedPrintController];
printController.printingItem = newImage;
// Present the AirPrint Dialog from Bar Button
[printController presentFromBarButtonItem:barBtn animated:TRUE completionHandler:nil];
UIViewPrintFormatter* printFormatter = [_webView viewPrintFormatter];
UIGraphicsBeginImageContext(_webView.frame.size);
[printFormatter.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// For Testing check the view layer size
//[UIImagePNGRepresentation(newImage) writeToFile:@"/Users/kito/Desktop/testfile.png" atomically:TRUE];
// Assign the AirPrint Job
UIPrintInteractionController* printController = [UIPrintInteractionController sharedPrintController];
printController.printingItem = newImage;
// Present the AirPrint Dialog from Bar Button
[printController presentFromBarButtonItem:barBtn animated:TRUE completionHandler:nil];
沒有留言:
張貼留言