FWIW here's complete working code to print a bitmap from any UIView from iPad/iPhone
NOTE, THIS ONLY PRINTS A BITMAP.
Note that (bizarrely) iOS seems to NOT INCLUDE the concept of rendering a UIView to postscript .. Print a UIView, but NOT by rendering as a bitmap image
In other words the following seems to be meaningless in iOS, as yet...
UIViewPrintFormatter *f = [self.view viewPrintFormatter];
Anyway the following will print (JUST AS A BITMAP) absolutely any UIView whatsoever...
You simply use renderInContext: or,
for more modern code,
the combination drawViewHierarchyInRect: and UIGraphicsGetImageFromCurrentImageContext()
- (IBAction)printB:(id)sender
{
// we want to print a normal view ... some UILabels, maybe a black line
// in this technique, depressingly we CREATE AN IMAGE of the view...
// step 1. make a UIImage, of the whole view.
UIGraphicsBeginImageContextWithOptions(self.printMe.bounds.size, NO, 0.0);
// [self.printMe.layer renderInContext:UIGraphicsGetCurrentContext()];
// UIImage *asAnImage = UIGraphicsGetImageFromCurrentImageContext();
// .... or, more futuristically.....
[self.printMe drawViewHierarchyInRect:self.printMe.bounds
afterScreenUpdates:NO];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// step 2. choose grayscale, etc
UIPrintInfo *info = [UIPrintInfo printInfo];
info.orientation = UIPrintInfoOrientationPortrait;
info.outputType = UIPrintInfoOutputGrayscale;
// step 3, print that UIImage
UIPrintInteractionController *pic =
[UIPrintInteractionController sharedPrintController];
pic.delegate = self;
//pic.printingItem = asAnImage;
pic.printingItem = snapshotImage;
pic.printInfo = info;
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
{
if (error)
NSLog(@"failed... %@ %ld", error.domain, (long)error.code);
if (completed)
NSLog(@"completed yes");
else
NSLog(@"completed no");
};
[pic presentAnimated:YES completionHandler:completionHandler];
}
It's really that simple, fortunately. But it is a rendered bitmap image.