iOS UIPrintInteractionController打印
- (void)printData{ //为打印做准备,创建一个指向sharedPrintController的引用
UIPrintInteractionController *printer = [UIPrintInteractionController sharedPrintController];
printer.delegate = self; //配置打印信息
UIPrintInfo *Pinfo = [UIPrintInfo printInfo];
Pinfo.outputType = UIPrintInfoOutputGeneral;//可打印文本、图形、图像
Pinfo.jobName = @"Print for xiaodui";//可选属性,用于在打印中心中标识打印作业
Pinfo.duplex = UIPrintInfoDuplexLongEdge;//双面打印绕长边翻页,NONE为禁止双面
Pinfo.orientation = UIPrintInfoOrientationPortrait;//打印纵向还是横向 // Pinfo.printerID = @"";//指定默认打印机,也可以使用UIPrintInteractionControllerDelegate来知悉
printer.printInfo = Pinfo; //设置页面范围 打印文字
// UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:@"哈护手霜按时哈哈"]; // textFormatter.startPage = 0;//指定从哪一张开始打印0代表第一张 // textFormatter.contentInsets = UIEdgeInsetsMake(36, 36, 36, 36);//72相当于1英寸,这样设置上下左右的边距都为0.5英寸 // textFormatter.maximumContentWidth = 504;//(72x7.5)相当于打印宽度为7英寸 // printer.printFormatter = textFormatter;
/*
- AirPrint可以直接打印一些内容。 这些内容是 NSData, NSURL, UIImage, and ALAsset 类的实例, 但是这些实例的内容, 或者引用的类型(NSURL)必须是 image 或者pdf.
- 对于 image来说, NSData, NSURL, UIImage, and ALAsset 类型都可以的。 对于PDF, 只能使用 NSData, NSURL。 然后需要将这些数据实例直接赋值 给 UIPrintInteractionController实例的 printingItem 或者 printingItems 属性。
*/
// printer.printingItem = [UIImage imageNamed:@"LaunchImage"];
printer.printingItems = @[[UIImage imageNamed:@"welcome_page2"], [UIImage imageNamed:@"LaunchImage"], [UIImage imageNamed:@"welcome_page1"],]; printer.showsPageRange = NO; [printer presentAnimated:YES completionHandler:^(UIPrintInteractionController * _Nonnull printInteractionController, BOOL completed, NSError * _Nullable error) { if (!completed && error) {
NSLog(@"Error");
}
}]; }
打印webView视图
初始化webView
- (UIWebView *)printWebView
{
if (!_printWebView) { _printWebView = [[UIWebView alloc] initWithFrame:CGRectMake(, , Main_Screen_Width, Main_Screen_Height)]; _printWebView.backgroundColor = HexRGB(0xf9f9f9); _printWebView.delegate = self; _printWebView.scalesPageToFit = YES;
}
return _printWebView;
}
加载视图
NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [self.printWebView loadRequest:request];
在加载完成中调用打印方法
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[self printWebViewPage];
} - (void)printWebViewPage{ UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { if(error){
NSLog(@"FAILED! due to error in domain %@ with error code %ld-- %@", error.domain, (long)error.code, completionHandler);
}
}; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = @"Print for xiaodui";; printInfo.duplex = UIPrintInfoDuplexLongEdge; controller.printInfo = printInfo; controller.showsPageRange = YES; UIViewPrintFormatter *viewFormatter = [self.printWebView viewPrintFormatter]; viewFormatter.startPage = ; controller.printFormatter = viewFormatter; [controller presentAnimated:YES completionHandler:^(UIPrintInteractionController * _Nonnull printInteractionController, BOOL completed, NSError * _Nullable error) {
if (!completed && error) {
NSLog(@"Error");
}
}];
}
如图:
iOS UIPrintInteractionController打印的更多相关文章
- iOS——关于打印控件
20.UIPrintFormatterUIPrintFormatter时打印格式化的抽象基类:展示了传统的可打印的内容对象可以跨页边界.由于打印格式化,打印系统,可以自动打印与打印格式化的内容相关联的 ...
- iOS UIPrintInteractionController在iPad的 iOS10 和 11上的奇怪bug
今天在弹出UIPrintInteractionController的时候,在ios10 和11的ipad 上测试,发现一直是protrait 方向弹出,结果就出现如下图的bug: 研究了好长时间,发现 ...
- iOS AFNetworking 打印从服务器返回的错误提示信息
每次做项目的时候都会在网络请求时候测试接口的时候会出现一些不同的错误,而控制台打印的错误提示信息都是data类型,看不出提示的错误的信息是什么.后面经过一些查阅发现其实是可以把这个转变为string的 ...
- iOS中打印系统详细日志
Q:如何打印当前的函数和行号? A:我们可以在打印时使用一些预编译宏作为打印参数,来打印当前的函数和行号.如: 1 NSLog(@"%s:%d obj=%@", __func__, ...
- ios runtime 打印内 内部调用的属性
unsigned int count = 0; // 拷贝出所有的成员变量列表 Ivar *ivars = class_copyIvarList([UITextField class], &c ...
- iOS - OC - 打印信息 - xcode 中文打印
#import <Foundation/Foundation.h> @implementation NSDictionary (Log) //重写系统的方法控制输出 -(NSString ...
- iOS字体打印
//打印所以字体 NSArray *familyNames = [UIFont familyNames]; for(NSString *familyName in familyNames) ...
- iOS 控制台打印unicode 转中文汉字 UTF8String
今天查看代码数据结构,就在控台直接打印了,soGa,我看到了什么!!!! 于是乎想到了不对劲,不对呀,之前打印都是 UTF8String的呀,怎么会这样,百思不得其姐,看了一下封装的网络类,SoGa, ...
- ios nslog 打印字典为中文
#import <Foundation/Foundation.h> @implementation NSDictionary (Log) - (NSString *)description ...
随机推荐
- supervisor 简单使用
supervisor是一个c/s系统,被用来在类Unix系统中监控进程状态.supervisor使用python开发. 服务端进程为supervisord,主要负责启动自身及其监控的子进程,响应客户端 ...
- Vue组件-组件的属性
在html中使用元素,会有一些属性,如class,id,还可以绑定事件,自定义组件也是可以的.当在一个组件中,使用了其他自定义组件时,就会利用子组件的属性和事件来和父组件进行数据交流. 比如,子组件需 ...
- appium===登陆应用的案例
import time import os from appium import webdriver from selenium.webdriver.support.ui import WebDriv ...
- ==和equals()方法的区别
==和equals()方法的区别 这是一道经典的面试题,但是很多人对其一直很困惑,最近刚好复习了他们两者的区别,现总结如下: 一.==:两端可以存放不同的数据 1.放基本数据类型:根据基本数据 ...
- printf格式化输出
基本格式 printf [format] [文本1] [文本2] .. 常用格式替换符 %s 字符串 %f 浮点格式 %c ASCII字符,即显示对应参数的第一个字符 %d,%i 十进制整数 %o 八 ...
- 使用Storm实现实时大数据分析(转)
原文链接:http://blog.csdn.net/hguisu/article/details/8454368 简单和明了,Storm让大数据分析变得轻松加愉快. 当今世界,公司的日常运营经常会生成 ...
- FineReport——发送邮件
在FR中,个用户之间可以通过邮件的形式进行通信,但是存在一个问题就是FineReport平台只能设置一个发件人账户,收件人账户可以有多个. 所以在实际的系统开发中可能需要自己开发信息交互的模块. 在系 ...
- java中的Map集合
Map接口 Map为一个接口.实现Map接口的类都有一个特点:有键值对,将键映射到值的对象. Map不能包含重复的键,每个键可以映射到最多一个值. Map常见的接口方法有: V put(K key, ...
- 四十一 常用内建模块 datetime
datetime是Python处理日期和时间的标准库. 获取当前日期和时间 我们先看如何获取当前日期和时间: >>> from datetime import datetime &g ...
- How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6
About Lemp LEMP stack is a group of open source software to get web servers up and running. The acro ...