我试图从我的应用程序文档目录中拉出.pdf并将其加载到PIC中。 PIC显示没有错误,但在预览中不显示数据。 我在这里错过了什么?我只是采取了一个完全错误的方法?如何打印应用程序文档目录中的.pdf文档
-(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月8日08:56:30.462 ShortShooter4 [16153:7505181]路径= /用户/名为myUsername /库/开发商/ CoreSimulator /设备/ 02F8C004- 6BA3-4F7B-9FC4-743DA205D7DD /数据/容器/数据/应用/ 796A70BC-4159-4B18-825E-B35043BC5704 /文件
2015年11月8日08:56:30.462 ShortShooter4 [16153:7505181] pdfFileName = /用户/ muUserName/Library/Developer/CoreSimulator/Devices/02F8C004-6BA3-4F7B-9FC4-743DA205D7DD/data/Containers/Data/Application/796A70BC-4159-4B18-825E-B35043BC5704/Documents/Observation.PDF 2015-11- 08 08:56:31.080 ShortShooter4 [16153:7505181]不平衡的开始/结束呼叫arance转换为。***
所以我可以看到文档在那里。我也有不平衡的电话问题,但我会分开攻击。