ios - 如何在打印输出中以 5x7"打印 UIImage?

标签 ios objective-c printing uiimage

我想让我的用户选择以 4x6 和 5x7 打印他们的照片。以 4x6"打印 UIImage 很容易,因为我所要做的就是

UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;

UIPrintInteractionController *printInteractionController = [UIPrintInteractionController sharedPrintController];

printInteractionController.printInfo = printInfo;
printInteractionController.printingItem = self.myImage;

但是,我还需要以 5x7 的分辨率打印我的 UIImage。关于如何做到这一点的任何想法?请提供代码示例。

谢谢!

最佳答案

首先,实现这个方法:

- (UIPrintPaper *) printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList {

// This will give us all the available paper sizes from the printer
for(int i = 0; i < paperList.count; i++) {
    UIPrintPaper* paper = [paperList objectAtIndex:i];
    NSLog(@"List paper size %f,%f",paper.paperSize.width, paper.paperSize.height);
}

// You're going to use precise numbers from the NSLog list here
CGSize pageSize = CGSizeMake(360, 504);

// Give our CGSize to the bestPaperForPageSzie method to try to get the right paper
UIPrintPaper* paper = [UIPrintPaper bestPaperForPageSize:pageSize withPapersFromArray:paperList];

// See if we got the right paper size back
NSLog(@"iOS says best paper size is %f,%f",paper.paperSize.width, paper.paperSize.height);
return paper;
}

不要忘记遵守 .h 文件中的委托(delegate):

@interface yourViewController : UIViewController <UIPrintInteractionControllerDelegate>

当您按下 AirPrint 上的“打印”按钮时,您将获得打印机支持的确切纸张尺寸的列表。对其进行测试,看看有哪些数字可用。

然后,将 CGSize pageSize 更改为记录的值之一。当最终的 NSLog“iOS 表示最佳纸张尺寸是”现在为您提供您选择的磅值而不是 4x6、Letter 尺寸或您不想要的其他尺寸时,您就会知道它是否有效。

您需要使用纸张列表中的尺寸的原因是 UIPrintPaper bestPaperForPageSize 方法似乎并不像其名称所暗示的那样。人们会认为,根据它的名字,它会处理一个关闭的输入并尝试找到类似的东西。但是,只有当您从支持的纸张尺寸列表中明确匹配它时,它才会返回正确的纸张尺寸。

我的问题是,无论我认为哪种磅值适用于 5x7,它似乎总是选择字母。实际磅值因地区和打印机而异。

只有从纸张列表中输入匹配的数字后,我才能在 5x7 上打印我的 PDF。

祝你好运!

关于ios - 如何在打印输出中以 5x7"打印 UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16995722/

相关文章:

java - Android热敏打印机阿拉伯语问题

c - 在 C 中打印不同格式的文件时需要帮助吗?

ios - 如何解决应用程序验证 "The app references non-public selectors in Payload/MyApp.app/MyApp: _setAlwaysRunsAtForegroundPriority:"?

iphone - 为什么 revmob 广告闪烁?

ios - 新的 iOS 10 Today Widget/Extension 的高度是多少?

objective-c - 如何确保我的计时器运行没有竞赛

ios - 当手机进入休眠状态时,Flutter 热重载停止工作

ios - 我怎样才能取消-[UIScrollView zoomToRect :animated:]?

ios - AutoLayout + heightForRowAtIndexPath/sizeWithFont 无法正常工作

delphi - 如何使用TPrinter的本地实例