1

我正在使用此代码从服务器下载 pdf 文件。

   NSString *urlString = @"https://developer.apple.com/library/ios/documentation/uikit/reference/UILabel_Class/UILabel_Class.pdf";

   NSURL *url = [NSURL URLWithString:urlString];

   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"UILabel.pdf"]];
   [request setDelegate:self]; 
   [request startAsynchronous];

下载功能运行良好。但我需要用 CGPDFDocumentRef 显示下载的 pdf。

提前致谢。

4

1 回答 1

3

下载您的 pdf 后,将该 pdf 文件保存到文档目录中,然后从那里检索您的 pdf 并使用 CGDocumentref 显示如下:

  CFURLRef pdfURL = (CFURLRef)[[NSURL alloc] initFileURLWithPath:[documentsDirectory stringByAppendingPathComponent:source]];
        //file ref
        CGPDFDocumentRef pdfRef = CGPDFDocumentCreateWithURL((CFURLRef) pdfURL);
于 2012-03-12T12:02:31.440 回答