7

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!

Kamchatka
  • 3,597
  • 4
  • 38
  • 69
  • Could you name a few characteristics of what you are drawing, where the images come from and how large the resulting files are? Did you pass a file to a external pdf compression tool and had a look at the differences? – Max Seelemann Sep 19 '10 at 16:41
  • The images are camera images, stored as JPEG and then read to UIImage objects. So I draw a UIImage.CGImage in the CGPDFContext. File size would be for instance 1.2 MB for a single page. If I try to downscale, I goes up to 3 MB. With a compression tool (quartz filter) it's more like 500KB. – Kamchatka Sep 19 '10 at 21:17

2 Answers2

2

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

rpetrich
  • 32,196
  • 6
  • 66
  • 89
  • 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 Sep 22 '10 at 04:33
  • 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 Sep 22 '10 at 23:28
  • 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 Sep 23 '10 at 05:54
  • Create a `CGBitmapContext` in the format you want, draw into it, then pull your new image out using `CGBitmapContextCreateImage`. – rpetrich Sep 23 '10 at 15:51
0

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
  • 36,122
  • 25
  • 118
  • 131