2011-10-04 21 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