Skip to main content

Creating TIFF documents

The Scanbot Web SDK offers functionality for binary-colored TIFF generation, which allows you to store your scans with minimal file size. Create the appropriate generator as follows:

const options: TIFFGeneratorParameters = { dpi: 123 };
const generator = await scanbotSDK.beginTiff(options);

Options

See the API reference for a list of available options.

Adding pages

You can add individual images to your TIFF document. To achieve the smallest file sizes, the images should be binarized. You can either binarize the image before adding it to the generator or use the ScanbotBinarizationFilter to binarize it on the fly.

If you obtained a document from the RTU UI, you can add all pages at once.

const imageArrayBuffer = await (await fetch("image.png")).arrayBuffer();

// If our image is already binarized, we can add it directly:
const generator = await scanbotSDK.beginTiff({ });
await generator.addPage(imageArrayBuffer, { binarize: "YES" });
await generator.addPages(document, { binarize: "YES" });

// Otherwise, we can use a binarization filter:
const generator = await scanbotSDK.beginTiff({ binarizationFilter: new scanbotSDK.Config.ScanbotBinarizationFilter() });
await generator.addPage(imageArrayBuffer, { binarize: "YES" });
await generator.addPages(document, { binarize: "YES" });

When all images have been added, complete the transaction and receive the resulting byte array:

const bytes = await generator.complete();

As an example, you can force the tiff download of the pages in the browser via:

function saveBytes(data, name) {
const extension = name.split(".")[1];
const a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
const blob = new Blob([data], {type: `application/${extension}`});
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = name;
a.click();
window.URL.revokeObjectURL(url);
}

And then call it as such:

saveBytes(bytes, "generated.tiff");

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?


On this page

Scroll to top