tags:

views:

676

answers:

4

I have raw data of base64Binary.

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

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

+1  A: 

All you need to do is run it through any Base64 decoder which will take your data as a string and pass back an array of bytes. Then, simply write that file out with pdf in the file name. Or, if you are streaming this back to a browser, simple write the bytes to the output stream, marking the appropriate mime-type in the headers.

Most languages either have built in methods for converted to/from Base64. Or a simple Google with your specific language will return numerous implementations you can use. The process of going back and forth to Base64 is pretty straightforward and can be implemented by even novice developers.

Mike Clark
+1  A: 

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();
MusiGenesis
Invalid length for a Base-64 char array. in setp 1
Novice Developer
@novicedeveloper: that usually means there's some weird character(s) in your string that make it an invalid Base-64 string. Do you happen to have two double quotes (`""`) at the end of the string?
MusiGenesis
Or is this string being passed to an ASP.Net page in the querystring?
MusiGenesis
I am not passing it in querystring.
Novice Developer
+1  A: 

Use System.Convert.FromBase64String

        using (var f= System.IO.File.Create("c:\\file.pdf") )
        {
            var b = Convert.FromBase64String(base64BinaryStr);
            f.Write(b,0,b.Length);
        }
rdkleine
A: 

EUREKA !!!

base64BinaryStr - from WEB SERVICE SOAP message

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

EUREKA !!!

BinaryTank