Copy link to clipboard
Copied
Hi everyone,
I have a question that may seem trivial, but I'm wondering if it's possible to synchronize the file name with a field within a PDF form. For example, if the file name changes, could it automatically update the assigned field within the form? If this is possible, any guidance would be greatly appreciated.
Thanks a lot.
Copy link to clipboard
Copied
Except that the field isn't update when the change is made. Good point about the dirty flag.
Here's a redo of the script:
this.getField("FileNameField").value = this.documentFileName;
this.dirty = false;
Copy link to clipboard
Copied
I tried to apply the following:
function setFieldValueOnOpen() {
var fileName = this.path.replace(/^.*[\\\/]/, '');
this.getField("FileNameField").value = fileName;
this.calculateNow();
}this.setAction("WillSave", "setFieldValueOnOpen()");
But still, the field doesn't update automatically when the file is opened
Copy link to clipboard
Copied
You can use a script at document open.
Copy link to clipboard
Copied
Thank you @Bernd Alheit I tried this but didn't work either, not sure what I'm doing wrong?
function setFieldValueOnOpen() {
var fileName = this.path.replace(/^.*[\\\/]/, '');
this.getField("FileNameField").value = fileName;
this.calculateNow();
}
setFieldValueOnOpen();
Copy link to clipboard
Copied
Do not use the script you posted. The only script needed is this one:
this.getField("FileNameField").value = this.documentFileName;
The "WillSave" script doesn't work because it is called before the name is changed. It is the "DidSave" script that should be used. Just enter the line of code above into the "DidSave" document action.
As Bernd states, the script should also be in a document script, which is run when the PDF is opened.
An alternate solution is to use the calcuation script on the "FileNameField" text field.
Copy link to clipboard
Copied
But using the Did Save event will make the file "dirty", which will mean the user will need to save it again, and so on and so on. I think doing it when the file is opened is a better option.
Copy link to clipboard
Copied
Except that the field isn't update when the change is made. Good point about the dirty flag.
Here's a redo of the script:
this.getField("FileNameField").value = this.documentFileName;
this.dirty = false;
Copy link to clipboard
Copied
Thank you so much all of you, really appreciat your help so far 🙂
Find more inspiration, events, and resources on the new Adobe Community
Explore Now