Skip to content

Most visited

Recently visited

navigation

PrintHelper

public final class PrintHelper
extends Object

java.lang.Object
   ↳ android.support.v4.print.PrintHelper


Helper for printing bitmaps.

Summary

Nested classes

interface PrintHelper.OnPrintFinishCallback

Callback for observing when a print operation is completed. 

Constants

int COLOR_MODE_COLOR

this is a color image (default)

int COLOR_MODE_MONOCHROME

this is a black and white image

int ORIENTATION_LANDSCAPE

Print the image in landscape orientation (default).

int ORIENTATION_PORTRAIT

Print the image in portrait orientation.

int SCALE_MODE_FILL

image will fill the paper and be cropped (default)

int SCALE_MODE_FIT

image will be scaled but leave white space

Public constructors

PrintHelper(Context context)

Returns the PrintHelper that can be used to print images.

Public methods

int getColorMode()

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

int getOrientation()

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

int getScaleMode()

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

void printBitmap(String jobName, Bitmap bitmap)

Prints a bitmap.

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

Prints a bitmap.

void printBitmap(String jobName, Uri imageFile)

Prints an image located at the Uri.

void printBitmap(String jobName, Uri imageFile, 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 systemSupportsPrint()

Gets whether the system supports printing.

Inherited methods

From class java.lang.Object

Constants

COLOR_MODE_COLOR

int COLOR_MODE_COLOR

this is a color image (default)

Constant Value: 2 (0x00000002)

COLOR_MODE_MONOCHROME

int COLOR_MODE_MONOCHROME

this is a black and white image

Constant Value: 1 (0x00000001)

ORIENTATION_LANDSCAPE

int ORIENTATION_LANDSCAPE

Print the image in landscape orientation (default).

Constant Value: 1 (0x00000001)

ORIENTATION_PORTRAIT

int ORIENTATION_PORTRAIT

Print the image in portrait orientation.

Constant Value: 2 (0x00000002)

SCALE_MODE_FILL

int SCALE_MODE_FILL

image will fill the paper and be cropped (default)

Constant Value: 2 (0x00000002)

SCALE_MODE_FIT

int SCALE_MODE_FIT

image will be scaled but leave white space

Constant Value: 1 (0x00000001)

Public constructors

PrintHelper

PrintHelper (Context context)

Returns the PrintHelper that can be used to print images.

Parameters
context Context: A context for accessing system resources.
Returns
the PrintHelper to support printing images.

Public methods

getColorMode

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

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

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

void printBitmap (String jobName, 
                Bitmap bitmap)

Prints a bitmap.

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

printBitmap

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

Prints a bitmap.

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

printBitmap

void printBitmap (String jobName, 
                Uri imageFile)

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 Uri: The Uri pointing to an image to print.
Throws
FileNotFoundException if Uri is not pointing to a valid image.

printBitmap

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

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 Uri: The Uri pointing to an image to print.
callback PrintHelper.OnPrintFinishCallback: Optional callback to observe when printing is finished.
Throws
FileNotFoundException if Uri is not pointing to a valid image.

setColorMode

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
colorMode int: The color mode which is one of COLOR_MODE_COLOR and COLOR_MODE_MONOCHROME.

setOrientation

void setOrientation (int orientation)

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.

setScaleMode

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
scaleMode int: SCALE_MODE_FIT or SCALE_MODE_FILL

systemSupportsPrint

boolean systemSupportsPrint ()

Gets whether the system supports printing.

Returns
boolean True if printing is supported.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.