当我尝试打印当前屏幕截图(对于iPad视图)时,我在控制台窗口中看到这个奇怪的错误: failed to find PDF header: %PDF not found
。控制台错误:无法找到PDF标头:'%PDF'找不到
我想知道为什么在控制台窗口中触发这个错误?为什么它提到了与PDF
相关的内容,尽管我在整个项目中没有使用任何PDF
相关的东西。
代码即时通讯使用打印截图:
- (IBAction)print:(id)sender {
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//saving the file to documents directory
NSData * imageData = UIImagePNGRepresentation(viewImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.png"];
[imageData writeToFile:documentsDirectory atomically:YES];
NSString *myFilePath = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.png"];
UIImage *screenShot = [UIImage imageWithData:imageData];
NSData *myData = [NSData dataWithData:UIImagePNGRepresentation(screenShot)];
self.pic = [UIPrintInteractionController sharedPrintController];
if (self.pic && [UIPrintInteractionController canPrintData:myData]) {
self.pic.delegate = self;
//filling up print info
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [myFilePath lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
self.pic.printInfo = printInfo;
self.pic.showsPageRange = YES;
self.pic.printingItem = myData;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error)
NSLog(@"FAILED! due to error in domain %@ with error code %u",
error.domain, error.code);
};
[self.pic presentFromRect:self.printButton.frame inView:self.view animated:YES completionHandler: completionHandler]; // iPad
}
}
文件路径(Screenshot.png)是正确的,它是正确保存到文档目录。
这是触发该错误的行:[self.pic presentFromRect:self.printButton.frame inView:self.view animated:YES completionHandler:completionHandler]; – JAHelia 2012-04-08 08:13:27
猜猜我猜错了!但是OS X和iOS打印系统通常基于PDF。也许印刷管道中的其他事情正在做类似的检查。 – 2012-04-08 08:18:09
那么,这个错误会在打印过程中引起问题吗?我无法测试打印过程,'因为我没有支持AirPlay的打印机。 – JAHelia 2012-04-08 08:24:51