3

我想打印 UIWebView。用户可以选择纵向或横向模式打印。但我不知道如何进行界面预览,因为我无法计算打印区域。请帮忙!

4

2 回答 2

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];

}

于 2013-10-05T08:25:54.057 回答
0

您可以只使用 UIView 的viewPrintFormatter属性。此属性允许您获取要打印的页面的可打印格式。

于 2012-02-24T10:29:12.517 回答