Iphone 从imageview打印图像:xcode
有人能告诉我如何使用UIPrintInteractionController从imageview打印图像吗。Iphone 从imageview打印图像:xcode,iphone,objective-c,xcode,uiimageview,airprint,Iphone,Objective C,Xcode,Uiimageview,Airprint,有人能告诉我如何使用UIPrintInteractionController从imageview打印图像吗。 谢谢将图像转换为pdf并打印pdf。首先阅读AirPrinter及其使用方法。点击链接: 您需要添加文件UYLGenericPrintPageRenderer.h和UYLGenericPrintPageRenderer.m 从这里获取: 这些是PrintPageRenderer文件 在类中导入此文件: #import "UYLGenericPrintPageRenderer.h" 现
谢谢将图像转换为pdf并打印pdf。首先阅读AirPrinter及其使用方法。点击链接: 您需要添加文件UYLGenericPrintPageRenderer.h和UYLGenericPrintPageRenderer.m 从这里获取: 这些是PrintPageRenderer文件 在类中导入此文件:
#import "UYLGenericPrintPageRenderer.h"
现在检查您的设备是否支持打印:
if ([UIPrintInteractionController isPrintingAvailable]) {
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(printImageView)];
[self.navigationItem setRightBarButtonItem:barButton animated:NO];
self.printButton = barButton;
[barButton release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Sorry, Printing is not available" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
现在将此处使用的printImageView图像打印为UIImageView类的对象
- (void)printImageView{
UIPrintInteractionController *pc = [UIPrintInteractionController sharedPrintController];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"Sample Print";
pc.printInfo = printInfo;
pc.showsPageRange = YES;
UYLGenericPrintPageRenderer *renderer = [[UYLGenericPrintPageRenderer alloc] init];
renderer.headerText = printInfo.jobName;
renderer.footerText = @"AirPrinter Sample";
UIViewPrintFormatter *formatter = [printImageView viewPrintFormatter];
[renderer addPrintFormatter:formatter startingAtPageAtIndex:0];
pc.printPageRenderer = renderer;
[renderer release];
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
DLog(@"Print failed - domain: %@ error code %u", error.domain, error.code);
}
};
[pc presentFromBarButtonItem:self.printButton animated:YES completionHandler:completionHandler];
}
生活和学习如何编程主要是自助式的: