【发布时间】:2020-07-26 20:42:59
【问题描述】:
我已经使用下面的代码成功地将 html 转换为图像,但是字体正在改变并且图像没有显示在图像上。
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://files.codepedia.info/files/uploads/iScripts/html2canvas.js"></script>
</head>
<body>
<div id="div_card" style="border-color:grey;border-style:solid;border-width:1px;width:600px; height:450px; padding:15px;margin-left:40px">
<div style="display:inline-block;height:20px;"> <div id="sp_name"> Author:John Michael Smith Junior</div></div><br>
<div style="display:inline-block;height:120px; width: 120px; float:right">
<img src="htmlimage.jpg" style="height:120px; width: 120px"> </div>
<div style="display:inline-block;height:20px;"><div> Published on March 1982 </div></div><br>
<div style="display:inline-block;height:20px;"> <div> Published by: Mark Vin book house</div></div><br>
<div style="display:inline-block;height:20px;"> <div>Last Edition Dec 1999</div></div><br>
<div style="display:inline-block;height:20px;"> <div>Sold Copies: 150000</div></div><br>
</div>
<a id="btn-Convert-Html2Image" href="#">Download</a>
<br />
<div id="previewImage" style="display: none;">
</div>
<script>
$(document).ready(function () {
var element = $("#div_card"); // global variable
var getCanvas; // global variable
html2canvas(element, {
onrendered: function (canvas) {
$("#previewImage").append(canvas);
getCanvas = canvas;
}
});
$("#btn-Convert-Html2Image").on('click', function () {
var imgageData = getCanvas.toDataURL("image/png");
// Now browser starts downloading it instead of just showing it
var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
$("#btn-Convert-Html2Image").attr("download", "your_pic_name.png").attr("href", newData);
});
});
</script>
</body>
</html>
我需要在不改变字体的情况下获取图像。我该怎么做??????
【问题讨论】:
-
世界上没有人回复
标签: javascript jquery html html5-canvas