从iOS打印的分步教程?

时间:2012-01-24 18:30:48

标签: ios iphone objective-c cocoa-touch printing

是否有任何有关在iOS 5应用程序中启用打印的详细分步教程?我有一个应用程序,需要有一个基本模板(看起来像一张票),它充满了来自对象的信息,然后在本地打印机上打印出来。我已经在iOS开发者网站上阅读了基本的AirPrint项目,但是希望找到一个很好的教程,将它们放在一起。

3 个答案:

答案 0 :(得分:8)

答案 1 :(得分:0)

2011年WWDC会议108被称为" iOS打印系统"并详细介绍了在iOS中打印的所有方法,包括创建自定义UIPrintPageRenderer的演示,这很可能是您需要做的事情。

您可以从Apple开发者网站获取视频,示例代码和幻灯片:https://developer.apple.com/videos/wwdc/2011/?id=108

答案 2 :(得分:0)

要从iOS设备打印任何文件或图像,我们可以使用UIPrintInteractionController

UIPrintInteractionController *pc = [UIPrintInteractionController
                                    sharedPrintController];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.orientation = UIPrintInfoOrientationPortrait;
printInfo.jobName =@"Report";

pc.printInfo = printInfo;
pc.showsPageRange = YES;
pc.printingItem = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://test.com/Print_for_Client_Name.pdf"]];
// You can use here image or any data type to print.


UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed,
  NSError *error) {
    if(!completed && error){
        NSLog(@"Print failed - domain: %@ error code %ld", error.domain,
              (long)error.code);
    }
};


[pc presentFromRect:CGRectMake(0, 0, 300, 300) inView:self.view animated:YES completionHandler:completionHandler];