2012-04-08 11 views
4

現在のスクリーンショット(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)が正しいか、そしてそれが正しくドキュメントディレクトリに保存されます。

答えて

2

これは、コンソール出力の原因となる行を正確に知るのに役立ちます。デバッガでそれを調べて見つけ出すことができます。

私の推測では、それは-[UIPrintInteractionController canPrintData:]の呼び出しです。 the documentation for that methodを読むと、そのデータにPDFが含まれているかどうかを確認する必要があります。試行錯誤して途中でメッセージを印刷するように見えます。

一般に、エンドユーザーはiOSコンソールを見ないので、これは非常に重要なバグではありません.Appleにとっては重要ではないようです。

+0

これはエラーを発生させる行です:[self.pic presentFromRect:self.printButton.frame inView:self.view animated:YES completionHandler:completionHandler]; – JAHelia

+0

私は間違っていると思います!しかし、OS XとiOSの印刷システムは、一般的にPDFに基づいています。おそらく、印刷パイプラインの何かが同様のチェックをしているかもしれません。 –

+0

そのエラーは印刷プロセスに問題を引き起こすでしょうか?私は印刷プロセスをテストすることはできません。 '私はAirPlayでサポートされているプリンタを持っていません。 – JAHelia

0

これも私に起こりました。私はすべての行を調べて、あなたがデータを印刷していることが原因であることを知りました。そして、イメージを直接印刷すると、この奇妙な警告が消えてしまいます。そのためUIPrintInteractionControllerフレームワークのAppleのファイルから:

@NSCopying public var printingItem: AnyObject? // single NSData, NSURL, UIImage, ALAsset 

printingItemは、上記の4種類のいずれかになります。私の推測では、AppleはデフォルトでデータをPDFデータとして扱いますが、これはUIImageから生成したデータのヘッダーデータではありません。

関連する問題