Search code examples
javascripthtmlpdfjspdfhtml2canvas

Error : ArrayBuffer is undefined


I am using html2canvas and jsPDF to export a div to PDF, is working on Google Chrome , Firefox and IE 11, but in versions 9 and 10 of IE is giving error: ArrayBuffer is undefined.

CODE:

function exportPDF(relatorio){

 var form = $(relatorio);

 var cache_width = form.width();

 var a4  =[ 595.28,  841.89];  

 getCanvas(form).then(function(canvas){

     var imgData = canvas.toDataURL('image/png');

     var imgWidth = 210; 

     var pageHeight = 295;  

     var imgHeight = canvas.height * imgWidth / canvas.width;

     var heightLeft = imgHeight;

     var doc = new jsPDF('p', 'mm');

     var position = 0;

     doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);

     heightLeft -= pageHeight;

     while (heightLeft >= 0) {

       position = heightLeft - imgHeight;

       doc.addPage();

       doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);

       heightLeft -= pageHeight;

     }

     doc.save('relatorioOrcadoRealizado.pdf');
     form.width(cache_width);

 });
}

function getCanvas(form){
 //CONVERT for canvas
 return html2canvas(form,{
     imageTimeout:2000,
     removeContainer:true
    }); 
}

Solution

  • Have look at this link: http://caniuse.com/#feat=typedarrays

    It will show you that ArrayBuffer is not supported in Internet Explorer 9 and only supported with caveats in Internet Explorer 10. This means you'll have to modify the code to use something else (this polyfill here for example: https://github.com/inexorabletash/polyfill/blob/master/typedarray.js) or that you'll have to live with your code not working in IE 9 and/or 10.