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

stamping my footers with values derived from a filename substring and switch statement...

mmetts
Registered: Feb 10 2011
Posts: 4

Folks,
 
I am a total novice Acrbat Javascript programmer. I'm not a Javascript programmer period. I'm another type of programmer by trade with a big deadline.
 
My quest is to create a footer stamp on one or more pages (not sure yet if it will be just the first page or every page) of 500+ .pdf files where the stamp value is dynamically determined by the characters in the filename of each file. So for instances, I have files
 
A_hello.pdf
Q_world.pdf
MUDD_puppy.pdf
A_goodbye.pdf
...
 
And my switch statement/etc. would stamp each of these with the corresponding footer values
 
Mother Night
War and Peas
Hot Tuna
Mother Night
...
 
As you can see, my mapping is driven by the first word in the filename. The switch statement might have a lot of elements but I don't care about that. I'd just like to get an example/pointers/help on how to get started. I've seen a few scripts around on the web but none seem to get me enough of the bits I need to pull this off.
 
So if anyone would be willing give me functioning script that I gets me part of the way there that I can hack, I would be most grateful.
 
Thanks in advance for any help,
Mike
ps - I'm running Acrobat X Pro and Acrobat 9 Pro on Windows

My Product Information:
Acrobat Pro 10.0, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi mmetts,

This is an excellent idea for an automation tool. While not exactly what you are asking for, you may want to download the "File Stamper" action from the Actions Exchange here at AUC (a link to the exchange is on the home page in the right side panel). The action doesn't provide an automated way to determine between your original list of PDF file names, but it does allow you to place custom text on a list of selected files- so it will get you part way. There are detailed instructions provided with the download that should also be helpful.



Hope this helps,

Dimitri
www.pdfscripting.com
www.windjack.com
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
To get the characters in the filename that exist before the first underscore character, you could use code like:

var id = documentFileName.split("_")[0];


Instead of a large switch statement, you could set up an object to associate the various prefixes with the description:

var myobj = {"A": "Mother Night", "B": "War and Peas", "MUDD": "Hot Tuna"};


and given a property name (id) based on the file name, retrieve the description like:

var desc = myobj[id];



mmetts
Registered: Feb 10 2011
Posts: 4
George, Thanks, that looks very handy.

Dimitri, I take it you mean this action here http://acrobatusers.com/content/file-name-stamper
The thing is, this script is pretty complicated (I had already seen it) and I'm hoping for some pointers on how I would hack it to do what I want vis-a-via George's helpful points and/or just something a little more straight-forward.

Mike


George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Do you really want a stamp, or just some way to place text on a page? It seems like you're looking for a way to do this all programmatically to a collection of documents, right?

You cannot add text to the regular page contents directly, so you have to use some sort of annotation, or add a new layer. Probably the simplest way is to add a text form field (doc.addField) to each page and set the field value to the text you want. You can then optionally flatten the page(s) (doc.flattenPage), which will convert the text field to regular page contents. All of this can be automated using JavaScript in a batch sequence in Acrobat. The script would be fairly simple and straightforward. If you need more pointers, post again.

The Acrobat JavaScript reference can be found here: http://www.adobe.com/devnet/acrobat/javascript.php
mmetts
Registered: Feb 10 2011
Posts: 4
George,

Actually, I'm not keen on flattening these documents since I'm already making them en masse from different chunks and in the past when I allowed any flattening, the fonts got hosed on some of the pages. I don't care, really, big any individual file gets so long as the contents can be view *and* printed and I can encrypt it so nobody can do anything with it but print it. For that matter, I'm happy to go with a "watermark" or "stamp" route to adding these text strings to the documents. To tell you the truth, I don't understand how they differ from adding a text form field.

So, then, the stamping script that Dimitri pointed to seems fine to me in the sense that it does almost do what I want, I'm just having trouble figuring out how to hack it so that "A_hello.pdf" becomes "Mother Night". All the other font, color, page range bits driven from the dialog box are things I would make use of.

Please advise.

Thanks,
Mike
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
OK, a text field should do fine. You'll want to set the readonly property to true and set the defaultValue to the same as the value.

So, you'd use the doc.addField method to add a text field on the pages at the location you want, set the value, set the defaultValue, and any other properties you want.

addField documentation which includes a sample batch sequence you can modify: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.435.php
mmetts
Registered: Feb 10 2011
Posts: 4
Folks,

I have managed to hack the "File Name Stamper Action Script" that Dimitri pointed me to making it do exactly what I've described above.

But, the dialog prompting is such that I must hit "Apply" for each file I process. I'm wondering if anyone is familar enough with this script to tell me how to change it so that I only have to hit "Apply" one time for any number of files and/or folders. I'm still looking for clues as to how to do this but have not figured it out so far.

Thoughts?

Thanks,
Mike
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
I think you're needlessly complicating things by trying to adapt that code. It's great for what it was designed for, but your needs seem to be different.

Here's how I see the flow of things:

1. For each document:
2. Set up the object associating the file prefix to a description (as shown above)
3. Get the file prefix (as shown above, single line of code)
4. Get the corresponding description from the object (as shown above, single line of code)
5. For each page in the document:
6. Add a text field (use doc.addField, single line of code)
7. Set text field's properties (one statement for each property)
8. Save document

#1 and #8 are taken car of by nature of a batch process (aka Action). Adding a text field is a single line of code and setting the field properties you want is an additional statement for each property. This way you won't have to deal with the dialog at all and have greatly simplified code to deal with.