title: Reduce pdf size - Objective c
body: <p>I have a pdf generation project, it consist of some texts and an image which is already stored in db, i want to preview and mail the pdf generated, everything is ok when there is only text data.</p>
  
  <p>Problem arises if there is image in our data. The mail receives
  the pdf of size 10MB or above even if it have image of size 1MB or below.It is working fine in simulator.My code to draw image is shown below: </p>
  
  <pre><code>        UIImage *plotImage=[[UIImage alloc]initWithContentsOfFile:[localPictureArray objectAtIndex:i]];                  
                  CGSize imageSize=plotImage.size;
                  CGFloat scaleFactor = 1.0;        
  
          if (imageSize.height&gt;(maxHeight-currentPageY) || imageSize.width&gt;maxWidth ) 
          {
             UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil);
             currentPageY = kMargin;
  
             if (!((scaleFactor = (maxWidth / imageSize.width)) &gt; ((maxHeight-currentPageY) / imageSize.height)))
              { 
              scaleFactor = (maxHeight-currentPageY) /imageSize.height; 
              // scale to fit heigth. 
              }
  
             CGRect rect = CGRectMake(kMargin,currentPageY,
             imageSize.width * scaleFactor, imageSize.height * scaleFactor);
             //Draw the image into the rect
             [plotImage drawInRect:rect];
           }
  
    else
        {
          plotImage drawInRect:normal size)];//Normal size we need
          NSLog(@"%@",NSStringFromCGSize(plotImage.size));
        }
  </code></pre>
  
  <p>Since iam a starter iam struggling to solve it.</p>