AC TIP | Convert Base64 to PDF in delivery

in  ACC Tips & Tricks, Adobe Campaign
1 minute read

Today I have a quick tip on how to convert data encoded in Base64 to PDF using JSAPI in Adobe Campaign Classic. AC can not directly attach Base64 attachment to the email:

data:applcation/pdf;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
    AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
        9TXL0Y4OHwAAAABJRU5ErkJggg=="

For this we need to first decode incoming file with the use of memory buffer and save it as file. Then such file can be referenced while attaching files for each recipient dynamically.

There are not much of practical examples on almost all functions described within JSAPI documantation, but a little bit of googling around I have found a nice example for memory buffer

var memBuff = new MemoryBuffer(),
    f = new File("path/to/export/test.pdf");

memBuff.appendBase64('JVBERi0xLBzb ... Cg==');

f.open("a");
f.writeln(memBuff.toString());
f.close();