Skip to main content
Known Participant
June 25, 2021
Question

Import JSON database with Javascript

  • June 25, 2021
  • 2 replies
  • 3690 views

Hello,

I would like to be able to create a .json file on my Desktop and then to be able to import/read it in my feilds of my PDF. I want to be able to choose elements from this file. For example, I will have a feild which will get a result from a sum, then in second feild a reference will appear from a database (my json file) due to the result of the first feild. 

I use javascript in calculate area of feilds to run codes.

Also, I'm using Adobe Acrobat Standard DC, maybe I can upgrade it to Acrobat pro if I need it.

 

However, if this solution is not working I can try something else with database (I don't know anaything at all about it that but I can learn).

 

I'm looking for a good solution for fews days now, but I didn't find something that working for me. 

I hope that someone would be able to help me !

 

Thanks in advance,

 

Tanguy

This topic has been closed for replies.

2 replies

Legend
June 25, 2021

On reflection, you could use Acrobat, and JavaScript, but not ONLY Acrobat and JavaScript.

 

Suggest you write an app using Visual Basic that handles the database access, then connects to Acrobat through the VB:JavaScript bridge. It can then set the fields in the PDF from the database values you already have.

Known Participant
June 25, 2021

Okay thank you very much for the answer !

 

Where can I learn easily how to doing that ?

Legend
June 25, 2021

Acrobat JavaScript can no longer read from a database; this function was removed almost 20 years ago. Acrobat really isn't designed for this task.

try67
Community Expert
Community Expert
June 25, 2021

A json file is a plain-text file, though, so it can be read, parsed and the data in it used in a script.

This is not a simple task, though.

Known Participant
June 25, 2021

Okay thank you very much.

 

I can't doing that, here what i successed to do : 

var oStream = util.readFileIntoStream();
var strJSON = util.stringFromStream(oStream);
var oData = eval("("+strJSON+")");
console.println(oData);

 

Thanks to this code I did appear this text :

{"name": "John", "age":31, "city":"Paris"}

 

This is from my JSON file where there is : 

'{"name": "John", "age":31, "city":"Paris"}'

 

Now my question is how to do in order to get only the name or the age ?