2011-08-28 49 views
0

我正在使用Leaves项目在我的iphone项目中显示我的PDF,但我遇到了问题,当我试图从文档中显示PDF时,并非来自捆绑包..我认为这是简单,但有一招我不能让因为我不是在PDF阅读:)iphone sdk - 从文档目录中加载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并没有工作,要么

所以这里任何一个有东西帮我:)

+1

有什么问题或问题?你说你有问题。它不显示?你有错误吗? – bryanmac

+0

是啊,它并没有显示,尽管它得到的页数,我为什么怀疑代码的位置有问题 –

回答

0

你已经把viewWillAppear中的代码,这可能是你的问题。在其他地方,代码可能会假定代码已被调用,并且PDF已经存在。尝试将它放入init中,并看看会发生什么。 viewWillAppear可能会被多次调用。

0

使用此代码

- (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查看init功能