Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 968
Brian Postow Avatar asked Dec 14 '25 20:12

Brian Postow


1 Answers

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

like image 177
JWWalker Avatar answered Dec 17 '25 19:12

JWWalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!