0

I'm not able to print PDF from webView. PrintManager library depreciated in android, So i'm finding library or method to fix this issue. Can anybody help?

private void createWebPrintJob(WebView webView) {
    /*if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
        return;*/
    // Get a PrintManager instance
    PrintManager printManager = (PrintManager) mContext.getSystemService(Context.PRINT_SERVICE);
    String jobName = "ReportGroupSrpf" + System.currentTimeMillis() + ".pdf";
    PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter(jobName);
    PrintAttributes.Builder builder = new PrintAttributes.Builder();
    builder.setMediaSize(PrintAttributes.MediaSize.ISO_A3);
    PrintJob printJob = printManager.print(jobName, printAdapter, builder.build());
    if (printJob.isCompleted()) {
        Toast.makeText(mContext, R.string.print_complete, Toast.LENGTH_LONG).show();
    } else if (printJob.isFailed()) {
        Toast.makeText(mContext, R.string.print_failed, Toast.LENGTH_LONG).show();
    }
}

"can print only from an activity" This error ahead. While i'm loading webView.

Need help to resolve this issue.

0 Answers0