I have developed a bar chart using Chart.js library in lighting as standard dashboard doesn't help me to meet my requirements. I want to export to PDF without using any other library.
I tried converting canvas to image(canvas.toDataURL method) and store it in attachment object and retrieve later in PDF. But got an exception (too long url to convert)

Is there a way to export customized chart to PDF.

  • Am not exactly sure, but I read somewhere that Html2canvas can be used to screenshot screen and save as image. html2canvas.hertzen.com Nov 18 '18 at 21:41
  • 2
    Salesforce's only PDF generation functionality is renderAs="pdf" on a Visualforce page. If that doesn't work for your use case - and I would be rather surprised if it did - you'll need to use some other type of functionality, whether that's another library, a document generation app, or an off-platform service.
    – David Reed
    Nov 18 '18 at 21:43

Salesforce's only PDF generation functionality is built around Visualforce pages. A Visualforce page can be set to renderAs="pdf" to always generate PDFs, or you can render a specific Visualforce page references as a PDF using the getContentAsPDF() method (which, incidentally but importantly, counts as a callout).

It's important to know as well that the PDF rendering library used by Salesforce is old and quirky, and lacks support for some modern web standards. I don't believe it supports JavaScript at all, although I cannot say I've tried it myself.

Put shortly, I don't think you have much in the way of options besides using another library, a document generation application, or an off-platform PDF service.

  • Thank you David. Visual force doesn't work with javascript chart rendering. Looking options for libraries now.
    – Alex
    Nov 20 '18 at 20:57

There are not much options are there. you can try client side pdf rendering. Using DomToImage & jsPDF to generate PDF. check this out -> pdf generate


You can use multiple JS lib to achieve this.

Chartjs - To render charts.

DomTOIMage - To convert chart canvas to Image

jsPDF - To create pdf and attach images

Check this post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.