Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

PrintHelper

class PrintHelper
kotlin.Any
   ↳ androidx.print.PrintHelper

Helper for printing bitmaps.

Summary

Nested classes
abstract

Callback for observing when a print operation is completed.

Constants
static Int

image will be scaled but leave white space

static Int

image will fill the paper and be cropped (default)

static Int

this is a black and white image

static Int

this is a color image (default)

static Int

Print the image in landscape orientation (default).

static Int

Print the image in portrait orientation.

Public constructors
<init>(@NonNull context: Context)

Constructs the PrintHelper that can be used to print images.

Public methods
Unit
setScaleMode(scaleMode: Int)

Selects whether the image will fill the paper and be cropped SCALE_MODE_FIT or whether the image will be scaled but leave white space SCALE_MODE_FILL.

Int

Gets the color mode with which the image will be printed.

Unit
setOrientation(orientation: Int)

Sets whether the image will be printed in landscape ORIENTATION_LANDSCAPE (default) or portrait ORIENTATION_PORTRAIT.

Unit
setColorMode(colorMode: Int)

Sets whether the image will be printed in color (default) COLOR_MODE_COLOR or in back and white COLOR_MODE_MONOCHROME.

Int

Gets whether the image will be printed in landscape or portrait.

Unit
printBitmap(@NonNull jobName: String, @NonNull bitmap: Bitmap)

Prints a bitmap.

Unit
printBitmap(@NonNull jobName: String, @NonNull bitmap: Bitmap, @Nullable callback: PrintHelper.OnPrintFinishCallback?)

Prints a bitmap.

Unit
printBitmap(@NonNull jobName: String, @NonNull imageFile: Uri)

Prints an image located at the Uri.

Unit
printBitmap(@NonNull jobName: String, @NonNull imageFile: Uri, @Nullable callback: PrintHelper.OnPrintFinishCallback?)

Prints an image located at the Uri.

Int

Returns the scale mode with which the image will fill the paper.

static Boolean

Gets whether the system supports printing.

Constants

SCALE_MODE_FIT

static val SCALE_MODE_FIT: Int

image will be scaled but leave white space

Value: 1

SCALE_MODE_FILL

static val SCALE_MODE_FILL: Int

image will fill the paper and be cropped (default)

Value: 2

COLOR_MODE_MONOCHROME

static val COLOR_MODE_MONOCHROME: Int

this is a black and white image

Value: PrintAttributes.COLOR_MODE_MONOCHROME

COLOR_MODE_COLOR

static val COLOR_MODE_COLOR: Int

this is a color image (default)

Value: PrintAttributes.COLOR_MODE_COLOR

ORIENTATION_LANDSCAPE

static val ORIENTATION_LANDSCAPE: Int

Print the image in landscape orientation (default).

Value: 1

ORIENTATION_PORTRAIT

static val ORIENTATION_PORTRAIT: Int

Print the image in portrait orientation.

Value: 2

Public constructors

<init>

PrintHelper(@NonNull context: Context)

Constructs the PrintHelper that can be used to print images.

Parameters
context Context: A context for accessing system resources.

Public methods

setScaleMode

fun setScaleMode(scaleMode: Int): Unit

Selects whether the image will fill the paper and be cropped SCALE_MODE_FIT or whether the image will be scaled but leave white space SCALE_MODE_FILL.

Parameters
scaleMode Int: SCALE_MODE_FIT or SCALE_MODE_FILL

getColorMode

fun getColorMode(): Int

Gets the color mode with which the image will be printed.

Return
Int: The color mode which is one of COLOR_MODE_COLOR and COLOR_MODE_MONOCHROME.

setOrientation

fun setOrientation(orientation: Int): Unit

Sets whether the image will be printed in landscape ORIENTATION_LANDSCAPE (default) or portrait ORIENTATION_PORTRAIT.

Parameters
orientation Int: The page orientation which is one of ORIENTATION_LANDSCAPE or ORIENTATION_PORTRAIT.

setColorMode

fun setColorMode(colorMode: Int): Unit

Sets whether the image will be printed in color (default) COLOR_MODE_COLOR or in back and white COLOR_MODE_MONOCHROME.

Parameters
colorMode Int: The color mode which is one of COLOR_MODE_COLOR and COLOR_MODE_MONOCHROME.

getOrientation

fun getOrientation(): Int

Gets whether the image will be printed in landscape or portrait.

Return
Int: The page orientation which is one of ORIENTATION_LANDSCAPE or ORIENTATION_PORTRAIT.

printBitmap

fun printBitmap(@NonNull jobName: String, @NonNull bitmap: Bitmap): Unit

Prints a bitmap.

Parameters
jobName String: The print job name.
bitmap String: The bitmap to print.

printBitmap

fun printBitmap(@NonNull jobName: String, @NonNull bitmap: Bitmap, @Nullable callback: PrintHelper.OnPrintFinishCallback?): Unit

Prints a bitmap.

Parameters
jobName String: The print job name.
bitmap String: The bitmap to print.
callback String: Optional callback to observe when printing is finished.

printBitmap

fun printBitmap(@NonNull jobName: String, @NonNull imageFile: Uri): Unit

Prints an image located at the Uri. Image types supported are those of android.graphics.BitmapFactory.decodeStream(java.io.InputStream)

Parameters
jobName String: The print job name.
imageFile String: The Uri pointing to an image to print.
Exceptions
FileNotFoundException if Uri is not pointing to a valid image.

printBitmap

fun printBitmap(@NonNull jobName: String, @NonNull imageFile: Uri, @Nullable callback: PrintHelper.OnPrintFinishCallback?): Unit

Prints an image located at the Uri. Image types supported are those of android.graphics.BitmapFactory.decodeStream(java.io.InputStream)

Parameters
jobName String: The print job name.
imageFile String: The Uri pointing to an image to print.
callback String: Optional callback to observe when printing is finished.
Exceptions
FileNotFoundException if Uri is not pointing to a valid image.

getScaleMode

fun getScaleMode(): Int

Returns the scale mode with which the image will fill the paper.

Return
Int: The scale Mode: SCALE_MODE_FIT or SCALE_MODE_FILL

systemSupportsPrint

static fun systemSupportsPrint(): Boolean

Gets whether the system supports printing.

Return
Boolean: True if printing is supported.