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 ...
随机推荐
- pxc群集搭建
pxc群集搭建 1.环境 Percona-XtraDB 5.7.22-22-29.26-log percona-xtrabackup-24-2.4.12 192.168.99.210:3101(第一节 ...
- glob模块的使用
glob模块 功能描述:glob模块可以使用Unix shell风格的通配符匹配符合特定格式的文件和文件夹,跟windows的文件搜索功能差不多.glob模块并非调用一个子shell实现搜索功能,而是 ...
- dockerfile实例--安装nginx
[root@localhost ~]# vi Dockerfile //ADD FROM centos_with_net MAINTAINER frankie onez0714@.com RUN yu ...
- 虚拟机安装苹果系统 VMware 12安装Mac OS X 10.10
工具/原料 VMware Workstation Pro 12 (这个可以自己下载,并激活,你懂得) Unlocker 207 (链接:http://pan.baidu.com/s/1i43obDb ...
- elasticsearch索引加别名
curl -XPOST 'http://localhost:9200/_aliases' -d ' { "actions": [ {&qu ...
- 【python】pip的使用
来源:http://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/ pip是用来安装python相关的包的.使用参数如下: # pip - ...
- 360杀毒导致的 VS 报扩展错误,请查看 ActiveLog.xml
360杀毒将 TypeScript的 tsserver.js 列为木马,结果导致VS2017启动时,总是报错,将其加为信任即可解决.
- lvm笔记
安装LVMyum -y install lvm* 创建PV# pvcreate /dev/md5 /dev/sdf1 /dev/sdg 查看PV# pvdisplay 还可以使用命令pvs 和pvsc ...
- 将xml文件转为c#对像
读取xml文件数据,通过序列化反序列化转为List<T>对象后,对对象进行操作.
- DaemonSet
What is a DaemonSet? DaemonSet能够让所有(或者一些特定)的Node节点运行同一个pod.当节点加入到kubernetes集群中,pod会被(DaemonSet)调度到该节 ...