You need the width and height of WebView CONTENTS after loading your HTML. YES, but there is no getContentWidth method (only the view port value), And getContentHeight () is inaccurate!
Answer: subclass of WebView:
package com.example.html2pdf;
import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
class CustomWebView extends WebView
{
public int rawContentWidth = 0;
public int rawContentHeight = 0;
Context mContext = null;
public CustomWebView(Context context)
{
super(context);
mContext = this.getContext();
}
public CustomWebView(Context context, AttributeSet attrs)
{
super(context,attrs);
mContext = context;
}
public int getContentWidth()
{
int ret = super.computeHorizontalScrollRange();
rawContentWidth = ret;
return ret;
}
public int getContentHeight()
{
int ret = super.computeVerticalScrollRange();
rawContentHeight = ret;
return ret;
}
}
source
share