首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用CGPDFDocumentRef显示下载的pdf

用CGPDFDocumentRef显示下载的pdf
EN

Stack Overflow用户
提问于 2010-12-28 19:28:25
回答 1查看 1.8K关注 0票数 3

我有一个问题,我希望有人能帮助我。

我将一个PDF文件下载到DocumentDirectory

代码语言:javascript
复制
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, TRUE);
NSString *documentsDirectory = [paths objectAtIndex:0];
studioPath = [[documentsDirectory stringByAppendingPathComponent:@"test.pdf"] retain];
ASIHTTPRequest *request = [[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://testURL.com/test.pdf"]] retain];
[request setDownloadDestinationPath:studioPath];

这不是全部代码,但我希望您能理解我的意思。

之后,我将显示此PDF

代码语言:javascript
复制
CGPDFDocumentRef pdf;
CFStringRef fullPathEscaped = CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)studioPath, NULL, NULL,kCFStringEncodingUTF8);

CFURLRef docUrl = CFURLCreateWithFileSystemPath (NULL, fullPathEscaped, kCFURLPOSIXPathStyle, FALSE);  
pdf = CGPDFDocumentCreateWithURL(docUrl);

但它总是崩溃,当我使用互联网的网址,而不是PDF的studioPath,它可以工作,但我不会下载pdf超过一次。

EN

回答 1

Stack Overflow用户

发布于 2012-03-12 20:44:09

试试这个

代码语言:javascript
复制
 CFURLRef pdfURL = (CFURLRef)[[NSURL alloc] initFileURLWithPath:[documentsDirectory stringByAppendingPathComponent:source]];
    //file ref
    CGPDFDocumentRef pdfRef = CGPDFDocumentCreateWithURL((CFURLRef) pdfURL);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4545681

复制
相关文章

相似问题

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