Can we take a print from Web View?

Issue

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.

Solution

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
	}

Answered By – user1035292

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published