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

Creating a PDF Form with fields that auto populate

New Here ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

I have an issue that I am unable to resolve using previous posts.  I am attempting to create PDF forms that are loaded with data that was preciously selected and stored in a database.  Once the page is loaded, it is no longer interactive for the person and it is viewable as a read only.  Although it is no longer interactive for the person, there are some additional fields that I would like to auto-populate on the form based on the data that is being loaded from the database.  I have tried calculation scripts, validation scripts, action custom scripts, etc.  These all work if the form is interactive and the selection is made on the form itself and not created as read only.  I think the problem is that these pre-loaded fields from the database do not perform an "action" on the form after it is loaded and therefore these scripts don't execute.  Is there a way to apply a script that will execute as the form is loading?  Or is there another way that this can be done?

 

Here is a calculation script that I tried.  The appl_withholding_status_S is a pre-selected field and loaded from a database.  This calculation script is applied to the field that should auto-populate based on the data in appl_withholding_status_S field.

 

var v = this.getField("appl_withholding_status_S").valueAsString;

if (v=="S"){

    event.value = 6000

} else event.value = "";

 

Here is another calculation script that I tried.  This was created as a Mouse Up Run Java Script on a check box where the value is also pulled from a database.  The result of the check box should prefill another field.  

 

if (event.target.value!="Off")
  this.getField("Calc_Ex_Single").value=1;

 

I have attempted countless other scripts and methods and none of them work.  The scripts work if I interact with the form but not if the fields are loaded from a database.  I am rAny suggestions?

 

 

 

TOPICS
Acrobat SDK and JavaScript

Views

3.0K

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 ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

You can put the code in a doc-level script to have it execute when the file is opened, but then you'll need to adjust your code, as event.value won't work in that context.

 

Alternatively, you can add the following command as a doc-level script:

this.calculateNow();

That will force all the calculation scripts in the file to execute.

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 ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

Also, It depends on the viewer in which the form is displayed, and the mechanism used to load the data.

So, how is the data merged into the PDF? and do you know the viewer of the person loading form. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Feb 21, 2020 Feb 21, 2020

Copy link to clipboard

Copied

Unfortunately, the merging of the data is done by a third party.  Therefore, I am not exactly sure how that is done.  I do know that the data is stored in SQL.  The viewing of the document, once completed, is accessed through a web browser and when loaded, it appears to use Acrobat Reader. 

 

I have made the changes to the document that try67 suggested and I have submitted that form to the third party vendor to load so that I can test.  My fingers are crossed! 

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 ,
Feb 21, 2020 Feb 21, 2020

Copy link to clipboard

Copied

LATEST

If the PDF is loaded through a browser link, then you have no control over the process. Each browser handles this differently. And it also depends on how the link is formed. There is a "download" property that tells the browser to automatically download the content at the URL for use in a native app, instead of the default browser handler. But this of course is subject to the particular browser implementation. 

 

Basically, you are better off either not using any scripting on the form and loading complete data,

Or trying to force the user to open the form in a compliant viewer, so you gain some control over the process.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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