Если вы хотите растровое изображение, используйте следующий класс, чтобы получить один
public class Screenshot {
public static Bitmap get(Context context,WebView view){
float width=getWindowWidth(context);
float height=view.getContentHeight() * getDensity(context);
return capture(view,width,height);
}
private static Bitmap capture(View view, float width, float height) {
if (!view.isDrawingCacheEnabled()) {
view.setDrawingCacheEnabled(true);
}
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
bitmap.eraseColor(Color.WHITE);
Canvas canvas = new Canvas(bitmap);
int left = view.getLeft();
int top = view.getTop();
int status = canvas.save();
canvas.translate(-left, -top);
float scale = width / view.getWidth();
canvas.scale(scale, scale, left, top);
view.draw(canvas);
canvas.restoreToCount(status);
Paint alphaPaint = new Paint();
alphaPaint.setColor(Color.TRANSPARENT);
canvas.drawRect(0f, 0f, 1f, height, alphaPaint);
canvas.drawRect(width - 1f, 0f, width, height, alphaPaint);
canvas.drawRect(0f, 0f, width, 1f, alphaPaint);
canvas.drawRect(0f, height - 1f, width, height, alphaPaint);
canvas.setBitmap(null);
return bitmap;
}
private static int getWindowWidth(Context context) {
return context.getResources().getDisplayMetrics().widthPixels;
}
private static float getDensity(Context context) {
return context.getResources().getDisplayMetrics().density;
}
}
Если вы хотите напечатать, попробуйте заменить
printMgr.Print("my page", webview.CreatePrintDocumentAdapter(), null);
на
printMgr.Print("my page", webview.CreatePrintDocumentAdapter(), new PrintAttributes.Builder().build()));
thisработал на меня