Load & Save

Methods
FileExists() LoadDibFromClipboard()
LoadImage() LoadImageEx()
LoadImageFromBase64Binary() SaveAllAsMultiPageTIFF()
SaveAllAsPDF() SaveAsBMP()
SaveAsJPEG() SaveAsPDF()
SaveAsPNG() SaveAsTIFF()
SaveSelectedImagesAsMultiPagePDF() SaveSelectedImagesAsMultiPageTIFF()
SaveSelectedImagesToBase64Binary() ShowFileDialog()
Properties
IfShowFileDialog
Events
OnGetFilePath OnPostLoad

Code example

The following code example demonstrates how to use the APIs above to perform basic scanning.

var imagedata;
DWObject.SelectedImagesCount = 1;
DWObject.SetSelectedImageIndex(0,0);
DWObject.GetSelectedImagesSize(EnumDWT_ImageType.IT_JPG);
imagedata = DWObject.SaveSelectedImagesToBase64Binary();
DWObject.LoadImageFromBase64Binary(imagedata, EnumDWT_ImageType.IT_JPG, function(){
    console.log('success');
    },function(){
    console.log('failure');
});

Methods

FileExists()
Checks whether a certain file exists on the local disk.
Syntax .FileExists(fileName);
Parameters string fileName: the absolute path of the file to be checked.
Return value boolean
Example
DWObject.FileExists("C:\\DWT\\WebTWAIN.jpg");
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v9.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
LoadDibFromClipboard()
Loads a DIB image from the system clipboard into Dynamic Web TWAIN.
Syntax .LoadDibFromClipboard([optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is loaded successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be loaded.
Return value boolean
Only valid when used synchronously.
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v4.1✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
LoadImage()
Loads local image(s) into the Dynamic Web TWAIN buffer.
Syntax .LoadImage(fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName: the absolute path to the file to be opened.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is loaded successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be loaded.
Return value boolean
Only valid when used synchronously.
Example
DWObject.LoadImage("C:\\DWT.jpg");
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v4.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0
Usage notes Dynamic Web TWAIN processes the image format according to the extension of fileName.
LoadImageEx()
Loads local image(s) into Dynamic Web TWAIN.
Syntax .LoadImageEx(fileName, imageType, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName: the absolute path to open the file.
EnumDWT_ImageType (int) imageType: the image format.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is loaded successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be loaded.
Return value boolean
Only valid when used synchronously.
Example
DWObject.IfShowFileDialog = true;
DWObject.LoadImageEx("", EnumDWT_ImageType.IT_ALL);
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v5.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes If you would like to load/open images by showing the 'Open File' dialog box, you can set IfShowFileDialog to true.
LoadImageFromBase64Binary()
Load image(s) from a base64 string.
Syntax .LoadImageFromBase64Binary(imageData, imageType, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string imageData: the base64 string that represents the image.
EnumDWT_ImageType (int) imageType: the image format.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the operation succeeds.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the operation fails.
Return value boolean
Example
var imagedata;
DWObject.SelectedImagesCount = 1;
DWObject.SetSelectedImageIndex(0,0);
DWObject.GetSelectedImagesSize(EnumDWT_ImageType.IT_JPG);
imagedata = DWObject.SaveSelectedImagesToBase64Binary();
DWObject.LoadImageFromBase64Binary(imagedata, EnumDWT_ImageType.IT_JPG, function(){
    console.log('success');
    },function(){
    console.log('failure');
});
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v6.2✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
SaveAllAsMultiPageTIFF()
Saves all the images in the buffer as a Multipage TIFF file.
Syntax .SaveAllAsMultiPageTIFF(fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName: the absolute path to save the file.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
DWObject.SaveAllAsMultiPageTIFF("C:\\DWT.tiff");
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v4.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes Multi-Page TIFF encoding is a built-in feature of Dynamic Web TWAIN, no extra dlls are required. If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveAllAsPDF()
Saves all the images in the buffer as a Multipage PDF file.
Syntax .SaveAllAsPDF(fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path to save the file.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
DWObject.SaveAllAsPDF("C:\\DWT.pdf");
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v5.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes Multi-Page PDF encoding is a built-in feature of Dynamic Web TWAIN, no extra dlls are required. If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveAsBMP()
Saves the image of a specified index in the buffer as a BMP file.
Syntax .SaveAsBMP(fileName, sImageIndex, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path on the client machine to save the file.
number sImageIndex : the index of the image in the buffer. The index is 0-based.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
//Callback functions for async APIs
function OnSuccess() {
    console.log('successful');
}
function OnFailure(errorCode, errorString) {            
    alert(errorString);
}
function btn_SaveOnClick() {
    if (DWObject.HowManyImagesInBuffer == 0){
        alert("No images in buffer.");
        return;                
    }
    DWObject.SaveAsBMP("D:\\test.bmp", 0, OnSuccess, OnFailure);
}
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v4.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveAsJPEG()
Saves the image of a specified index in the buffer as a JPEG file.
Syntax .SaveAsJPEG(fileName, sImageIndex, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path on the client machine to save the file.
number sImageIndex : the index of the image in the buffer. The index is 0-based.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
//Callback functions for async APIs
function OnSuccess() {
    console.log('successful');
}
function OnFailure(errorCode, errorString) {
        alert(errorString);
}
function btn_SaveOnClick() {
    if (DWObject.HowManyImagesInBuffer == 0){
        alert("No images in buffer.");
        return;
    }
    DWObject.SaveAsJPEG("D:\\test.jpg", 0, OnSuccess, OnFailure);
}
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v4.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveAsPDF()
Saves the image of a specified index in the buffer as a PDF file.
Syntax .SaveAsPDF(fileName, sImageIndex, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path on the client machine to save the file.
number sImageIndex : the index of the image in the buffer. The index is 0-based.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
//Callback functions for async APIs
function OnSuccess() {
    console.log('successful');
}
function OnFailure(errorCode, errorString) {            
    alert(errorString);
}
function btn_SaveOnClick() {
    if (DWObject.HowManyImagesInBuffer == 0){
        alert("No images in buffer.");
        return;                
    }
    DWObject.SaveAsPDF("D:\\test.pdf", 0, OnSuccess, OnFailure);
}
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v5.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveAsPNG()
Saves the image of a specified index in the buffer as a PNG file.
Syntax .SaveAsPNG(fileName, sImageIndex, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path on the client machine to save the file.
number sImageIndex : the index of the image in the buffer. The index is 0-based.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
//Callback functions for async APIs
function OnSuccess() {
    console.log('successful');
}
function OnFailure(errorCode, errorString) {
    alert(errorString);
}        
function btn_SaveOnClick() {
    if (DWObject.HowManyImagesInBuffer == 0){
        alert("No images in buffer.");
        return;
    }
    DWObject.SaveAsPNG("D:\\test.png", 0, OnSuccess, OnFailure);
}
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v4.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveAsTIFF()
Saves the image of a specified index in the buffer as a TIFF file.
Syntax .SaveAsTIFF(fileName, sImageIndex, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path on the client machine to save the file.
number sImageIndex : the index of the image in the buffer. The index is 0-based.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
//Callback functions for async APIs
function OnSuccess() {
    console.log('successful');
}
function OnFailure(errorCode, errorString) {            
    alert(errorString);
}
function btn_SaveOnClick() {
    if (DWObject.HowManyImagesInBuffer == 0){
        alert("No images in buffer.");
        return;                
    }
    DWObject.SaveAsTIFF("D:\\test.tif", 0, OnSuccess, OnFailure);
}
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v3.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveSelectedImagesAsMultiPagePDF()
Saves the selected images in the buffer as a Multipage PDF file.
Syntax .SaveSelectedImagesAsMultiPagePDF(fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path on the client machine for saving the file.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
DWObject.SelectedImagesCount = 1;
DWObject.SetSelectedImageIndex(0,0);
DWObject.SaveSelectedImagesAsMultiPagePDF("C:\\DWT.pdf");
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v6.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes Multi-Page PDF encoding is a built-in feature of Dynamic Web TWAIN, no extra dlls are required. If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveSelectedImagesAsMultiPageTIFF()
Saves the selected images in the buffer as a Multipage TIFF file.
Syntax .SaveSelectedImagesAsMultiPagePDF(fileName, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);
Parameters string fileName : the absolute path to save the file.
The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.
OnSuccess Function optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
OnFailure Function optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.
Return value boolean
Only valid when used synchronously.
Example
DWObject.SelectedImagesCount = 1;
DWObject.SetSelectedImageIndex(0,0);
DWObject.SaveSelectedImagesAsMultiPageTIFF("C:\\DWT.tiff");
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v6.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes Multi-Page TIFF encoding is a built-in feature of Dynamic Web TWAIN, no extra dlls are required. If you would like to save images by showing the 'Save File' dialog box, you can set IfShowFileDialog to true.
SaveSelectedImagesToBase64Binary()
Saves the selected images in the buffer to a base64 string.
Syntax .SaveSelectedImagesToBase64Binary();
Parameters None
Return value string
The result string is the pure base64 string with no extra info. For example,
"/9j/4AAQSkZJRgABA...".
To use the string in most circumstances, you need to add extra info like
data:image/png;base64,"/9j/4AAQSkZJRgABA...".
Example
var imagedata;
DWObject.SelectedImagesCount = 1;
DWObject.SetSelectedImageIndex(0, 0);
DWObject.GetSelectedImagesSize(EnumDWT_ImageType.IT_JPG);
imagedata = DWObject.SaveSelectedImagesToBase64Binary();
newImage.src = "data:image/png;base64," + imagedata;
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v6.2✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes Please invoke GetSelectedImagesSize before invoking this method to specify the target format. The default value is IT_JPG and it doesn't support black and white images.
ShowFileDialog()
Show the system's save-file dialog or open-file dialog.
Syntax .ShowFileDialog(bSave, filter, filterIndex, defaultExtension, initialDir, allowMultiSelect, overwritePrompt, flags);
Parameters boolean bsave: true -- show save-file dialog, false -- show open-file dialog.
string filter: the filter name specifies the filter pattern (for example, "JPG | *.jpg"). To specify multiple filter patterns use a semicolon to separate the patterns (for example, "JPG, PNG and TIF | *.jpg;*.png;*.tif" or "JPG, PNG , TIF" for macOS). A pattern string can be a combination of valid file extensions with asterisk (*). Do not include spaces in the pattern string. To show all files, use the string "All Files | *.*".
int filterIndex: determines the index for the filter string we set, in other words, where the filter string should appear in the dialog's filters drop-down box. By default, it's 0 and you don't need to change it. This parameter doesn't work on macOS.
string defaultExtension: define the default extension which will be appended to the file name. Only useful when you try to save an image or images. If this member is NULL and the user fails to type an extension, no extension is appended.
string initialDir: the initial directory. The algorithm for selecting the initial directory varies on different platforms.
boolean allowMultiSelect: true -- allow multiple selections, false -- only allow single file selection.
boolean overwritePrompt: true -- if a file already exists with the same name, the user needs to confirm before the existing file is overwritten, false -- if a file already exists with the same name, it will be overwritten without further user confirmation.
int flags: if this parameter equals 0, the program will be initiated with the custom settings. Otherwise it will be initiated with default flags, which means allowMultiSelect and overwritePrompt will not work.
Return value boolean
Example
DWObject.RegisterEvent('OnGetFilePath', function(bSave, filesCount, 
index, path, filename){
    alert(" fileCount: " +  filesCount + " index: " +  index + 
    " path: " +  path + "\\" +  filename);
});
//On macOS
var result = DWObject.ShowFileDialog(false, "TIF,TIFF,JPG,JPEG,PNG,PDF", 0, 
"", "", true, false, 0);
//On Windows
var result = DWObject.ShowFileDialog(false, "TIF,TIFF,JPG,JPEG,PNG,PDF", 0, 
"", "", true, true, 0)
alert(result);
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v8.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes For Mac Edition, the method performs differently.
This method will trigger OnGetFilePath event even when it fails. If multiple files are selected, the event will be called multiple times.

Properties

IfShowFileDialog
Returns or sets whether to show open/save file dialog when saving scanned images or loading images from a local directory.
Type boolean
Accessors Get Set
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v6.2✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes When loading, the property only works for the method LoadImageEx.

Events

OnGetFilePath
This event is triggered when a file path is returned from the operating system this occurs when the ShowFileDialog method is called or when the LoadImageEx method is called with IfShowFileDialog set to true.
Syntax .RegisterEvent('OnGetFilePath',function(bSave, filesCount, index, path, filename){...});
Arguments
  • boolean bSave: 'true' -- show save file dialog, 'false' -- show open file dialog.
  • number filesCount: How many files were selected. 0 means no file was selected or the user closed/cancelled.
  • number index: The index of the currently selected file. 0-based. -1 means no file was selected.
  • string path: The parent path of currently selected file(s), "\\" is not included. If the methed ShowFileDialog() failed, the initial directory path set in the ShowFileDialog method is returned.
  • string filename: The current file name.
Example
DWObject.RegisterEvent('OnGetFilePath', function(bSave, filesCount, 
index, path, filename)
{
    alert("bSave:" + bSave + " fileCount: " +  filesCount + " index: " +  index + 
    " path: " +  path + "\\" +  filename);
});
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v8.0✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
OnPostLoad
This event is triggered when an image file from a local directory has been loaded into the control.
Syntax .RegisterEvent('OnPostLoad',function(path, name, type){...});
Arguments
  • string path: the local path of the loaded image. For example, C:\Users\[username]\Downloads\
  • string name: the name of the loaded image. For example, image1.jpg
  • EnumDWT_ImageType type: Image format.
Example
DWObject.RegisterEvent('OnPostLoad', function(path, name, type) {
    alert(path + '\\' + name);
});
Availability
ActiveXH5(Windows)H5(macOS/TWAIN)H5(macOS/ICA)H5(Linux)
✓ | v6.3✓ | v10.0 ✓ | v10.0 ✓ | v11.0 ✓ | v12.1
Usage notes If multiple image files are loaded, this event will be triggered once for each image.

results matching ""

    No results matching ""

    results matching ""

      No results matching ""