Need a special offer?Find out if your project fits.
+

cannot export to image/pdf - html2canvas/jspdf is not defined despite files being loaded

Answered
Yousif Ahmed asked on March 22, 2019

Hello,
I have been trying to get image/pdf exports working, but I always get an error 'html2canvas is not defined'. Initially I thought I needed to include these libraries myself for this to work, but then I saw that flexmonster ships with a lib/ directory containing these libraries already, and in the examples on your website it seems to be working without any additional setup.
I'm pretty sure I've set the componentFolder property correctly as the toolbar is displaying, and when I attempt to export the pivot I can see in the debugger that html2canvas.js is being loaded from flexmonster/lib/, but I still get the same error message.
We are using requirejs to manage modules in our app, and both html2canvs and jspdf have UMD functions that register the module using define(), however it seems like the pivot exports only work if these libraries are defined as globals? Since these libraries dont create globals by default this seems a bit odd, and the only way I have found to make it work is to force this with:

window["html2canvas"] = require("html2canvas")

This seems like a bug to me, or am I missing something? Does flexmonster have support for AMD modules or will we have to work around it by forcing those libraries to be global using the code above?
 
Kind regards,
 
Yousif

1 answer

Public
Tanya Gryshko Tanya Gryshko Flexmonster March 22, 2019

Hello, Yousif,

Thank you for posting your question.

It seems that this issue is closely connected to the following one: https://www.flexmonster.com/question/flexmonster-deployment-via-gulp-build/. Please check our answer there.

Please let me know in case of further questions.

Regards,
Tanya

Please login or Register to Submit Answer