javascript - 快速打印 HTML5 Canvas

标签 javascript jquery html canvas

我想将 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/

相关文章:

javascript - 在框内水平移动垂直线

javascript - 如何强制将焦点设置在输入字段上?

javascript - 在没有调用函数的情况下返回如何在 Javascript 中工作?

javascript - Firebase函数在数据完全获取之前返回

javascript - 如何获取上传的SVG文件对象的内容

JavaScript/jQuery : how to catch a click that targets any element except for several specified elements?

c# - 如何设计我的 C# jQuery API,使其使用起来不会混淆?

javascript - 如何最初隐藏表单,但在屏幕重新加载时呈现表单?

javascript - 取消 componentWillUnmount 方法中的所有 Subscriptions 和 Asyncs,如何?

javascript - 如何在 jQuery Mobile 中动态创建选择菜单?