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 Capacitor 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 Document.writeImage method. Pass the page you want to export as JPG and the target path where to save it:

import { DocutainSDK } from '@docutain/capacitor-plugin-docutain-sdk';

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

try{
const pageCount = (await DocutainSDK.pageCount()).count;
for(let i = 1; i <= pageCount; i++){
var destinationUri = (await Filesystem.getUri({ path: `image${i}.jpg`, directory:Directory.Data })).uri;
const imageUri = (await DocutainSDK.writeImage({
pageNumber: i,
fileUri: destinationUri
})).fileUri
}
}catch (error) {
console.error(error);
}

Get images as Base64 encoded string

You also have the possibility to get the images as Base64 encoded string:

import { DocutainSDK, PageSourceType } from '@docutain/capacitor-plugin-docutain-sdk';

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

try{
const pageCount = (await DocutainSDK.pageCount()).count;
for(let i = 1; i <= pageCount; i++){
const imageBytes = (await DocutainSDK.getImageBytes({
pageNumber: i,
pageSourceType: PageSourceType.CutFilter
})).bytes
}
}catch (error) {
console.error(error);
}

PageSourceType

When getting the images as Base64 encoded string, you can define a PageSourceType.

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.CUT_FILTER. 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.