use*_*354 1 javascript google-chrome jspdf
我在尝试预览使用 jsPDF API 生成的 PDF 文件时遇到问题,当我向文档添加超过 3 张图像(每张图像 300-400KB)时,我可以正确下载文档,但无法显示在浏览器中使用 jsPDF 方法:doc.output('dataurlnewwindow')。我的网络浏览器上打开了一个新选项卡,但它是空白的(选项卡顶部显示“正在充电...”,但从未显示。但是,我可以使用 jsPDF 将 PDF 文件下载到我的电脑上,没有任何问题方法: doc.save( this.reportFileName );
您知道为什么会发生这种情况吗?可能是与我需要在网络浏览器中预览的 PDF 文件大小有关的问题?这样做有最大尺寸吗?任何帮助将非常感激。
谢谢!
this.doc = new jsPDF({orientation: "p", unit: "pt", format: "a4"})
// ....
// doing some stuff in the doc file
// adding images of 400 KB aprox. (it works with 3 images... but with 4 or more doesn't
this.doc.addImage('data:image/jpeg;base64,'+ logoFooter, 'JPEG', this.marginLeft+40, 794, 40, 45);
// ....
preview () {
try {
this.doc.output('dataurlnewwindow'); // >> doesn't work and an empty tab is being opened in muy web browser
}
catch(error){
console.log(error);
}
save () {
try {
this.doc.save( this.reportFileName ); // this works fine and the PDF file is being downloaded
}
catch(error){
console.log(error);
},
Run Code Online (Sandbox Code Playgroud)
好吧,我在这里找到了解决方案:https://github.com/parallax/jsPDF/issues/300#issuecomment-49363483
摘要...执行以下操作:
var blob = this.doc.output("blob");
window.open(URL.createObjectURL(blob));
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!
| 归档时间: |
|
| 查看次数: |
1313 次 |
| 最近记录: |