I'm new to this forum and I'm trying to develop an application generating a PDF file from photo taken by the user. My problem is that when I draw a JPEG image in the PDF context, it works, but leaks, which does not if I use a PNG Image.
Here is a small test method which shows the problem.
Even if in both cases (JPG/PNG), the pdf file is correctly generated with the image in it, the leak only appears with the JPG version.
Creating an image file from a PDF file with desired page number
Creates UIImage file from a PDF page of a PDF document & stores the image in the iPad Library.-
Code:
-(IBAction)pdf2image
{
// m_webView is a UIWebView
UIGraphicsBeginImageContext(m_webView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, m_webView.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// The file DemoPDF.pdf is in the Resource Folder of the Project
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("DemoPDF.pdf"), NULL, NULL);
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL(pdfURL);
// m_pnTf is the UITextField which is used to enter the desired page number
int pageNumber = [m_pnTf.text intValue];
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(document, pageNumber);
CGContextDrawPDFPage(context, pdfPage);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
// The final image is saved in the iPad Library
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}