首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文档目录中的iphone sdk -Loading PDF

文档目录中的iphone sdk -Loading PDF
EN

Stack Overflow用户
提问于 2011-08-28 23:01:32
回答 2查看 575关注 0票数 0

我正在使用Leaves项目在我的iphone项目中显示我的pdf文件,但是当我试图显示来自文档而不是捆绑包中的pdf时,我遇到了一个问题。我认为这很简单,但有一个技巧我无法理解,因为我不是pdf阅读方面的专家:)

我使用了下面的代码

代码语言:javascript
复制
-(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中,而不是像leaves那样放在init中。我使用了这个LINK上的解决方案,但它也不起作用

所以在座的任何人有什么可以帮助我的:)

EN

回答 2

Stack Overflow用户

发布于 2011-09-16 01:50:01

您已经将代码放在viewWillAppear中,这可能是您的问题所在。在其他地方,代码可能假设代码已经被调用,并且PDF已经在那里。试着把它放到init中,看看会发生什么。viewWillAppear可能会被调用多次。

票数 0
EN

Stack Overflow用户

发布于 2012-03-11 05:17:22

使用此代码

代码语言:javascript
复制
- (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函数

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7221718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档