一直报错onrendered option is deprecated, html2canvas returns a Promise with the canvas as the value!如下图
图片说明
6条回答 默认 最新
- fangBlood 2018-10-11 19:43关注
js代码
$("#btn_upload4").click(function () { var filename = 1+ "_fansImages.pdf"; // 将 id 为 Modal5 的 div 渲染成 canvas html2canvas(document.getElementById("Modal5"), { // 渲染完成时调用,获得 canvas onrendered: function(canvas) { // 从 canvas 提取图片数据 var imgData = canvas.toDataURL('image/jpeg'); var canWidth = canvas.width; var canHeight = canvas.height; var arrDPI = js_getDPI();//获取显示器DPI var dpiX = 96; var dpiY = 96; if(arrDPI.length>0){ dpiX = arrDPI[0]; dpiY = arrDPI[1]; } // var doc = new jsPDF("p", "mm", "a4"); var doc = new jsPDF('', 'in', [(canWidth+10)/dpiX,(canHeight+10)/dpiY]);//设置PDF宽高为要显示的元素的宽高,将像素转化为英寸 // doc.addImage(imgData, 'JPEG', 0, 0,210,297); doc.addImage(imgData, 'JPEG', 0, 0,0,0); doc.save(filename); }, background : "#f7f7f7" //设置PDF背景色(默认透明,实际显示为黑色) }); })
html代码
<div class="modal fade" id="Modal5" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="z-index: 1050;"> <div class="modal-dialog modal-lg" > <div class="modal-content" style="width:1000px;margin-left:-5%" > <div class="modal-header" style="height:60px"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel" style="float:left ;">正太分析图</h4> <button type="button" class="btn btn-default" style="background-color:#337ab7;color:#fff;margin-top:3px;float:right" id="btn_upload4" >打印正太图</button> </div> <!--startprint--> <div class="modal-body"> <div class="ibox" > <div style="width:21%;height:40%; float:left; border:1px solid;margin-top:30px" > <p style="text-align: center;">Process Data</p></br> <div class="col-md-6">LSL:</div> <div class="col-md-6"><span id="lsl"></span></div> <div class="col-md-6">Target:</div> <div class="col-md-6"><span id="Target"></span></div> <div class="col-md-6">USL:</div> <div class="col-md-6"><span id="USL"></span></div> <div class="col-md-6">SampleM:</div> <div class="col-md-6"><span id="SM"></span></div> <div class="col-md-6">SampleN:</div> <div class="col-md-6"><span id="SampleN"></span></div> <div class="col-md-6">Within:</div> <div class="col-md-6"><span id="Within"></span></div> <div class="col-md-6">Overall:</div> <div class="col-md-6"><span id="Overall"></span></div> </div> <!-- echart图 --> <div id="main" style="width: 500px;height:300px;background-color: #ffffff;margin: 0 auto"></div> <div style="width: 22%;height:20% ; float:right;margin-top:-31%;"> <div style="border:1px solid;width:150px;height:50px"> <p>————With in</p> <p>—— ——Over all</p> </div> <div style="border:1px solid;width:200px;height:150px;margin-top:5px"> <p style="text-align: center;">Potential(Within)Capabilitys</p> <div class="col-md-6">Cp:</div> <div class="col-md-6"><span id="Cp"></span></div> <div class="col-md-6">CPL:</div> <div class="col-md-6"><span id="CPL"></span></div> <div class="col-md-6">CPU:</div> <div class="col-md-6"><span id="CPU"></span></div> <div class="col-md-6">CPK:</div> <div class="col-md-6"><span id="CPK"></span></div> <div class="col-md-6">CCPK:</div> <div class="col-md-6"><span id="CCPK"></span></div> </div> <div style="border:1px solid;width:200px;height:150px;"> <p style="text-align: center;">Overall Capability</p> <div class="col-md-6">Pp:</div> <div class="col-md-6"><span id="Pp"></span></div> <div class="col-md-6">PPL:</div> <div class="col-md-6"><span id="PPL"></span></div> <div class="col-md-6">PPU:</div> <div class="col-md-6"><span id="PPU"></span></div> <div class="col-md-6">PPK:</div> <div class="col-md-6"><span id="PPK"></span></div> <div class="col-md-6">CPM:</div> <div class="col-md-6"><span id="CPM"></span></div> </div> </div> <div class="content" style="width: 100%;height:20%;margin-top: 8%;"> <div id="right" style="border:1px solid;width:225px;height:130px;margin-top:5px"> <p style="text-align: center;">O bserv ed Performnance</p> <div class="col-md-6">PPM < LSL:</div> <div class="col-md-6" style="text-align:center"><span id="ppmlsl" ></span></div> <div class="col-md-6">PPM > USL:</div> <div class="col-md-6" style="text-align:center"><span id="ppmtotal" ></span></div> <div class="col-md-6">PPM Total:</div> <div class="col-md-6" style="text-align:center"><span id="ppmusl" ></span></div> </div> <div id="mid" style="border:1px solid;width:225px;height:130px;margin-top:5px;"> <p style="text-align: center;">Exp.Within Performance</p> <div class="col-md-6">PPM < LSL:</div> <div class="col-md-6" style="text-align:center"><span id="ppmlsls" ></span></div> <div class="col-md-6">PPM > USL:</div> <div class="col-md-6" style="text-align:center"><span id="ppmtotals" ></span></div> <div class="col-md-6">PPM Total:</div> <div class="col-md-6" style="text-align:center"><span id="ppmusls" ></span></div> </div> <div id="left" style="border:1px solid;width:225px;height:130px;margin-top:5px"> <p style="text-align: center;">Exp.Overall Performance</p> <div class="col-md-6">PPM < LSL:</div> <div class="col-md-6" style="text-align:center"><span id="ppmlsl1" ></span></div> <div class="col-md-6">PPM > USL:</div> <div class="col-md-6" style="text-align:center"><span id="ppmtotal1" ></span></div> <div class="col-md-6">PPM Total:</div> <div class="col-md-6" style="text-align:center"><span id="ppmusl1" ></span></div> </div> <div id="passTital" style="border:1px solid;width:165px;height:130px;margin-left:5px;margin-top:5px;float:left"> <p style="text-align: center;">Percent Of Pass</p > <div class="col-md-6">PASS:</div> <div class="col-md-6" style="text-align:center"><span id="pass" ></span></div> </div> </div> </div> </div> </div> <!--endprint--> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal --> </div>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥25 Android上传文件报错 java.net.SocketException: Broken pipe
- ¥15 有关汽车的MC9S12XS128单片机实验
- ¥15 求c语言动态链表相关课程有偿,或能将这块知识点讲明白
- ¥15 FLKT界面刷新异常
- ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
- ¥50 单细胞测序拟时序分析
- ¥50 运行springboot项目报错
- ¥15 FTP 站点对站点传输失败
- ¥15 宝塔面板一键迁移使用不了
- ¥15 求一个按键录像存储到内存卡的ESP32CAM代码