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