Save base64 string to pdf file

1,473 views
Skip to first unread message

Lefteris Chatzimichail

unread,
May 4, 2017, 4:08:15 AM5/4/17
to Softone Developers Network
I have a base64 string which is returned by a web service.
I would like to decode this base64 string and save it to a pdf file with javascript.

Is this possible?

Νίκος Μάλιακκας

unread,
May 4, 2017, 6:55:21 AM5/4/17
to Softone Developers Network
You will need to be within a softone module (i.e ITEM)

if you control the web service, you can save the file to the webserver and then download it from softone module:

function Download(file) {
    strFileURL = 'http://your.url/' + file;
    var softOneDir = X.DIR('HTML');
    strHDLocation = softOneDir + file;
    var objXMLHTTP = new ActiveXObject('MSXML2.XMLHTTP');
    objXMLHTTP.open('GET', strFileURL, false);
    objXMLHTTP.send();
    if (objXMLHTTP.Status == 200) {
        var objADOStream = new ActiveXObject('ADODB.Stream');
        objADOStream.Open;
        objADOStream.Type = 1;
        objADOStream.Write(objXMLHTTP.ResponseBody);
        objADOStream.Position = 0;
        objADOStream.SaveToFile(strHDLocation, 2);
        objADOStream.Close;
        objADOStream = null;
    }
    objXMLHTTP = null;
}


if you dont control the webservice, you can get localy the base64 string  with

    var objXMLHTTP = new ActiveXObject('MSXML2.XMLHTTP');
    var strFileURL = "http://your.url/here";
    objXMLHTTP.open('GET', strFileURL, false);
    objXMLHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    objXMLHTTP.send();
    if (objXMLHTTP.Status == 200) {
        var myscript = objXMLHTTP.ResponseText;
    }

But I don't think it is possible to save the recoded pdf using X.TOFILE , the result will probably not be a pdf file or you will get an error.
What it is possible is to save it in a blob field is sql server using a store procedure that takes the base64 string and recodes it.

Lefteris Chatzimichail

unread,
May 30, 2017, 3:29:00 AM5/30/17
to Softone Developers Network
Nick, you were rgiht. Saving the base64 string to a file with  X.TOFILE it creates an invalid file.
I abandon the idea implementing this functionality with javascript.
I implemented with a in-process .NET dll with this functionality only and add it to the click event of a button (ExecCommand(int Cmd)).
Thank you for your time.
Reply all
Reply to author
Forward
0 new messages