Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert base64Binary to pdf

Tags:

I have raw data of base64Binary.

string base64BinaryStr = "J9JbWFnZ......"

How can I make pdf file? I know it need some conversion. Please help me.

like image 858
Novice Developer Avatar asked Oct 26 '09 19:10

Novice Developer


People also ask

What is Base64 PDF?

Base64 encoding is used to encode binary data, such as a PDF file, into an ASCII string format that is compatible with systems that can only handle text. For example, email attachments and binary uploads in HTML forms are converted and transmitted as Base64 encoded data.

What is base64binary?

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.


2 Answers

Step 1 is converting from your base64 string to a byte array:

byte[] bytes = Convert.FromBase64String(base64BinaryStr);

Step 2 is saving the byte array to disk:

System.IO.FileStream stream = 
    new FileStream(@"C:\file.pdf", FileMode.CreateNew);
System.IO.BinaryWriter writer = 
    new BinaryWriter(stream);
writer.Write(bytes, 0, bytes.Length);
writer.Close();
like image 96
MusiGenesis Avatar answered Sep 28 '22 05:09

MusiGenesis


using (System.IO.FileStream stream = System.IO.File.Create("c:\\temp\\file.pdf"))
{
    System.Byte[] byteArray = System.Convert.FromBase64String(base64BinaryStr);
    stream.Write(byteArray, 0, byteArray.Length);
}
like image 41
Ralf de Kleine Avatar answered Sep 28 '22 07:09

Ralf de Kleine