title: can we save the contents drawn on the pdf as a new pdf ? xcode
body: <p>Can we save the contents drawn over the pdf , as pdf again , i tried to save the pdf with the contents but with no luck , it saves with blank pdf </p>
  
  <p>the code:</p>
  
  <pre><code>- (void)drawRect:(CGRect)rect
  {
  NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
  NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
  document = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfUrl);
  size_t count = CGPDFDocumentGetNumberOfPages (document);// 3
  
  if (count == 0)
  {
      NSLog(@"PDF needs at least one page");
      return;
  }
  
  CGRect paperSize = CGRectMake(0.0,0.0,595.28,841.89);
  
  CGContextRef currentContext = UIGraphicsGetCurrentContext();
  
  // flip context so page is right way up
  CGContextTranslateCTM(currentContext, 0, paperSize.size.height);
  CGContextScaleCTM(currentContext, 1.0, -1.0); 
  
  CGPDFPageRef page = CGPDFDocumentGetPage (document, 1); // grab page 1 of the PDF 
  
  CGContextDrawPDFPage (currentContext, page); // draw page 1 into graphics context
  
  // flip context so annotations are right way up
  CGContextScaleCTM(currentContext, 1.0, -1.0);
  CGContextTranslateCTM(currentContext, 0, -paperSize.size.height);
  
  ////////////////////////////////
  
  [curImage drawAtPoint:CGPointMake(0, 0)];
  CGPoint mid1 = midPoint(previousPoint1, previousPoint2); 
  CGPoint mid2 = midPoint(currentPoint, previousPoint1);
  
  CGContextRef context = UIGraphicsGetCurrentContext(); 
  
  [self.layer renderInContext:context];
  
  CGContextMoveToPoint(context, mid1.x, mid1.y);
  CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); 
  CGContextSetLineCap(context, kCGLineCapRound);
  CGContextSetLineWidth(context, self.lineWidth);
  CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
  
  CGContextStrokePath(context);
  
  [super drawRect:rect];
  
  // get a temprorary filename for this PDF
  
  NSString* path = [[NSBundle mainBundle] pathForResource:@"sampleData" ofType:@"plist"];
  path = NSTemporaryDirectory();
  self.pdfFilePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.pdf", [[NSDate date] timeIntervalSince1970] ]];
  
  UIGraphicsBeginPDFContextToFile(@"test.pdf", paperSize, nil);
  
  [@"annotation" drawInRect:CGRectMake(100.0, 100.0, 200.0, 40.0) withFont:[UIFont systemFontOfSize:18.0]];
  }
  </code></pre>
  
  <p>And I tried to close the PDF on button click </p>
  
  <pre><code>- (IBAction)buttonPressed:(UIButton *)button {
   UIGraphicsEndPDFContext();
   return;
  }
  </code></pre>
  
  <p>But it's not working.</p>
  
  <p>Any help will be greatly appreciated , thanks in advance</p>