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 ...
随机推荐
- 获取并编译最新的Notepad++源码
获取并编译最新的Notepad++源码 http://blog.csdn.net/u012814856/article/details/68947310 Notepad++源码编译及其分析 http: ...
- python string 对齐文本的几个方法
用rjust().ljust()和center()方法对齐文本
- C基础入门 - 第一章 - C语言绪言
第1章 C语言绪言 1.1 C语言概述 1.1.1 C语言世界 1.1.2 C语言学习, 能当饭吃吗 1.2 开发环境构建 1.2.1 visual studio安装使用 1.2.2 visual s ...
- 使用Storm实现实时大数据分析(转)
原文链接:http://blog.csdn.net/hguisu/article/details/8454368 简单和明了,Storm让大数据分析变得轻松加愉快. 当今世界,公司的日常运营经常会生成 ...
- 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到Ubuntu 16.04
.Net Core 部署到Ubuntu 16.04 中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务 ...
- java获取项目路径,url路径
我的web项目名iamgeModel. 工作空间在D盘 先获取url相关: 需要是HttpServletRequest request; 获取IP: request.getServerName() / ...
- numpy及scipy的使用
numpy的使用 把list A转换为numpy 矩阵 np.array(A) np.array(A, 'int32') numpy加载txt文件里面的矩阵 matrix = np.loadtxt(t ...
- HTTP协议——请求与响应
摘要:1.HTTPHTTP:HyperTextTransferProtocol,超文本传输协议的缩写,是本地浏览器和服务器之间进行通信的传送协议.基于TCP/IP协议来传送数据,如HTML文件,图片等 ...
- [BZOJ4456] [Zjoi2016]旅行者 分治+最短路
4456: [Zjoi2016]旅行者 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 777 Solved: 439[Submit][Status] ...
- AC日记——「SCOI2016」美味 LiBreOJ 2016
#2016. 「SCOI2016」美味 思路: 主席树: 代码: #include <bits/stdc++.h> using namespace std; #define maxa 26 ...