Creating a PDF on iOS

I’m amazed at how easy it is to create a PDF on iOS.

CGRect pageRect = CGRectMake(0, 0, 850, 1100);
UIGraphicsBeginPDFContextToFile(outputFlePath, pageRect, nil);
CGContextRef pdfContext = UIGraphicsGetCurrentContext();

[self drawMyPageInContext:pdfContext];


That’s it. You’ll have a PDF in the file identified by outputFilePath that has whatever you drew in the drawMyPageInContext method. Beautiful.