Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGPDFDocumentRef from NSData

I get my PDF from SQLite DB into a NSData variable. Now what are my options to create CGPDFDocumentRef from this NSData?

Or what are my options anyway to create this CGPDFDocumentRef, have the data in SQLite?

like image 293
Oleg Danu Avatar asked Feb 02 '11 14:02

Oleg Danu


1 Answers

You can create a PDF document using this function:

CGPDFDocumentRef CGPDFDocumentCreateWithProvider (
   CGDataProviderRef provider
);

To create the provider you can use this function:

CGDataProviderRef CGDataProviderCreateWithCFData (
   CFDataRef data
);

and consider that NSData and CFDataRef are toll-free bridged so you can use them interchangeably.

So summarizing try this:

NSData *data = ... my data from SQLite ...
CFDataRef myPDFData = (CFDataRef)data;
CGDataProviderRef provider = CGDataProviderCreateWithCFData(myPDFData);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(provider);

Don't forget to CFRelease all unused data.

like image 160
viggio24 Avatar answered Nov 01 '22 19:11

viggio24