Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grandM

macrumors 68000
Original poster
Oct 14, 2013
1,551
309
Hi

I'm looking for a library. This library would make it easy to generate PDF from data in my CoreData setup. I would prefer it being in swift. I have been fumbling around with a tutorial of raywenderlich. This allowed me to create PDF's on a rudimentary level using Core Text. It works and I'll gladly share it with you. Problem is it lacks a lot of functionality I'm looking for. For instance it seems I would have to calculate when to create a new page. I also doesn't break up text. I have been googling but did not find anything useful. Certainly nothing that I understood.

So I wondered if any of you knew a good library easy to implement?

Thanks!
 
Two I know of are PDFGenerator and SimplePDF. Both are in Swift. You can find them on Cocoapods of github.
 
@grandM, SimplePDF looks like it will paginate text for you. Even if you don't use that class you should look at the code it uses to draw attributed strings, which paginates the string using Core Text.
 
@grandM, SimplePDF looks like it will paginate text for you. Even if you don't use that class you should look at the code it uses to draw attributed strings, which paginates the string using Core Text.
Thanks I winded up writing my own class. The only thing I'm still wondering about is if I have to manually release memory? I'm using Core Text. But in the tutorial there were things like
Code:
CFRelease(frameRef)
CFRelease(stringRef)
CFRelease(framesetter)
CGPathRelease(framePath)
Or are these no longer needed with ARC?
 
If you're writing this code in swift then you don't need the CFRelease() calls. This is not because of ARC but rather that the swift versions of these method calls return swift objects, that are automatically memory managed.

If you're writing in Objective-C it's probably different.
 
  • Like
Reactions: grandM
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.