Create PDF

suggest change
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, nil);

UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
    
[self drawText];
    
UIGraphicsEndPDFContext();

fileName is the path of the PDF file to create or replace.

NSString *temporaryFile = @"firstIOS.PDF";
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString *fileName = [path stringByAppendingPathComponent:temporaryFile];

drawText is:

- (void)drawText
{
 NSString* textToDraw = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";

 CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
 
 CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
 
 CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
 
 CGRect frameRect = CGRectMake(0, 0, 300, 100);
 
 CGMutablePathRef framePath = CGPathCreateMutable();
 
 CGPathAddRect(framePath, NULL, frameRect);
 
 CFRange currentRange = CFRangeMake(0, 0);
 
 CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
 CGPathRelease(framePath);
 
 CGContextRef currentContext = UIGraphicsGetCurrentContext();
 

 CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
 

 CGContextTranslateCTM(currentContext, 0, 450);
 
 CGContextScaleCTM(currentContext, 2, -2);
 
 CTFrameDraw(frameRef, currentContext);
 
 CFRelease(frameRef);
 CFRelease(currentText);
 CFRelease(framesetter);
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents