Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Mac OS X Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-03-2010, 03:30 PM   #1 (permalink)
Registered Member
 
Jume's Avatar
 
Join Date: Jul 2008
Location: Slovenia, EU
Posts: 264
Send a message via Skype™ to Jume
Default Save PDF pages as image files

Hi,

I am trying to save each PDF's page as an image file on my mac. I've come up with the Quartz solution, but it's giving me problems.... Here's my code:

Code:
NSData *pdfData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://localhost/uniki/unicenter/static/images/cluster/test.pdf"]];
CFDataRef pdfDataRef = (CFDataRef)pdfData;
	
CGImageSourceRef imgSoureRef = CGImageSourceCreateWithData(pdfDataRef, NULL);
NSLog(@"Number of sources: %d", GImageSourceGetCount(imgSoureRef));
	
CGImageRef imgRef = NULL;
CFDictionaryRef dictP = NULL;

if (imgSoureRef) {
	imgRef = CGImageSourceCreateImageAtIndex(imgSoureRef, 0, NULL);
	dictP  = CGImageSourceCopyPropertiesAtIndex(imgSoureRef, 0, NULL);
}

	
NSURL *outPath = [NSURL fileURLWithPath:@"/Users/mac/Desktop/page01.jpg"];
CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)outPath, (CFStringRef)@"public.jpeg" , 1, NULL);
CGImageDestinationAddImage(dest, imgRef, dictP);
CGImageDestinationFinalize(dest);
This are the errors that I'm getting. I tried google on this error but without any success. I really don't understand what are these errors trying to say to me... any help?

2010-02-03 19:29:11.331 UNILoader[6716:a0f] Number of sources: 4
Wed Feb 3 19:29:11 Macintosh-96.local UNILoader[6716] <Error>: CGImageDestinationAddImage image parameter is nil
Wed Feb 3 19:29:11 Macintosh-96.local UNILoader[6716] <Error>: CGImageDestinationFinalize image destination does not have enough images

Last edited by Jume; 02-03-2010 at 04:30 PM.
Jume is offline   Reply With Quote
Old 02-06-2010, 10:03 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default

It's basically telling you that "imgRef" is nil so it can't create an image.
harrytheshark is offline   Reply With Quote
Old 02-16-2010, 04:17 AM   #3 (permalink)
Registered Member
 
Jume's Avatar
 
Join Date: Jul 2008
Location: Slovenia, EU
Posts: 264
Send a message via Skype™ to Jume
Default

Quote:
Originally Posted by harrytheshark View Post
It's basically telling you that "imgRef" is nil so it can't create an image.
I knew that but didn't know what was the problem. I found out with the help from people from the Quartz mailing list...

CGImageSourceCreateImageAtIndex should not be used to create CGImageRef from PDF source ... Instead CGImageSourceCreateThumbnailAtIndex should be used. It worked after I used this method, but there are other problems with this.

There is a bug in Apple frameworks by using CGImageSourceCreateThumbnailAtIndex which end up in huge memory leaks. It only happens when source is PDF. I tried PSD source and no leaks, but having leaks with PDF source. I filled a bug report for this issue.
Jume is offline   Reply With Quote
Old 06-29-2010, 01:09 PM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 1
Default

Quote:
Originally Posted by Jume View Post
I

CGImageSourceCreateImageAtIndex should not be used to create CGImageRef from PDF source ... Instead CGImageSourceCreateThumbnailAtIndex should be used. It worked after I used this method, but there are other problems with this.
Yes, but this only works if the PDF has an embedded thumbnail and it only returns an image of the size of the thumbnail. Doesn't do a conversion as I understand it.
wingspinner is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 250
12 members and 238 guests
2WeeksToGo, AdamL, ADY, BrianSlick, Dani77, Dattee, headkaze, mer10, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,746
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:48 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0