title: Preview PDF Document in iOS Before Saving
body: <p>I am working on building an app that will generate PDFs.  I can generate the PDF just fine, but it is a one-click action that builds and saves the PDF.  What I would like to do is change it to showing a preview of the PDF and then giving the option to edit things, or save it to the Documents folder.  How can I go about doing this?  Here is what I have that saves it. </p>
  
  <pre><code>- (IBAction)generatePdfButtonPressed:(id)sender
  {
      pageSize = CGSizeMake(792, 612);
      NSString *fileName = @"Demo.pdf";
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
  
      [self generatePdfWithFilePath:pdfFileName];
  }
  - (void) generatePdfWithFilePath: (NSString *)thefilePath
  {
      UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);
  
  
      BOOL done = NO;
      do
      {
  
          UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
  
  
           [self drawImage];
  
          [self drawText];
          [self drawText2];
          [self drawText3];
          [self drawText4];
  
  
          done = YES;
      }
      while (!done);
  
      // Close the PDF context and write the contents out.
      UIGraphicsEndPDFContext();
  }
  </code></pre>