gpt4 book ai didi

javascript - 快速打印 HTML5 Canvas

转载 作者:太空狗 更新时间:2023-10-29 13:32:50 26 4
gpt4 key购买 nike

我想将 Canvas 图像直接发送/打印到默认打印机。这意味着快速打印。

任何人都可以给出提示。

Javascript 或 jQuery。

最佳答案

我搜索了很多并找到了一个完美的解决方案:)使用onclick事件

function printCanvas()  
{
var dataUrl = document.getElementById('anycanvas').toDataURL(); //attempt to save base64 string to server using this var
var windowContent = '<!DOCTYPE html>';
windowContent += '<html>'
windowContent += '<head><title>Print canvas</title></head>';
windowContent += '<body>'
windowContent += '<img src="' + dataUrl + '">';
windowContent += '</body>';
windowContent += '</html>';
var printWin = window.open('','','width=340,height=260');
printWin.document.open();
printWin.document.write(windowContent);
printWin.document.close();
printWin.focus();
printWin.print();
printWin.close();
}

关于javascript - 快速打印 HTML5 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12809971/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com