Addon.PDF.ConvertToImage()

Description

Converts a local PDF file into an image with a specified resolution.

Syntax

.Addon.PDF.ConvertToImage(fileName, resolution, [optionalAsyncSuccessFunc, optionalAsyncFailureFunc]);

Parameters

<string> fileName: the name of the PDF to be converted. It should be the absolute path of the PDF on the local disk.
<float> resolution: specifies the output image resolution.

The following two parameters are optional. If either one exists or both exist, the method is asynchronous, otherwise it's synchronous.

<OnSuccess function> optional optionalAsyncSuccessFunc: callback function triggered when the file is saved successfully.
<OnFailure function> optional optionalAsyncFailureFunc: callback function triggered when the file failed to be saved.

Please refer to the function prototype OnSuccess or OnFailure.

Return value

Only valid when used synchronously.

bool

true indicates success. false indicates failure.

When false is returned, check ErrorCode or ErrorString for error information.

See also

Addon.PDF.Download
OnGetFilePath
ShowFileDialog

Example

//Callback functions for async APIs
function OnSuccess() {
    console.log('successful');
}
function OnSuccess_2() {
    console.log('successful');
    DWObject.ShowFileDialog(false, "PDF (*.pdf)|*.pdf", 0, "", "", true, true, 0);
}
function OnFailure(errorCode, errorString) {
    alert(errorString);
}
function LoadPDF() {
    if (DWObject) {
        if (location.hostname != "") {
            var CurrentPathName = unescape(location.pathname); // get current PathName in plain ASCII	
            var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
            var strPDFfilepath = CurrentPath + "Resources/addon/DynamicPDF.zip";
            var strHostIP = location.hostname;
            var port = location.port == "" ? 80 : location.port;
            DWObject.HTTPPort = port;
            var remoteFile = "http://" + strHostIP + ":" + port + strPDFfilepath;
            DWObject.Addon.PDF.Download(remoteFile, OnSuccess_2, OnFailure);
        }
    }
}
function Dynamsoft_OnGetFilePath(bSave, count, index, path, name) {
    fileName = path + "\\" + name;
    DWObject.Addon.PDF.ConvertToImage(fileName, 200, OnSuccess, OnFailure);
}