我有一个应用程序,需要打印收据和通行证从iPad。我已经实现了AirPrint软件开发工具包,它工作正常,即我能够使用AirPrint兼容的打印机从iPad打印文档。
问题是,我需要这些收据和通行证在半页(即A4页的一半)或A5页上。无论我对打印作业做什么更改,它总是在整个A4页面和横向打印。
下面是我要打印的代码:
UIPrintInteractionController *printer = [UIPrintInteractionController sharedPrintController];
UIPrintInfo *printObject = [UIPrintInfo printInfo];
[printObject setJobName:@"Receipt"];
[printObject setOutputType:UIPrintInfoOutputGeneral];
[printObject setOrientation:UIPrintInfoOrientationLandscape];
UIPrintFormatter *printFormatter = [[UIPrintFormatter alloc] init];
[printFormatter setContentInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[printer setPrintFormatter:printFormatter];
[printer setPrintInfo:printObject];
[printer setDelegate:self];
[printer setPrintingItem:targetURL];
[printer presentFromRect:sender inView:view animated:YES completionHandler:^(UIPrintInteractionController *printInteractionController,BOOL completed, NSError *error){}];我还尝试实现了choosePaper委托方法,但也没有帮助。哦,在创建文档时,我指定了大小:
CGSize pageSize = CGSizeMake(595, 420);
NSString* fileName = @"GatePass.PDF";
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);理想情况下,它的工作方式是,如果用户在打印中使用A5纸,则正常打印。如果用户使用A4纸张,则只打印半页,依此类推。
你知道如何实现这一点吗?
发布于 2014-05-08 02:27:29
使用chosePaper委托方法。如果A5列在给出的列表中,那么选择那篇论文。如果打印机有A5并且知道它有A5,那么您应该会得到A5输出。您还需要以从chosePaper返回的大小创建PDF。
您可以使用打印机模拟器对此进行测试。使用加载纸张大小按钮将其中一台打印机设置为“模拟纸张传感器”,并将A5加载到其中一个纸盒中。
https://stackoverflow.com/questions/23523337
复制相似问题