- (IBAction)printf:(UIButton *)sender {
UIPrintInteractionController *print = [UIPrintInteractionControllersharedPrintController];
print.delegate = self;
UIPrintInfo *printinfo = [UIPrintInfoprintInfo];
/**
* 包括文本,图形,图像
*/
printinfo.outputType = UIPrintInfoOutputGeneral;
printinfo.jobName = @"打印";
/**
* 双面打印的属性
*/
printinfo.duplex = UIPrintInfoDuplexLongEdge;
/**
* 配置UIPrintInfo对象
*/
print.printInfo = printinfo;
/**
* 可以让用户选择打印的页面
*/
print.showsPageRange = YES;
/**
* 创建UISimpleTextPrintFormatter对象,给他分配内存并使用要打印的文本来初始化它
*/
UISimpleTextPrintFormatter *textFormattter = [[UISimpleTextPrintFormatteralloc] initWithText:_textView.text];
/**
* 索引0 表示从第一页开始打印
*/
textFormattter.startPage = 0;
/**
* 设置内边距
*/
textFormattter.contentInsets = UIEdgeInsetsMake(25, 25, 25, 25);
/**
* 设置最大宽度
*/
textFormattter.maximumContentWidth = 520;
print.printFormatter = textFormattter;
void(^completionHandler)(UIPrintInteractionController * , BOOL, NSError *) =^(UIPrintInteractionController *print,BOOL completed,NSError *error)
{
if (!completed&&error){
NSLog(@"error!");
}
};
/**
* pad 上用次方法
*/
[print presentFromRect:sender.boundsinView:sender animated:YEScompletionHandler:completionHandler];
}