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

Date in Acrobat / Problem No. 3 …

Explorer ,
Jan 16, 2023 Jan 16, 2023

It is a real pain to work with Date-functions in PDFs if you are supposed to use the “dd.mm.yyyy” Syntax (which is common standard in German-Language Countries and afaik in many other countries too, but apparently unknown to Adobe-Developers….) I remember having these problems back in the 1980ies when working with US-programms. And I’m really … that I run into these ancient problems again using Adobe in 2023!!! Sorry for this prologue …

 

Now. Next problem with date():

I have a field, defined as date “dd.mm.yyyy”:

GGN_0-1673891634208.png

 

 

 

I want to assign a default-value for this field. The following command returns the date in the wanted format:

GGN_1-1673891634209.png

 

 

Now I thought – just put this as Default Value:

GGN_2-1673891634210.jpeg

 

 

 

And I guess every other program in this world would gladly accept a default-value in exactly the same format that is specified for this very field – but unlike Acrobat:

 

GGN_3-1673891634211.png

 

 

Something wrong with ME?

TOPICS
JavaScript , PDF forms
4.1K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 16, 2023 Jan 16, 2023

You can't use a script as default value.

Use a date like: 01.01.1980

 

Or set the default value at document open with the script.

View solution in original post

Translate
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 ,
Jan 16, 2023 Jan 16, 2023

You can't use a script as default value.

Use a date like: 01.01.1980

 

Or set the default value at document open with the script.

Translate
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
Explorer ,
Jan 17, 2023 Jan 17, 2023

Thank you @Bernd Alheit!

I don't want to set a fixed date. The field should be filled with the current date. But that means you can't use a calculation to set a default value? I can't believe it ... and why doesn't Adobe care to display more precise error message?

Well, guess I have to find another way ... I had the experience, that document scripts sometimes don't work in Reader. So maybe I give the "Actions" a try.

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

You can use a document level script to fill in a new date in that field every time you open a document.

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

I think the error message is very good, in this instance. What you tried to do was simply incorrect. You assumed you could use a script as the default value and that it would be executed, but that's not the case. The default value is a plain string. And there's no reason a doc-level script wouldn't be executed when the file is opened in Reader, assuming JS is enabled.

Also, even if the code was executed, it wouldn't have done anything, because that's not how you apply a value to a field in Acrobat JS. To do so use the following:

 

this.getField("FieldName").defaultValue = util.printd("mm.dd.yyyy", new Date());

 

Note that this doesn't mean the value will be shown, though, as the default value and actual values are not the same thing.

Translate
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
Explorer ,
Jan 17, 2023 Jan 17, 2023

Thank you @try67!

 

>I think the error message is very good, in this instance. 

Apparantly we have pretty different opinions about the quality of error-messages 😉

 

>You assumed you could use a script as the default value 

Okay, you are right, I should have cheked - but it's like - well ... in 30 years, I never worked with a program, that was not capable of using calculations as default-values ...

 

>And there's no reason a doc-level script wouldn't be executed when the file is opened in Reader, assuming JS is enabled.

 

True, we couldn't find no reason so far - yet this problem has occured several times and giving us lots of trouble! Of course we are not sure what causes the problem, since there are lots of issues, but for me it was amazing to find out, that moving the scripts from doc- to field-level solved this issue ...

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

- What kind of better error message you would like to see in this case?

- It is possible, just not the way you did it.

- Please provide an example of a file where this happens.

Translate
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
Explorer ,
Jan 17, 2023 Jan 17, 2023

>What kind of better error message you would like to see in this case?

I know that it is (economical) not possible to analyse the input under all aspects. But it would be easy to give an error message, that lists all known possible reasons. Roughly:

 

There is something wrong, either:

- Format don't match. Please check ...

- You are trying to use a calculation as Default. Only fixed values are allowed.

- ... //other known reasons 

- If none of the above reasons fits please report to ....

 

>It is possible, just not the way you did it.

Okay, got that

 

>Please provide an example of a file where this happens.

 

You have had one (https://community.adobe.com/t5/acrobat-discussions/java-script-done-in-pro-works-in-pro-and-ms-edge-...)

But unfortunately you were (afair) the only one, who haven't had problems in Reader DC ...

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

"(which is common standard in German-Language Countries and afaik in many other countries too, but apparently unknown to Adobe-Developers….)"

This is because you're using Acrobat in English language.

I have the same issue with the French date format (dd/mm/yyyy), it's only available when I use Acrobat in French language.

So, I assume that the German date format should be available when using Acrobat in German language.

 

Capture_2301170947.png


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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
Explorer ,
Jan 17, 2023 Jan 17, 2023

Thank you @JR Boulay !

I'm using the English Version on one and the German on another Computer. When posting on this forum I usually take the Englisch one.

Regarding the Date-Format, It's true, there are diffferences, but even in the German version they offer "tt/mm/yyyy" and "tt-mm-yyyy" which come pretty close, but are still unusual in Germany.

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

Hi,

You can use a date format in German (or another language) whatever the language of the software!

For a German format: event.value=util.printd("date(de){DD.MMMM YYYY}",new Date(),true);
For the same in French: event.value=util.printd("date(fr){DD.MMMM YYYY}",new Date(),true);

...in Spanish: event.value=util.printd("date(es){DD.MMMM YYYY}",new Date(),true);

...in English: event.value=util.printd("date(en){DD.MMMM YYYY}",new Date(),true);

...etc

Below with FrenchAcrobat version, the date in German, English and Spanish.

Capture d’écran 2023-01-17 à 13.01.51.png

@+

 

Translate
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
Explorer ,
Jan 17, 2023 Jan 17, 2023

Yeah - but the problem starts when you want to do any calculations with these dates:

GGN_0-1673962240738.png

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

That wouldn't work with any format. You must convert them first to Date objects (using util.scand) and then you could use them for calculations.

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

In any case everyone should consider this:

😉

 

ISO-8601 Date format.png


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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 ,
Jan 17, 2023 Jan 17, 2023

There's always an XKCD... 🙂

Translate
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 ,
Jan 17, 2023 Jan 17, 2023

...and it's also the easiest format for sorting!

@+

 

Translate
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
Explorer ,
Jan 17, 2023 Jan 17, 2023

no, no, no, that would be to easy 😄

Back in the 1970's, I spent a few months as a foreign student at a US highschool. In science the decimal system was scheduled. We were told that non-metric measurements will be replaced by the year 2000.

Translate
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
Explorer ,
Jan 17, 2023 Jan 17, 2023
LATEST

Well actually there were many good answers. But @Bernd Alheit was the first one to mention the alternative way.

And I'm still reluctant to use document level script. So I ended up with a script in the field-action / On Focus:

 

if (this.getField("Beginn").value == "") {this.getField("Beginn").value=this.getField("datumheute").value;}

//datumheute is an existing field that already calculates the current date for other purposes too

 

Thank you all! For the other issues discussed - especially my struggels with converting or calculating dates in JS and the Pro-Reader problem I better start separate tickets.

Translate
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