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

Javascript Print Today's Date Stopped Working - Prints Created Date Instead

New Here ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

We use javascript on our PDF documents that print today's date. Last week the javascript stopped working and prints the date the PDF was created instead.

Here is the javascript we use:

var f = this.getField("DatePrinted");

        f.hidden = false;

        f.value = "Printed on: " + util.printd("mmm dd, yyyy", new Date());

These are our company's legal documents and the printed date is very important, as the documents are uncontrolled 24 hours after printing.

Could anyone provide assistance to this?

Thank you.

TOPICS
Acrobat SDK and JavaScript

Views

564

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
LEGEND ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Where is that code placed, exactly, and what PDF viewer is being used to open the document?

Votes

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
New Here ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Hi George,

Thank you for your reply. The code is placed in a field called "DatePrinted" and we are using Adobe Acrobat and Reader to open the files. This has worked for us for years, so I'm all sorts of confused as to why it would suddenly print the document's creation date instead. All of our PDFs are now suddenly doing this.

Thanks,

Lynda

Votes

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
LEGEND ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

OK, you told us what field the script is placed in, but not the event (e.g., calculate, validate, format, etc.) The script may not be getting triggered as you expect, depending on where it is placed.

Votes

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
New Here ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Oh, sorry abou that. We use "Document Javascripts" and type "Load" in the "Script Name" field. We click "Add" and paste the javascript in that window.

We have hundreds of controlled documents with this script going back 5 years now - changing it would be next to impossible and the older documents are also printing the date incorrectly, not just the new ones we are creating. 

I'll add that these documents are secured and not accessible for editing by anyone but me.

Thanks again!

Votes

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 ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Open the file in Adobe Acrobat. What date does you see in the field?

Votes

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
New Here ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Hi Bernd,

The field is set as "Hidden but Printable" and "Read Only" is checked. 

Votes

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 ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Use the menu File > Print. What can you see on the printout?

Votes

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
LEGEND ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

OK, so the script is supposed to be executed when the document is opened. You might want to check the JavaScript console (Ctrl+J) to see if any errors are reported. It's hard to say what's going on without being able to test one of the documents myself.

Votes

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
New Here ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

LATEST

Thanks George. I'm thinking it has something to do with the documents being secured. I just printed one that's unsecured and it printed today's date (this doc was created in March of 2019). I have "Enable Global Object Security Policy" checked in "Preferences - Javascript".

I wonder if something changed with Acrobat recently that overwrites Javascript running on a secured document, as these documents have always been secured and have always printed today's date.

What I noticed was the debugger said "NotAllowedError: Security settings prevent access to this property or method. Field.value:3:Document-Level:Load"

The debugger did not have an error on the unsecured file. 

Votes

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 ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Use the script at the event "Document Will Print".

Votes

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