To answer your question and for anyone else who happens to read this, I do not think you should ever want to do this because the amount of support effort and risk of corrupting data is far outweighed by having this handled on the sending side, which should be an easy task as it is probably just some reconfiguration at most. You really should have your sender send non-encoded and HL7 escaped data if that is how you want to forward it on.
I feel like by doing it within Cloverleaf code, even when you get it working it is just a bandaid compared to having your sender do it.
With that said, to get your incoming data out of base64 is pretty simple in TCL… simply add this command (to any scripting location you want, probably even within an Xlate copy?):
set unencodedData [decode $base64encodedinput ]
That is the easy part. If you were to dump $unencodedData into a file, say “output.pdf” you would see your document.
However, as Jim says above, continuing that data as HL7 is another story. You will now have a document that needs to be prepared/escaped for HL7 before it can be forwarded (escape ampersands, backslashes, handle spacing, etc). Pretty much all of David’s code above is to handle this piece.
Good luck!