0

I created a application which loads a webview inside the app. Its a POS application (Web application) loads inside the webview. But when a receipt in generated, I want to take the screenshot of the receipt. But not the whole page. only that particular container that holds in receipt. How could I achieve that? any Suggestion? My intention is to print receipt by taking the screenshot saving in device and printing.

enter image description here

Jon Goodwin
  • 9,053
  • 5
  • 35
  • 54
Karthik CP
  • 1,150
  • 13
  • 24

1 Answers1

2

You can export needed div or whatever contains a receipt setting its and its children' css to actually used values (see Extract the current DOM and print it as a string, with styles intact).

Then you can just output the element to another WebView for printing.

Anton Malyshev
  • 8,686
  • 2
  • 27
  • 45
  • How could i export this div contents to my android code? – Karthik CP Oct 12 '17 at 09:24
  • Look at the https://stackoverflow.com/questions/4325639/android-calling-javascript-functions-in-webview – Anton Malyshev Oct 12 '17 at 09:27
  • The problem is that i could not edit the server codes! Without editing server codes is there any ways! Completely from android application – Karthik CP Oct 12 '17 at 09:29
  • You don't need to edit server codes, you can execute javascript on the webpage locally and get html out of it. – Anton Malyshev Oct 12 '17 at 09:31
  • Yes i tried that! Using ` webView.loadUrl("javascript:HtmlViewer.showHTML" + "(document.getElementsByClassname('pos-center-align')[0].innerHTML);");` – Karthik CP Oct 12 '17 at 09:34
  • But this works in page reloads! But in POS page URL doesnt change on navigation! Url remains same! Everything works like jquery pages! Even if internet is off this page works – Karthik CP Oct 12 '17 at 09:34