I am trying to generate a PDF file out of the banana dashboard.
I have made the following changes to the files:
- Added a div id to the main div in index.html file
<div ng-view id="myDiv"></div>
- Added two js files necessary for PDF generation into
vendorfolder of banana application
html2canvas.js
pdfmake.js
Updated the
require.config.jsfile to point to these two new js files as below:html2canvas: ../vendor/html2canvas,pdfmake: ../vendor/pdfmakeUpdated the
dashLoader.htmlfile to include another item in the showdown list as 'Export to PDF'
<li ng-show="dashboard.current.loader.save_local">
<a href="" alt="Export to File" title="Export to PDF" class="link" ng-click="dashboard.to_pdf()">
<i class="icon-download"></i> Export to PDF</a>
<tip>Export layout and data to PDF file</tip>
</li>
Finally updated the
dashboard.jsfile as below:this.to_pdf = function () { var inclusions = document.getElementById('myDiv'); console.log(inclusions); html2canvas(inclusions).then(function(canvas) {//this line is throwing error as html2canvas is not defined inclusions.appendChild(canvas); data_1 = canvas.toDataURL(); resolve(data_1); console.log(inclusions); }); return true; };
But when I click on the Export to PDF option I get the error “Error: html2canvas is not defined”. Please refer the screenshot attached.
Any help on where I am going wrong would be very thankful!

A standalone Hello World html2canvas html program helped to fix this. The correct way to invoke html2canvas and then pdfmake (or any other pdf generation library) is as below: