ioscocoapdfcgimagecgpdfcontext

What size a CGPDFContext has to have?


I have to write a CGPDFContext. This PDF contains just one image.

The image has 2100 x 3000 pixels.

Suppose I open this image on Photoshop and print it at 300 dpi. Photoshop will use 300 pixels to build every inch of printed material, so this image will have 7 x 10 inches.

This image has this size because of that.

Now I have to create a CGPDFContext. I read somewhere that this context has to be created in points and there is a mention that on a CGPDFContext one point = 1/72 inches, meaning that the context will have 72 dpi (?).

So, what size should I create this context to have maximum quality at 300 dpi.

Another question is this: supposing this context is created based on the 1/72 stuff, than 7 x 10 inches will represent 504 x 720 pt. If this is the size I have to create the context, what happens when I write the image to the context using this?

CGImageRef imageRef = image.CGImage; // this image is 2100x3000 pixels

// mediaBox = 0,0,504,720
CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, &mediaBox, auxillaryInformation);

CGContextDrawImage(pdfContext, CGRectMake(0.0f, 0.0f, 504, 720), imageRef);

will the 2100x3000 pixels image be embedded on the context without losing pixels? I don't want the image to be reduced to 504x720


Solution

  • If your image is 2100*3000 pixels and you draw it on a PDF page that is 7*10 inches (504*720 points) then your image will be embedded at 300 dpi.
    The image size will be kept at 2100*3000 pixels and it will not be downscaled at 504*720 pixels.