I'm trying to generate a PDF from a Lightning Page using jsPDF.

When I use the addHTML function in jsPDF I get an error (but only if locker service is enabled). The problem is in the use of html2canvas in jsPDF, I believe in these lines:

var container = containerDocument.createElement("iframe");
var documentClone = container.contentWindow.document;

document is undefined on the contentWindow of the container. Are there any ways around this locker service restriction by editing this html2canvas function?

Or are there any libraries that do allow for either converting html to an image or creating a pdf from html?

  • 3
    Did you consider visualforce render as pdf option
    – RedDevil
    Jun 27, 2018 at 3:25
  • 1
    @RedDevil from what I know, the render as pdf doesn't work very well. I will be in contact with Salesforce soon and will be discussing the possibility of using the 'Advanced render as pdf' which is in pilot at the moment and seems to be a possible solution, but until then I'm looking for other alternatives to printing as pdf.
    – Aequitas
    Jun 27, 2018 at 7:10

1 Answer 1


To get around LockerService restrictions you can use a VisualForce page and then you can create the components from lightning.

See this question for info on how to host lightning components in visualforce.

From there as long as you use apex:includeScript (and URLfor if using a zipped static resource) to include jsPdf and html2canvas, you will be able to call addHtml without locker service restrictions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .