我正在使用 AirPrint 打印出 UIImage
,但页边距不正确。这是打印时的样子:
有没有办法让它完美地贴合在纸上?
这是请求的代码:
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];
最佳答案
最好的办法可能是将图像按打印图像的比例缩小,这样您就可以在页面上看到整个内容。
有几种方法可以做到这一点,所以我只告诉你我会做的方法。我维护一个名为 ANImageBitmapRep 的类有几种不同类型的图像缩放。您想要的缩放比例保留整个图像,但将其居中放置在特定大小的矩形内。首先,您必须将 ANImageBitmapRep 源文件添加到您的项目中,然后#import ANImageBitmapRep.h:
#import "ANImageBitmapRep.h"
然后,像这样缩放图像:
pic.printingItem = [[UIImage imageWithContentsOfFile:path] imageFittingFrame:CGSizeMake(478, 640)];
您可以将 CGSizeMake(x, y)
更改为您想要的任何值,以调整缩放图像的比例和分辨率。
关于objective-c - 使用 AirPrint 打印 UIImage 导致内容被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7652082/