Hi, -[NSBitmapImageRep representationOfImageRepsInArray:usingType:properties:] requires an array of NSBitmapImageReps, not arbitrary NSImageReps.
-Ken On Tue, Sep 1, 2009 at 3:26 AM, DairyKnight <dairykni...@gmail.com> wrote: > 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 (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com > > This email sent to kenfe...@gmail.com > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com