Example usage for android.print PrintManager print

List of usage examples for android.print PrintManager print

Introduction

In this page you can find the example usage for android.print PrintManager print.

Prototype

public @NonNull PrintJob print(@NonNull String printJobName, @NonNull PrintDocumentAdapter documentAdapter,
        @Nullable PrintAttributes attributes) 

Source Link

Document

Creates a print job for printing a PrintDocumentAdapter with default print attributes.

Usage

From source file:net.gsantner.opoc.util.ShareUtil.java

/**
 * Print a {@link WebView}'s contents, also allows to create a PDF
 *
 * @param webview WebView//from  w  w w .  j a v  a  2s  . c o m
 * @param jobName Name of the job (affects PDF name too)
 * @return {{@link PrintJob}} or null
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@SuppressWarnings("deprecation")
public PrintJob print(WebView webview, String jobName) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        PrintDocumentAdapter printAdapter;
        PrintManager printManager = (PrintManager) webview.getContext().getSystemService(Context.PRINT_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            printAdapter = webview.createPrintDocumentAdapter(jobName);
        } else {
            printAdapter = webview.createPrintDocumentAdapter();
        }
        if (printManager != null) {
            return printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        }
    } else {
        Log.e(getClass().getName(), "ERROR: Method called on too low Android API version");
    }
    return null;
}