CGImageDestinationFinalize image destination does not have enough images ?
CGImageDestinationFinalize image destination does not have enough images ?
- Subject: CGImageDestinationFinalize image destination does not have enough images ?
- From: DairyKnight <email@hidden>
- Date: Tue, 1 Sep 2009 18:26:54 +0800
Hi,
I'm trying to extract pages from PDF files and save them to jpg. But keep
getting the 'doesnt have enough images'
error. Anyone knows why?
Thanks.
Here's the code:
// Opens the pdf file and gets the PdfPage
PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:[NSURL
fileURLWithPath:filename]];
PDFPage *page = [pdfDoc pageAtIndex:1];
NSPDFImageRep *pdfImg = [NSPDFImageRep imageRepWithData:[page
dataRepresentation]];
NSSize size;
size.width = 1024;
size.height = 768;
NSImage *img = [[NSImage alloc] initWithSize:size];
[img lockFocus];
// Draw the pdf page in an offscreen NSImage
[pdfImg drawInRect:NSMakeRect(0, 0, 1024, 768)];
[img unlockFocus];
[img setCacheMode:NSImageCacheNever];
if (![img isValid])
NSLog(@"img is not valid");
[imgView setImage:img];
// Saves the NSImage to disk.... getting the error
NSArray *representations;
NSData *bitmapData;
representations = [img representations];
bitmapData = [NSBitmapImageRep representationOfImageRepsInArray
:representations
usingType:NSJPEGFileType properties:nil];
[bitmapData writeToFile:@"/Users/Tom/test.jpeg" atomically:YES];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden