Skip to main content

Image Export

In addition to exporting scanned documents as PDF, you can also retrieve the pages of the currently scanned document as image files (JPG).

Initialization

Initialize the Docutain SDK for Flutter as described here.

Export scanned pages as image files

Write images to local files

In order to write the currently scanned pages to local JPG files, you can use the DocutainSdkDocument.writeImage method. Pass the page you want to export as JPG and the target path where to save it. If you want to export all pages as JPG, you can get the number of pages via DocutainSdkDocument.pageCount() and loop through all pages like in the follwing example:

//...
//scan a document
//...

final pageCount = await DocutainSdkDocument.pageCount();
for (var i = 1; i <= pageCount; i++) {
var fileReturn = await DocutainSdkDocument.writeImage(
i, path, "Image$i.jpg");
}

Get images as Uint8List (ByteData)

You also have the possibility to get the images as Uint8List which you can use for further processing, for example wrapping it in ByteData:

//...
//scan a document
//...

final pageCount = await DocutainSdkDocument.pageCount();
for (var i = 1; i <= pageCount; i++) {
var bytes = await DocutainSdkDocument.getImageBytes(i);
}

PageSourceType

When getting the images as Uint8List, you can define a PageSourceType.

//...
//scan a document
//...

final pageCount = await DocutainSdkDocument.pageCount();
for (var i = 1; i <= pageCount; i++) {
var bytes = await DocutainSdkDocument.getImageBytes(i,
pageSourceType: PageSourceType.cutFilter);
}

You have the following options:

  • PageSourceType.cutFilter This is the default value if you do not provide any. The image will be the cut and filtered image which is the one the user sees when finishing the scan process.

  • PageSourceType.cutOnly This will give you the cut but unfiltered image. If you for example use the image for further processing in your own OCR pipeline which uses custom filter operations, this option might improve your OCR results as opposed to PageSourceType.cutFilter. But this is no general rule and highly depends on your pipeline.

  • PageSourceType.original This will give you the uncut, unfiltered image as it was provided by the camera.