我有一个 iOS iPad 应用程序,它显示一个用户可以选择打印的 web 视图。虽然显示的内容只有一页,但在第一页之后打印垃圾页,这是浪费碳粉。我只想打印第 1 页,但到目前为止,我能找到的唯一解决方案是使用确实不能解决我的问题的 showsPageRange = YES 选项。
谁能建议一个简单的方法来做到这一点?
用一个按钮测试这个你在视图中包含的所有内容都是打印
///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];