2015-11-08 109 views
0

我試圖從我的應用程序文檔目錄中拉出.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轉換爲。***

所以我可以看到文檔在那裏。我也有不平衡的電話問題,但我會分開攻擊。

回答

0

問題通過刪除解決:

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

希望這可以幫助別人。