Printing UIImage using AirPrint causes cut-off content
Asked Answered
J

1

6

I am printing out a UIImage using AirPrint but the margins aren't correct. This is what it looks like when it prints:
Photo of printout

Is there a way I can make it fit perfectly on the paper?

Here's the code as requested:

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    //pic.delegate = del;

    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = [NSString stringWithFormat:@"New Ticket"];
    pic.printInfo = printInfo;


    pic.printingItem = [UIImage imageWithContentsOfFile:path];

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if (!completed && error) {
            UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error." 
                                                   message:[NSString stringWithFormat:@"An error occured while printing: %@", error]
                                                  delegate:nil 
                                         cancelButtonTitle:@"OK" 
                                         otherButtonTitles:nil, nil];

            [av show];
            [av release];
        }
    };

    [pic presentAnimated:YES completionHandler:completionHandler];
Jozef answered 4/10, 2011 at 17:59 Comment(2)
You probably need to show us your code.Applicant
If you are printing a UIImage, why aren't you setting printInfo.outputType to UIPrintInfoOutputPhoto instead of UIPrintInfoOutputGeneral?Insignificance
A
0

Your best bet is probably to scale the image down to the ratio of the printed image, that way you can see the whole thing on the page.

There are several ways of doing this, so I will just tell you the way that I would do it. I maintain a class called ANImageBitmapRep that has several different types of image scaling. The kind of scaling that you want keeps the entire image, but centers it inside of a rectangle of a certain size. First, you must add the ANImageBitmapRep source files to your project, and #import ANImageBitmapRep.h:

#import "ANImageBitmapRep.h"

Then, scale the image like this:

pic.printingItem = [[UIImage imageWithContentsOfFile:path] imageFittingFrame:CGSizeMake(478, 640)];

You can change the CGSizeMake(x, y) to whatever you want, in order to adjust the scale and resolution of the scaled image.

Agathaagathe answered 14/10, 2011 at 23:3 Comment(2)
Hi i sort of have the same problem. #11578513Hawley
just to add if OxSina had problems regarding the content being too big i think mine should be imageFillingFrame but i have a question if i would depend on the image.size.height the height of the printed outcome will be small and not enough to cover long content. any ideas? thanksHawley

© 2022 - 2024 — McMap. All rights reserved.