Kex Kex - 1 year ago 111
iOS Question

Converting a pdf image to NSData for

I am using vector graphics in my application and want to store some on I need to first convert these to NSData before upload. Is it possible to convert a pdf file to NSData?

UIImage *image = [UIImage imageNamed:@"coolImage.pdf"];
NSData *data = UIImageJPEGRepresentation(image);

I know NSData allows for a jpg of png representation but what about pdfs? Any tips on this would be greatly appreciated!

Answer Source
//to convert pdf to NSData
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"test.pdf"]; 
NSData *myData = [NSData dataWithContentsOfFile:pdfPath]; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download