• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

New Here ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

142

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines