使用AirPrint打印UIImage会导致截止内容

时间:2011-10-04 17:59:18

标签: objective-c ios cocoa-touch airprint

我正在使用AirPrint打印UIImage,但边距不正确。这就是打印时的样子:
Photo of printout

有没有办法让它完美贴合纸张?

以下是所要求的代码:

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

1 个答案:

答案 0 :(得分:0)

您最好的选择可能是将图像缩小到打印图像的比例,这样您就可以在页面上看到整个图像。

有几种方法可以做到这一点,所以我会告诉你我会这样做的方式。我维护了一个名为ANImageBitmapRep的类,它有几种不同类型的图像缩放。您想要的缩放类型会保留整个图像,但会将其置于特定大小的矩形内部。首先,您必须将ANImageBitmapRep源文件添加到项目中,并且#import ANImageBitmapRep.h

#import "ANImageBitmapRep.h"

然后,像这样缩放图像:

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

您可以将CGSizeMake(x, y)更改为您想要的任何内容,以便调整缩放图像的比例和分辨率。

相关问题