How to trigger calculate event when pdf is opened.
Copy link to clipboard
Copied
I want to trigger the calculate event so that the bar code is drawn as soon the pdf is opened.
I need this because my pdf form contains dynamic data filled on the server , and this data is not reflected in the barcode unless I make a change in the form data.
( This triggers a calculate event which causes all my barcodes in the pdf to be redrawn. I want this to happen as soon as I open the pdf )
Copy link to clipboard
Copied
You can use the calculateNow document method. I would put this in a document-level JavaScript outside of a function so it gets executed whenever the form is opened. An alternative is to place it as the initial page's Page Open JavaScript. More info is in the Acrobat JavaScript reference.
Copy link to clipboard
Copied
I tried the calculate now method inside an existing document level javascript , but it did not help. I still had to make some change to the form data inorder for the barcode to be redrawn with all form data.
//<Document-Level>
//<ACRO_source>!ADBE::0050_FieldInit_g28_page1_barcode</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:!ADBE::0050_FieldInit_g28_page1_barcode ***********/
if ((app.viewerVersion < 5) && (app.viewerVersion > 0) && (this.getField("g28_page1_barcode") != null)){
this.getField("g28_page1_barcode").value = "";
this.calculateNow();
}
//</ACRO_script>
//</Document-Level>
This was an existing document level javascript. I added the second line inside the if block like you suggested.
I have even tried providing a randomo value in line 1 inside if but that did not help too.
BTW , I have not writen this script . I was auto generated.
Copy link to clipboard
Copied
With that code the calculateNow statement will only execute if the viewer version is less than 5, which means Acrobat/Reader 3.5, 4.0, and 4.05, which don't support bar code fields. What are you using?
Copy link to clipboard
Copied
Ahh !! I am using acrobat pro 2015.023 version. Should I try this line outside if block. I went into all Javascripts and edited this. At first I tried going into document javascript where I saw 6 doc level javascripts , but was not able to add a new doc level javascript. The add button was disabed.
Copy link to clipboard
Copied
I moved the this.calculateNow() into the else block and now atleast its trying to execute the calculate block.
But I get this in console.
Exception in line 69 of function top_level, script Field:Calculate
Copy link to clipboard
Copied
It's hard to say from that what's wrong. I'd need to see the document to debug further.

