We tries to print a webview content over google cloud print, but no matter what we do the resulted printout adds some margin.
Is there a way to remove this margin? We tried:
<body style="margin: 0; padding: 0">
then
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
then
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
none worked...
Use the following code to remove margins when printing the WebView.
@page{
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
margin-bottom: 0px;
}
Just Use It *{margin:0px; padding:0px} Add In Your Style Sheet And Check Once
*{margin:0px; padding:0px}
body,html{padding:0px;margin:0px;}
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
By Default HTML web pages have a padding and margin of 10px; You have to set in your head section or or css file:
<style type="text/css">
html, body {
width:100%;
height: 100%;
margin: 0px;
padding: 0px;
}
It's work for me. Hope it will help you :)
or you can try another one:
Replace your tag with this one:
<body style='margin:0;padding:0;'>
Here's another tip for images in a webview: add a styling that fits images in the width of the screen. Works great on all screen sizes:
<style type='text/css'>
img {max-width: 100%;height:initial;} div,p,span,a {max-width: 100%;}
</style>
If using the css doesn't solve your issue, you can try using a TextView with fromHtml instead of using a webview:
TextView myTextView = (TextView) view.findViewById(R.id.my_textview);
Spanned textviewHtml;
//Note : fromHtml needs a display flag as second argument from API 24
if (Build.VERSION.SDK_INT >= 24) {
textviewHtml= Html.fromHtml(yourHtmlHere, Html.FROM_HTML_MODE_COMPACT);
}
else {
textviewHtml= Html.fromHtml(yourHtmlHere);
}
myTextView.setText(textviewHtml);
For more options on fromHtml you can refer to https://developer.android.com/reference/android/text/Html.html
Hope this helps! ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With