(Objective-C) PDF File Encoding to Base64
Demonstrates how to encode a PDF file to base64, and then decode.
#import <CkoBinData.h>
#import <NSString.h>
CkoBinData *pdfData = [[CkoBinData alloc] init];
BOOL success = [pdfData LoadFile: @"qa_data/helloWorld.pdf"];
if (success != YES) {
NSLog(@"%@",@"failed to load PDF file.");
return;
}
// Encode the PDF to base64
// Note: to produce base64 on multiple lines (as it would appear in the MIME of an email),
// pass the string "base64_mime" instead of "base64".
NSString *b64 = [pdfData GetEncoded: @"base64"];
NSLog(@"%@",b64);
// Decode from base64 PDF.
CkoBinData *pdfData2 = [[CkoBinData alloc] init];
[pdfData2 AppendEncoded: b64 encoding: @"base64"];
success = [pdfData2 WriteFile: @"qa_output/helloWorld2.pdf"];
if (success != YES) {
NSLog(@"%@",@"failed to write PDF file.");
return;
}
|