UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIFont *bigFont = [UIFont systemFontOfSize:bigFontSize-2];
NSMutableParagraphStyle *paragraphStyleCenter = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyleCenter.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyleCenter.alignment = NSTextAlignmentCenter;
NSDictionary *bigCenter = @{ NSFontAttributeName: bigFont,NSParagraphStyleAttributeName: paragraphStyleCenter };
CGRect renderingRect = CGRectMake(kMarginInset, kMarginInset -15, (pageSize.width - 2*kMarginInset), stringSize.height);
[tempS drawInRect:renderingRect withAttributes:bigCenter];
This is only a crash when creating a PDF using UIGraphicsBeginPDFContextToFile.
I use the same code for UIView and it works fine.
This works great for iOS7
source
share