-(void) Printdata
{
Prepare for printing, create a reference to Sharedprintcontroller
Uiprintinteractioncontroller *printer = [Uiprintinteractioncontroller Sharedprintcontroller];
Printer.delegate = self;
Configure printing information
Uiprintinfo *pinfo = [Uiprintinfo printinfo];
Pinfo.outputtype = uiprintinfooutputgeneral;//printable text, graphics, images
Pinfo.jobname = @ "Print for Xiaodui";//optional attribute for identifying print jobs in the print center
Pinfo.duplex = uiprintinfoduplexlongedge;//Double-sided printing around the long side of the page, none to prohibit double-sided
Pinfo.orientation = uiprintinfoorientationportrait;//Print portrait or landscape
Pinfo.printerid = @ "";//Specify the default printer, or you can use Uiprintinteractioncontrollerdelegate to know
Printer.printinfo = Pinfo;
Set Page Range
Uisimpletextprintformatter *textformatter = [[Uisimpletextprintformatter alloc] initwithtext:@ "aha hand cream on time haha"];
Textformatter.startpage = 0;//Specifies from which one to start printing 0 for the first one
Textformatter.contentinsets = Uiedgeinsetsmake (36, 36, 36, 36),//72 equals 1 inches, so the margin between the upper and lower left is 0.5 inches
Textformatter.maximumcontentwidth = 504;//(72x7.5) is equivalent to a print width of 7 inches
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 Printing