快速打印 HTML5 画布 [英] Quick Print HTML5 Canvas
本文介绍了快速打印 HTML5 画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将画布图像直接发送/打印到默认打印机.这意味着快速打印.
I want to send/print the canvas image directly to the default printer. That means a quick printing.
任何人都可以给出提示.
Anyone can give a hint.
Javascript 或 jQuery.
Javascript or jQuery.
推荐答案
我搜索了很多,找到了一个完美的解决方案 :)使用了 onclick 事件
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屋!
查看全文