javascript – 快速打印HTML5画布

前端之家收集整理的这篇文章主要介绍了javascript – 快速打印HTML5画布前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将画布图像直接发送/打印到默认打印机.这意味着快速打印.

任何人都可以提示.

Javascript或jQuery.

解决方法

搜索了很多,找到了一个完美的解决方案:)
使用onclick事件
  1. function printCanvas()
  2. {
  3. var dataUrl = document.getElementById('anycanvas').toDataURL(); //attempt to save base64 string to server using this var
  4. var windowContent = '<!DOCTYPE html>';
  5. windowContent += '<html>'
  6. windowContent += '<head><title>Print canvas</title></head>';
  7. windowContent += '<body>'
  8. windowContent += '<img src="' + dataUrl + '">';
  9. windowContent += '</body>';
  10. windowContent += '</html>';
  11. var printWin = window.open('','','width=340,height=260');
  12. printWin.document.open();
  13. printWin.document.write(windowContent);
  14. printWin.document.close();
  15. printWin.focus();
  16. printWin.print();
  17. printWin.close();
  18. }

猜你在找的JavaScript相关文章