javascript - JsPDF .save() 不起作用

标签 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

最佳答案

这是库上的错误/限制,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);

关于javascript - JsPDF .save() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25263605/

相关文章:

ios - Phonegap - 打开/复制 PDF 文件到 iBook

html - 为每个页面 jsPDF 添加一个固定的页眉/页脚

javascript - Ember.js - 管理异步事件和回调

c# - 在Windows Phone 8上从iframe播放YouTube视频

javascript - 动态 jQuery 内容加载

javascript - 使用 IFrame 阻止 URL

javascript - 如何获取 iframe 的innerHTML?

javascript - jsPDF : Uncaught (in Promise) Error: Could not load dompurify: Error: cannot find module 'dompurify' 的问题

javascript - 部分文本未显示在屏幕上。 JavaScript初学者

javascript - 在 Promise 构造函数之外公开 resolve() 和 reject() 有什么缺点吗?