简体   繁体   English

在jsPDF从PNG转换为JPEG时显示透明背景

[英]Displaying transparent background in conversion from PNG to JPEG for jsPDF

I am using jsPDF to convert images within canvas to toDataURL() . 我正在使用jsPDFcanvas图像转换为toDataURL() Specifically I am dealing with PNG 's that once converted to JPEG and saved to a PDF file using the jsPDF plugin. 具体来说,我处理的是PNG ,一旦转换为JPEG并使用jsPDF插件保存为PDF文件。 I recieve a black background. 我收到黑色背景。 I know this has to do with the PNG being able to handle transparent backgrounds and JPEG unable to register that. 我知道这与PNG能够处理透明背景而JPEG无法注册有关。 I know there are work arounds by creating some sort of background to replace the black background already inserted within that newly created JPEG but I am not sure how I can accomplish this? 我知道可以通过创建某种背景来替换已经插入到该新创建的JPEG的黑色背景来解决该问题,但是我不确定如何做到这一点?

Suggestions, thoughts? 建议,想法?

Heres what I am doing: 这是我在做什么:

       $(".email_button").click(function(){
            // LOOP THROUGH EACH CANVAS SECTION AND STORE THE DATA INTO PDF FORM USING JSPDF CONVERT 
            var canvas = $(".ifp_container_printing_15 canvas").get();
            var imgData = canvas[0].toDataURL('image/jpeg');
            console.log(imgData);
            var doc = new jsPDF();
            doc.addImage(imgData, "JPEG", 60,50);           
            doc.output('dataurlnewwindow');
        });

Try: 尝试:

var canvas = $(".ifp_container_printing_15 canvas").get(0);
var imgData = canvas.toDataURL('image/jpeg');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM