Convert Base64 > Binary PDF

Convert Base64 > Binary PDF

  

Hi all,

I am trying to show/download a PDF file which is created from a Base64 string. With the Base64 to Binary API I can create a Binary String and download or open it as an Image in Outsystems without any problems. Unfortunately it is not possible to read it in PDF (Error: Failed to load PDF document). 

Does someone know how I can manage this? 

Thanks in advance

Hi Martijn, have you tried using it?

Hello Martijn,

Are you sure that the Base64 string is not the PDF itself? Because a PDF is not really a "binary" file.

If you open a PDF file in an editor, you will see something like this:

%PDF-1.4
%Ç쏢
5 0 obj
<</Length 6 0 R/Filter /FlateDecode>>
stream
...
endstream
endobj
56 0 obj
...

Are you sure you can't just save it as something.pdf and open it?

Cheers.

PAULO RICARDO FAGUNDES JUNIOR wrote:

Hi Martijn, have you tried using it?

Hi Paulo,

This is what I use. So the binary comes out perfect and I can manage it to download it in .jpg, but unable to open/download it in PDF. 


Eduardo Jauch wrote:

Hello Martijn,

Are you sure that the Base64 string is not the PDF itself? Because a PDF is not really a "binary" file.

If you open a PDF file in an editor, you will see something like this:

%PDF-1.4
%Ç쏢
5 0 obj
<</Length 6 0 R/Filter /FlateDecode>>
stream
...
endstream
endobj
56 0 obj
...

Are you sure you can't just save it as something.pdf and open it?

Cheers.

Hi Eduardo,

Thanks for your reply. I am sure that the string is not PDF itself. The Base64 string looks more like: 

SyntaxEditor Code Snippet

iVBORw0KGgoAAAANSUhEUgAAAJsAAAA8CAYAAABxeMjaAAAKcklEQVR4Ae2ddZAbORPFs7wVZlqOfczMzMzMzMzMzMzMGD4M7H3HzAxhXggv

So I have to convert it to Binary or maybe a different type, but I don't know which that would be. 

Besides that, if I want to download it, my flow ends with a Download statement. The input must be of a Binary Data Type. 



Solution

Hi Martijn,


Ok. PDF in base64 are useful to show in browser, but the PDF file format is not base64, is just "text" (afaik).
So, you need to convert this base64 string back to text...

So, you may need to convert to binary and than from binary to text? (just guessing, as I didn't found any direct conversion from base64 to text).

EDIT:

Ok. Base64 is for see in the browser, for example. Do download you have to convert it to binary. It should work out of the box... Let me try something here...

Confirmed. If your base64 is really a PDF file, converting to binary and download would work out of the box.

See my attached example.

Cheers.

Solution

Hi Eduardo,

Thank you very much. I think I was comparing apples with oranges. I was constantly trying to get an Image converting to PDF with this method. Does not work ofcourse.. I tried with a PDF file and it worked. Seems like it is friday afternoon... 

Your help was much appreciated. 

Have a good one!