views:

136

answers:

2

Hello,

I'm looking for a way to reduce PDF size that I generate with Quartz. I'm drawing images with CGContextDrawImage in a CGPDFContext. What I'm afraid of is that the images are saved as Bitmap and not JPEG. Is there a way to check for that and a way to control that when writing the PDF?

I also tried reducing downscaling the image before writing it to the PDF context but I end up with an even larger file (although the page size in pixels is smaller).

Thanks!

A: 

There is no public API for setting CGPDFContext's image compression settings.

rpetrich
I also tried another library with compression settings available. The pattern seems similar: the size of the image doesn't matter much compared to the size of the PDF page.
Kamchatka
Perhaps try reducing the color depth on the `CGImage` that you're writing? A 16-bit image will be half the size _if_ `CGPDFContext` stores images in their source formats
rpetrich
I looked into that but couldn't find any API to reduce the depth of a CGImage. Would you know how to do that?
Kamchatka
Create a `CGBitmapContext` in the format you want, draw into it, then pull your new image out using `CGBitmapContextCreateImage`.
rpetrich
Thanks, this is really helpful.
Kamchatka
A: 

I'm not sur if you need to reduce PDF on the iPhone or if it's acceptable for you to reduce them on a PC/Mac.

On PC/Mac, Adobe Acrobat Pro (a commercial product not to be mistaken with Adobe Reader) has a PDF optimizer. Menu "Adavanced" > "PDF Optimizer...". This can downscale images, fonts, etc. As there is also a command-line interface (using AutoBatch). It isn't cheap but it's probably the best PDF compressor out there.

Wernight