| layout | default-layout |
|---|---|
| needAutoGenerateSidebar | true |
| title | Dynamic Web TWAIN SDK Features - Exporting Locally |
| keywords | Dynamic Web TWAIN, Documentation, save, output, export, web, download, local save, local, save to file, print |
| breadcrumbText | Exporting Locally |
| description | Dynamic Web TWAIN SDK Documentation Local Export |
Prerequisite: DWT Initialization
Prerequisite: Managing the Image Buffer
DWT offers several methods to save images from the WebTwain image buffer locally. This includes saving the images to files on the end user's file system, exporting from the image buffer to binary Blobs and Base64 strings, and also printing to connected printers.
The WebTwain image buffer can output images directly to disk, and supports BMP , JPG , TIF , PNG and PDF formats. Of note, TIF and PDF come with multi-image support. Learn more about supported file formats here.
Each file format has its own file saving API, as shown here:
SaveAsBMP()SaveAsJPEG()SaveAsPDF()SaveAsPNG()SaveAsTIFF()SaveSelectedImagesAsMultiPagePDF()SaveSelectedImagesAsMultiPageTIFF()SaveAllAsPDF()SaveAllAsMultiPageTIFF()
Note that multi-page saving requires separate APIs from their single page counterparts.
The image buffer can export images as Blobs or Base64 strings, which are useful for processing images outside of DWT, whether for custom image upload logic, or other purposes within the web application.
ConvertToBlob() converts selected images to a Blob, as demonstrated here:
DWTObject.ConvertToBlob(
[0, 1, 2],
Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
function(result, indices, type) {
console.log(result.size);
},
function(errorCode, errorString) {
console.log(errorString);
}
);APIs used:
Here, ConvertToBlob() takes a zero-indexed array of image indices (of the image buffer) which indicates the images it exports, and uses the Dynamsoft.DWT.EnumDWT_ImageType enum to specify the file format (in this case, single-page PDF). Just as when saving to files locally, use the dedicated multi-page enums when saving multi-page PDFs and TIFs.
The Blob accessible through the result argument of the success callback.
Likewise, ConvertToBase64() outputs a Base64 string:
DWTObject.ConvertToBase64(
[0, 1, 2],
Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
function(result, indices, type) {
console.log(result.getData(0, result.getLength()));
},
function(errorCode, errorString) {
console.log(errorString);
}
);APIs used:
The Base 64 string accessible through the result argument of the success callback. Note that this is a Base64Result object.
Finally, DWT can also print directly to a printer through the Print() API. This API brings all images from the image buffer into the browser's print dialog. Alternatively, while running on Windows, the API can also take an argument to use the Windows OS print dialog instead.