Support Portal

for ProcessRobot and WinAutomation

Start a new topic

Save data in variable as Binary File

I'm pulling my hair out trying to work on a solution to a problem I never imagined would exist!  Anyone with an idea of what I should be doing please help!


I have downloaded a PDF document encoded in Base64 - which I have stored in a variable.


To create a PDF I need to save the data I have in the variable as a 'binary file', has anyone came across this problem before and has a solution that they could share?



Well spotted!  By the way I'm only using that website to verify the Base64 supplied by a courier's API works and can be turned into a PDF.


I've tried your suggestion... I have a feeling it would have worked - however I think my Base64 string might be too long for PowerShell.. I'm getting this message:

image


Hi David,


Please recheck your input base64, the total length of string should be divisible by 4. Most of the time equal signs are placed on the end to pad the string if it is not divisible by 4 (i.e., YWJjZGVmPT0=). Remove trailing spaces before and after. That error means you have given a string of unqualified length to be considered as base64. I have tried it now on my pc, since I got to the office, and it worked as expected.

image


Just copy and pasted the contents of the text file you provided (BASE64 PDF.txt).

Note: I have no WinAutomation software available. Just relaying info from experience.

Hope you make it work.

Regards,
Lean


1 person likes this

That makes sense. Then the original generated pdf file is actually encoded in iso-8859-1. It may be pure luck, but I somehow consider it and use that charset for the second decoding in that ps script. But hey, it works. Hope you make it work, I will not be replying anytime soon since its office hours. --- Lean


1 person likes this

Lean, I can't thank you enough!!  Tried, tested and WORKING!!


I've spent over 72hrs trying to find a solution - learning new things all along the way!  I'd given up on Powershell until you mentioned it again - yet now I can't imagine that there is a better way of achieving it!


Thanks again!!!!!!!!!!!!!


Dave

Glad to hear it finally worked out. It just so happen that we have the same use case. And I went the same, just a tad longer, 4days of research back then. Happing coding. Regards, Lean
Login or Signup to post a comment