2012-02-24 127 views
2

我想打印UIWebView。用戶可以選擇以縱向或橫向模式打印。但我不知道如何進行界面預覽,因爲我無法計算打印區域。請幫忙!如何預覽UIWebview打印?

回答

0

您可以使用UIView的viewPrintFormatter屬性。 該屬性允許您獲取要打印的頁面的可打印格式。

+0

是我設置:_printController.printFormatter = [_webView viewPrintFormatter]但之後,我得到的所有屬性UIPrintFormatter對象不能用於我的目標。 – 9891541 2012-02-24 10:40:32

+0

「不能用於我的目標」是什麼意思?如果你發佈一些代碼,也許,更容易理解你的問題是什麼。 – Mat 2012-02-24 11:05:01

1

你可以這樣做

-(void)printWebView{ 
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; 
UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
printInfo.outputType = UIPrintInfoOutputGeneral; 
pic.printInfo = printInfo; 
pic.printFormatter = [webView viewPrintFormatter]; 
pic.showsPageRange = YES; 
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = 
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) 
{ 
    if (!completed && error) 
    { 
     NSLog(@"Printing could not complete because of error: %@", error); 
    } 
}; 
[pic presentAnimated:YES completionHandler:completionHandler]; 

}