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

Java Script done in Pro, works in Pro and MS-Edge but doesn’t work in Adobe Reader?

Explorer ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

I have to modify a PDF-form a coworker created some years ago. Two pretty big if-then-else scripts (~ 450 lines) used to work well. And they still work well if you use Acrobat Pro or MS-Edge (sic!), but fail with Adobe Reader.

I’ve changed the huge if-then-else to an array – again, works fine in Pro and Edge – but not in Reader...

Any Idea what might go wrong. Aside from the size it is a simple if-then-else script, nothing special about it. Other JS in this very form work fine with Reader too …

 

Additional Question: Actually the two scripts should be a big one. I thought, when changing to an array I could combine them in a single field. But there seems to be a limit to the number of lines allowed in Acrobat. Though there is no error, values at the end of this array are simply not found …?

Thank you

TOPICS
JavaScript

Views

10.9K

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

correct answers 1 Correct answer

Explorer , Dec 22, 2022 Dec 22, 2022

Thank you all!

I did a lot more reworking on these forms as I planed ... Though I still can't tell where the problems came from. They simply vanished as I worked my way through the form. Well apparantly there was to much ... in the whole form (and still is), but for now they work fine.

 

I still have some questions concerning arrays, but I think I set up a speciel test-form and a separate thread for that next year.

 

I wish you a peaceful Christmas and a good start into the New Year!

 

Votes

Translate

Translate
Community Expert ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

For the scripts use you the internal or a external editor?

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
Explorer ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

External editor (internal editor can handle only small scripts). Does it make a difference?

BTW: As you might have realized, I have posted this problem in Acronaut forum too. Since I got some helpful tips there, but not a real solution, I’ve tried this forum too.

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 ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

Can you share the form?

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 ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

What exactly happens when you use it in Reader? Is there an error message?

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

@try67 There is no error message. The field simply does not calculate (Keeps blank if you start with an empty form, value doesn’t change if you start with a form that was calculated in Pro before).

If you activate “Show Console on errors …” The Debugger says: “ReferenceError: ... in not defined”

I enclose some Screenshots and the corresponding JS.

Ablauf.js calculates the date in ProCalcOkay

PLZB_VarBD.js = 22

PLZB1_VarBD.js = 42

 

@Bernd AlheitWell, I'll try to get allowance from my boss to upload the whole documnet

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

These error messages have nothing to do with the code you posted. They are from the calculation event of a field where you selected field names that do not exist. They probably existed when you set it up, but then you renamed them, or removed them, and didn't update the calculation. It should produce the same result in Acrobat, by the way. Maybe you don't have the option to show the Console on errors enabled there, though. If you could share the actual file with us that would be very helpful.

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Thank you Try67 - but negative. I can enabled the option to show the Console on errors in Pro too. And no, no errors in Pro ...

For further information please see my answer to Bernd.

 

 

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Does you use several folder level scripts?

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Thank you Bernd!

To be honest - I don't even know what "folder level scripts" are.

I enclose the original PDF - before I made any changes, except, that I moved the three fields PLZB, PLZB1 and PLZBB from page 3 to page 2 and made them visible.

I should add, that I'm an insurance expert, not a IT-expert. I build some PDF-Forms many years ago together with an IT-Expert. Unfortunately this guy is not available any more. I got other jobs and a Coworker took over. He did build the enclosed PDF-Form, but he also left the company. So I was asked to do some changes. The PDF-forms will be substituted by a new online-calculator next year, so the company doesn't want to invest in the PDF-forms. First I thought the problems were due to the changes I made, but by now found out that the original form already have had this problem - no idea, why nobody found out before ...  Now I have "den schwarzen Peter" (Bernd, you know ..). 

 

I realized that the calculations, that fail, are functions in "Document Java Script", so I moved them to "Field-Script". That did solve the problem with "Ablauf" Date, but not with the "Tarifzonen". I also  changed the two huge if-then-else scripts in functions PLZ() and PLZ1() to an array and got rit of the redundant calculations in PLZ2() and PLZ21() , but that didn't do the job either.... I will enclose a version of my experiments later on.

 

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

There are plenty of issues with your code, but the calculation you mentioned worked fine for me in Reader DC.

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

>There are plenty of issues with your code,

 

Well, I definitely agree. I would love to rework the whole form together with a real PDF expert, but as I mentioned in my response to Bernd ...

 

>but the calculation you mentioned worked fine for me in Reader DC.

 

I was afraid of that ... 😞  But that explains, why no one else reported that problem before. Of course, we often have complaints about calculations not working, but that was always due to using Not-Adobe-Readers.

 

What Reader-Version you use? Mine is 2022.003.20282

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

> What Reader-Version you use? Mine is 2022.003.20282

Same here, on Windows 10 (not that it should matter what OS it is).

 

Folder-level scripts are placed in a .js file in a special folder on your computer, and the code in them is executed whenever the application is opened. This is not relevant to your situation, though.

My guess (although my first one was off) is that it's an issue with the order in which the code is loaded, or an error occurs when you open the file, which prevents the rest of the code to load.

The first step would be to optimize your code and combine all the functions that edit the same field to a single location. It's not a good idea to call two separate functions in a field's custom calculation event, both of which do more or less the same, but with different values. They need to be merged.

If the code is too long, use an external editor.

Also, the code can be made much shorter (and easier to read) if you defined variables for the field values, instead of accessing them each time. For example, all of these parts:

this.getField("PLZ").value

Can be replaced with just "plz" (without the quotes) if you added this line at the top:

var plz = this.getField("PLZ").value;

This change alone will cut down your code in about 33%, I estimate.

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Thank you very much again!

I'll come back to your tips later. For today I'm done - and the next day I wan't find time to try these things.

I've already changed some code. But regarding limitations in size. The editor is not the problem. I did combine the code and even changed the if-then-else-function to an array. That cut the code down to less then 50 percent, but still there is an issue about the lenght of the block. If you look for a value in the lower half of the array it is simply not found. No error. I enclose the two arrays I've tried.   PLZ_Array didn't work at all. PLZ_ArrayContructor does work generally - but if you surch for e.g. "87487" this value will not be found ...

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

You must define the lwValue and stValue variables outside the if-condition, because if it's not true they are undefined and then the last line of the code will result in an error.

Also, in your array you're overwriting the values of these variables each time. Do you expect the if-condition to only be true once? If so, you should break the array when that happens. If not, only the last instance of it being true will be used, unless you change the code.

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
Explorer ,
Dec 16, 2022 Dec 16, 2022

Copy link to clipboard

Copied

Thanks again!

The if-condition can only be true once - or maybe not true! Of course you are right, it it is not true there should be some action - I'll think about that.

I've already noticed, that there should be some kind of "EXIT FOR" statement, but couldnt find none. Okay, it is BREAK - Thank you!

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

When I activate "keine Selbstbeteiligung" I get following errors:

 

ReferenceError: PLZ is not defined
1:Field:Calculate
ReferenceError: PLZ2 is not defined
1:AcroForm:PLZB1:Calculate
ReferenceError: ablauf_ankreuzen is not defined
1:AcroForm:Ablauf:Calculate

 

I use Acrobat DC Pro version 2022.003.20282

 

There is something wrong with the form.

 

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

This message comes with Reader if you activate whatever Field you want ... But that's really strange: Try67 doesn't has this problem with Reader, like I (and others in the company) had. You have this problem with Pro, while my Pro (exactly same version!) does work  without any errors ...???

 

>There is something wrong with the form.

That's what we are here for 🙂

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

What operating system does you use?

 

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Win 10 Pro

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 ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

You must check the value of the "Product" column for all methods and properties used in your scripts.

Some cannot be used in Reader:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html#table-quick-key

 

You should know that the values F, C and S are now equivalent to "All" because these Rights are no longer required since Reader XI.

 

Capture_2212151407.png

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
Explorer ,
Dec 15, 2022 Dec 15, 2022

Copy link to clipboard

Copied

Thank you JR! But I'm lost ... I gues it's a problem of size, rather the a specific method, but I couldn't find any information about size-limitations. But of course I didn't work my way through all this information...

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 ,
Dec 16, 2022 Dec 16, 2022

Copy link to clipboard

Copied

Can you share (part of) this document?

It would be easier to analyze it.

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
Explorer ,
Dec 16, 2022 Dec 16, 2022

Copy link to clipboard

Copied

@JR Boulay  I did alreay share the document. It's in my Post from 15.12.2022 - too bad, this forum doesn't show timestamp ... well, the one starting: "Thank you Bernd!"

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 ,
Dec 18, 2022 Dec 18, 2022

Copy link to clipboard

Copied

OK, I found it.

 

The issue is the same with Acrobat Reader, I think you don't see it because the "Show console on errors and message" option is not enabled in the Preferences.

 

Capture_154.png

 

Capture_155.png

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