These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Call batch java script from Perl (or other external program)?

Lady Cygnus
Registered: Mar 17 2009
Posts: 19
Answered

I have hundreds of journal articles arranged in year folders with non-informative names that I need renamed to journal.v[volume].n[issue].[first_page].

This is what I'm starting with:

Quote:

E:\Files\1985\4478798.pdf
E:\Files\1985\4478799.pdf
E:\Files\1985\4478800.pdf
E:\Files\1985\4478801.pdf
...
E:\Files\1985\4478823.pdf
E:\Files\1985\4478824.pdf

This is what I want:

Quote:

E:\Files\1985\jrn.v41.n1.0.pdf
E:\Files\1985\jrn.v41.n1.5.pdf
E:\Files\1985\jrn.v41.n1.12.pdf
E:\Files\1985\jrn.v41.n1.32.pdf
...
E:\Files\1985\jrn.v41.n2.0.pdf
E:\Files\1985\jrn.v41.n2.7.pdf

Each of the pages in the files are labeled using the actual page number, with the cover of the journal labeled "[unnumbered]". Using Batch Processing to write a java script I can get the volume {year (folder) - first-year = volume} & first page label. I'm looking for suggestions for getting the issue numbers.

It appears that the adobe batch doesn't do global variables when running on several files in a folder since it starts back at zero with each file. I'm not sure I'd want it to because I need to restart the count in each folder. Thus I can't simply iterate over the folder adding one to a variable when each "[unnumbered]" label is found.

I could make this work by having adobe run and output "jrn.v41.n4478###.[page#]" and then run a batch...or perl script on the folder to substitute the issue iteration. However, it was bad enough to have to run a batch process on 50 folders, but to do that and run another program gets tedious.

So, it would be great if I could get the result of "this.getPageLabel(0)" outside adobe, or run the batch itself from outside adobe and finish this project in Perl or a windows batch. OR - find a way to get the issue using the java script...

Thanks in advance for your help.
Christina

My Product Information:
Acrobat Pro 8.1.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Batch processing does support Acrobat JavaScript's global variables, [url=http://www.planetpdf.com/developer/article.asp?ContentID=generating_reports_with_javasc&gid=6570]Generating Reports with JavaScript[/url] by Dave Wright, but you may need to run a separate scrpt for initialializaiton and within the batch sequence check to make sure the global variables are initialized.

George Kaiser

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
To start off, Batch processes cannot be controlled from an external program, or even from JavaScript in the Acrobat environment. But, I think you should be able to get what you want from a single batch process.

To provide a strategy you'll need to post a shorter and clearer explaination. For example, you want to both rename file and label the pages, is this correct? Where do the issue numbers come from? Please be clear about what it is you want to do.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Lady Cygnus
Registered: Mar 17 2009
Posts: 19
I'm sorry, math & science were my strong points; writing not so much.
thomp wrote:
To provide a strategy you'll need to post a shorter and clearer explaination. For example, you want to both rename file and label the pages, is this correct?
The start files have the pages labeled, I don't care if the end-files have labeled pages (I suppose it would be nice if they did). I more need the file name to be in the specific format jrn.v[vol #].n[iss #].[first-page #].

Quote:
Where do the issue numbers come from? Please be clear about what it is you want to do.
The articles are in folders based on year without any indication of which issue they belong to. However, they do appear in the correct order. So issue 1 articles come before issue 2 articles. The first "article" of each issue is a miscellaneous pdf with the cover image and ads that appear in that issue of the journal. The cover is labeled "[unnumbered]" which I'm setting to "0".

My idea to get the issue number was to set a variable...I'll write it in scratch-code. Note, I don't actually [i]know[/i] java, I typically bludgeon perl or windows batch scripts into producing results.

var i = 0for (files in folder) {var label = this.getPageLabel(0);if (label == "[unnumbered]") {i++;var issue = i;};};

This mess is what I have so far, feel free to yell at me for bad coding practices (I must learn somehow...)

try { // regular expression to pull the directory (year) and filenamevar re = /[\w\s\.\/]+(\d{4})\/(\w+)\.pdf/;var myText = this.path;if(re.test(myText)) {var year = myText.replace(re,"$1")var filename = myText.replace(re,"$2")var volume = year-1944 // Get firstpage labelvar label_start = this.getPageLabel(0);if (label_start == "[unnumbered]") {label_start = "0";} var doi = "faj.v" + volume + ".n" + "issue" + "." + label_start;// where "issue" would eventually be the variable this.extractPages({cPath : "end_results_folder/" + doi + ".pdf"}); // for testing (to cut down on excess "bad files") - instead of the extract I've been using:// app.alert ("Found " + doi); } else { app.alert ("Your folder & file don't match the reg expression!"); }} catch (e) { app.alert("Aborted: " + e) }
Lady Cygnus
Registered: Mar 17 2009
Posts: 19
gkaiseril wrote:
Batch processing does support Acrobat JavaScript's global variables, [url=http://www.planetpdf.com/developer/article.asp?ContentID=generating_reports_with_javasc&gid=6570]Generating Reports with JavaScript[/url] by Dave Wright, but you may need to run a separate scrpt for initialializaiton and within the batch sequence check to make sure the global variables are initialized.
The Generating Reports with JavaScript is interesting, could that be used to create a list of my files with the page labels? Something that could (possibly) be made into a tab delimited text file of the format:

[b]File Name getPageLabel(0)[/b]
File100001 0
File100002 5
File100003 12
File100004 35
File100005 47
Lady Cygnus
Registered: Mar 17 2009
Posts: 19
Lady Cygnus wrote:
gkaiseril wrote:
Batch processing does support Acrobat JavaScript's global variables, [url=http://www.planetpdf.com/developer/article.asp?ContentID=generating_reports_with_javasc&gid=6570]Generating Reports with JavaScript[/url] by Dave Wright, but you may need to run a separate scrpt for initialializaiton and within the batch sequence check to make sure the global variables are initialized.
The Generating Reports with JavaScript is interesting, could that be used to create a list of my files with the page labels? Something that could (possibly) be made into a tab delimited text file of the format:

[b]File Name getPageLabel(0)[/b]
File100001 0
File100002 5
File100003 12
File100004 35
File100005 47
SWEET! It will give me a pdf file with the info I need - I'm just going to do a perl script to rename them.

Thanks!