Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Dev Center
Table of contents

{WebTwainObject} IO

The properties and methods on this page live in the namespace {WebTwainObject}. {WebTwainObject} denotes the WebTwain instance. Learn about how to create a web twain object.

Methods

Input Methods

       
LoadImage() LoadImageEx() LoadImageFromBase64Binary() LoadImageFromBinary()
LoadDibFromClipboard() FTPDownload() FTPDownloadEx() HTTPDownload()
HTTPDownloadEx() HTTPDownloadThroughPost() HTTPDownloadDirectly()  

Output Methods

     
ConvertToBase64() ConvertToBlob() FTPUpload()
FTPUploadEx() FTPUploadAllAsMultiPageTIFF() FTPUploadAllAsPDF()
FTPUploadAsMultiPagePDF() FTPUploadAsMultiPageTIFF() HTTPUpload()
HTTPUploadThroughPutEx() HTTPUploadThroughPost() HTTPUploadThroughPostEx()
HTTPUploadAllThroughPostAsMultiPageTIFF() HTTPUploadAllThroughPostAsPDF() HTTPUploadThroughPostAsMultiPagePDF()
HTTPUploadThroughPostAsMultiPageTIFF() HTTPUploadThroughPostDirectly() SaveAsBMP()
SaveAsJPEG() SaveAsPDF() SaveAsPNG()
SaveAsTIFF() SaveSelectedImagesAsMultiPagePDF() SaveSelectedImagesAsMultiPageTIFF()
SaveAllAsMultiPageTIFF() SaveAllAsPDF()  

Other Methods

       
ClearTiffCustomTag() SetTiffCustomTag() ClearAllHTTPFormField() SetHTTPFormField()
SetHTTPHeader() SetUploadSegment() ShowFileDialog() Print()
PrintEx()      

Properties

       
FTPPassword FTPPort FTPUserName IfPASVMode
HttpFieldNameOfUploadedImage HTTPPort IfSSL HTTPPostResponseString
IfShowFileDialog IfShowCancelDialogWhenImageTransfer IfShowProgressBar JPEGQuality
IfTiffMultiPage TIFFCompressionType MaxUploadImageSize  

Events

     
OnGetFilePath OnPostLoad OnInternetTransferPercentage

LoadImage

Load image(s) specified by its absolute path.

Syntax

LoadImage(
    fileName: string,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The path of the image to load.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v10.0+ v11.0+ not supported not supported

Example

DWObject.LoadImage(
    "C:\\test\\DWT.jpg",
    function () {
        console.log("success");
    },
    function (errorCode, errorString) {
        console.log(errorString);
    }
);

LoadImageEx

Load image(s) specified by its absolute path.

Syntax

LoadImageEx(
    fileName: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The path of the image to load.

type: The format of the image. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.1+

Usage Notes

On mobile devices, Dynamsoft.DWT.EnumDWT_ImageType.IT_ALL means “JPG, PNG, TIF” while it means “BMP, JPG, PNG, TIF, PDF” on desktop.

You can set IfShowFileDialog before calling this API to enable/disable “Open File” dialog.

Example

DWObject.IfShowFileDialog = true; //"Open File" dialog will be opened.

DWObject.LoadImageEx(
    "", //file name can be empty if "Open File" dialog is called.
    Dynamsoft.DWT.EnumDWT_ImageType.IT_JPG,
    function () {
        console.log("success");
    },
    function (errorCode, errorString) {
        console.log(errorString);
    }
);
DWObject.IfShowFileDialog = false; //Default value is true.

DWObject.LoadImageEx(
    "C:\\test\\DWT.jpg",
    Dynamsoft.DWT.EnumDWT_ImageType.IT_JPG,
    function () {
        console.log("success");
    },
    function (errorCode, errorString) {
        console.log(errorString);
    }
);

Remark

Load Guide


LoadImageFromBase64Binary

Load image(s) from a base64 string.

Syntax

LoadImageFromBase64Binary(
    imageData: string,
    imageType: Dynamsoft.DWT.EnumDWT_ImageType,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

imageData: The image data which is a base64 string without the data URI scheme.

imageType: The format of the image. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.2+ v10.0+ v10.0+ v11.0+ v12.1+ v16.1+

Usage Notes

You may leverage ConvertToBase64 to get a base64 string.

Example

DWObject.ConvertToBase64(
    [0, 1, 2],
    Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
    function (result, indices, type) {
        DWObject.LoadImageFromBase64Binary(
            result.getData(0, result.getLength()),
            Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
            function () {
                console.log("success");
            },
            function (errorCode, errorString) {
                console.log(errorString);
            }
        );
    },
    function (errorCode, errorString) {
        console.log(errorString);
    }
);

Remark

Load Guide


LoadImageFromBinary

Load image(s) from a binary object (Blob or ArrayBuffer).

Syntax

LoadImageFromBinary(
    imageData: Blob | ArrayBuffer,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

imageData: The image data.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v16.0+ v16.0+ v16.0+ v16.0+ v16.0+

Usage Notes

You may leverage ConvertToBlob to get a Blob object.

Example

DWObject.ConvertToBlob(
    [0, 1, 2],
    Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
    function (result, indices, type) {
        DWObject.LoadImageFromBinary(
            result,
            function () {
                console.log("success");
            },
            function (errorCode, errorString) {
                console.log(errorString);
            }
        );
    },
    function (errorCode, errorString) {
        console.log(errorString);
    }
);

Remark

Load Guide


LoadDibFromClipboard

Load an image from the system clipboard. The image must be in DIB format.

Syntax

LoadDibFromClipboard(
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.1+ v10.0+ v10.0+ v11.0+ v12.1+ not supported

Usage Notes

If called without any callback functions, these methods (except for LoadImageFromBinary() ) become synchronously and return a boolean value to indicate whether it succeeded.

However, calling them asynchronously is recommended.


OnGetFilePath

This event is triggered when ShowFileDialog() is called or when LoadImageEx() is called with IfShowFileDialog set to true.

Syntax

RegisterEvent(
    "OnGetFilePath",
    function (
        isSave: boolean,
        filesCount: number,
        index: number,
        directory: string,
        fileName: string
    ) {}
);

Parameters

isSave: Whether to show a save-file dialog (true) or an open-file dialog (false).

filesCount: How many files were selected.

index: The index of the current image.

directory: The parent directory of currently selected file(s), “\\” is not included. If the methed ShowFileDialog failed, the initial directory path set in the ShowFileDialog method is returned.

fileName: The current file name.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v8.0+ v10.0+ v10.0+ v11.0+ v12.1+ not supported

Example

DWObject.RegisterEvent('OnGetFilePath', function(isSave, filesCount, index, directory, filename) {
    alert("isSave:" + isSave + " fileCount: " +  filesCount + " index: " +  index + " directory: " +  directory + "\\" +  filename);
});

OnPostLoad

This event is triggered when a file from a local directory has been loaded into the control.

Syntax

RegisterEvent(
    "OnPostLoad",
    function (directory: string, fileName: string, fileType: string) {}
);

Parameters

directory: The directory of the loaded file. For example, “C:\Users\[username]\Downloads”.

fileName: The name of the loaded file. For example, “image1.jpg”.

fileType: The file type. Please refer to EnumDWT_ImageType.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.3+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Example

DWObject.RegisterEvent("OnPostLoad", function (path, name, type) {
    alert(path + "\\" + name);
});

FTPDownload

Download the specified file via FTP.

Syntax

FTPDownload(
    host: string,
    path: string,
    successCallback: () => void,
    failureCallBack: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

path: Specify the file to download.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ not supported

FTPDownloadEx

Download the specified file via FTP.

Syntax

FTPDownloadEx(
    host: string,
    path: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback: () => void,
    failureCallBack: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

path: Specify the file to download.

type: The format of the file. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ not supported

Example

/* The sample file path is: 
 * "ftp://192.168.8.20/files/sample.pdf"
 */
var onSuccess = function() {
    console.log("Downloaded a file successfully!");
};

var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};

DWObject.FTPPort = 21;
DWObject.FTPUserName = "FTPUser";
DWObject.FTPPassword = "SomePassword";
DWObject.FTPDownloadEx("192.168.8.20", "/files/sample.pdf", Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF, onSuccess, onFailure);

FTPUpload

Upload the specified image via FTP.

Syntax

FTPUpload(
    host: string,
    index: number,
    path: string,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

index: Specify the index of the image in the buffer. The index is 0-based.

path: The path to save the file.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ not supported

Example

var onSuccess = function() {
    console.log("Uploaded a file successfully!");
};

var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};

DWObject.FTPUserName = 'test';
DWObject.FTPPort = 21;
DWObject.FTPPassword = 'test';
DWObject.FTPUpload(
    '192.168.8.222', //The FTP Host
    0, // The index of the image
    'test.pdf', // The path & name of the file 
    onSuccess, // Callback in case of success
    onFailure // Callback in case of failure
);

FTPUploadEx

Upload the specified image via FTP.

Syntax

FTPUploadEx(
    host: string,
    index: number,
    path: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

index: Specify the index of the image in the buffer. The index is 0-based.

path: The path to save the file.

type: The format of the file. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ not supported

FTPUploadAllAsMultiPageTIFF

Upload all images as a multi-page TIFF via FTP.

Syntax

FTPUploadAllAsMultiPageTIFF(
    host: string,
    path: string,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

path: Specify the path to save the file.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ not supported

FTPUploadAllAsPDF

Upload all images as a multi-page PDF via FTP.

Syntax

FTPUploadAllAsPDF(
    host: string,
    path: string,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

path: Specify the path to save the file.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ not supported

FTPUploadAsMultiPagePDF

Upload selected images as a multi-page PDF via FTP.

Syntax

FTPUploadAsMultiPagePDF(
    host: string,
    path: string,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

path: Specify the path to save the file.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v6.0+ v6.0+ v6.0+ v6.0+ not supported

FTPUploadAsMultiPageTIFF

Upload selected images as a multi-page TIFF via FTP.

Syntax

FTPUploadAsMultiPageTIFF(
    host: string,
    path: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The FTP Host.

path: Specify the path to save the file.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v6.0+ v6.0+ v6.0+ v6.0+ not supported

FTPUserName

The password to connect to the FTP.

Syntax

FTPUserName: string;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.2+ v5.2+ v5.2+ v5.2+ v5.2+ not supported

FTPPassword

The password to connect to the FTP.

Syntax

FTPPassword: string;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.2+ v5.2+ v5.2+ v5.2+ v5.2+ not supported

FTPPort

The port to connect to the FTP.

Syntax

FTPPort: number;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.2+ v5.2+ v5.2+ v5.2+ v5.2+ not supported

IfPASVMode

Return or set whether to use passive mode when connect to the FTP.

Syntax

IfPASVMode: boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v6.0+ v6.0+ v6.0+ v6.0+ not supported

HTTPPassword

Return or set the password used to log into the HTTP server.

Syntax

HTTPPassword: string;

HTTPUserName

Return or set the user name used to log into the HTTP server.

Syntax

HTTPUserName: string;

HTTPDownload

Download the specified file via a HTTP Get request.

Syntax

HTTPDownload(
    host: string,
    path: string,
    successCallback: () => void,
    failureCallback: (
        errorCode: number,
        errorString: string) => void
): void;

Parameters

host: The HTTP Host.

path: Specify the path of the file to download.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ v16.0+

Example

/* The sample file path is: 
 * "http://localhost:300/files/sample.tif"
 */
var onSuccess = function() {
    console.log("Downloaded a file successfully!");
};

var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};

DWObject.HTTPPort = 300;
DWObject.HTTPDownload("localhost", "/files/sample.tif", onSuccess, onFailure);

Remark

Download Guide


HTTPDownloadEx

Download the specified file via a HTTP Get request.

Syntax

HTTPDownloadEx(
    host: string,
    path: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback: () => void,
    failureCallback: (
        errorCode: number,
        errorString: string) => void
): void;

Parameters

host: The HTTP Host.

path: Specify the path of the file to download.

type: The format of the file. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ not supported

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.

Example

In this example, the URL points to a server-side script.

The server-side script can be written in any language and in any logic as long as it returns a file. Please refer to Download-Server-Script.

/* The sample file path is: 
 * "http://localhost:300/files/sample.tif"
 */
var onSuccess = function() {
    console.log("Downloaded a file successfully!");
};

var onFailure = function(errorCode, errorString) {
    console.log(errorString);
};

DWObject.HTTPPort = 300;
DWObject.HTTPDownloadEx("localhost", "/getFile.aspx", Dynamsoft.DWT.EnumDWT_ImageType.IT_TIF, onSuccess, onFailure);

Remark

Download Guide


HTTPDownloadThroughPost

Download the specified file via a HTTP Post request.

Syntax

HTTPDownloadThroughPost(
    host: string,
    path: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (errorCode: number, errorString: string, response: string) => void,
): void;

Parameters

host: The HTTP Host.

path: Specify the path of the file to download.

type: The format of the file. Please refer to EnumDWT_ImageType.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v5.0+ v5.0+ v5.0+ v5.0+ not supported

HTTPDownloadDirectly

Download the specified file via a HTTP Get request.

Syntax

HTTPDownloadDirectly(
    host: string,
    path: string,
    localPath: string,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The HTTP Host.

path: Specify the path of the file to download.

localPath: Specify where to save the file.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v7.0+ v7.0+ v7.0+ v7.0+ v7.0+ not supported

Usage notes

The Dynamic Web TWAIN library will decode the downloaded data based on the type parameter ( HTTPDownloadEx() , HTTPDownloadThroughPost() ) or the extension of the file in the path parameter ( HTTPDownload() ).

For security reasons, the method HTTPDownloadDirectly() can only download the specified file to a whitelisted location. In other words, the user needs to call the method ShowFileDialog() and then get a whitelisted location to use. Check out the example below.

Example

DWObject.RegisterEvent(
    "OnGetFilePath",
    function (isSave, filesCount, index, directory, fileName) {
        DWObject.HTTPDownloadDirectly(
        "tst.dynamsoft.com",
        "/public/download/tools/Twack_32.msi",
        directory + "\\" + fileName,
        function () {},
        function (errorCode, errorString) {
            console.log(errorString);
        }
        );
    }
);

DWObject.ShowFileDialog(true, "MSI|*.msi", 0, ".msi", "", true, false, 1);

HTTPUpload

Upload the specified image(s) via a HTTP Post.

Syntax

HTTPUpload(
    URL: string,
    indices: number[],
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    dataFormat: Dynamsoft.DWT.EnumDWT_UploadDataFormat | number,
    fileName: string,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (errorCode: number, errorString: string, response: string) => void
): void;
HTTPUpload(
    URL: string,
    indices: number[],
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    dataFormat: Dynamsoft.DWT.EnumDWT_UploadDataFormat | number,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (errorCode: number, errorString: string, response: string) => void
): void;

Parameters

URL: The server-side script to receive the post. For the sample code of Server Script, please refer to Upload-Server-Script.

indices: Specify the image(s).

type: The format of the file. Please refer to EnumDWT_ImageType.

dataFormat: Whether to upload the file as binary or a base64 string. Please refer to EnumDWT_UploadDataFormat.

fileName: The file name.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode The error code.
  • errorString The error string.
  • response The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v12.0+ v12.0+ v12.0+ v12.0+ v16.0+

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.

Example

DWObject.HTTPUpload(
    'https://www.dynamsoft.com/SaveToFile.aspx', 
    [0,1],  
    Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF, 
    Dynamsoft.DWT.EnumDWT_UploadDataFormat.Binary, 
    'test.pdf', 
    OnEmptyResponse, 
    OnServerReturnedSomething
);

function OnEmptyResponse() {
    console.log('Success');
}

function OnServerReturnedSomething(errCode, errString, responseStr) {
    console.log(errString);
}

Remark

Upload Guide


HTTPUploadThroughPutEx

Upload the specified image via a HTTP Put request.

Syntax

HTTPUploadThroughPutEx(
    host: string,
    index: number,
    path: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback: () => void,
    failureCallback: (errorCode: number, errorString: string) => void
): void;

Parameters

host: The HTTP Host.

index: Specify the image.

path: Specify the path to put the file.

type: The format of the file. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ not supported

HTTPUploadThroughPost

Upload the specified image via a HTTP Post request.

Syntax

HTTPUploadThroughPost(
    host: string,
    index: number,
    target: string,
    fileName: string,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (errorCode: number, errorString: string, response: string) => void
): void;

Parameters

host: The HTTP Host.

index: Specify the image.

target: The target where the request is sent. For the sample code of Server Script, please refer to Upload-Server-Script.

fileName: The file name.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ not supported

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.

Example

var strHTTPServer = location.hostname; //The name of the HTTP server. For example: "www.dynamsoft.com";
var CurrentPathName = unescape(location.pathname);
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
var strActionPage = CurrentPath + "SaveToFile.aspx";

DWObject.IfSSL = false; // Set whether SSL is used
DWObject.HTTPPort = location.port == "" ? 100 : location.port;

var Digital = new Date();
var uploadfilename = Digital.getMilliseconds();

DWObject.HTTPUploadThroughPost(
    strHTTPServer,
    DWObject.CurrentImageIndexInBuffer,
    strActionPage,
    uploadfilename + ".jpg",
    function () {
        console.log("Empty response");
    },
    function (errorCode,errorString,response) {
        console.log(response);
    }
);

HTTPUploadThroughPostEx

Upload the specified image in a specific image format via a HTTP Post request.

Syntax

HTTPUploadThroughPostEx(
    host: string,
    index: number,
    target: string,
    fileName: string,
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (
        errorCode: number,
        errorString: string,
        response: string) => void
): void;

Parameters

host: The HTTP Host.

index: Specify the image.

target: The target where the request is sent. For the sample code of Server Script, please refer to Upload-Server-Script.

fileName: The file name.

type: The format of the file. Please refer to EnumDWT_ImageType.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ not supported

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.


HTTPUploadAllThroughPostAsMultiPageTIFF

Upload all images in the buffer as a TIFF file via a HTTP Post request.

Syntax

HTTPUploadAllThroughPostAsMultiPageTIFF(
    host: string,
    target: string,
    fileName: string,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (
        errorCode: number,
        errorString: string,
        response: string) => void
): void;

Parameters

host: The HTTP Host.

target: The target wherethe request is sent. For the sample code of Server Script, please refer to Upload-Server-Script.

fileName: The file name.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v4.0+ v4.0+ v4.0+ v4.0+ not supported

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.


HTTPUploadAllThroughPostAsPDF

Upload all images in the buffer as a PDF file via a HTTP Post request.

Syntax

HTTPUploadAllThroughPostAsPDF(
    host: string,
    target: string,
    fileName: string,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (
        errorCode: number,
        errorString: string,
        response: string) => void
): void;

Parameters

host: The HTTP Host.

target: The target where the request is sent. For the sample code of Server Script, please refer to Upload-Server-Script.

fileName: The file name.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ not supported

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.


HTTPUploadThroughPostAsMultiPagePDF

Upload all selected images in the buffer as a PDF file via a HTTP Post request.

Syntax

HTTPUploadThroughPostAsMultiPagePDF(
    host: string,
    target: string,
    fileName: string,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (
        errorCode: number,
        errorString: string,
        response: string) => void
): void;

Parameters

host: The HTTP Host.

target: The target where the request is sent. For the sample code of Server Script, please refer to Upload-Server-Script.

fileName: The file name.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v6.0+ v6.0+ v6.0+ v6.0+ not supported

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.


HTTPUploadThroughPostAsMultiPageTIFF

Upload all selected images in the buffer as a TIFF file via a HTTP Post request.

Syntax

HTTPUploadThroughPostAsMultiPageTIFF(
    host: string,
    target: string,
    fileName: string,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (
        errorCode: number,
        errorString: string,
        response: string) => void
): void;

Parameters

host: The HTTP Host.

target: The target where the request is sent. For the sample code of Server Script, please refer to Upload-Server-Script.

fileName: The file name.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v6.0+ v6.0+ v6.0+ v6.0+ not supported

Usage Notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.


HTTPUploadThroughPostDirectly

Syntax

HTTPUploadThroughPostDirectly(
    host: string,
    path: string,
    target: string,
    fileName: string,
    onEmptyResponse: () => void,
    onServerReturnedSomething: (
        errorCode: number,
        errorString: string,
        response: string) => void
): void;

Parameters

host: The HTTP Host.

path: Specify the file to upload.

target: The target where the request is sent. For the sample code of Server Script, please refer to Upload-Server-Script.

fileName: The file name.

onEmptyResponse: A callback function that is executed if the response is empty.

onServerReturnedSomething: A callback function that is executed if the response is not empty.

  • errorCode: The error code.
  • errorString: The error string.
  • response: The response string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v7.0+ v7.0+ v7.0+ v7.0+ v7.0+ not supported

Usage notes

If you want to use this method to upload / download files through HTTPS, please don’t forget to set IfSSL to true and set the correct HTTPPort.

For security reasons, the method HTTPUploadThroughPostDirectly() can only upload a whitelisted file. In other words, the local file to upload should be either created by the library or selected manually by the user.

To select a local file to upload, call the method ShowFileDialog() and then get the file path in the callback OnGetFilePath. Check out the example below.

Example

DWObject.RegisterEvent(
  "OnGetFilePath",
  function (isSave, filesCount, index, directory, fileName) {
    DWObject.HTTPUploadThroughPostDirectly(
      "localhost",
      directory + "\\" + fileName,
      "SaveUploadedFile.aspx",
      fileName,
      function () {},
      function (errorCode, errorString, response) {
        console.log(errorString + " " + response);
      }
    );
  }
);
DWObject.ShowFileDialog(false, "All Files|*.*", 0, "", "", false, false, 1);

HttpFieldNameOfUploadedImage

Return or set the field name for the uploaded file. By default, it’s “RemoteFile”.

Syntax

HttpFieldNameOfUploadedImage: string;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v6.0+ v6.0+ v6.0+ v6.0+ not supported

HTTPPort

Return or set the HTTP Port. The default value is 80.

Syntax

HTTPPort: number;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.2.1+ v4.2.1+ v4.2.1+ v4.2.1+ v4.2.1+ not supported

IfSSL

Return or set whether to use SSL in HTTP requests. The default value is false.

Syntax

IfSSL: boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.2+ v5.2+ v5.2+ v5.2+ v5.2+ not supported

HTTPPostResponseString

Return the response string of the latest HTTP Post request.

Syntax

readonly HTTPPostResponseString: string;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v3.0.3+ v3.0.3+ v3.0.3+ v3.0.3+ v3.0.3+ not supported

MaxUploadImageSize

Return or set the maximum allowed size of a file to upload (in bytes). The default value is -1 which indicates there is no limit over the upload size. The value should be equal or smaller than 2147483647 which essentially means 2 GB.

Syntax

MaxUploadImageSize: number;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.2+ v5.2+ v5.2+ v5.2+ v5.2+ v16.0+

OnInternetTransferPercentage

This event is triggered multiple times during a HTTP upload or download request.

Syntax

RegisterEvent("OnInternetTransferPercentage", function (percentage: number) {});

Parameters

percentage: Return the progress by percentage.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ not supported

ConvertToBase64

Convert the specified images to a base64 string.

Syntax

ConvertToBase64(
    indices: number[],
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback: (result: Base64Result, indices: number[], type: number) => void,
    failureCallBack: (errorCode: number, errorString: string) => void
): void;

interface Base64Result {
    /**
     * Return the length of the result string.
     */
    getLength(): number;
    /**
     * Return part of the string.
     * @param offset The starting position.
     * @param length The length of the expected string.
     */
    getData(offset: number, length: number): string;
    /**
     * Return the MD5 value of the result.
     */
    getMD5(): string;
}

Parameters

indices: Specify one or multiple images.

type: The file type. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

  • result: The resulting base64 string.
  • indices: The indices of the converted images.
  • type: The file type.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v12.0+ v12.0+ v12.0+ v12.1+ v16.0+

Usage Notes

getData() returns the pure base64 string without the data URI scheme. For example, “/9j/4AAQSkZJRgABA…”. If you want to use the string, you probably need to add the scheme. For example, “data:image/png; base64, /9j/4AAQSkZJRgABA…”.

Example

DWObject.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);
    }
);

ConvertToBlob

Convert the specified images to a blob.

Syntax

ConvertToBlob(
    indices: number[],
    type: Dynamsoft.DWT.EnumDWT_ImageType | number,
    successCallback: (result: Blob, indices: number[], type: number) => void,
    failureCallBack: (errorCode: number, errorString: string) => void
): void;

Parameters

indices: Specify one or multiple images.

type: The file type. Please refer to EnumDWT_ImageType.

successCallback: A callback function that is executed if the request succeeds.

  • result: The resulting blob.
  • indices: The indices of the converted images.
  • type: The file type.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v13.0+ v13.0+ v13.0+ v13.0+ v16.0+

Example

DWObject.ConvertToBlob(
    [0, 1, 2],
    Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
    function (result, indices, type) {
        console.log(result.size);
    },
    function (errorCode, errorString) {
        console.log(errorString);
    }
);

SaveAsBMP

Save the specified image as a BMP file.

Syntax

SaveAsBMP(
    fileName: string,
    index: number,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

index: The index which specifies the image to save.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ not supported

Usage Notes

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.


SaveAsJPEG

Save the specified image as a JPEG file.

Syntax

SaveAsJPEG(
    fileName: string,
    index: number,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

index: The index which specifies the image to save.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.


SaveAsPDF

Save the specified image as a PDF file.

Syntax

SaveAsPDF(
    fileName: string,
    index: number,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

index: The index which specifies the image to save.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

Learn about how to config PDF save settings.

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.


SaveAsPNG

Save the specified image as a PNG file.

Syntax

SaveAsPNG(
    fileName: string,
    index: number,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

index: The index which specifies the image to save.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.


SaveAsTIFF

Save the specified image as a TIFF file.

Syntax

SaveAsTIFF(
    fileName: string,
    index: number,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v3.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Parameters

fileName: The name to save to (or specify the absolute path).

index: The index which specifies the image to save.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Usage notes

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.


SaveAllAsMultiPageTIFF

Saves all the images in buffer as a multi-page TIFF file.

Syntax

SaveAllAsMultiPageTIFF(
    fileName: string,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode The error code.
  • errorString The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

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 buffer as a multi-page PDF file.

Syntax

SaveAllAsPDF(
    fileName: string,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

Learn about how to config PDF save settings.

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.


SaveSelectedImagesAsMultiPagePDF

Saves all selected images in buffer as a multi-page PDF file.

Syntax

SaveSelectedImagesAsMultiPagePDF(
    fileName: string,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

Learn about how to config PDF save settings.

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.

Example

function SaveAll() {
    DWObject.SelectImages([0,1]); // select first 2 images.
    DWObject.IfShowFileDialog = true; // Set "true" to show "Save File" dialog.
    DWObject.SaveSelectedImagesAsMultiPagePDF(
        "C:\\Users\\UserName\\Desktop\\multi-save.pdf",
        function () {
            console.log("Success");
        },
        function (errorCode, errorString) {
            console.log(errorString);
        }
    );
}

SaveSelectedImagesAsMultiPageTIFF

Saves all selected images in buffer as a multi-page TIFF file.

Syntax

SaveSelectedImagesAsMultiPageTIFF(
    fileName: string,
    successCallback ? : () => void,
    failureCallback ? : (errorCode: number, errorString: string) => void
): void | boolean;

Parameters

fileName: The name to save to (or specify the absolute path).

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

If called without any callback functions, these methods become synchronously and return a boolean value to indicate whether it succeeded. However, calling them asynchronously is recommended.

If you are using WASM mode on the desktop, the image will always be saved to the Downloads folder even if you specify an absolute path.

If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog to true.

function SaveAll() {
    DWObject.SelectImages([0,1]); // select first 2 images.
    DWObject.IfShowFileDialog = true; // Set "true" to show "Save File" dialog.
    DWObject.SaveSelectedImagesAsMultiPageTIFF(
        "C:\\Users\\UserName\\Desktop\\multi-save.tif",
        function () {
            console.log("Success");
        },
        function (errorCode, errorString) {
            console.log(errorString);
        }
    );
}

ClearTiffCustomTag

Clear the content of all custom tiff tags.

Syntax

ClearTiffCustomTag(): boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v10.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

SetTiffCustomTag

Sets a custom tiff tag (up to 32 tags). The string to be set in a tag can be base64 encoded.

Syntax

SetTiffCustomTag(
    id: number,
    content: string,
    useBase64Encoding: boolean
): boolean;

Parameters

id: The id of the custom tag.

content: The content of the tag.

useBase64Encoding: Whether the content is encoded.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v10.0+ v10.0+ v10.0+ v11.0+ v12.1+ v16.0+

Usage notes

The method SetTiffCustomTag() sets one or up to 32 tags to be added to a TIFF file when generating it. The content of the tags can be plain text or a base64-encoded string. If it’s encoded, it’ll be decoded when generating the TIFF file.

To make sure you don’t included unwanted tags, call ClearTiffCustomTag() to clear old tags before setting up new ones.

Example

DWObject.ClearTiffCustomTag();
DWObject.SetTiffCustomTag(700, "Created By DWT", false);
DWObject.SaveAsTIFF("C:\\DWT.tiff", 0);

ClearAllHTTPFormField

Clear all the custom fields from the HTTP Post Form.

Syntax

ClearAllHTTPFormField(): boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ v16.0+

SetHTTPFormField

Add a custom field to the HTTP Post Form. Or add a binary file to the HTTP Post Form.

Syntax

SetHTTPFormField(
    name: string,
    value: string
): boolean;
SetHTTPFormField(
    name: string,
    content: Blob,
    fileName ? : string
): boolean;

Parameters

name: The name of the field.

value: The value of the field.

content: The content of the file.

fileName: The name of the file.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v5.0+ v5.0+ v5.0+ v5.0+ v16.0+

SetHTTPHeader

Add a custom header to the HTTP Post Form.

Syntax

SetHTTPHeader(
    name: string,
    value: string
): boolean;

Parameters

name: The name of the header.

value: The value of the header.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v12.0+ v12.0+ v12.0+ v12.0+ v16.0+

SetUploadSegment

Set the segmentation threshold and segment size.

Syntax

SetUploadSegment(
    threshold: number,
    size: number
): boolean;

Parameters

threshold: Specify the threshold (in MB).

size: Specify the segment size (in KB).

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v12.1+ v12.1+ v12.1+ v12.1+ not supported

IfShowFileDialog

Return or set whether to show open/save file dialog when saving images in the buffer or loading images from a local directory.

Syntax

IfShowFileDialog: boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.2+ v10.0+ v11.0+ v11.0+ v12.1+ not supported

Usage notes

Supported in Service mode only.


IfShowCancelDialogWhenImageTransfer

Return or set whether to show the progress of an operation with a button to cancel it.

Syntax

IfShowCancelDialogWhenImageTransfer: boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.2+ v5.2+ v5.2+ v5.2+ v5.2+ not supported

IfShowProgressBar

Return or set whether the progress bar is/should be displayed during encoding or decoding. It works for any image encoding/decoding related methods. For example: LoadImage, LoadImageEx, ConvertToBlob, etc.

Syntax

IfShowProgressBar: boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v8.0+ v10.0+ v10.0+ v11.0+ v12.1+ not supported

ShowFileDialog

Show the system’s save-file dialog or open-file dialog.

Syntax

ShowFileDialog(
    isSave: boolean,
    filter: string,
    filterIndex: number,
    defaultExtension: string,
    initialDirectory: string,
    allowMultiSelect: boolean,
    showOverwritePrompt: boolean,
    flag: number
): boolean;

Parameters

isSave: Whether to show a save-file dialog (true) or an open-file dialog (false).

filter: The filter pattern like “JPG or *.jpg”.

filterIndex: The order of the filter. Normally, just put 0.

defaultExtension: Extension to be appended to the file name. Only valid in a save-file dialog.

initialDirectory: The initial directory that the dialog opens.

allowMultiSelect: Whether or not multiple files can be selected at the same time. Only valid in an open-file dialog.

showOverwritePrompt: Whether or not a prompt shows up when saving a file may overwrite an existing file.

flag: If set to 0, bAllowMultiSelect and bShowOverwritePrompt will be effective. Otherwise, these two parameters are ignored.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v8.0+ v10.0+ v10.0+ v11.0+ v12.1+ not supported

Usage notes

Supported in Service mode only.

The filter pattern string consists of a combination(s) of valid file extensions with asterisk (*). For example: JPG, PNG and TIF | *.jpg;*png;*.tif . On macOS, the string is different. For example JPG, PNG , TIF . To show all files, use All Files | *.* . Do not include spaces in the pattern string.

This method will trigger OnGetFilePath event even when it fails. If multiple files are selected, the event will be called multiple times.

Example

DWObject.RegisterEvent(
    "OnGetFilePath",
    function (isSave, filesCount, index, directory, fileName) {
        alert(" directory: " + directory + "\\" + fileName);
    }
);

//On macOS
DWObject.ShowFileDialog(
    false,
    "TIF,TIFF,JPG,JPEG,PNG,PDF",
    0,
    "",
    "",
    true,
    false,
    0
);

//On Windows
DWObject.ShowFileDialog(
    false,
    "BMP,TIF,JPG,PNG,PDF|*.bmp;*.tif;*.png;*.jpg;*.pdf;*.tiff;*.jpeg",
    0,
    "",
    "",
    true,
    false,
    0
);

Print

Export all image data in the buffer to a new browser window and use the browser’s built-in print feature to print the image(s).

Syntax

Print(useOSPrintWindow ? : boolean): boolean;

Parameters

useOSPrintWindow: Whether to use the print feature of the operating system instead.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Usage Notes

The parameter only works in Windows Service mode.


PrintEx

Print selected image(s).

Syntax

PrintEx(indices: number[]): void;

Parameters

indices: Specify the image.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v17.0+ v17.0+ v17.0+ v17.0+ v17.0+

JPEGQuality

Return or set the quality for JPEG compression.

Syntax

JPEGQuality: number;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v5.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Usage notes

The default value of JPEGQuality property is 80.

The valid range is 0-100. The higher the JPEGQuality property, the better the quality and the bigger the size of the file.


IfTiffMultiPage

Return or set whether to append to or replace an existing TIFF file with the same name.

Syntax

IfTiffMultiPage: boolean;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v3.0+ v10.0+ v11.0+ v11.0+ v12.1+ not supported

Usage notes

When you save a new image in the same name of an existing TIFF file:

1) If this property is true, the new image will be added to the existing file.

2) If this property is false, the new image will replace the existing file.


TIFFCompressionType

Return or set the compression type for TIFF files.

Syntax

TIFFCompressionType: Dynamsoft.DWT.EnumDWT_TIFFCompressionType | number;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Usage notes

When set to TIFF_AUTO (0), 1-bit images will be compressed in TIFF_T6 (4) while images with other bit depth will be compressed in TIFF_LZW (5).

When set to TIFF_JPEG (7), 1-bit images will be compressed in TIFF_T6 (4), color images or grey images (8-bit or higher) in TIFF_JPEG (7) standard, and other images by TIFF_LZW (5).

TIFF_T4 (3) and TIFF_FAX3 (3) are two names for the same compression type. So are TIFF_T6 (4) and TIFF_FAX4 (4).

TIFF_RLE (2), TIFF_T4 (3), TIFF_FAX3 (3) and TIFF_PACKBITS (32773) only support compression of 1-bit images. TIFF_JPEG (7) supports compression of 8-bit above color images and 8-bit grey images.

When TIFF_JPEG (7) is used, you can use JPEGQuality to further reduce the size of the TIFF file.

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest Version
    • Version 17.2.1
    • Version 17.1.1
    • Version 17.0
    • Version 16.2
    • Version 16.1.1
    Change +
    © 2003–2022 Dynamsoft. All rights reserved.
    Privacy Statement / Site Map / Home / Purchase / Support