我们可以从 Web View 打印吗? [英] Can we take a print from Web View?

查看:41
本文介绍了我们可以从 Web View 打印吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的简单问题是我们可以通过 WIFI 打印从 Web 视图打印页面吗?
我制作了一页并显示在 Web 视图中,我可以打印该页吗?
在模拟器中,它没有任何选项,但在 android wifi 支持手机中有打印选项.
请帮忙.

My simple question is Can we Print the page from Web View through WIFI printing?
I have made one page and displayed in Web View so, can i print that page?
In emulator it doesn't get any options for that, But in android wifi support phone have the print option.
Please help.

推荐答案

试试下面的代码

public  void createWebPagePrint(WebView webView) {
		/*if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) 
            return;*/
	    PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
	    PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();
	    String jobName = getString(R.string.webapp_name) + " Document";
	    PrintAttributes.Builder builder = new PrintAttributes.Builder();
	    builder.setMediaSize(PrintAttributes.MediaSize.ISO_A5);
	    PrintJob printJob = printManager.print(jobName, printAdapter, builder.build());
	   
	    if(printJob.isCompleted()){
	    	Toast.makeText(getApplicationContext(), R.string.print_complete, Toast.LENGTH_LONG).show();
	    }
	    else if(printJob.isFailed()){
	    	Toast.makeText(getApplicationContext(), R.string.print_failed, Toast.LENGTH_LONG).show();
	    }
	    // Save the job object for later status checking
	}

这篇关于我们可以从 Web View 打印吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆