我无法下载带有背景图像的“ jpg / png / pdf”,而只能下载文本。使用JavaScript或jQuery。
<script>
$(document).ready(function() {
var element = $("#html-content-holder"); // 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");
var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
$("#btn-Convert-Html2Image").attr("download", "your_pic_name.png").attr("href",
newData);
});
});
</script>
答案 0 :(得分:0)
此元素“#btn-Convert-Html2Image”应支持“ href”属性,并且应为<a>
您可以将按钮包装到<a>
例如
看这个例子how to save canvas as png image?