使用 AirPrint 打印 UIImage 导致内容被截断
我正在使用 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];
I am printing out a UIImage
using AirPrint but the margins aren't correct. This is what it looks like when it prints:
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的选择可能是将图像缩小到打印图像的比例,这样您就可以看到页面上的整个内容。
有多种方法可以做到这一点,所以我只告诉你我会这样做的方法。我维护一个名为 ANImageBitmapRep 的类,它具有几种不同类型的图像缩放。您想要的缩放类型会保留整个图像,但将其置于特定大小的矩形内部的中心。首先,您必须将 ANImageBitmapRep 源文件添加到您的项目中,并 #import ANImageBitmapRep.h:
然后,像这样缩放图像:
您可以更改
CGSizeMake(x, y) code> 为您想要的任何内容,以调整缩放图像的比例和分辨率。
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:
Then, scale the image like this:
You can change the
CGSizeMake(x, y)
to whatever you want, in order to adjust the scale and resolution of the scaled image.