title: how to save pdf file in document directory
body: <p>I am beginner of iPhone. I have no idea about how to save pdf file in document directory. I have make the folder in document directory. I have first open the pdf in Webview.but how to store pdf in document directory.</p>
  
  <p>This is my code is...</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
   NSArray *path = [[NSBundle mainBundle] pathsForResourcesOfType:@"pdf" inDirectory:nil];
    UIBarButtonItem *tempButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"starbtnwhite.png"] style:UIBarButtonItemStylePlain target:self action:@selector(favbtnClicked:)];
  
      self.navigationItem.rightBarButtonItem = tempButton;
  
   NSFileManager *fileManager = [NSFileManager defaultManager];
      NSString *documentFolderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
      NSString *imagesFolderPath = [documentFolderPath stringByAppendingPathComponent:@"Favourite"]; 
  
      //Check if the videos folder already exists, if not, create it!!!
      BOOL isDir;
  
      if (([fileManager fileExistsAtPath:imagesFolderPath isDirectory:&amp;isDir] &amp;&amp; isDir) == FALSE) 
      {
          [[NSFileManager defaultManager] createDirectoryAtPath:imagesFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
      }
  
  
  if(sel_id==0)
      {
              NSURL *targetURL = [NSURL fileURLWithPath:[path objectAtIndex:0]];
              NSLog(@"targeUrl--%@",targetURL);
  
              NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
              NSLog(@"request--%@",request);
  
              [webView loadRequest:request];
              [self.view addSubview:webView];
  //            [webView release];
  
      }
      else if(sel_id == 1)
      {
          NSURL *targetURL = [NSURL fileURLWithPath:[path objectAtIndex:1]];
          NSLog(@"targeUrl--%@",targetURL);
  
          NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
          NSLog(@"request--%@",request);
  
          [webView loadRequest:request];
          [self.view addSubview:webView];
  //        [webView release];
  
      }
      else if(sel_id == 2)
      {
          NSURL *targetURL = [NSURL fileURLWithPath:[path objectAtIndex:2]];
          NSLog(@"targeUrl--%@",targetURL);
  
          NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
          NSLog(@"request--%@",request);
  
          [webView loadRequest:request];
          [self.view addSubview:webView];
  //        [webView release];
  
      }
  
  }
  
  -(IBAction)favbtnClicked:(id)sender
  {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSData *datapdf=[[NSData alloc]init];
      NSString *documentDirectory=[paths objectAtIndex:0];
  
  
  
      NSString *finalPath=[documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"Favourite/%@",webView]];
      NSLog(@"finalpath--%@",finalPath);
      [datapdf writeToFile:finalPath atomically:YES];
      NSLog(@"data--%@",datapdf);
  
  }
  </code></pre>
  
  <p>sel_id is return the cell of raw selected in tableview and I have make the Favourite folder in document directory and I want to add pdf file in Favourite folder. for that purpose I have created method of favbtnClicked: it is I have save the pdf file in document directory.</p>
  
  <p>but in save like this formate...</p>
  
  <p>Favourite folder
       ></p>
  
  <p>but I want to save only pdf file like abc.pdf not  this formate ></p>
  
  <p>so give any suggestion and source code which is apply in my apps....</p>