Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从imageview打印图像:xcode_Iphone_Objective C_Xcode_Uiimageview_Airprint - Fatal编程技术网

Iphone 从imageview打印图像:xcode

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" 现

有人能告诉我如何使用UIPrintInteractionController从imageview打印图像吗。
谢谢

将图像转换为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];
}

生活和学习如何编程主要是自助式的: