2012-04-27 66 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];