PDF And Salesforce B2C Commerce Cloud

Download,Pdf,File.,Group,Of,People,With,Pdf,Document,And

Everyone knows PDF, right? It has been around for many years, and it has been the go-to file format to transfer text documents. And within the e-commerce space, this has not been that different:

  • Invoices
  • Coupons
  • Gift Cards
  • Entry-Tickets

These are just a few of the example use-cases to which you would want to provide PDF files to your consumers through your website.

The problem (untill now)

When we look at the history of Salesforce Commerce Cloud, anything that had to do with file generation was challenging (except XML, CSV, or plain text).

And it is no secret that the reason for this is the back-end system hidden behind the Rhino engine. It may be Java, but not all of the magic that Java offers is exposed to the developers.

What could we do until now to resolve this “limitation”? Well, not much, and we would have to look towards third-party services or generate these PDF files client-side with a Node module.

The solution

As luck would have it, one of the “solutions” I had used until now was generating the PDF files client-side using jsPDF created by Parallax. Although the effort you have to make to create complex PDF files is relatively high, it gets the job done wonderfully.

Thanks to Oleg Sapishchuk for looking into this. It turns out that an older version of this plugin (with minor modifications) is compatible with the Rhino engine!

After reading that message on the Unofficial Slack, I could not contain myself to try this out. And what do you know, only an hour later, I had a working prototype that would generate a PDF server-side and render it on the client-side on the fly!

A few hours later, I found 15 minutes to spare and created a working job step using the same methodology to save it on the WebDAV rather than generate it on the fly.

And not to worry, these examples, together with the library, are available here to download and try out yourself.

An example of code using jsPDF and the resulting PDF preview on the right.

With great power, comes great responsibility

Now with all things, and especially when working with sensitive personal data, you need to think before you do.

Legislation

One of the first replies on my LinkedIn post was by Jordane Bachelet, a Senior Technical Architect working for Salesforce. When generating certain types of files like Invoices, you need to think about the legislation of the countries you are operating.

The example given in this case was France, where you must keep your invoices for ten years. And with every change you make to the invoice, a new copy has to be generated. But what does this mean?

  • On-The-Fly: This is no longer an option as you are not persisting the generated invoice yourself, so this needs to be stored somewhere before giving it to the consumer to be in line with the local legislation.

  • Storing it on the WebDAV: Within the world of Commerce Cloud, this is also not the best option as this kind of information should be kept somewhere closer to your invoicing system. Also, keeping all your generated invoices on B2C Commerce for ten years is too long to stay over there. It is your commerce platform, not your finance platform.

Looking at the above statements, it seems more sense to let something else take care of these invoices! But this will, again, depend on where you operate and what the rules of engagement are.

GDPR

Now let us look at a completely different beast than before, GPDR! As with most developers and architects, just hearing about GDPR will bring tears of joy to your eyes! No?

With rules like the “right to be forgotten,” using on-the-fly generation starts to make more sense. Since none of the files are stored somewhere, you do not have to take them into account when cleaning someone’s data that wants to be “forgotten.”

Think before you do

As mentioned before, generating PDF files both on the fly or storing them through a Job are great new features available to us in the SFCC world, but use this new tool with care!

Table of Contents

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More From My Blog

Let’s GO-LIVE: eCDN

So, you want to set a website live on Salesforce B2C Commerce Cloud. It is all relatively new to you, but your task is to

Read More »

Let’s GO-LIVE: SEO

When going live with a website, SEO is an integral part that should not be overlooked. It is a long-term strategy that should be started

Read More »