快速打印HTML5画布 [英] Quick Print HTML5 Canvas
本文介绍了快速打印HTML5画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将画布图像直接发送/打印到默认打印机。这意味着快速打印。
任何人都可以提示。
Javascript或jQuery。
解决方案
我搜索了很多,发现了一个完美的解决方案:)
使用 onclick event
function printCanvas()
{
var dataUrl = document.getElementById('anycanvas') .toDataURL(); //尝试使用这个var
将base64字符串保存到服务器var windowContent ='<!DOCTYPE html>';
windowContent + ='< html>'
windowContent + ='< head>< title>打印画布< / 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();
}
I want to send/print the canvas image directly to the default printer. That means a quick printing.
Anyone can give a hint.
Javascript or jQuery.
解决方案
I have searched alot and found a solution which works perfectly :) Used onclick event
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();
}
这篇关于快速打印HTML5画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文