1. 程式人生 > >iOS UIPrintInteractionController打印

iOS UIPrintInteractionController打印

hand and tput ani star elf items share null

- (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;

// 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");

}

}];

}

iOS UIPrintInteractionController打印