减少pdf大小 - 目标c [英] Reduce pdf size - Objective c

查看:106
本文介绍了减少pdf大小 - 目标c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pdf生成项目,它包含一些文本和已存储在db中的图像,我想预览并邮寄生成的pdf,当只有文本数据时一切正常。

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.

如果我们的数据中有图像,则会出现问题。邮件收到
大小为10MB或以上的pdf,即使它有1MB或以下的图像。它在模拟器中工作正常。我的代码绘制图像如下所示:

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:

        UIImage *plotImage=[[UIImage alloc]initWithContentsOfFile:[localPictureArray objectAtIndex:i]];                  
                CGSize imageSize=plotImage.size;
                CGFloat scaleFactor = 1.0;        

        if (imageSize.height>(maxHeight-currentPageY) || imageSize.width>maxWidth ) 
        {
           UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, kDefaultPageWidth, kDefaultPageHeight), nil);
           currentPageY = kMargin;

           if (!((scaleFactor = (maxWidth / imageSize.width)) > ((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));
      }

因为iam是一个难以解决问题的初学者。

Since iam a starter iam struggling to solve it.

推荐答案

我挣扎了很多..最后用jpeg格式将图像写成pdf页面时使用下面的代码,大小减少了十倍!!不知道这是正确的方法...

I struggled a lot.. at last when wrote image in jpeg format to pdf page using below code, size got reduced ten times!! Don't know it is the right method...

UIImage *lowResImage = [UIImage imageWithData:UIImageJPEGRepresentation(plotImage, 0.02)];

这篇关于减少pdf大小 - 目标c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆