views:

181

answers:

2

I'm rendering PDF pages on iPhone using the code below. It works, but the margins seem much wider than when I view the same PDF using a Acrobat Reader or the Mac's Preview, and that consequently scales the content down much smaller than it otherwise would be. Is my code actually causing this behavior?

In regards to the bounds below, I verified the bounds being used by the code are basically the height and width of the entire screen area, less the status bar.

CGContextSetStrokeColorWithColor(context, backgroundColor.CGColor);
CGContextSetFillColorWithColor(context,backgroundColor.CGColor); 
CGContextSetLineWidth(context, 2.0);
CGContextAddRect(context, CGRectMake(0.0,0.0, self.bounds.size.width, self.bounds.size.height));
CGContextDrawPath(context, kCGPathFillStroke);
CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGPDFPageRef page = CGPDFDocumentGetPage(myPDF, (size_t) pageNum);
CGContextSaveGState(context);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, self.bounds, 0, true);
CGContextConcatCTM(context, pdfTransform);
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
+1  A: 

Preview usually shows a PDF file's crop box, so you should use kCGPDFCropBox instead of kCGPDFMediaBox as the box parameter to CGPDFPageGetDrawingTransform.

However, I have not yet gotten Quartz to actually scale the page up if the crop box is set to a small rectangle.

Norman
Thanks Norman. Based on the few responses I've gotten (yours), this is obviously a very difficult thing to accomplish, or extremely easy and we're both missing something. <sigh>
skantner
A: 

I got an answer for this here

http://stackoverflow.com/questions/3908624/cgcontext-pdf-page-aspect-fit

Anil Sivadas