Convert PDF to JPG in COCOA

In my cocoa application, I need to save each pdf page as jpg .. How can I accomplish using Objective-C

+4
source share
1 answer

Using pure Objective-C (Cocoa and PDF Kit ), iterate over the pages of your PDF document and for each of them create an NSImage the size of which corresponds to the media box of the page, lock the focus on it, inform the page about it, create an NSBitmapImageRep with a focused view (image), unlock the focus on the image, then ask the image image for the bitmap image for JPEG data and write that data to a file. (This solution sucks, do not use it.)

Another way is Core Graphics and ImageIO. Create a raster image context corresponding to the media box and color space of the document, then for each page create an image destination for the JPEG file, get the page from the document, draw the page in context, create a CGImage from the context, clear the context using CGContextClearRect , add the image to destination and complete the appointment.

+5
source

All Articles