PrintHelper


public final class PrintHelper


Helper for printing bitmaps.

Summary

Nested types

Callback for observing when a print operation is completed.

Constants

static final int

this is a color image (default)

static final int

this is a black and white image

static final int

Print the image in landscape orientation (default).

static final int

Print the image in portrait orientation.

static final int

image will fill the paper and be cropped (default)

static final int

image will be scaled but leave white space

Public constructors

Constructs the PrintHelper that can be used to print images.

Public methods

int

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

int

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

int

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

void
printBitmap(@NonNull String jobName, @NonNull Bitmap bitmap)

Prints a bitmap.

void
printBitmap(@NonNull String jobName, @NonNull Uri imageFile)

Prints an image located at the Uri.

void
printBitmap(
    @NonNull String jobName,
    @NonNull Bitmap bitmap,
    @Nullable PrintHelper.OnPrintFinishCallback callback
)

Prints a bitmap.

void
printBitmap(
    @NonNull String jobName,
    @NonNull Uri imageFile,
    @Nullable PrintHelper.OnPrintFinishCallback callback
)

Prints an image located at the Uri.

void
setColorMode(int colorMode)

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

void
setOrientation(int orientation)

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

void
setScaleMode(int scaleMode)

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.

static boolean

Gets whether the system supports printing.

Constants

COLOR_MODE_COLOR

Added in 1.0.0
public static final int COLOR_MODE_COLOR = 2

this is a color image (default)

COLOR_MODE_MONOCHROME

Added in 1.0.0
public static final int COLOR_MODE_MONOCHROME = 1

this is a black and white image

ORIENTATION_LANDSCAPE

Added in 1.0.0
public static final int ORIENTATION_LANDSCAPE = 1

Print the image in landscape orientation (default).

ORIENTATION_PORTRAIT

Added in 1.0.0
public static final int ORIENTATION_PORTRAIT = 2

Print the image in portrait orientation.

SCALE_MODE_FILL

Added in 1.0.0
public static final int SCALE_MODE_FILL = 2

image will fill the paper and be cropped (default)

SCALE_MODE_FIT

Added in 1.0.0
public static final int SCALE_MODE_FIT = 1

image will be scaled but leave white space

Public constructors

PrintHelper

Added in 1.0.0
public PrintHelper(@NonNull Context context)

Constructs the PrintHelper that can be used to print images.

Parameters
@NonNull Context context

A context for accessing system resources.

Public methods

getColorMode

Added in 1.0.0
public int getColorMode()

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

Returns
int

The color mode which is one of COLOR_MODE_COLOR and COLOR_MODE_MONOCHROME.

getOrientation

Added in 1.0.0
public int getOrientation()

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

Returns
int

The page orientation which is one of ORIENTATION_LANDSCAPE or ORIENTATION_PORTRAIT.

getScaleMode

Added in 1.0.0
public int getScaleMode()

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

Returns
int

The scale Mode: SCALE_MODE_FIT or SCALE_MODE_FILL

printBitmap

Added in 1.0.0
public void printBitmap(@NonNull String jobName, @NonNull Bitmap bitmap)

Prints a bitmap.

Parameters
@NonNull String jobName

The print job name.

@NonNull Bitmap bitmap

The bitmap to print.

printBitmap

Added in 1.0.0
public void printBitmap(@NonNull String jobName, @NonNull Uri imageFile)

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

Parameters
@NonNull String jobName

The print job name.

@NonNull Uri imageFile

The Uri pointing to an image to print.

Throws
java.io.FileNotFoundException

if Uri is not pointing to a valid image.

printBitmap

Added in 1.0.0
public void printBitmap(
    @NonNull String jobName,
    @NonNull Bitmap bitmap,
    @Nullable PrintHelper.OnPrintFinishCallback callback
)

Prints a bitmap.

Parameters
@NonNull String jobName

The print job name.

@NonNull Bitmap bitmap

The bitmap to print.

@Nullable PrintHelper.OnPrintFinishCallback callback

Optional callback to observe when printing is finished.

printBitmap

Added in 1.0.0
public void printBitmap(
    @NonNull String jobName,
    @NonNull Uri imageFile,
    @Nullable PrintHelper.OnPrintFinishCallback callback
)

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

Parameters
@NonNull String jobName

The print job name.

@NonNull Uri imageFile

The Uri pointing to an image to print.

@Nullable PrintHelper.OnPrintFinishCallback callback

Optional callback to observe when printing is finished.

Throws
java.io.FileNotFoundException

if Uri is not pointing to a valid image.

setColorMode

Added in 1.0.0
public void setColorMode(int colorMode)

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

Parameters
int colorMode

The color mode which is one of COLOR_MODE_COLOR and COLOR_MODE_MONOCHROME.

setOrientation

Added in 1.0.0
public void setOrientation(int orientation)

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

Parameters
int orientation

The page orientation which is one of ORIENTATION_LANDSCAPE or ORIENTATION_PORTRAIT.

setScaleMode

Added in 1.0.0
public void setScaleMode(int scaleMode)

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
int scaleMode

SCALE_MODE_FIT or SCALE_MODE_FILL

systemSupportsPrint

Added in 1.0.0
public static boolean systemSupportsPrint()

Gets whether the system supports printing.

Returns
boolean

True if printing is supported.