Когда я пытаюсь распечатать текущий скриншот (для iPad-вида), я получаю эту странную ошибку в окне консоли: failed to find PDF header: %PDF not found
.Ошибка консоли: не удалось найти PDF-заголовок: `% PDF 'не найден
Интересно, почему эта ошибка запускается в окне консоли? почему он упоминает что-то, связанное с PDF
, хотя я не использую никаких связанных с PDF
материалов во всем проекте.
Код Im используя для печати скриншоте:
- (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 completeHandler: completeHandler]; – JAHelia
Угадайте, я догадался, что неправильно! Но системы печати OS X и iOS обычно основаны на PDF. Возможно, что-то еще в конвейере печати выполняет аналогичную проверку. –
так, возникла бы эта ошибка в процессе печати? Я не могу протестировать процесс печати, потому что у меня нет принтера с поддержкой AirPlay. – JAHelia