saravanar saravanar - 1 month ago 9
Objective-C Question

How to convert PDF to binary in Objective C

i have a PDF file, got it from iCloud and want to convert that PDF file to binary.

Code Snippet :

UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@""]
documentPicker.delegate = self;

documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];

#pragma mark - iCloud files
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
if (controller.documentPickerMode == UIDocumentPickerModeImport)
NSString *alertMessage = [NSString stringWithFormat:@"Successfully imported %@", [url lastPathComponent]];

NSLog(@"alertMessage %@",alertMessage);

Using this code i got the PDF file from iCloud. alertMessage got it that PDF file. how can i convert into binary. help me. thanks advance.


You can get a NSData object for NSURL:

[NSData dataWithContentsOfURL: url]

(I have no way to test for you, if it doesn't work you have the get the path: url.path)

and then you can get the binary from NSData with this answer