iosobjective-cairprint

Air printing image showing unnecessary lines in page


Im trying to print a image with air printer . Everything works fine except after it printed the page contains unnecessary line

Here is my code for printing

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

Here is the code for UIView to UIImage conversion

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

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return img;
}

Here how its look like after printing We can see there are lots of horizontal lines . But I needed a simple white background for my label. And i'm sure about not drawing this lines on the image and the print preview also don't show any lines . Thanks in Advance if anyone can help.

Printer Model - Brother ql-720nw


Solution

  • Okey i found the answer by myself . I used a light gray backgroud color for the UIView which i converted to image. When i made the background color white it works perfectly. I guess this type of printer cant draw a full background with other colors. If anyone use air printer with this type of label printer (brother ql 720nw) it will be better to use white background.