簡體   English   中英

iphone sdk-從文檔目錄加載PDF

[英]iphone sdk -Loading PDF from document directory

我正在使用Leaves項目在我的iphone項目中顯示我的PDF,但是當我嘗試從文檔而不是捆綁包中顯示PDF時出現問題。我認為這很簡單,但是有一個竅門,我無法得到原因我不是pdf閱讀專家:)

我正在使用以下代碼

-(void) viewWillAppear:(BOOL)animated{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
pListPath = [ documentDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",self.fileName]];


CFURLRef pdfURL = (CFURLRef)[NSURL fileURLWithPath:pListPath];    


//  CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("fekhElSunaI.pdf"), NULL, NULL);

pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
NSLog(@"%@",pListPath);

//    CFRelease(pdfURL);

   [self init];
}

您會注意到,我沒有像葉子那樣將代碼放在viewWillAppear中。.pdf沒有出現並且沒有初始化,我使用了此LINK上的解決方案,但它也不起作用

所以這里的任何人都可以幫助我的事情:)

您已將代碼放入viewWillAppear中,這可能就是您的問題。 在其他地方,該代碼可能假定該代碼已經被調用,而PDF已經存在。 嘗試將其放入init中,看看會發生什么。 viewWillAppear可能會被調用多次。

使用此代碼

- (id)init {
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];

  myPathDocs =  [documentsDirectory stringByAppendingPathComponent:@"abc.pdf"];
  pdfURL = (CFURLRef)[NSURL fileURLWithPath:myPathDocs];    
  NSLog(@"myString %@",myPathDocs);

  pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);        //        }

  size_t pageCount = CGPDFDocumentGetNumberOfPages(pdf);
}

為您的Leavies View init功能

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM