Sample code for 30+ languages & platforms
Delphi ActiveX

Base64 Encode a File

_LANGUAGE_ to Base64 encode the contents of a file.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
fac: TCkFileAccess;
strBase64: WideString;

begin
success := 0;

// Get the contents of a file into a base64 encoded string:
fac := TCkFileAccess.Create(Self);
strBase64 := fac.ReadBinaryToEncoded('c:/data/something.pdf','base64');
if (fac.LastMethodSuccess <> 1) then
  begin
    Memo1.Lines.Add(fac.LastErrorText);
    Exit;
  end;

// Now write the string to a file:
success := fac.WriteEntireTextFile('c:/data/something_pdf_base64.txt',strBase64,'us-ascii',0);
if (success <> 1) then
  begin
    Memo1.Lines.Add(fac.LastErrorText);
    Exit;
  end;

Memo1.Lines.Add('Success!');
end;