Skip to main content

Creating TIFF Documents | Android Document Scanner

Get an instance of TIFFWriter from ScanbotSDK:

val scanbotSDK = ScanbotSDK(context);
val tiffWriter = scanbotSDK.createTiffWriter();

There are a few supported methods: The first method renders the given list of bitmaps into a multi-page TIFF and stores it as a file. For each image, a separate page is generated.

    fun writeTIFFFromImages(images: Array<Bitmap>,
targetFile: File,
parameters: TIFFImageWriterParameters): Boolean

Input args:

  • images - Input images as an array of [Bitmap] in the correct order (image element 1 => page 1, etc).
  • targetFile - Address of the file where we should save the TIFF.
  • parameters - Additional TIFF format parameters:
    • binarizationFilter - One of the SDK supported binarization [ParametricFilter]s (ScanbotBinarizationFilter, CustomBinarizationFilter or one of the legacy binariazation filters) or null.
    • dpi - Optional integer value for dots per inch.
    • compression - Optional TIFF compression type as an enum of [TIFFImageWriterCompressionOptions]. Should be used with binarization filters only, otherwise set to TIFFImageWriterCompressionOptions.NONE

Result:

  • boolean - true if the file was successfully created.

The second method renders the given list of image files into a multi-page TIFF and stores it as a file. For each image, a separate page is generated.

    fun writeTIFFFromFiles(sourceFiles: List<File>,
sourceFilesEncrypted: Boolean,
targetFile: File,
parameters: TIFFImageWriterParameters): Boolean

Input args:

  • images - Input images as an array of file URIs in the correct order (image element 1 => page 1, etc).
  • sourceFilesEncrypted - Should be true if the source files are encrypted with our SDK.
  • targetFile - Address of the file where we should save the TIFF.
  • parameters - Additional TIFF format parameters:
    • binarizationFilter : One of the SDK supported binarization [ParametricFilter]s (ScanbotBinarizationFilter, CustomBinarizationFilter or one of the legacy binariazation filters) or null
    • dpi - Optional integer value for dots per inch.
    • compression - Optional TIFF compression type as an enum of [TIFFImageWriterCompressionOptions]. Should be used with binarization filters only, otherwise set to TIFFImageWriterCompressionOptions.NONE

Result:

  • boolean - true if the file was successfully created.

The third method renders the given list of bitmaps into a multi-page TIFF and returns a byte array with the file data. For each image, a separate page is generated. This is useful when it's necessary to not create a temporary file in storage.

    fun writeTIFFFromImages(images: Array<Bitmap>,
parameters: TIFFImageWriterParameters): ByteArray

Input args:

  • images - Input images as an array of file URIs in the correct order (image element 1 => page 1, etc).
  • parameters - Additional TIFF format parameters:
    • binarizationFilter - One of the SDK supported binarization [ParametricFilter]s (ScanbotBinarizationFilter, CustomBinarizationFilter or one of the legacy binariazation filters) or null
    • dpi - Optional integer value for dots per inch.
    • compression - Optional TIFF compression type as an enum of [TIFFImageWriterCompressionOptions]. Should be used with binarization filters only, otherwise set to TIFFImageWriterCompressionOptions.NONE

Result:

  • ByteArray - Non-empty byte array if the TIFF was successfully created.

Default TIFFImageWriterParameters

Scanbot SDK provides 2 default TIFFImageWriterParameters instances for convenience:

  • TIFFImageWriterParameters.defaultParameters() where:
    • binarizationFilter is null
    • dpi is 72
    • compression is TIFFImageWriterCompressionOptions.COMPRESSION_LZW
    • userDefinedFields are empty
  • TIFFImageWriterParameters.defaultParametersForBinarizedImages() where:
    • binarizationFilter is ScanbotBinarizationFilter
    • dpi is 72
    • compression is TIFFImageWriterCompressionOptions.COMPRESSION_CCITTFAX4
    • userDefinedFields are empty

Supported TIFF Compression Types

  • NONE - No compression. Supported for all image filters.
  • CCITT_T6 - "CCITT Fax 4" compression type. Most common and recommended type for binarized (1-bit) black and white images to achieve a small TIFF file size.
  • ADOBE_DEFLATE - "ZIP" compression type. Most common type for color images.
  • CCITTRLE
  • CCITTFAX3
  • CCITT_T4
  • CCITTFAX4
  • CCITTRLEW
  • LZW
  • PACKBITS
  • DEFLATE
caution

Please note that the following compression types are only compatible with binarized images (1-bit encoded black & white images): CCITTRLE, CCITTFAX3, CCITT_T4, CCITTFAX4, CCITT_T6, CCITTRLEW.

Want to scan longer than one minute?

Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.

Get your free Trial License

What do you think of this documentation?