Created
August 1, 2017 16:20
-
-
Save randycasburn/802f278c3cfef0873dd086c34bbb9fee to your computer and use it in GitHub Desktop.
This makes a HTTP GET request from within Adobe Acrobat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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}); |
If I want to run a specific GET or POST request in a Adobe Javascript Button can I call your script to run it?
Also, after update of Adobe will be deleted?
I want to send a post request similar to this:
function leerenboard() {
try {
var campoVuoto = false; // Variabile di controllo
var campoVuotoNome = null; // Memorizza il nome del campo vuoto
var selectboard = 1;
var dati = {
selectboard: selectboard
};
var datiJSON = JSON.stringify(dati);
// Invia app.launchURL con i dati della singola riga
var url = "https://localhost/script/scriptleeren.php?dati=" + encodeURIComponent(datiJSON);
app.launchURL(url, true);
if (!campoVuoto) {
console.println("Tutti i dati sono stati inviati con successo.");
} else {
console.println("Nessun dato da inviare o campo vuoto trovato.");
console.println("Campo vuoto individuato: " + campoVuotoNome);
}
} catch (e) {
console.println("Errore durante l'invio dei dati: " + e);
}
}
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
};
@xator91 - Mirko - What have you tried? What didn't work?
@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
Hi fclcodan - replace the
console.log()
with.getField(name)
. Assign the field object to a variable and then simply assign the variable a value. That should do it. Something like this:The docs can be found here: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#field