August 04th, 2012
In July I started working on iFXPDFFactory, a new PDF library for iOS and OS X. It is being developed entirely in Objective-C with a native Objective-C public interface.
The reason I started this library is that there is no native Objective-C library for iOS and Mac OS X. PDFKit for Mac OS X, although has an Objective-C interface, is very limited in features and libHaru, PoDoFo and CGPDF* API are all C/C++ based so no ARC or garbage collection. PDFKit is mainly designed to display PDF files, libHaru can only create PDF files, PoDoFo can create and modify PDF files but it has to be built from source code, not a simple thing for novices, and CGPDF* API is a readonly API for reading PDF files at very low level. The graphic context on iOS/OS X lets you also create PDF files but it is limited to graphic features available in all types of graphic contexts so no standard PDF features such as annotations or form fields.
With iFXPDFFactory I plan to fix several of the problems above. It is designed specifically for iOS/OS X and being written in Objective-C lets you take advantage of ARC or garbage collection on OS X. It will support both PDF creation and editing of existing PDF files. Some of the planned PDF features are: multiple colorspaces, fonts, images, vector graphics, form XObjects, annotations, form fields, encryption, content extraction and many more.
The library is in the early stages of development but the basic PDF creation has been implemented. This is how the API looks like:
// Create a new PDF document with an empty collection of pages. IFXPDFDocument* document = [[IFXPDFDocument alloc] init]; // The 'emptyPage' selector returns an autoreleased page object. IFXPDFPage* page = [IFXPDFPage emptyPage]; // Add the page to the document. [document.pages addPage: page]; // Work with the page here // Save the PDF document as a PDF file and release it. [document writeToFile: pathToPdfFile]; [document release];
A more compact version of the code above looks as follows:
// Create a new PDF document with an empty collection of pages. IFXPDFDocument* document = [[IFXPDFDocument alloc] init]; // The 'addEmptyPage' selector creates a page object, // adds it at the end of the pages collection and then returns the autoreleased page object. IFXPDFPage* page = [document.pages addEmptyPage]; // Work with the page here // Save the PDF document as a PDF file and release it. [document writeToFile: pathToPdfFile]; [document release];
This is what I have so far. Over the course of next months I'll keep you posted with the development progress. As soon as a feature becomes available I'll write a post about it.
If you have any questions, feedback, criticism about this library feel free to contact me by posting a comment here.