1. - (UIImage *)p_w_picpathFromPDFWithDocumentRef:(CGPDFDocumentRef)documentRef {
  2.     CGPDFPageRef pageRef = CGPDFDocumentGetPage(documentRef, 1);
  3.     CGRect pageRect = CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox);
  4.  
  5.     UIGraphicsBeginImageContext(pageRect.size);
  6.     CGContextRef context = UIGraphicsGetCurrentContext();
  7.     CGContextTranslateCTM(context, CGRectGetMinX(pageRect),CGRectGetMaxY(pageRect));
  8.     CGContextScaleCTM(context, 1, -1);  
  9.     CGContextTranslateCTM(context, -(pageRect.origin.x), -(pageRect.origin.y));
  10.     CGContextDrawPDFPage(context, pageRef);
  11.  
  12.     UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
  13.     UIGraphicsEndImageContext();
  14.     return finalImage;
  15. }