Skip to content

Instantly share code, notes, and snippets.

@randycasburn
Created August 1, 2017 16:20
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randycasburn/802f278c3cfef0873dd086c34bbb9fee to your computer and use it in GitHub Desktop.
Save randycasburn/802f278c3cfef0873dd086c34bbb9fee to your computer and use it in GitHub Desktop.
This makes a HTTP GET request from within Adobe Acrobat
/*
This file must be placed with the user JavaScript file location or the Acrobat JavaScript file location.
This provides FOLDER level privilege for the script.
This script WILL NOT WORK if created within the document using the script editor. This is due to DOCUMENT priviledge restrictions.
Once installed,
1. Open any PDF file in Acrobat
2. Pull down [File] and click [Get Mock Data]
3. Open the JavaScript Debug Console to view output.
/--------------/
1. Adds new menu item to File menu of Acrobat - Get Mock Data
2. Calls jsonplaceholder mock data service and requests post id # 1 to be returned
3. Upon return, prints any errors to the console, converts the stream to a string, convers the string to a JS object and prints
the object properties and values to the console.
*/
// Make HTTP GET request
ajax = app.trustedFunction(function(fURL) {
app.beginPriv();
Net.HTTP.request({ cVerb:"GET", cURL:fURL, oHandler: ajaxCallback});
app.endPriv();
});
// process the response
ajaxCallback = {
response:function(msg,uri,e){
var stream = msg;
var string = "";
var error = e == undefined? 'No HTTP errors' : "ERROR: " + e;
string = SOAP.stringFromStream( stream );
oResult = JSON.parse(string);
console.println(error);
console.println( "id: " + oResult.id);
console.println( "userId: " + oResult.userId);
console.println( "title: " + oResult.title);
console.println( "body: " + oResult.body);
}
};
// Add menu item to kick it all off
app.addMenuItem({
cName: "Get Mock Data", cParent: "File",
cExec: 'ajax("https://jsonplaceholder.typicode.com/posts/1");',
nPos: 0});
@xator91
Copy link

xator91 commented Mar 20, 2024

@xator91 - Mirko - What have you tried? What didn't work?

I have a PHP script that wait for a get request through URL, and i want that work without opening an external browser, is that possible?

  • Now it works. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment