空气打印图像显示页面中不必要的行

时间:2016-06-05 07:36:37

标签: ios objective-c airprint

我试图用空气打印机打印图像。一切正常,除非它打印页面包含不必要的行

这是我的打印代码

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
    if(!controller){
        NSLog(@"Couldn't get shared UIPrintInteractionController!");
        return;
    }

    controller.delegate = self;
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputPhoto;
    printInfo.orientation = UIPrintInfoOrientationLandscape;
    printInfo.jobName = @"AirPrintSample";
    controller.printInfo = printInfo;


    UIImage *printImage = [self imageWithView:self.printView];
    controller.printingItem = printImage;

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {

        if(completed && error)
        {
            NSLog( @"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason );
        }
        else
        {
            if(completed)
            {
               // Did Some Other[enter image description here][1] Stuff
            }
        }
    };

    if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        [controller presentFromRect:self.view.frame inView:self.view animated:YES completionHandler:completionHandler];
    }
    else {
        [controller presentAnimated:YES completionHandler:completionHandler];
    }

以下是UIView到UIImage转换的代码

- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return img;
}

这是打印后的样子 我们可以看到有很多水平线。但我的标签需要一个简单的白色背景。我确信不会在图像上画这条线,打印预览也不会显示任何线条。如果有人可以提供帮助,请提前致谢。

打印机型号 - 兄弟ql-720nw

1 个答案:

答案 0 :(得分:0)

Okey我自己找到了答案。我用UIView的浅灰色背景颜色转换成图像。当我将背景颜色设为白色时,效果非常好。我猜这种打印机不能用其他颜色绘制完整的背景。如果有人使用这种类型的标签打印机(兄弟ql 720nw)的空气打印机,最好使用白色背景。