1

I have a web view that displays a fancy bar graph. I need to basically take a screenshot of it (entire HTML document, not just area currently visible in the webview control) and stuff it into a PDF. The HTML file is generated by my app, so I can add anything I want to it. Working with PDF is also not an issue.

The question is how do I go about grabbing rendered HTML document as a bitmap? Ideas on a high level approach would be helpful.

Note that HTML graph is done with DHTML and not canvas, so solution described here does not apply

Community
  • 1
  • 1
Ilia G
  • 10,043
  • 2
  • 40
  • 59
  • 1
    If the second answer to that question -- using `capturePicture()` -- does not apply, then you are out of luck for doing anything on the device, AFAIK. – CommonsWare Jan 04 '13 at 20:05

1 Answers1

0

If you can use stream for generate pdf starting for generated image the path is that:

Picture picture = webView.capturePicture();
Bitmap  b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), 
                                Bitmap.Config.ARGB_8888);

Canvas c = new Canvas( b );        
picture.draw( c );

FileOutputStream out = null;
byte[] byteArchadeImage = null;

try {
    out = new FileOutputStream(new File("/sdcard/snapshot/view-cutted.jpg"));

    if ( out != null ) {
        b.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    }
} catch( Exception e ) {
    Log.e("MSG", e.getLocalizedMessage());    
}          

You can redirect stream for pdf generation with any tool for pdf generate that functioning on android. I believe that iText is one sample for that.