首先,实现这个方法:
- (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 文件中的委托:
@interface yourViewController : UIViewController <UIPrintInteractionControllerDelegate>
当您按下 AirPrint 上的“打印”按钮时,您将获得打印机支持的确切纸张尺寸列表。测试它并查看可用的数字。
然后,将 CGSize pageSize 更改为记录的值之一。当最终的 NSLog “iOS 说最好的纸张尺寸是”现在给你选择的磅值而不是 4x6、Letter 尺寸或其他你不想要的尺寸时,你就会知道它是否有效。
您需要使用纸张列表中的尺寸的原因是 UIPrintPaper bestPaperForPageSize 方法似乎并没有像它的名字所暗示的那样做。有人会认为,根据它的名字,它会处理一个关闭的输入并尝试找到类似的东西。但是,只有当您从支持的纸张尺寸列表中明确匹配时,它才会返回正确的纸张尺寸。
我的问题是,无论我认为哪种点大小适用于 5x7,它似乎总是会选择 Letter。实际的磅值因地区和打印机而异。
只有从纸张列表中输入匹配的数字后,我才能在 5x7 上打印我的 PDF。
祝你好运!