Skip to main content
Participant
August 8, 2018
Question

java script to place file name in document as text doesn't update when file name changes

  • August 8, 2018
  • 1 reply
  • 476 views

I'm using a script I found online to place the file name of a PDF within the document itself (we use the file name as a purchase order number).

I have a text box with properties under the Format tab, format category Custom, Customer Format Script is

var name = this.documentFileName

name = name.substr(0, name.lastIndexOf('.'));

event.value = name;

When first entered as text field property it adds file name to the field (yay!), but when the file name is changed the text field doesn't update, just stays the same. We use the file name as a reference for a purchase order system, so it'd be nice if the bookkeeper could see what the file name was that printed the document.

Any ideas on how to get it to update the text field with the current file name, even when the file name changes?

Thanks,

Mike

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
August 9, 2018

Wrong location for the script, which is overly complicated. The correct place is in either a document script, which updates when the PDF is opened or the DidSave Script, which updates after the form is saved. 

Here's a shorter version of the same script

this.getField("NameField").value = this.documentFileName.replace(/\.pdf/,"");

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often