#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
CGContextStrokePath(context);
}
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.