
I built a SVG to PNG rasterizer in pure APEX
Did you know...that you can make pdfs in Salesforce with images?
While in and of itself, that isn't that big of a deal, but when you look at heap limitations of Salesforce you quickly realize that 6MB (sync) isn't a whole lot of pictures, in fact neither is 12MB (async).
They are however vital to produce high quality documents. Salesforce's new blob.topdf() upgrade unlocked some really cool things that allowed us to put in a bunch of images by referencing them in relative URLs that are accessible via the server. Because they are already on the server, no heap is used to use those images.
Knowing that we could do this we decided to take it one step further. What if we could create the images on the fly? And that is what we did, we built a charting engine that is accessible through merge tags. In order to make it look crisp we draw the charts using SVG. Unfortunately Salesforce doesn't process SVG files so we had to take it one step further. We had to build a SVG to PNG rasterizer. So we did...in pure apex.
We can literally make art on the fly and have it show up on your outputted pdf.
Here's the flow:
0.) Install Portwood DocGen https://portwood.dev
1.) Put Merge Tags in Template
2.) SVG Generation from tags
3.) Apex Rasterizer does it's work
4.) PDF Renders
Here are the results:
Disclaimer and pricing: 100% Free, 100% Native, 100% Open Source, I am affiliated with Portwood, but there is no cost for the app...$0. You are able to buy service or implementation but those are 100% optional.