Big*_*uce 4 printing objective-c uiimage ios
我想让我的用户选择以4x6和5x7打印他们的照片.以4x6"打印UIImage很容易,因为我所要做的就是
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
UIPrintInteractionController *printInteractionController = [UIPrintInteractionController sharedPrintController];
printInteractionController.printInfo = printInfo;
printInteractionController.printingItem = self.myImage;
Run Code Online (Sandbox Code Playgroud)
但是,我需要以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;
}
Run Code Online (Sandbox Code Playgroud)
不要忘记符合.h文件中的委托:
@interface yourViewController : UIViewController <UIPrintInteractionControllerDelegate>
Run Code Online (Sandbox Code Playgroud)
当您按下AirPrint上的"打印"按钮时,您将获得打印机支持的确切纸张尺寸列表.测试它并查看可用的数字.
然后,将CGSize pageSize更改为其中一个记录值.当最终的NSLog"iOS表示最佳纸张尺寸"现在为您提供所选的点尺寸而不是4x6,Letter尺寸或其他您不想要的尺寸时,您将知道它是否有效.
您需要使用纸质列表中的大小的原因是UIPrintPaper bestPaperForPageSize方法似乎不像它的名字所暗示的那样.人们会认为,基于它的名称,它会处理一个密切的输入,并尝试找到类似的东西.但是,只有从支持的纸张尺寸列表中明确匹配时,它才会返回正确的纸张尺寸.
我的问题是,无论我认为什么样的尺寸可以用于5x7,它总是会选择Letter.实际的点大小因地区和打印机而异.
只有在从纸质列表中输入匹配的数字后,我才能在5x7上打印PDF.
祝好运!
| 归档时间: |
|
| 查看次数: |
1741 次 |
| 最近记录: |