Take the 2-minute tour ×

I'm trying to convert HTML to PDF on iOS. The first page always looks fine, but then every page after that stops printing to the page higher and higher up. It appears as if the bottom margin is mysteriously growing. I have dug through it numerous times and can't locate what I'm doing wrong.

Here is the primary method where I think the problem is.

- (NSData*) printToPDF
    NSMutableData *pdfData = [NSMutableData data];

    UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil );

    [self prepareForDrawingPages: NSMakeRange(0, self.numberOfPages)];

    CGRect bounds = UIGraphicsGetPDFContextBounds();

    for ( int i = 0 ; i < self.numberOfPages ; i++ )

        [self drawPageAtIndex: i inRect: bounds];


    return pdfData;

You can also see the entire thing here.


share|improve this question
try using UIGraphicsBeginPDFPageWithInfo(pageSize, nil); –  Luke Feb 8 '13 at 16:02
Tried that, the result is the same. –  bigtunacan Feb 9 '13 at 5:00

1 Answer 1

You A4 size is incorrect. As a result margin increases

#define kPaperSizeA4 CGSizeMake(595.2,841.8
share|improve this answer
Wow; digging through some old posts there! This was a bug in the library I was using at the time that has since been fixed. The kPaperSizeA4 is defined within the library, not within my project. At the time it was being defined as CGSizeMake(595, 841) so the imprecision built up over time as the page number grew. –  bigtunacan Oct 13 at 13:31

Your Answer


