2012-04-27 64 views
1

我有,我正在使用如何从iPhone中的URL加载PDF?

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

现在我想从我的Web服务器加载它加载从包一个PDF的应用程序。我用

NSString *strUlr = [NSString stringWithFormat:@"https://s3.amazonaws.com/hgjgj.pdf"]; 

CFStringRef aCFString = (CFStringRef)strUlr; 

//CFURLRef pdfURL = aCFString; 
// NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

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

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),aCFString, NULL, NULL); 
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); 
    NSLog(@"%@",pdf); 
//CFRelease(pdfURL); 

字符串的URL,但没有任何人success..Can知道如何使此代码working.I不需要加载它到PDF,因为有些人reasons.Can的帮助我做到了?

+0

你能请参阅此问题[Questin链接] http://stackoverflow.com/questions/10347887/how-to-load-a-pdf-from- iphone- – 2014-09-22 05:25:02

+0

我有这个问题,所以请帮助我你有d一个这 – 2014-09-22 05:26:10

+0

您好@hacker请你帮忙我有同样的问题,我已经发布的问题,我已经做了所有在你的答案,但我不明白如何使用PDF文档对象 – 2014-11-12 07:27:57

回答

1

您仍然尝试将url应用于应用程序包中的资源,而不是在远程服务器上。创建网址正确的方法将CFURLCreateWithString:

CFURLRef pdfURL = CFURLCreateWithString(NULL, aCFString, NULL); 

请记住,它可能是更好的下载PDF格式,并缓存在本地显示之前 - 这种做法也将让您在错误处理和可能的验证挑战更大的灵活性为您的网址

+0

它的作品谢谢... – hacker 2012-04-27 09:25:36

+0

嗨@Vladimir你可以解释它是如何工作的,因为我已经完成了上面的代码,在上面的评论中我已经发布了我的问题,所以你可以请看看我的问题,缺什么请解释 – 2014-11-12 07:31:36

+0

请帮我我花了很多时间在这但没有成功,请帮助我! @Vladimir – 2014-11-12 07:32:21

0

仅供阅读,您可以通过url在Uiwebview中加载PDF文件。

0

如果我没有记错的话,那么你可能想阅读从网络服务器PDF在您的iPhone,如果是的话那么你可以有一个UIWebView对你的要求:这里是你如何能读取并存储在本地:

首先创建一个UIWebView并包括< < UIWebViewDelegate >>

NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
    NSString *documentsPath = [paths objectAtIndex:0]; 
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"YourPDF.pdf"]; 
if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]){ 
      // download file , here "https://s3.amazonaws.com/hgjgj.pdf" = pdf downloading link 
     NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"https://s3.amazonaws.com/hgjgj.pdf"]]; 
      //Store the downloaded file in documents directory as a NSData format 
     [pdfData writeToFile:filePath atomically:YES]; 
    } 

    NSURL *url = [NSURL fileURLWithPath:filePath]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
    [yourWebView setUserInteractionEnabled:YES]; 
    [yourWebView setDelegate:self]; 
    yourWebView.scalesPageToFit = YES; 
    [yourWebView loadRequest:requestObj];