Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:12:53+00:00 2026-05-26T14:12:53+00:00

I have a Base64 encoded String that contains PDF data. Using the EncdDecd unit

  • 0

I have a Base64 encoded String that contains PDF data. Using the EncdDecd unit I can decode the String to a Byte Array.

This is where I am having trouble: I tried saving the characters to a String but once it hits a zero value (ASCII = 0 or #0 or $00) the String no longer appends. Example:

uses
  EncdDecd;
var
  EncodedString : String;
  Report : String;
  Base64Bytes: TBytes; // contains the binary data
begin
  Base64Bytes := DecodeBase64(EncodedString);
  for I := 0 to Length(Base64Bytes) - 1 do
    begin
      Report := Report + Chr(Base64Bytes[I]);
    end;

Writing to a text file seems to work better but after renaming it to .PDF the file does not open correctly.

How can I write to a binary file in Delphi? Or even save the data to a stream? Basically I am just trying to take the encoded String and save it to a PDF/binary file, or display the PDF in Delphi.

I have looked around quite a bit and found a possible solution in
Saving a Base64 string to disk as a binary using Delphi 2007 but is there another way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:12:53+00:00Added an answer on May 26, 2026 at 2:12 pm

    This should do it:

    procedure DecodeBaseToFile(const FileName: string; 
      const EncodedString: AnsiString);
    var
      bytes: TBytes;
      Stream: TFileStream;
    begin
      bytes := DecodeBase64(EncodedString);
      Stream := TFileStream.Create(FileName, fmCreate);
      try
        if bytes<>nil then
          Stream.WriteBuffer(bytes[0], Length(bytes));
      finally
        Stream.Free;
      end;
    end;
    

    Note: I have only compiled this in my head.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service that returns a base64 encoded string of a PDF
I have a .NET string which is Base64 encoded representation of an array of
I have an application, currently written in C#, which can take a Base64-encoded string
I have an encrypted, base64 encoded array that I need to put into a
I have a base64 encoded string that I would like to convert into an
I have an function which decodes the encoded base64 data in binary data but
Can Unicode characters be encoded and decoded with Base64 ? I have attempted to
I have a simple question. Should I return a byte-array or simply base64 encode
I have a PHP script that can encode a PNG image to a Base64
I have a binary that I want to convert to standard MIME-compliant base64 string.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.