Skip to main content

PDF & TIFF Creation | Web Document and Barcode Scanner

The Scanbot Web SDK offers functionality for PDF & TIFF generation. Create the appropriate generator as follows:

const options: PdfGenerationOptions = {standardPaperSize: "A4", landscape: true, dpi: 100};const generator = await scanbotSDK.beginPdf(options);
const options: TiffGenerationOptions = {binarizationFilter: "deepBinarization", dpi: 123};const generator = await scanbotSDK.beginTiff(options);

Options#

  • Paper size calculation:
    • If a standard paper size is given, that paper size is used,
    • Otherwise, if both paperWidthInches and paperHeightInches is set, those values are used
    • Otherwise, the paper size is calculated to fit the input image exactly at the given DPI. If no DPI value is given, a default DPI of 72 is used.
  • DPI calculation:
    • If a DPI is provided, then that value is used.
    • If the value is not given or that value is too small for the entire image to fit on the page, then the smallest possible DPI value is chosen so that the entire image fits on the page.

Adding pages#

In order to allow for memory optimization, you can load an image from storage one at a time and add it to the generator:

await generator.addPage(image);

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 pdf download of the pages in the browser via:

static 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.pdf");