使用 AirPrint 打印 UIImage 导致内容被截断

发布于 2024-12-08 10:26:20 字数 1339 浏览 1 评论 0原文

我正在使用 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:
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];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2024-12-15 10:26:20

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

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

#import "ANImageBitmapRep.h"

然后,像这样缩放图像:

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

您可以更改 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:

#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文