3

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?

jlstrecker
  • 4,953
  • 3
  • 46
  • 60

2 Answers2

2

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.

Community
  • 1
  • 1
Ed Kirk
  • 583
  • 1
  • 4
  • 9
  • Well, it's not the miraculous solution I was hoping for, but I guess printing is just not easy in Android yet. Thanks for the pointer to the other answer, too -- `Canvas.toDataURL` looks intriguing. – jlstrecker May 04 '12 at 17:43
0

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

SteelBytes
  • 6,905
  • 1
  • 26
  • 28