使用jspdf以pdf格式添加图像 [英] Add image in pdf using jspdf

查看:8308
本文介绍了使用jspdf以pdf格式添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jspdf将图像转换为PDF。

I am using jspdf to convert an image into a PDF.

我已使用base64encode将图像转换为URI。但问题是控制台中没有显示错误或警告。

I have converted the image into a URI using base64encode. But the problem is that there are no errors or warnings shown in the console.

生成包含文本Hello World但未添加图像的PDF。

A PDF is generated with the text Hello World on it but no image is added in it.

此处是我的代码。

function convert(){
        var doc = new jsPDF();
        var imgData = 'data:image/jpeg;base64,'+ Base64.encode('Koala.jpeg');
        console.log(imgData);
        doc.setFontSize(40);
        doc.text(30, 20, 'Hello world!');
        doc.output('datauri');
        doc.addImage(imgData, 'JPEG', 15, 40, 180, 160);

    }


推荐答案

虽然我我不确定,因为您在添加之前创建了输出,因此可能无法添加图像。尝试:

Though I'm not sure, the image might not be added because you create the output before you add it. Try:

function convert(){
    var doc = new jsPDF();
    var imgData = 'data:image/jpeg;base64,'+ Base64.encode('Koala.jpeg');
    console.log(imgData);
    doc.setFontSize(40);
    doc.text(30, 20, 'Hello world!');
    doc.addImage(imgData, 'JPEG', 15, 40, 180, 160);
    doc.output('datauri');
}

这篇关于使用jspdf以pdf格式添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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