Printing photo from URL using UIPrintInteractionController clips parts of my photo

635 Views Asked by At

I'm trying to get a photo printed through UIPrintInteractionController. It should print as a 4x6, and it does, but it clips parts of the photo (not all of it, but something like half an inch on both directions). I'm printing directly from a URL, and the final pixel size of the image is 600 x 900 px.

Does Apple have a specific pixel size it expects for images to print as 4x6 perfectly? Does anyone know it? Am I doing something wrong?

Code:

NSURL *imageURL = [NSURL URLWithString:urlOfImage];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *imageToPrint = [[UIImage alloc] initWithData:data];

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];

if(!controller){
    NSLog(@"Couldn't get shared UIPrintInteractionController!");
    return;
}

    controller.delegate = self;

// We need a completion handler block for printing.
UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    if(completed && error)
        NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);

};

// Obtain a printInfo so that we can set our printing defaults.
UIPrintInfo *printInfo = [UIPrintInfo printInfo];

// This application prints photos. UIKit will pick a paper size and print
// quality appropriate for this content type.
printInfo.outputType = UIPrintInfoOutputPhoto;
// The path to the image may or may not be a good name for our print job
// but that's all we've got.
printInfo.jobName = [[imageURL path] lastPathComponent];

if(!controller.printingItem && imageToPrint.size.width > imageToPrint.size.height)
    printInfo.orientation = UIPrintInfoOrientationLandscape;

controller.printInfo = printInfo;

controller.printingItem = nil;

if(imageURL && [UIPrintInteractionController canPrintURL:imageURL])
    controller.printingItem = imageURL;

 if(!controller.printingItem)
 {
     PrintPhotoPageRenderer *pageRenderer = [[PrintPhotoPageRenderer alloc]init];
     // The PrintPhotoPageRenderer subclass needs the image to draw. If we were taking
     // this path we use the original image and not the fullScreenImage we obtained from
     // the ALAssetRepresentation.
     pageRenderer.imageToPrint = imageToPrint;
     controller.printPageRenderer = pageRenderer;
 }

[controller presentAnimated:YES completionHandler:completionHandler];

The PrintPhotoRenderer is taken directly from Apple's PrintPhoto code.

Any tips or ideas would be greatly appreciated!

0

There are 0 best solutions below