How to print a WebView?

江枫思渺然 提交于 2020-01-01 14:38:00

问题


My Android app renders a WebView containing a canvas. Cloud Print wants a PDF. How can I generate a PDF with my WebView to send to Cloud Print?


回答1:


You could first capture the canvas as a png: (taken from stackoverflow answer)

var canvas = document.getElementById("mycanvas");
var img    = canvas.toDataURL("image/png");

Then next step get this into a pdf. I haven't seen a javascript based converter, but one could send the png to a custom web service (perhaps running on Google Apps, Amazon AWS or a traditional hosted machine) which simple returns a pdf. ImageMagick could be used here with a wrapper cgi script or you could use some library. Alternatively it might be possible to do the conversion within the android app.




回答2:


there is also WebView.capturePicture() http://developer.android.com/reference/android/webkit/WebView.html#capturePicture()



来源:https://stackoverflow.com/questions/10320883/how-to-print-a-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!