Skip to main content

Creating PDF Documents | Web Document Scanner

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

interface PdfGenerationOptions {
standardPaperSize?: PageSize;
pageDirection?: PageDirection;
pageFit?: PageFit;
dpi?: number;
jpegQuality?: number;
resample?: boolean;
}

const options: PdfGenerationOptions = { standardPaperSize: "A4", pageDirection: "PORTRAIT", pageFit: "FIT_IN", dpi: 72, jpegQuality: 80, resample: false };
const generator = await scanbotSDK.beginPdf(options);

Options

Possible options for standardPaperSize are as follows:

    "LETTER"      // 8.5 x 11 (inches)        612 x 792 (pixels)
"LEGAL" // 8.5 x 14 (inches) 612 x 1008 (pixels)
"A3" // 297 x 420 (mm) 841.89 x 1199.551 (pixels)
"A4" // 210 x 297 (mm) 595.276 x 841.89 (pixels)
"A5" // 148 x 210 (mm) 419.528 x 595.276 (pixels)
"B4" // 250 x 353 (mm) 708.661 x 1000.63 (pixels)
"B5" // 176 x 250 (mm) 498.898 x 708.661 (pixels)
"EXECUTIVE" // 7.25 x 10.5 (inches) 522 x 756 (pixels)
"US4x6" // 4 x 6 (inches) 288 x 432 (pixels)
"US4x8" // 4 x 8 (inches) 288 x 576 (pixels)
"US5x7" // 5 x 7 (inches) 360 x 504 (pixels)
"COMM10" // 4.125 x 9.5 (inches) 297 x 684 (pixels)
"CUSTOM" // uses image size

Possible options for pageDirection are as follows:

    "PORTRAIT" 
"LANDSCAPE"
"AUTO" // decides based on image aspect ratio

Possible options for pageFit are as follows:

"FIT_IN"  // fit image into page, preserves aspect ratio
"FILL_IN" // fill page with image, preserves aspect ratio
"STRETCH" // stretch image to fill page, does NOT preserve aspect ratio
"NONE" // no resizing, centers the image

Please see the API reference for a detailed description of the other options and how they play together.

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");

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