0

我对 iOS 很陌生。我现在创建PDF并加载它 这次我想在 iPhone 中保存或下载它PDF,当我们点击下载按钮然后所有退出支持者显示就像打开 ibook 一样,在 chrome 中打开。这种类型的选项会显示,但是当我们点击任何一个时,我的应用程序就会关闭。UIWebView
PDFPDF

在此处输入图像描述

  -(void)show_Button
  {

    NSArray *docDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *docDirectory = [docDirectories objectAtIndex:0];

   NSString *filePAth = [docDirectory stringByAppendingPathComponent:@"myPDF.pdf"];

   NSLog(@"filePath = %@", filePAth);
   NSURL *url2 = [NSURL fileURLWithPath:filePAth];
   NSLog(@"url2 = %@", url2);

   UIDocumentInteractionController *docContr = [UIDocumentInteractionController
                                             interactionControllerWithURL:url2];
   docContr.delegate=self;
  [docContr presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
  }

那么如何在Iphone中保存或下载此pdf请解决此问题....

4

2 回答 2

0

我相信你可以简单地使用下面两条线:

NSData *myFile = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"your_url"]]; 
[myFile writeToFile:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"yourfilename.pdf"] atomically:YES];
于 2013-07-22T16:50:50.437 回答
0

我希望这会对你有所帮助,将 pdf 保存到应用程序中

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: path]]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);         
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"pdfname.pdf"];      
NSError *writeError = nil;   
     [imageData writeToFile:filePath options:NSDataWritingAtomic error:&writeError];
           if (writeError) {
              NSLog(@"Error writing file: %@", writeError);    }

从 NSDocument 目录获取 pdf

NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];

NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:&error];

for(int i=0;i<[filePathsArray count];i++)
{
    NSString *strFilePath = [filePathsArray objectAtIndex:i];
    if ([[strFilePath pathExtension] isEqualToString:@"pdf"]) 
    {
        NSString *pdfPath = [[stringPath stringByAppendingFormat:@"/"] stringByAppendingFormat:strFilePath];
        NSData *data = [NSData dataWithContentsOfFile:pdfPath];
        if(data)
        {
            UIImage *image = [UIImage imageWithData:data];
            [arrayOfImages addObject:image];
        }
    }
}
于 2013-07-22T10:16:06.413 回答