I have following code
NSString *filePath=[[NSString alloc] initWithString:[[NSBundle mainBundle] pathForResource:pdfname ofType:@"pdf" inDirectory:@"appMasterPdf"]];
NSURL *url = [NSURL fileURLWithPath:filePath];
[filePath release];
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)url);
CGFloat scaleRatio;
UIGraphicsBeginImageContext(CGSizeMake(width, height));
CGContextRef context = UIGraphicsGetCurrentContext();
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber);
pageRect = CGPDFPageGetBoxRect(page, kCGPDFBleedBox);
width=pageRect.size.width;
height=pageRect.size.height;
if(pageRect.size.width/pageRect.size.height < 1.0) {
scaleRatio = height/pageRect.size.height;
}
else {
scaleRatio = width/pageRect.size.width;
}
CGFloat xOffset = 0.0;
CGFloat yOffset = height;
if(pageRect.size.width*scaleRatio<width) {
xOffset = (width/2)-(pageRect.size.width*scaleRatio/2);
}
else {
yOffset = height-((height/2)-(pageRect.size.height*scaleRatio/2));
}
CGContextTranslateCTM(context, xOffset, yOffset);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSaveGState(context);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page,
kCGPDFBleedBox, CGRectMake(0, 0, pageRect.size.width, pageRect.size.height),
0, true);
pdfTransform = CGAffineTransformScale(pdfTransform, scaleRatio, scaleRatio);
CGContextConcatCTM(context, pdfTransform);
CGContextDrawPDFPage(context, page);
UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(context);
UIGraphicsEndPDFContext();
UIGraphicsEndImageContext();
CGContextRelease(context);
CGPDFPageRelease(page);
return tempImage;
This function is acalling in for loop
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)url); These lines give me a memory leaks. Please help me . Thanx in advanced