Kex Kex - 4 months ago 37
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!

//to convert pdf to NSData
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"test.pdf"]; 
NSData *myData = [NSData dataWithContentsOfFile:pdfPath];