Copy link to clipboard
Copied
I have a bunch of documents named similar to the following:
ThisProduct_01-TEXT.pdf
ThisProduct_02-TEXT.pdf
and JPG covers for them:
ThisProduct_01-COVER-FRONT.jpg
ThisProduct_01-COVER-BACK.jpg
ThisProduct_02-COVER-FRONT.jpg
ThisProduct_02-COVER-BACK.jpg
(etc.)
What I currently have:
I have a working script that works as follows:
[1] Before running script > Open a PDF, then drop the two cover images at the front of the doc.
[2] Run script > Script moves cover JPGs to correct place and renumbers pages accordingly.
What I want to be able to do:
I want to be able to have JS access the filename of the currently open document so that I can then run some string replacements that enable it to automatically find the JPGs and run the rest of the script that I have working. The workflow would look like this
[1] Open document
[2] Run script
... and there is no messing around trying to find the right images as Acrobat JS determines what they are called based on the open filename
My Question:
How can I retrieve the filename of the currently open document using JS?
The simplest thing for me would be a demo JS that when run just states the name of the file, then I could figure out the rest (string replacements and so on) myself.
Can anyone help with this bit? I found a few similar solutions but couldn't quite figure out if they needed a list of filenames supplied and so on, I couldn't tell if they were for the open document.
Slow Down.
There are mistakes in the hard coded coverPath in your last code post. the backslash is the escape character. It is used to insert special characters into a string. So you can't use it directly in a string literal. There are also spaces which probably don't belong. This is why the insertPage function isn't working. The path must be exact and correct.
Insert console.println() calls into your code to show the progress of building the path and you'll see the missing bits caused by th
...Copy link to clipboard
Copied
This is where I'm up to ... I'm getting a popup with "Undefined" in it:
// PDF filenames and the JPG covers are very similar
// just some differences in last part of name and suffix and so...
// Determine names of cover JPGs based on name of PDF
frontCover = this.documentFileName.replace(/-TEXT.pdf/,"-DIGI_COVER_front.jpg");
backCover = this.documentFileName.replace(/-TEXT.pdf/,"-DIGI_COVER_back.jpg");
// Specify path where cover JPGs are located
coverPath = "/Volumes/Disk2/SVN/FB Publishing Files/trunk/DigitalCovers/";
// prepend filepath to file name
frontCover = coverPath.frontCover;
backCover = coverPath.backCover;
// Debug ... maybe there's a better way
// I just want to see if it's constructed the filename and path correctly so far
app.alert(frontCover, 3);
Copy link to clipboard
Copied
Still working on it. I seem to have set the filepath correctly now, I'm getting a "file error" in the console now. I'm trying to mess around with escaping spaces in the string and wondering if it's that.
// PDF filenames and the JPG covers are very similar
// just some differences in last part of name and suffix and so...
// Determine names of cover JPGs based on name of PDF
var frontCover = this.documentFileName.replace(/-TEXT.pdf/,"-DIGI_COVER_front.jpg");
// Specify path where cover JPGs are located
var coverPath = "/Volumes/Disk2/SVN/FB\ Publishing\ Files/trunk/DigitalCovers/";
// prepend filepath to file name
frontCover = coverPath + frontCover;
// Debug ... This now shows the correct filename and path of the JPG
// I just want to see if it's constructed the filename and path correctly so far
// app.alert(frontCover, 3);
this.insertPages ({
nPage: -1,
cPath: frontCover,
nStart: 0
});
Copy link to clipboard
Copied
I've now made PDFs of the JPGs in case it was that, and tried inserting those after adjusting the paths etc and still no luck. If I can just get it to make this minor filepath mod and use that to insert a similarly named PDF or JPG from another folder I'll be away!
Copy link to clipboard
Copied
Slow Down.
There are mistakes in the hard coded coverPath in your last code post. the backslash is the escape character. It is used to insert special characters into a string. So you can't use it directly in a string literal. There are also spaces which probably don't belong. This is why the insertPage function isn't working. The path must be exact and correct.
Insert console.println() calls into your code to show the progress of building the path and you'll see the missing bits caused by the escapes.
Are you running all your code from the console? This is where you should be doing development.
Copy link to clipboard
Copied
Hi Thom
in that last example I am backslashing the spaces in "FB Publishing Files" like this "FB\ Publishing\ Files" or do you not need to backslash spaces?
Copy link to clipboard
Copied
Yes it turned out to be a combination of filename errors and inconsistencies, long with poor debugging skills. Once I'd got my head around some basic use of the console for debugging using your console.println(); suggestion everything was a lot easier.
The following is up and working:
var coverPath = "/Volumes/Disk2/SVN/FB | Publishing/trunk/DigitalCovers/";
var frontCover = coverPath + this.documentFileName.replace(/TEXT.*/,"DIGI_COVER_front.pdf");
/*
console.println("------");
console.println("FC: " + frontCover);
console.println("------");
*/
this.insertPages ({
nPage: -1,
cPath: frontCover,
nStart: 0
});