jsPDF:fromHTML与addHTML [英] jsPDF: fromHTML vs addHTML

查看:1312
本文介绍了jsPDF:fromHTML与addHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导出html(具有ID的div内),并设法使用fromHTML()做到了这一点,但是不幸的是,它没有读取/使用我拥有的任何CSS.这就是说,我尝试使用addHTML函数,但是当我使用以下代码时,似乎没有任何反应:

I'm trying to export an html(within a div with ID), and have managed to do so with fromHTML(), but unfortunately it doesn't read/use any css I have. This said, I tried with addHTML function, but it looks like nothing happens when I use following code:

function pdfExport(id) {
    window.html2canvas = html2canvas;
    var dddoc = new jsPDF('p', 'px', 'a4');
    var elem_to_export = $("#cmodal-id-" + id)[0];

    dddoc.addHTML(document.body, function(){
        console.log('saving');
        dddoc.save('test.pdf');
    });
}

此外,请注意,我没有将任何内容打印到控制台中.不确定是否值得:在运行此函数pdfExport()之前-(运行onclick)-在js控制台中出现get get错误,因为该图像不存在.现在,当我运行该函数时,再次出现相同的错误,就像试图再次加载该图像一样.

Also, note that I don't get anything printed into console. Not sure if it's worth anything: Before I run this function pdfExport() - (it's ran onclick) - I get one get error in js console, as said image doesn't exist. Now, when I run the function, same error appears again, just as if that image is tried to be loaded again.

推荐答案

这不起作用,因为我同时使用了html2canvas和jsPDF的最新版本.当我将其更改为从以下位置加载时:

This wasn't working because I used latest versions of both html2canvas and jsPDF. When I changed those to load from:

' https://cdnjs.cloudflare. com/ajax/libs/jspdf/1.0.272/jspdf.debug.js ', ' https://cdnjs.cloudflare.com/ajax/libs /html2canvas/0.4.1/html2canvas.js '

一切正常.

这篇关于jsPDF:fromHTML与addHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆