使用AirPrint打印UIImage会导致截断内容 [英] Printing UIImage using AirPrint causes cut-off content

查看:219
本文介绍了使用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 ;& error){
UIAlertView * av = [[UIAlertView alloc] initWithTitle:@Error。
message:[NSString stringWithFormat:@打印时出错:%@,错误]
委托:nil
cancelButtonTitle:@OK
otherButtonTitles:nil,nil ];

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

[pic presentAnimated:YES completionHandler:completionHandler];


解决方案

打印的图像的比例,这样你可以看到页面上的整个事情。



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

  #importANImageBitmapRep.h

然后,按如下比例缩放图片:

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

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


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

解决方案

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.

这篇关于使用AirPrint打印UIImage会导致截断内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆