Sample code for 30+ languages & platforms
Objective-C

PDF File Encoding to Base64

See more Base64 Examples

Demonstrates how to encode a PDF file to base64, and then decode.

Chilkat Objective-C Downloads

Objective-C
#import <CkoBinData.h>
#import <NSString.h>

BOOL success = NO;

CkoBinData *pdfData = [[CkoBinData alloc] init];

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;
}