Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we take a print from Web View?

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.

like image 813
posteritysystem Avatar asked Jul 18 '12 08:07

posteritysystem


1 Answers

Try below code

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
	}
like image 115
user1035292 Avatar answered Sep 24 '22 18:09

user1035292