2011-10-04 67 views
6

我使用AirPrint打印出UIImage,但边距不正确。这是它打印时的样子:
Photo of printout使用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]; 
+0

您可能需要向我们显示您的代码。用代码更新了 –

+0

。 – 0xSina

+0

如果您正在打印'UIImage',为什么不将'printInfo.outputType'设置为'UIPrintInfoOutputPhoto'而不是'UIPrintInfoOutputGeneral'? –

回答

0

您最好的选择可能是按比例缩小图片打印图像的比例,这样你可以在网页上看到了整个事情。

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

#import "ANImageBitmapRep.h" 

然后,扩展这样的形象:

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

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

+0

嗨,我有点问题。 http://stackoverflow.com/questions/11578013/printing-uiimage-using-epos-sdk – jongbanaag

+0

只是添加如果OxSina有关于内容太大的问题,我认为我应该imageFillingFrame,但我有一个问题,如果我会依赖在image.size.height上,打印结果的高度会很小,不足以覆盖较长的内容。有任何想法吗?谢谢 – jongbanaag