JsPDF .save()不起作用

时间:2014-08-12 11:52:48

标签: javascript iframe jspdf

此代码让我下载pdf,但在将其放入iframe时会出错:

docNormale.save('Ordini.pdf');
var iframe = document.getElementById('outputPDFnormale');
iframe.style.width = '60%';
iframe.style.height = '650px';
iframe.src = docNormale.output('datauristring');

此代码允许我在iframe中插入pdf,但在下载pdf时出错:

    var iframe = document.getElementById('outputPDFnormale');
    iframe.style.width = '60%';
    iframe.style.height = '650px';
    iframe.src = docNormale.output('datauristring');
    docNormale.save('Ordini.pdf');

两种情况都是相同的错误,它是:Uncaught TypeError:无法读取未定义的属性'toFixed'

我是最新的Chrome

1 个答案:

答案 0 :(得分:2)

这是对lib的错误/限制,save()是一个输出操作,并且不支持两个这样的连续操作atm,所以请随意在他们的问题跟踪器上提交错误:https://github.com/MrRio/jsPDF/issues

同时,这应该有效:

var rawdata = docNormale.output();

var len = rawdata.length,
    ab = new ArrayBuffer(len),
    u8 = new Uint8Array(ab);

    while(len--) u8[len] = rawdata.charCodeAt(len);

var blob = new Blob([ab], { type : "application/pdf" });

saveAs(blob, 'Ordini.pdf');

var iframe = document.getElementById('outputPDFnormale');
iframe.style.width = '60%';
iframe.style.height = '650px';
iframe.src = URL.createObjectURL(blob);