Ben*_*tto 4 printing iphone ios
我正在iOS应用程序中实现打印.我在Mac上有一个打印代理应用程序,用于物理测试打印机,这是一台美国Letter打印机.iOS模拟器附带的打印机模拟器也默认为US Letter.
有人建议我如何测试其他默认纸张尺寸?
谢谢!
如果我理解的iOS打印功能正确地-这是一个很大的如果 -那么打印模拟器将被调整到美国Letter或A4取决于你送什么的尺寸.因此,如果您发送A4尺寸的东西,它将选择A4,如果您发送美国信件大小的东西,它将选择美国信件.
但是,我发现实际打印时,这并不总是有效.为了做到这一点,我发现与明确鼓励iOS选择A4纸张尺寸有所不同.这是在UIPrintInteractionController委托中的printInteractionController:choosePaper:方法中完成的(参见下面的代码).如果有人在那里了解更好,请发布.
更一般地说(并且有点问题......)我打印的方法是为美国Letter或A4设置应用程序.当应用程序首次启动时,它会检查它是否是美国(通过测试[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]),如果是,则选择US Letter.否则它是A4.用户可以更改此设置.(我让用户导出PDF,因此,如果她是英国用户向美国朋友发送PDF,她可以让他们看起来正确.)
要打印,我首先创建一个A4或US Letter PDF.Apple的示例代码将引导您完成美国信函大小.对于A4,您需要将PDF的尺寸设置为大约595.4 x 841.7.(对于使用其他大小,请注意这些数字是以点为单位,其中点密度为72dpi,即您以英寸为单位并乘以72.)然后,我在UIPrintInteractionController上使用setPrintingItem:并为PDF提供NSURL.
我发现iOS打印文档非常具有挑战性,因此可以使用更简单/更好/更强大的方法来处理A4/US Letter等.但希望我在这里写的一些内容是有帮助的.
委托代码
// code in the UIPrintInteractionController delegate
// The [Shared settings] object returns paperWidth and paperHeight depending on the app wide A4 or US Letter setting
- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList
{
CGSize pageSize = CGSizeMake([[Settings shared] paperWidth], [[Settings shared] paperHeight]);
return [UIPrintPaper bestPaperForPageSize:pageSize withPapersFromArray:paperList];
}
Run Code Online (Sandbox Code Playgroud)
创建PDF代码
UIGraphicsBeginPDFContextToFile(CGRectMake(0.0, 0.0, [[Settings shared] paperWidth], [[Settings shared] paperHeight]), nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0.0, 0.0, [[Settings shared] paperWidth], [[Settings shared] paperHeight]), nil);
// create the PDF
UIGraphicsEndPDFContext();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4033 次 |
| 最近记录: |