4
A
回答
18
我寻觅了很多,发现该工程完美的解决方案:) 使用的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();
}
0
2
我发现,我第一次印刷,画布是空白的。我添加了一个事件监听器来等待图像/文档加载。现在画布已准备好每次打印。以下是适用于我的代码:
const dataUrl = document.getElementById('the-pdf-canvas').toDataURL();
let windowContent = '<!DOCTYPE html>';
windowContent += '<html>';
windowContent += '<head><title>Print canvas</title></head>';
windowContent += '<body>';
windowContent += '<img src="' + dataUrl + '">';
windowContent += '</body>';
windowContent += '</html>';
const printWin = window.open('', '', 'width=' + screen.availWidth + ',height=' + screen.availHeight);
printWin.document.open();
printWin.document.write(windowContent);
printWin.document.addEventListener('load', function() {
printWin.focus();
printWin.print();
printWin.document.close();
printWin.close();
}, true);
相关问题
- 1. 打印HTML5画布元素
- 2. 打印出html5画布?
- 3. 打印多页HTML5画布元素
- 4. 打印html5画布的部分
- 5. 在IE6/7中打印HTML5画布
- 6. 画布打印 - wpf
- 7. 如何快速打印groovy.util.slurpersupport.Node?
- 8. 点阵快速打印
- 9. 在c中快速打印#
- 10. IP地址打印(快速)
- 11. HTML5画布测速仪不需要与
- 12. 从Tkinter打印画布
- 13. 打印画布内容
- 14. 从处理打印画布
- 15. 滚动HTML5画布视口进行打印
- 16. 如何用它打印html5画布父div div
- 17. 在Java中使用精确布局的点阵快速打印
- 18. Html5画布动画
- 19. 快速调整大型画布元素
- 20. C#POS快速收据打印
- 21. 打印负美元快速路值
- 22. 快速的Windows控制台打印
- 23. 如何通过终端快速打印?
- 24. 120dpi拧紧快速报告打印
- 25. 通过快速I/O打印long long
- 26. 打印整数到画布快而没有垃圾收集
- 27. Devexpress:快速打印系统 - 打印2 cxgrid的内容
- 28. onmouse画布HTML5
- 29. HTML5画布,GUI
- 30. 从HTML5画布
你有什么问题?打印图像或从画布上获取图像?或两者?请更具体一些。另外,你到目前为止尝试过什么? –
toDataURL(),给我们从画布的图像数据。我想直接发送到打印机。 – Derin