2012-02-27 21 views
1

私はあなたの助けが必要です。私はリンゴの印刷に関するドキュメントを読んだが、私はスクロールビューのすべての内容を印刷する方法を理解するのが難しい。私は、プリンタは、誰かが実際の印刷ジョブのためのコードを提供することができれば、私は非常に感謝するでしょうiPhone:スクロール表示のすべての内容を印刷

//-----------Check for printer------------------- 
if ([UIPrintInteractionController isPrintingAvailable]) { 
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction 
                       target:self 
                       action:@selector(printWebView:)]; 

    [self.navigationItem setLeftBarButtonItem:barButton animated:NO]; 
    self.printButton = barButton; 
} 

利用可能であるかどうかを確認するために、これまで知っています。 ありがとうございます...

+0

Scrollviewの内側に何を印刷するには?内容を動的に更新していますか? – Prajoth

+0

スクロールビューの内側には、テキストフィールドと、それらのテキストフィールドからの数学的結果を保持するラベルがあります。 –

答えて

1

UIImage(スクリーンショット、並べ替え)を作成し、結果のイメージを印刷することを検討しましたか?私は印刷について知らないが、私はスクリーンショットを手伝うことができる。スクロールビューが画面に収まらない場合は、次のコードを変更してより大きな範囲にする必要があります。私はチュートリアルからこのコードを持って:

は注意

ダミアン

- (UIImage*)screenshot { 
// Create a graphics context with the target size 
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration 
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext 
CGSize imageSize = [[UIScreen mainScreen] bounds].size; 
if (NULL != UIGraphicsBeginImageContextWithOptions) 
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); 
else 
    UIGraphicsBeginImageContext(imageSize); 

CGContextRef context = UIGraphicsGetCurrentContext(); 

// Iterate over every window from back to front 
for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{ 
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) 
    { 
     // -renderInContext: renders in the coordinate space of the layer, 
     // so we must first apply the layer's geometry to the graphics context 
     CGContextSaveGState(context); 
     // Center the context around the window's anchor point 
     CGContextTranslateCTM(context, [window center].x, [window center].y); 
     // Apply the window's transform about the anchor point 
     CGContextConcatCTM(context, [window transform]); 
     // Offset by the portion of the bounds left of and above the anchor point 
     CGContextTranslateCTM(context, 
           -[window bounds].size.width * [[window layer] anchorPoint].x, 
           -[window bounds].size.height * [[window layer] anchorPoint].y); 

     // Render the layer hierarchy to the current context 
     [[window layer] renderInContext:context]; 

     // Restore the context 
     CGContextRestoreGState(context); 
    } 
} 

// Retrieve the screenshot image 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

return image; 
} 

、お楽しみください。それは動作します(私は出荷されたコードで)が、私はすべての行を理解していない。

+0

私はすでにスクリーンショットを撮る方法を知っていますが、スクリーンショットの印刷方法はわかりません!あなたの時間をありがとう! –

2

スクリーンショットを取得し、

/*グラブのスクリーンショットおよび印刷*/

-(void)printItem { 

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 


UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController]; 

if(printController) { 

    printController.delegate = self; 

    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
    printInfo.outputType = UIPrintInfoOutputGeneral; 
    printInfo.jobName = @"resultado"; 
    printInfo.duplex = UIPrintInfoDuplexLongEdge; 
    printController.printInfo = printInfo; 
    printController.showsPageRange = YES; 
    printController.printingItem = newImage; 

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { 
     if (!completed && error) { 
      NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code); 
     } 
    }; 

    [printController presentAnimated:YES completionHandler:completionHandler]; 

} 
} 
関連する問題