我有一个生成PDF的项目,其中包含一些文本和已在数据库中存储的图像,我想预览和发送生成的PDF,当只有文本数据时一切正常。
如果我们的数据中有图像,则会出现问题。即使图片大小为1MB或更小,邮件接收到的PDF文件大小也会达到10MB或以上。在模拟器中一切正常。下面是我的绘制图像代码:
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));
}
由于我是一名初学者,所以我很难解决这个问题。
}
,这只是一个打字错误吗? - Manuelif (imageSize.height>(maxHeight-currentPageY) || imageSize.width>maxWidth ) {
。难道else {
应该是这样的:} else {
? - Manuel