Brian Postow
Brian Postow

Reputation: 12187

Getting a CGImageRef out of a PDFDocument

I have a PDFDocument (made up of PDFPages ofcourse) and I need a CGImageRef to stick into my IKImageView.

Currently, I get the datarepresentation from the PDFPage, put it into an NSImage, then get the TIFFRepresentation of the NSImage, put it into a CGImageSource, and then get the CGImage out of the source.

That seemsneedlessly complicated, going through two NSData steps...

However, when I try to put the PDF data directly into the CGImageSource, even though that APPEARS to work, when I get the CGImage out, it is always NULL. is there something specific I should be doing to get this to work?

Upvotes: 3

Views: 981

Answers (3)

0xced
0xced

Reputation: 26518

Look at the CreatePDFPageImage function in my CGPDFAdditions code. I think that's exactly what you need.

Upvotes: 1

Peter Hosey
Peter Hosey

Reputation: 96333

Try feeding the data for the PDF document (as opposed to a single page) into the CGImageSource. Images from the source should correspond to pages in the document.

Upvotes: 0

JWWalker
JWWalker

Reputation: 22707

In Snow Leopard there is a method -[NSImage CGImageForProposedRect:context:hints:]. Or you could draw the page into a CGBitmapContext and use CGBitmapContextCreateImage.

Upvotes: 1

Related Questions