Wider than expected margins with CGContextDrawPDFPage
        Posted  
        
            by skantner
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by skantner
        
        
        
        Published on 2010-03-18T18:17:56Z
        Indexed on 
            2010/03/18
            18:21 UTC
        
        
        Read the original article
        Hit count: 664
        
iphone
|pdf-generation
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?
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);
        © Stack Overflow or respective owner