Print manager in android

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 2

Jul 30, 2017, 1:58:35 PM via Website

In my android application, I have an option to print the invoices for the delivery order. I am generating the Invoice content as html and sending it to android print manager as a string to print it. It is getting opened in print dialog and I am able to select a printer for printing. But after the print, my application is getting closed. But I want to redirect to the same page after the print.
Also I want to set the number of copies to 2 while printing programmatically from the android print manager. this is my source code.

public void printContent(View view) {
WebView webView = new WebView(this);
webView.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view,
                                                String url)
            return false;

        public void onPageFinished(WebView view, String url) {
            mWebView = null;



    webView.loadDataWithBaseURL(null, html,
            "text/HTML", "UTF-8", null);

    mWebView = webView;


@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public  void createWebPrintJob(WebView webView) {

    PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
    PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();
    String jobName = getString(R.string.app_name) + " Document";
    PrintAttributes.Builder builder = new PrintAttributes.Builder();
    android.print.PrintJob printJob = printManager.print(jobName, printAdapter,
            new PrintAttributes.Builder().build());


        startActivity(new Intent(Delivery_Order_Print.this, Delivery_Order_Activity.class));
    else if(printJob.isFailed()){
        Toast.makeText(getApplicationContext(),"Print Failed", Toast.LENGTH_LONG).show();


Henry Samuel