Thanks for Downloading Dynamic Web TWAIN 30-Day Trial!
Your download will start shortly. If your download does not begin, click here to retry.
{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
Output Methods
Other Methods
Properties
Events
OnGetFilePath |
OnPostLoad |
OnInternetTransferPercentage |
The Android Service Edition only supports a subset of the APIs available in the Desktop Service Edition. For the APIs that are compatible with both editions, the usage remains the same. To learn how to use the APIs, please refer to the documentation for the Desktop Service Edition.
Methods
Input Methods
LoadImageEx() |
LoadImageFromBase64Binary() |
LoadImageFromBinary() |
LoadDibFromClipboard() |
HTTPDownload() |
HTTPDownloadEx() |
HTTPDownloadThroughPost() |
loadFromLocalStorage() |
Output Methods
Other Methods
ClearTiffCustomTag() |
SetTiffCustomTag() |
ClearAllHTTPFormField() |
SetHTTPFormField() |
SetHTTPHeader() |
SetUploadSegment() |
Print() |
PrintEx() |
createLocalStorage() |
localStorageExist() |
removeLocalStorage() |
Properties
HttpFieldNameOfUploadedImage |
HTTPPort |
IfSSL |
HTTPPostResponseString |
IfShowCancelDialogWhenImageTransfer |
IfShowProgressBar |
JPEGQuality |
IfTiffMultiPage |
TIFFCompressionType |
MaxUploadImageSize |
Events
OnPostLoad |
OnInternetTransferPercentage |
LoadImage()
Load image(s) specified by its absolute path.
Syntax
LoadImage(
fileName: string
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
LoadImage(
fileName: string,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v4.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | not supported |
Example
DWTObject.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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
LoadImageEx(
fileName: string,
type: Dynamsoft.DWT.EnumDWT_ImageType | number,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v5.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage Notes
You can set IfShowFileDialog
before calling this API to enable/disable “Open File” dialog.
Example
DWTObject.IfShowFileDialog = true; //"Open File" dialog will be opened.
DWTObject.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);
}
);
DWTObject.IfShowFileDialog = false; //Default value is true.
DWTObject.LoadImageEx(
"C:\\test\\DWT.jpg",
Dynamsoft.DWT.EnumDWT_ImageType.IT_JPG,
function () {
console.log("success");
},
function (errorCode, errorString) {
console.log(errorString);
}
);
Remark
LoadImageFromBase64Binary()
Load image(s) from a base64 string.
Syntax
LoadImageFromBase64Binary(
imageData: string,
imageType: Dynamsoft.DWT.EnumDWT_ImageType
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
LoadImageFromBase64Binary(
imageData: string,
imageType: Dynamsoft.DWT.EnumDWT_ImageType,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v6.2+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage Notes
You may leverage ConvertToBase64()
to get a base64 string.
Example
DWTObject.ConvertToBase64(
[0, 1, 2],
Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
function (result, indices, type) {
DWTObject.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
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) | Android Service |
not supported | v16.0+ | v16.0+ | v16.0+ | v16.0+ | v18.2+ |
Usage Notes
You may leverage ConvertToBlob()
to get a Blob object.
Example
DWTObject.ConvertToBlob(
[0, 1, 2],
Dynamsoft.DWT.EnumDWT_ImageType.IT_PDF,
function (result, indices, type) {
DWTObject.LoadImageFromBinary(
result,
function () {
console.log("success");
},
function (errorCode, errorString) {
console.log(errorString);
}
);
},
function (errorCode, errorString) {
console.log(errorString);
}
);
Remark
LoadDibFromClipboard()
Load an image from the system clipboard. The image must be in DIB format.
Syntax
LoadDibFromClipboard(): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
LoadDibFromClipboard(
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v4.1+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
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: number,
filesCount: number,
index: number,
directory: string,
fileName: string
) {}
);
Parameters
isSave
: Whether or not the event is triggered after a save-file dialog was shown. 0
means false, 1
means true.
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) |
v8.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ |
Example
DWTObject.RegisterEvent('OnGetFilePath', function(isSave, filesCount, index, directory, filename) {
alert("isSave:" + isSave + " fileCount: " + filesCount + " index: " + index + " directory: " + directory + "\\" + filename);
});
OnPostLoad
This event triggers upon returning from LoadImage()
or LoadImageEx()
, regardless of whether they succeed or not.
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) |
v6.3+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ |
Example
DWTObject.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) |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ |
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) |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ |
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);
};
DWTObject.FTPPort = 21;
DWTObject.FTPUserName = "FTPUser";
DWTObject.FTPPassword = "SomePassword";
DWTObject.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) |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ |
Example
var onSuccess = function() {
console.log("Uploaded a file successfully!");
};
var onFailure = function(errorCode, errorString) {
console.log(errorString);
};
DWTObject.FTPUserName = 'test';
DWTObject.FTPPort = 21;
DWTObject.FTPPassword = 'test';
DWTObject.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) |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.0+ |
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) |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ |
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) |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ |
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) |
v6.0+ | v6.0+ | v6.0+ | v6.0+ | v6.0+ |
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) |
v6.0+ | v6.0+ | v6.0+ | v6.0+ | v6.0+ |
FTPUserName
The user name to connect to the FTP.
Syntax
FTPUserName: string;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
v5.2+ | v5.2+ | v5.2+ | v5.2+ | v5.2+ |
FTPPassword
The password to connect to the FTP.
Syntax
FTPPassword: string;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
v5.2+ | v5.2+ | v5.2+ | v5.2+ | v5.2+ |
FTPPort
The port to connect to the FTP.
Syntax
FTPPort: number;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
v5.2+ | v5.2+ | v5.2+ | v5.2+ | v5.2+ |
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) |
v6.0+ | v6.0+ | v6.0+ | v6.0+ | v6.0+ |
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) | Android Service |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ | v18.2+ |
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);
};
DWTObject.HTTPPort = 300;
DWTObject.HTTPDownload("localhost", "/files/sample.tif", onSuccess, onFailure);
Remark
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) | Android Service |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.0+ | v18.2+ |
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);
};
DWTObject.HTTPPort = 300;
DWTObject.HTTPDownloadEx("localhost", "/getFile.aspx", Dynamsoft.DWT.EnumDWT_ImageType.IT_TIF, onSuccess, onFailure);
Remark
HTTPDownloadThroughPost()
Download the specified file via a HTTP Post request.
Syntax
HTTPDownloadThroughPost(
host: string,
path: string,
type: Dynamsoft.DWT.EnumDWT_ImageType | number,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string, response?: any) => 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.response
: The response from your server.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) | Android Service |
not supported | v5.0+ | v5.0+ | v5.0+ | v5.0+ | v18.2+ |
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. If fileName
specifies the extension of the file additionally,
- if the extension is not the same as the format of the file which is specified by
type
, the extra extension will be added to the file name. For example,fileName
is set to"test.jpg"
, andtype
isDynamsoft.DWT.EnumDWT_ImageType.IT_PDF
, the final file name would betest.jpg.pdf
and the file format is PDF. - if the extension is the same as the format of the file which is specified by
type
, the file name equals to the string which is specified byfileName
. For example,fileName
is set to"test.pdf"
, andtype
isDynamsoft.DWT.EnumDWT_ImageType.IT_PDF
, the final file name would betest.pdf
and the file format is PDF.
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) | Android Service |
v18.0+ | v12.0+ | v12.0+ | v12.0+ | v12.0+ | v18.2+ |
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
DWTObject.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
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) | Android Service |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.0+ | v18.2+ |
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) | Android Service |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ | v18.2+ |
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";
DWTObject.IfSSL = false; // Set whether SSL is used
DWTObject.HTTPPort = location.port == "" ? 100 : location.port;
var Digital = new Date();
var uploadfilename = Digital.getMilliseconds();
DWTObject.HTTPUploadThroughPost(
strHTTPServer,
DWTObject.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) | Android Service |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.0+ | v18.2+ |
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) | Android Service |
v4.0+ | v4.0+ | v4.0+ | v4.0+ | v4.0+ | v18.2+ |
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) | Android Service |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.0+ | v18.2+ |
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) | Android Service |
v6.0+ | v6.0+ | v6.0+ | v6.0+ | v6.0+ | v18.2+ |
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) | Android Service |
v6.0+ | v6.0+ | v6.0+ | v6.0+ | v6.0+ | v18.2+ |
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
.
httpUploadBlob()
Upload images which are in blob format.
Syntax
httpUploadBlob(
URL: string,
blobData: Blob,
fileName: string,
optionConfig?:{
responseType?: Dynamsoft.DWT.EnumDWT_ResponseType,
formFields?:{
name: string,
value: Blob | string,
fileName?: string
}[],
headers?:{
name: string,
value: string
}[]
}
): Promise<any>;
Parameters
URL
: The server-side script to receive the post. For the sample code of Server Script, please refer to Upload-Server-Script.
blobData
: The blob data of the image to upload.
fileName
: The file name. If fileName
specifies the extension of the file additionally,
- if the extension is not the same as the blob type, the extra extension will be added to the file name. For example,
fileName
is set to"test.jpg"
, and blob type isapplication/pdf
, the final file name would betest.jpg.pdf
and the file format is PDF. - if the extension is the same as the blob type, the file name equals to the string which is specified by
fileName
. For example,fileName
is set to"test.pdf"
, and blob type isapplication/pdf
, the final file name would betest.pdf
and the file format is PDF.
optionConfig
:
responseType
: The response type. Please refer toEnumDWT_ResponseType
.formFields
: The fields to the HTTP Post Form.name
: The name of field.value
: The value of field.fileName
: Specify the file name, ifvalue
isBlob
.
headers
: The headers to the HTTP Post Form.name
: The name of header.value
: The value of header.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |
Usage notes
Supported blob type: image/jpeg
, image/png
, image/bmp
, image/tiff
, application/pdf
, image/jpg
, image/tif
.
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) |
v6.0+ | v6.0+ | v6.0+ | v6.0+ | v6.0+ |
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) |
v4.2.1+ | v4.2.1+ | v4.2.1+ | v4.2.1+ | v4.2.1+ |
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) |
v5.2+ | v5.2+ | v5.2+ | v5.2+ | v5.2+ |
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) |
v3.0.3+ | v3.0.3+ | v3.0.3+ | v3.0.3+ | v3.0.3+ |
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) |
v5.2+ | v5.2+ | v5.2+ | v5.2+ | v5.2+ |
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) |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.0+ |
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;
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. Please refer toBase64Result
.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) |
v18.0+ | v12.0+ | v12.0+ | v12.0+ | v12.1+ |
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
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);
}
);
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) |
not supported | v13.0+ | v13.0+ | v13.0+ | v13.0+ |
Example
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);
}
);
OutputSelectedAreaAsync()
Copy selected area to Blob or base64.
Syntax
OutputSelectedAreaAsync(
index: number,
area: {
x: number,
y: number,
width: number,
height: number
},
type: Dynamsoft.DWT.EnumDWT_ImageType | number,
imageFormatType: Dynamsoft.DWT.EnumDWT_ImageFormatType | number
): Promise < Blob | string > ;
Parameters
index
: Image to be copied from.
area
: Area of image to be copied. X,Y is top left corner origin, width and height is size of area to be copied
type
: The target image type of the blob/base64 (See Dynamsoft.DWT.EnumDWT_ImageType
for allowable types).
imageFormatType
: Specify if the return should be Blob or base64 string (Dynamsoft.DWT.EnumDWT_ImageFormatType
for values)
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) | Android Service |
N/A | v18.4+ | v18.4+ | v18.4+ | v18.4+ | v18.4+ |
SaveAsBMP()
Save the specified image as a BMP file.
Syntax
SaveAsBMP(
fileName: string,
index: number
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveAsBMP(
fileName: string,
index: number,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v4.0+ | v10.0+ | v11.0+ | v11.0+ | v12.1+ | v18.2+ |
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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveAsJPEG(
fileName: string,
index: number,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v4.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage notes
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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveAsPDF(
fileName: string,
index: number,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v5.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage notes
Learn about how to config PDF save settings.
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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveAsPNG(
fileName: string,
index: number,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v4.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage notes
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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveAsTIFF(
fileName: string,
index: number,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) | Android Service |
v3.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
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 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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveAllAsMultiPageTIFF(
fileName: string,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v4.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage notes
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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveAllAsPDF(
fileName: string,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v5.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage notes
Learn about how to config PDF save settings.
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
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveSelectedImagesAsMultiPagePDF(
fileName: string,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v6.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
Usage notes
Learn about how to config PDF save settings.
If you would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog
to true
.
SaveSelectedImagesAsMultiPageTIFF()
Saves all selected images in buffer as a multi-page TIFF file.
Syntax
SaveSelectedImagesAsMultiPageTIFF(
fileName: string
): boolean;
// Call this API asynchronously to avoid blocking the browser's main thread
SaveSelectedImagesAsMultiPageTIFF(
fileName: string,
successCallback: () => void,
failureCallback: (errorCode: number, errorString: string) => void
): void;
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) | Android Service |
v6.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
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 would like to save images by showing the ‘Save File’ dialog box, you can set IfShowFileDialog
to true
.
saveBlob()
Save image which are in blob format.
Syntax
saveBlob(
fileName: string,
blobData: Blob,
): Promise<void>;
Parameters
fileName
: The file name. If fileName
specifies the extension of the file additionally,
- if the extension is not the same as the blob type, the extra extension will be added to the file name. For example,
fileName
is set to"test.jpg"
, and blob type isapplication/pdf
, the final file name would betest.jpg.pdf
and the file format is PDF. - if the extension is the same as the blob type, the file name equals to the string which is specified by
fileName
. For example,fileName
is set to"test.pdf"
, and blob type isapplication/pdf
, the final file name would betest.pdf
and the file format is PDF.
blobData
: The blob data of the image to save.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |
Usage notes
Supported blob type: image/jpeg
, image/png
, image/bmp
, image/tiff
, application/pdf
, image/jpg
, image/tif
.
ShareImages()
Shares images using Android’s built in share functionality.
Syntax
ShareImages(
fileName: string,
indices: number[],
type: Dynamsoft.DWT.EnumDWT_ImageType
): Promise< void>;
If indicies
is an array, the behavour is dependant on type
:
-
If type is set to PDF or TIFF, a single multi-page file is shared
-
If any other type is set, mutiple single page files will be shared in the format of filename1.filetype, filename2.filetype, etc.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) | Android Service |
not supported | not supported | not supported | not supported | not supported | v18.2+ |
ClearTiffCustomTag()
Clear the content of all custom tiff tags.
Syntax
ClearTiffCustomTag(): boolean;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
v10.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ |
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) |
v10.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ |
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
DWTObject.ClearTiffCustomTag();
DWTObject.SetTiffCustomTag(700, "Created By DWT", false);
DWTObject.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) |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.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) |
v5.0+ | v5.0+ | v5.0+ | v5.0+ | v5.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) |
not supported | v12.0+ | v12.0+ | v12.0+ | v12.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) |
not supported | v12.1+ | v12.1+ | v12.1+ | v12.1+ |
IfShowFileDialog
Return or set whether to show open/save file dialog when saving images in the buffer or loading images from a local directory.
Note: This does not affect the Android Service edition. The dialog will always show not matter what IfShowFileDialog
is set to.
Syntax
IfShowFileDialog: boolean;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) | Android Service |
v6.2+ | v10.0+ | v11.0+ | v11.0+ | v12.1+ | not supported |
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) | Android Service |
v5.2+ | v5.2+ | v5.2+ | v5.2+ | v5.2+ | v18.2+ |
Usage Notes
This API is only valid if IfShowProgressBar
is set to true
.
IfShowProgressBar
Return or set whether the progress bar will be displayed during any encoding, decoding, or transfer activities.
Syntax
IfShowProgressBar: boolean;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) | Android Service |
v8.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ | v18.2+ |
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 or an open-file dialog.
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, allowMultiSelect
and showOverwritePrompt
will be effective. Otherwise, these two parameters are ignored.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
v8.0+ | v10.0+ | v10.0+ | v11.0+ | v12.1+ |
Usage notes
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
DWTObject.RegisterEvent(
"OnGetFilePath",
function (isSave, filesCount, index, directory, fileName) {
alert(" directory: " + directory + "\\" + fileName);
}
);
//On macOS
DWTObject.ShowFileDialog(
false,
"TIF,TIFF,JPG,JPEG,PNG,PDF",
0,
"",
"",
true,
false,
0
);
//On Windows
DWTObject.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) |
v6.0+ | v10.0+ | v11.0+ | v11.0+ | v12.1+ |
Usage Notes
The parameter only works in Windows Service mode.
PrintEx()
Print selected image(s).
Syntax
PrintEx(indices: number[]): boolean;
Parameters
indices
: Specify the image.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v17.0+ | v17.0+ | v17.0+ | v17.0+ |
createLocalStorage()
Create a storage folder locally to save the cache of encrypted images.
Syntax
createLocalStorage(
settings?: {
password?: string;
}
): Promise<string>;
Parameters
settings
:
password
: Specify the password which is used to protect the storage folder. Up to 32 characters.
Return value
A Promise object which will be resolved with the uid string which will be used as the storage folder’s name when the folder is created successfully.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |
Usage notes
- If
password
is not specified, the returneduid
string will be set as the password of the storage folder. - The local directory of the created storage folder is under
- Windows:
C:\Windows\SysWOW64\Dynamsoft\DynamsoftServicex64_{versionnumber}\storage
- macOS:
Go > Applications > Dynamsoft > DynamsoftServicex64_{versionnumber} > {installed version No.} > storage
- Linux:
/opt/dynamsoft/DynamsoftService/storage
- Windows:
-
The creation will not be successful, if the remaining disk space is less than
System Remaining Disk Space Windows x86 < 1.2GB Windows x64 < 4GB macOS 32bit < 1.2GB macOS 64bit < 4GB Linux < 4GB Android < 100MB
localStorageExist()
Determine whether the storage folder exists or not.
Syntax
localStorageExist(uid: string):Promise<boolean>;
Parameters
uid
: Specify the uid of the storage folder to determine.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |
saveToLocalStorage()
Save encrypted image caches to the specified storage folder.
Syntax
saveToLocalStorage(
settings:{
uid: string;
password?: string;
indices?: number[];
}
): Promise<string[]>;
Parameters
settings
:
uid
: Specify the storage folder to save the images cache.password
: The password of the specified storage folder.indices
: Specify the indices to save.- If not set, means all images in buffer.
- If set to
[]
, all cache in the specified storage folder will be clear.
Return value
A Promise object which will be resolved with the array of image ids which are saved to the storage folder successfully.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |
Usage notes
- Each time this method is called successfully, the original cache in the specified folder will be overwritten by the new cache.
-
The remaining disk space is calculated before saving each encrypted image caches. Subsequent saves will not be successful, if the remaining disk space is less than
System Remaining Disk Space Windows x86 < 1.2GB Windows x64 < 4GB macOS 32bit < 1.2GB macOS 64bit < 4GB Linux < 4GB Android < 100MB
loadFromLocalStorage()
Load image from the specified storage folder.
Syntax
loadFromLocalStorage (
settings:{
uid: string,
password?:string,
}
): Promise<{oriImageId: string, newImageId: string}[]>;
Parameters
settings
:
uid
: Specify the storage folder to load the images.password
: The password of the specified storage folder.
Return value
A Promise object which will be resolved with the array of object which contains the original image id (in storage folder) and the new image id (in Web TWAIN buffer) of the loaded image.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |
removeLocalStorage()
Remove the specified storage folder.
Syntax
removeLocalStorage(
settings:{
uid: string,
password?: string,
}
): Promise<boolean>;
Parameters
settings
:
uid
: Specify the storage folder to remove.password
: The password of the specified storage folder.
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |
JPEGQuality
Return or set the quality for JPEG compression.
Syntax
JPEGQuality: number;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
v5.0+ | v10.0+ | v11.0+ | v11.0+ | v12.1+ |
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) |
v3.0+ | v10.0+ | v11.0+ | v11.0+ | v12.1+ |
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. Please refer to EnumDWT_TIFFCompressionType
.
Syntax
TIFFCompressionType: Dynamsoft.DWT.EnumDWT_TIFFCompressionType | number;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
v4.0+ | v10.0+ | v11.0+ | v11.0+ | v12.1+ |
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.
IfSortBySelectionOrder
Whether to load the files by the selection order when load files by open file dialog.
Syntax
IfSortBySelectionOrder: boolean;
Availability
ActiveX | H5(Windows) | H5(macOS/TWAIN) | H5(macOS/ICA) | H5(Linux) |
not supported | v18.5+ | v18.5+ | v18.5+ | v18.5+ |