Salesforce, as a technology platform, has come a long way in the past decade or so, incorporating the latest technology trends eventually but surely. Be it moving to Lightning Experience or adopting the ES6 compliant Lightning Web Components, Salesforce has tried to keep the developer experience in mind as well while reshaping the customer experience.
But one problem that has remained constant over the years is the ability to generate PDFs, especially if there is a need to incorporate charts in them. Imagine a requirement where utilization graphs have to be embedded in an invoice PDF before emailing it to a client or a bar chart showing comparison between the subscribed quantities from last year and this year have to be included in a PDF.
As developers, all of us would have faced this one time or the other and would have scoured the ends of the internet to find native Salesforce solutions to achieve this seemingly innocuous requirement, just to discover this immense white space – there is no native solution to do this!
So, in case you are dealing with the same conundrum, here are the top approaches that might help you this festive season:
Approach 1: Generate and Save Visualforce Charts as an image
Sounds simple, right? The downsides do not make it so simple. The PDF generation becomes a two-step process since all the charts have to be rendered on the UI before they can be saved and embedded in the PDF. It also utilizes File storage to save the chart images which then need to be cleaned up later. And, since the charts are converted into a base64 encoded string value before being saved, there is a chance of hitting the string character limit if the chart is complicated enough.
Approach 2: Using Chart-to-Image libraries / tools
Online tools like Google Image Charts, Image-Charts or QuickChart provide GET / POST based solutions which provide chart images in response to chart parameters and data provided as part of the request. These images can then be inserted into the Visualforce page rendered as a PDF.
If you are worried about your data leaving the secure space of Salesforce, this approach will definitely give your security team a nightmare. Also, there are compatibility issues, licensing requirements etc. that need to be considered based on the solution of choice.
Approach 4: AppExchange Solutions
Though there are multiple AppExchange solutions available for document generation, it is not readily evident if all of them support inclusion of charts in the generated documents. One product that does support charting is Conga Composer with the Conga Grid add-on. I mean this was expected – Conga is one of the leaders in the space; it would have been a surprise if they didn’t support this.
However, buying and setting up something like Conga is a costly and time-consuming affair. So, a clear roadmap and utilization scope for such a solution needs to be considered before diving head-first into the procurement process.
This list is certainly not exhaustive. There will be more brilliant solutions developed by the ever-effervescent members of the Salesforce Ohana. Do feel free to share about your experience with PDF generation and how you were able to achieve it. Hopefully, this will be addressed by a more native capability within the platform in the times to come.