Member-only story

PDF Creation in iOS

Mr.Javed Multani
1 min readOct 2, 2020

--

Create PDF

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

fileName is the document file where You are going to append or attach

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

Where 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)…

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet