0

我正在尝试从我的应用程序文档目录中提取 .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] Path = /Users/myUserName/Library/Developer/CoreSimulator/Devices/02F8C004-6BA3-4F7B-9FC4-743DA205D7DD/数据/容器/数据/应用程序/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/Application/796A70BC -4159-4B18-825E-B35043BC5704/Documents/Observation.PDF 2015-11-08 08:56:31.080 ShortShooter4[16153:7505181] 对 .*** 的开始/结束外观转换的不平衡调用

所以我可以看到文件在那里。我也有不平衡的通话问题,但我会单独进行攻击。

4

1 回答 1

0

通过删除解决的问题:

UIViewPrintFormatter *viewFormatter = [self.view viewPrintFormatter];
viewFormatter.startPage = 0;
print.printFormatter = viewFormatter;

希望这对其他人有帮助。

于 2015-11-14T13:35:45.223 回答