# PrintHelper

Artifact: [androidx.print:print](https://developer.android.com/jetpack/androidx/releases/print) [View Source](https://cs.android.com/search?q=file:androidx/print/PrintHelper.java+class:androidx.print.PrintHelper) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

*** ** * ** ***


```
public final class PrintHelper
```

<br />

*** ** * ** ***

Helper for printing bitmaps.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/print/PrintHelper.OnPrintFinishCallback` Callback for observing when a print operation is completed. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_COLOR() = 2` this is a color image (default) |
| `static final int` | `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_MONOCHROME() = 1` this is a black and white image |
| `static final int` | `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_LANDSCAPE() = 1` Print the image in landscape orientation (default). |
| `static final int` | `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_PORTRAIT() = 2` Print the image in portrait orientation. |
| `static final int` | `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FILL() = 2` image will fill the paper and be cropped (default) |
| `static final int` | `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FIT() = 1` image will be scaled but leave white space |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/print/PrintHelper#PrintHelper(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Constructs the PrintHelper that can be used to print images. |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/print/PrintHelper#getColorMode()()` Gets the color mode with which the image will be printed. |
| `int` | `https://developer.android.com/reference/androidx/print/PrintHelper#getOrientation()()` Gets whether the image will be printed in landscape or portrait. |
| `int` | `https://developer.android.com/reference/androidx/print/PrintHelper#getScaleMode()()` Returns the scale mode with which the image will fill the paper. |
| `void` | `https://developer.android.com/reference/androidx/print/PrintHelper#printBitmap(java.lang.String,android.graphics.Bitmap)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` Prints a bitmap. |
| `void` | `https://developer.android.com/reference/androidx/print/PrintHelper#printBitmap(java.lang.String,android.net.Uri)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html imageFile)` Prints an image located at the Uri. |
| `void` | `https://developer.android.com/reference/androidx/print/PrintHelper#printBitmap(java.lang.String,android.graphics.Bitmap,androidx.print.PrintHelper.OnPrintFinishCallback)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html bitmap, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/print/PrintHelper.OnPrintFinishCallback callback )` Prints a bitmap. |
| `void` | `https://developer.android.com/reference/androidx/print/PrintHelper#printBitmap(java.lang.String,android.net.Uri,androidx.print.PrintHelper.OnPrintFinishCallback)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html imageFile, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/print/PrintHelper.OnPrintFinishCallback callback )` Prints an image located at the Uri. |
| `void` | `https://developer.android.com/reference/androidx/print/PrintHelper#setColorMode(int)(int colorMode)` Sets whether the image will be printed in color (default) `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_COLOR()` or in back and white `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_MONOCHROME()`. |
| `void` | `https://developer.android.com/reference/androidx/print/PrintHelper#setOrientation(int)(int orientation)` Sets whether the image will be printed in landscape `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_LANDSCAPE()` (default) or portrait `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_PORTRAIT()`. |
| `void` | `https://developer.android.com/reference/androidx/print/PrintHelper#setScaleMode(int)(int scaleMode)` Selects whether the image will fill the paper and be cropped `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FIT()` or whether the image will be scaled but leave white space `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FILL()`. |
| `static boolean` | `https://developer.android.com/reference/androidx/print/PrintHelper#systemSupportsPrint()()` Gets whether the system supports printing. |

## Constants

### COLOR_MODE_COLOR

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#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](https://developer.android.com/jetpack/androidx/releases/print#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](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public static final int ORIENTATION_LANDSCAPE = 1
```

Print the image in landscape orientation (default).

### ORIENTATION_PORTRAIT

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public static final int ORIENTATION_PORTRAIT = 2
```

Print the image in portrait orientation.

### SCALE_MODE_FILL

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#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](https://developer.android.com/jetpack/androidx/releases/print#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](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public PrintHelper(@NonNull Context context)
```

Constructs the PrintHelper that can be used to print images.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | A context for accessing system resources. |

## Public methods

### getColorMode

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#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 `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_COLOR()` and `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_MONOCHROME()`. |

### getOrientation

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#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 `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_LANDSCAPE()` or `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_PORTRAIT()`. |

### getScaleMode

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public int getScaleMode()
```

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

| Returns |
|---|---|
| `int` | The scale Mode: `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FIT()` or `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FILL()` |

### printBitmap

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

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

Prints a bitmap.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName` | The print job name. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | The bitmap to print. |

### printBitmap

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#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 `https://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeStream(java.io.InputStream)`

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName` | The print job name. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html imageFile` | The `Uri` pointing to an image to print. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/FileNotFoundException.html` | if `Uri` is not pointing to a valid image. |

### printBitmap

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

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

Prints a bitmap.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName` | The print job name. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | The bitmap to print. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/print/PrintHelper.OnPrintFinishCallback callback` | Optional callback to observe when printing is finished. |

### printBitmap

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#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 `https://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeStream(java.io.InputStream)`

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html jobName` | The print job name. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html imageFile` | The `Uri` pointing to an image to print. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/print/PrintHelper.OnPrintFinishCallback callback` | Optional callback to observe when printing is finished. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/FileNotFoundException.html` | if `Uri` is not pointing to a valid image. |

### setColorMode

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public void setColorMode(int colorMode)
```

Sets whether the image will be printed in color (default) `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_COLOR()` or in back and white `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_MONOCHROME()`.

| Parameters |
|---|---|
| `int colorMode` | The color mode which is one of `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_COLOR()` and `https://developer.android.com/reference/androidx/print/PrintHelper#COLOR_MODE_MONOCHROME()`. |

### setOrientation

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public void setOrientation(int orientation)
```

Sets whether the image will be printed in landscape `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_LANDSCAPE()` (default) or portrait `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_PORTRAIT()`.

| Parameters |
|---|---|
| `int orientation` | The page orientation which is one of `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_LANDSCAPE()` or `https://developer.android.com/reference/androidx/print/PrintHelper#ORIENTATION_PORTRAIT()`. |

### setScaleMode

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public void setScaleMode(int scaleMode)
```

Selects whether the image will fill the paper and be cropped `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FIT()` or whether the image will be scaled but leave white space `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FILL()`.

| Parameters |
|---|---|
| `int scaleMode` | `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FIT()` or `https://developer.android.com/reference/androidx/print/PrintHelper#SCALE_MODE_FILL()` |

### systemSupportsPrint

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/print#1.0.0)

```
public static boolean systemSupportsPrint()
```

Gets whether the system supports printing.

| Returns |
|---|---|
| `boolean` | True if printing is supported. |