Copy link to clipboard
Copied
So, I am trying to figure out how to get code to run within the console. It seems like for simple things like 1+2 it works but any functions I have written as a document JS does not work. What am I missing?
For reference, I am splitting some files...
function Split() {
var totalPages;
var i;
var arrNames = [ "SOME ARRAY HERE" ];
var targetPath = "/C/Users/SOMEPATH/";
totalPages = this.numPages;
try { for (i = 0; i < totalPages; i++)
this.extractPages({
nStart: i,
cPath: targetPath +arrNames + ".pdf"
});
console.println(targetPath +arrNames + ".pdf");
} catch (e) {
console.println("Aborted: " + e)
}
}
Copy link to clipboard
Copied
Does you execute the function? Any error message in the console?
Copy link to clipboard
Copied
Yes, I typed Split in console to execute but it actually returned the actual code for the function, which is super duper confusing. None of the console.println showed properly at all.
Copy link to clipboard
Copied
Like, when I say actual code, I meant it literally.
i.e. I typed:
Split
Then this appeared below:
function Split() {
var totalPages;
var i;
var arrNames = [ "SOME ARRAY HERE" ];
var targetPath = "/C/Users/SOMEPATH/";
totalPages = this.numPages;
try { for (i = 0; i < totalPages; i++)
this.extractPages({
nStart: i,
cPath: targetPath +arrNames + ".pdf"
});
console.println(targetPath +arrNames + ".pdf");
} catch (e) {
console.println("Aborted: " + e)
}
}
Copy link to clipboard
Copied
You must execute the function with:
Split();
Copy link to clipboard
Copied
So, I tried it and yes, it no longer spit out the entire function. Yay!
But it didn't generate any of the lines that console.println() is supposed to either. Any suggestions?
Copy link to clipboard
Copied
Try it without the try-catch.
Copy link to clipboard
Copied
1. I take it that your actual code did not include, literally, SOMEPATH....? Sorry if it's too obvious a point.
2. Question: Did running Split() produce any messages at all (expected or not)?
Copy link to clipboard
Copied
Yea. I wrote the code so, no, SOMEPATH isn't there. It's a real path...
Split did not produce any messages at all. Zero. But I actually got it to work by copying the whole document JS into the console, and highlighted the code block and do a Ctrl+Enter. But that seems, purpose defeating? I mean, why have document JS included with the document when the code cannot be called from console??? How would you debug things otherwise??
And FYI, I copied the code from the API directly for the most part, but it apparently missed a curly bracket, added now below:
function Split() {
var totalPages = this.numPages;
var i;
var arrNames = [ "SOME ARRAY HERE" ];
var targetPath = "/C/Users/SOMEPATH/";
try {
for (i = 0; i < totalPages; i++) {
this.extractPages({
nStart: i,
cPath: targetPath +arrNames + ".pdf"
});
console.println(targetPath +arrNames + ".pdf");
}
} catch (e) {
console.println("Aborted: " + e)
}
}
Like (0) •
Copy link to clipboard
Copied
Where does you save the script in the document?
Copy link to clipboard
Copied
[Question moved to the JavaScript forum]