我有一个iOS iPad应用程序,显示webview,用户可以选择打印。虽然呈现的内容仅为一页,但是在第一页之后正在打印垃圾页,这是浪费墨粉。我想只打印第1页,但到目前为止,我能找到的唯一解决方案是使用showsPageRange = YES选项,这实际上无法解决我的问题。
有人可以建议一种简单的方法吗?
答案 0 :(得分:0)
使用按钮测试此项,您在视图中包含的所有内容都是打印
///PRINT///
UIGraphicsBeginImageContextWithOptions(self.ImagentoPrint.bounds.size, normal, 0.0);
[self.ImagentoPrint drawViewHierarchyInRect:self.ImagentoPrint.bounds
afterScreenUpdates:normal];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIPrintInfo *info = [UIPrintInfo printInfo];
info.orientation = UIPrintInfoOrientationLandscape;
info.outputType = UIPrintInfoOutputPhoto;
UIPrintInteractionController *pic =
[UIPrintInteractionController sharedPrintController];
pic.delegate = self;
pic.printingItem = snapshotImage;
pic.printInfo = info;
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
{
if (error)
NSLog(@"failed... %@ %ld", error.domain, (long)error.code);
if (completed)
NSLog(@"completed yes");
else
NSLog(@"completed no");
};
[pic presentFromRect:CGRectMake(600, 650, 100, 200) inView:_ImagentoPrint animated:YES completionHandler:completionHandler];