美文网首页
iOS开发--Airprint

iOS开发--Airprint

作者: 酱油之神 | 来源:发表于2016-09-27 16:54 被阅读185次

Airprint是iOS系统自带的打印服务框架,利用她可以很简单系统打印服务,打印word,PDF,图片,也可以打印html网页。

Dome地址:https://github.com/wyhu/AirPrintDemo

// 打印
-(void)printActionsbutton:(id)sender{
//获取要打印的图片
UIImage * scanImage = [self scaleToSize:printImage size:CGSizeMake(595, 1660)];

UIImage *jietuImage = [self imageFromImage:scanImage inRect:CGRectMake(0, 0, 595, 880)];

UIPrintInteractionController *printC = [UIPrintInteractionController sharedPrintController];//显示出打印的用户界面。
    printC.delegate = self;

if (!printC) {
    NSLog(@"打印机不存在");
    
}


printC.showsNumberOfCopies = YES;
printC.showsPageRange = YES;


NSData *imgDate = UIImagePNGRepresentation(jietuImage);

NSData *data = [NSData dataWithData:imgDate];



NSString *pdf = [[NSBundle mainBundle] pathForResource:@"PDF使用指南.pdf" ofType:nil];

NSData *pdfData = [NSData dataWithContentsOfFile:pdf];


//        NSArray *arr = @[data,data];//打印多张图片


if (printC && [UIPrintInteractionController canPrintData:pdfData]) {
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];//准备打印信息以预设值初始化的对象。
    printInfo.outputType = UIPrintInfoOutputGeneral;//设置输出类型。
    printC.showsPageRange = YES;//显示的页面范围
    
    printInfo.jobName = @"my.job";
    
    printC.printInfo = printInfo;
    
    //设置打印源文件
    printC.printingItem = pdfData;//single NSData, NSURL, UIImage, ALAsset
        
    
    
    // 等待完成
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        
        if (!completed && error) {
            NSLog(@"可能无法完成,因为印刷错误: %@", error);
        }
        
        
        
        if (completed) {
            NSLog(@"完成了");
        }else{
            NSLog(@"出错了");

        }
            
    };
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:sender];//调用方法的时候,要注意参数的类型-下面presentFromBarButtonItem:的参数类型是 UIBarButtonItem..如果你是在系统的UIToolbar or UINavigationItem上放的一个打印button,就不需要转换了。
        
        
        [printC presentFromBarButtonItem:item animated:YES completionHandler:completionHandler];//在ipad上弹出打印那个页面
    } else {
        
        
        [printC presentAnimated:YES completionHandler:^(UIPrintInteractionController * _Nonnull printInteractionController, BOOL completed, NSError * _Nullable error) {
            
            
            
        }];
        
//            [printC presentAnimated:YES completionHandler:completionHandler];//在iPhone上弹出打印那个页面
        }

}
}

相关文章

  • iOS开发--Airprint

    Airprint是iOS系统自带的打印服务框架,利用她可以很简单系统打印服务,打印word,PDF,图片,也可以打...

  • iOS打印 AirPrint

    使用iOS AirPrint 让你的APP轻松实现打印功能 2016/05/13 · iOS开发 · 打印分享到:...

  • iOS打印 AirPrint

    使用iOS AirPrint 让你的APP轻松实现打印功能 1, 什么是AirPrint 其实就是将iOS(iph...

  • iOS AirPrint

    最近做了个小需求,为了以后查阅方便写下这篇文章 主要介绍ios通过wifi连接打印机,调用api打印 苹果内置了p...

  • iOS 后台无UI交互打印

    iOS airPrint有交互打印http://www.jianshu.com/p/f5863a1833d0 需求...

  • iOS 打印 AirPrint无线打印

    主要功能:使用iPhone、PC连接同一个WiFi,iPhone 上App有打印功能,点击打印,实现打印文档功能。...

  • iOS打印 AirPrint 及 普通打印机如何适配

    1.什么是AirPrint AirPrint是可以让应⽤用软件通过Apple的⽆无驱动程序打印体系结构,创建⽆无损...

  • AirPrint:iOS的打印机

    昨天看到安卓QQ有直接打印资料的功能,看了一下iOS的,没有看到,于是查了一下iOS打印的资料 原理 在iOS里边...

  • iOS 使用AirPrint实现无线打印功能

    无线打印打印流程 a.创建 UIPrintInteractionController 实例。 b.创建UIPrin...

  • iOS开发优秀博客和软件推荐

    iOSBlogAndTools iOS开发优秀博客和软件推荐 iOS开发中文博客 iOS开发工具 iOS开发网站 ...

网友评论

      本文标题:iOS开发--Airprint

      本文链接:https://www.haomeiwen.com/subject/ctacyttx.html