我正在尝试从我的应用文档目录中提取.pdf并将其加载到PIC中。 PIC显示没有错误,但在预览中没有显示数据。 我在这里错过了什么?我只是采取了一种完全错误的做法吗?
-(IBAction)actPrintPDF:(id)sender
{
NSString* fileName = @"Observation.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
NSLog(@"Path = %@",path);
NSLog(@"pdfFileName = %@",pdfFileName);
NSData *myData = [NSData dataWithContentsOfFile:path];
UIPrintInteractionController *print = [UIPrintInteractionController sharedPrintController];
print.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [pdfFileName lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
print.printInfo = printInfo;
print.showsPageRange = YES;
print.printingItem = myData;
UIViewPrintFormatter *viewFormatter = [self.view viewPrintFormatter];
viewFormatter.startPage = 0;
print.printFormatter = viewFormatter;
UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {};
[print presentAnimated:YES completionHandler:completionHandler];
}
日志显示如下: *** 2015-11-08 08:56:30.462 ShortShooter4 [16153:7505181]路径= / Users / myUserName / Library / Developer / CoreSimulator / Devices / 02F8C004-6BA3-4F7B-9FC4-743DA205D7DD / data / Containers / Data /应用/ 796A70BC-4159-4B18-825E-B35043BC5704 /文件
2015-11-08 08:56:30.462 ShortShooter4 [16153:7505181] pdfFileName = / Users / muUserName / Library / Developer / CoreSimulator / Devices / 02F8C004-6BA3-4F7B-9FC4-743DA205D7DD / data / Containers / Data /应用程序/ 796A70BC-4159-4B18-825E-B35043BC5704 /文档/ Observation.PDF 2015-11-08 08:56:31.080 ShortShooter4 [16153:7505181]不平衡调用开始/结束外观转换。***
所以我可以看到文件在那里。我也有不平衡的呼叫问题,但我会单独攻击它。
答案 0 :(得分:0)
通过删除解决问题:
UIViewPrintFormatter *viewFormatter = [self.view viewPrintFormatter];
viewFormatter.startPage = 0;
print.printFormatter = viewFormatter;
希望这有助于其他人。