Skip to content

🔥 Join 600+ readers. Get our newsletter for code and tips.

How To Convert Base64 to PDF attachment
686 views

How To Convert Base64 to PDF attachment

View favourites

In this article, I will provide a simple trick for converting Base64 encoded data to PDF using JSAPI in Adobe Campaign Classic. Due to AC’s inability to attach Base64-encoded files directly to emails, this method can prove to be highly useful.

Base64 data format that would be easy to use when supperted by Adobe Campaign Classic:

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

To accomplish this task, we must first decode the incoming file using a memory buffer and save it as a file. Once saved, we can then reference the file while attaching it dynamically for each recipient.

While there may not be many practical examples of the functions outlined in the JSAPI documentation, with some online research, I was able to locate a helpful example for using a memory buffer.

A memory buffer is a data structure that is used to store data temporarily in computer memory. It is a contiguous block of memory that can be accessed and manipulated like an array, but its size can be dynamically adjusted as needed.

Memory buffers are commonly used in programming languages like JavaScript to manipulate and process binary data such as images, audio files, and PDFs.

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();

This script creates a new memory buffer object called “memBuff”. It also creates a new file object called “f” and assigns it the file path “path/to/export/test.pdf”.

The script then appends Base64 encoded data to the memory buffer using the “appendBase64” method.

Next, the file is opened with the “open” method in “append” mode (“a”), which means the data will be added to the end of the file. The memory buffer is then converted to a string using the “toString” method and written to the file using the “writeln” method. Finally, the file is closed using the “close” method.

In summary, this script reads Base64 encoded data from a memory buffer and writes it to a file in PDF format.

Oh hi there đź‘‹
I have a SSJS skill for you.

Sign up now to get an SSJS skill that can be used with your AI companion

We don’t spam! Read our privacy policy for more info.

Share With Others

The author
Marcel Szimonisz Platinum

Marcel Szimonisz

Marketing Automation Consultant

I specialize in solving marketing technology challenges, automating processes, and turning ideas into practical solutions with Salesforce Marketing Cloud and Adobe Campaign. Through MarTechNotes, I share technical guides and insights that make complex topics easier to understand

Latest badges
Weekend Regular Weekend Regular Profile Complete Profile Complete Simple Start Simple Start 5 Day Streak 5 Day Streak First Comment First Comment

Your email address will not be published. Required fields are marked *

Get exclusive tips, scripts and news

Choose your topics

We don’t spam! Read our privacy policy for more info.

Similar posts

Add to this article

Share your experience

Your contribution

Article history

What changed