i am very new to iOS programming and encountered a issue. I have a pdf i want to print off the internet. How do i print this through my app without a third-party app? Also, i have heard about apple's AirPrint, and that it is pre-installed on the iOS device. How would i use that? Thanks.
Asked
Active
Viewed 1,361 times
1 Answers
3
.H File Code
#import
@interface xyviewController : UIViewController <...,UIPrintInteractionControllerDelegate> {
UIPrintInteractionControllerDelegate should be delegate
}
-(IBAction)printdoc;
.M File Code
-(IBAction)printdoc
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"jpg"];
NSData *myData = [NSData dataWithContentsOfFile: path];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
if(pic && [UIPrintInteractionController canPrintData: myData] ) {
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = myData;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
//self.content = nil;
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
}
}

iProgrammed
- 980
- 2
- 10
- 29
-
thanks! hey..also, how would i print this pdf? Also, when i display it in a webview, why is it not scaled? http://laurelchristian.org/wp-content/uploads/2013/01/Lunch-Menu-February-2013.jpg – Hunter Mitchell Jan 24 '13 at 02:24