We tries to print a webview content over google cloud print, but no matter what we do the resulted printout adds some margin.
我们尝试通过谷歌云打印打印webview内容,但无论我们做什么,结果打印输出都会增加一些余量。
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...
没人工作......
4 个解决方案
#1
5
Just Use It *{margin:0px; padding:0px} Add In Your Style Sheet And Check Once
Just Use It * {margin:0px;填充:0px}添加样式表并检查一次
*{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">
#2
1
By Default HTML web pages have a padding and margin of 10px; You have to set in your head section or or css file:
默认情况下,HTML网页的填充和边距为10px;您必须在头部或css文件中设置:
<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:
这是webview中图像的另一个提示:添加适合屏幕宽度图像的样式。适用于所有屏幕尺寸:
<style type='text/css'>
img {max-width: 100%;height:initial;} div,p,span,a {max-width: 100%;}
</style>
#3
1
If using the css doesn't solve your issue, you can try using a TextView with fromHtml instead of using a webview:
如果使用css无法解决您的问题,您可以尝试使用带有fromHtml的TextView而不是使用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
有关fromHtml的更多选项,请参阅https://developer.android.com/reference/android/text/Html.html
Hope this helps! ;-)
希望这可以帮助! ;-)
#4
1
Use the following code to remove margins when printing the WebView.
在打印WebView时,使用以下代码删除边距。
@page{
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
margin-bottom: 0px;
}
#1
5
Just Use It *{margin:0px; padding:0px} Add In Your Style Sheet And Check Once
Just Use It * {margin:0px;填充:0px}添加样式表并检查一次
*{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">
#2
1
By Default HTML web pages have a padding and margin of 10px; You have to set in your head section or or css file:
默认情况下,HTML网页的填充和边距为10px;您必须在头部或css文件中设置:
<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:
这是webview中图像的另一个提示:添加适合屏幕宽度图像的样式。适用于所有屏幕尺寸:
<style type='text/css'>
img {max-width: 100%;height:initial;} div,p,span,a {max-width: 100%;}
</style>
#3
1
If using the css doesn't solve your issue, you can try using a TextView with fromHtml instead of using a webview:
如果使用css无法解决您的问题,您可以尝试使用带有fromHtml的TextView而不是使用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
有关fromHtml的更多选项,请参阅https://developer.android.com/reference/android/text/Html.html
Hope this helps! ;-)
希望这可以帮助! ;-)
#4
1
Use the following code to remove margins when printing the WebView.
在打印WebView时,使用以下代码删除边距。
@page{
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
margin-bottom: 0px;
}