you're reading...
Social Media

#iOS PDF programming isn’t that difficult either. The hard part is to know where to start ;)


I like to create a PDF file in my iPhone app. I then did spent to much time looking at various PDF framework. I didn't want to reinvent anything, but the frameworks I looked at just made things more complicated. So today I started to do it the Apple way, that's using Quartz 2D framework in iOS SDK.

Happily I already have iPhone 4 Development Essesials for XCode 4 in my Kindle, so I started on Chapters 32 and 33, which gives an introduction and lesson in Quarts 2D programming. I started with drawing lines, rectangles and ended up with ellipses. And the code drawing the image wasn't difficult at all:

– (void)drawRect:(CGRect)rect
    // Setting context
    CGContextRef context = UIGraphicsGetCurrentContext();
    // Setting line width
    CGContextSetLineWidth(context, 2.0);
    // Setting color
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
    // Create a rectangle
    CGRect rectangle = CGRectMake(60,170,200,80);
    // Create an ellipse inside
    CGContextAddEllipseInRect(context, rectangle);
    // Draw

Somehow, I can use Quartz 2D to draw text too. That's the task in the next post where I will combine Apple's tutorial and what I've learned about PDF in iOS from Spitzkoff.

About mortjac

Norwegian social entrepreneur, blogger&Swift programmer. PM for the OMG GL standard. Using #ULab to give #Villajoyosa sustainable tourism&tunable pipe organs.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: