Skip to main content
Participating Frequently
August 15, 2019
解決済み

Persistent data

  • August 15, 2019
  • 返信数 3.
  • 1315 ビュー

I have an array of objects that need to be persistent.  I have read that saving complex data can't be done as is but can be saved if in a string format.  Any help in this area will be greatly appreciated.  Also is there a special location to make this data persistent ie: global.setPersistent()?

このトピックへの返信は締め切られました。
解決に役立った回答 Joel Geraci

With Acrobat DC, you can use JSON.stringify() and JSON.parse() instead of toSource() and eval().

返信数 3

Jeff1776作成者
Participating Frequently
August 16, 2019

Thanks!!  Where does the persistent data get saved (shitdows)?

Joel Geraci
Community Expert
Community Expert
August 16, 2019

I use a folder level JavaScript and a PDF to save my persistent data into a form field in that PDF. It's stored as a JSON string that I parse into an object. The PDF gets opened as a hidden file and is disclosed so all other PDFs can get access to the object. It's stored in the same folder as the JavaScript.

Joel Geraci
Community Expert
Community Expert
August 15, 2019

I store my complex data as strings... of JSON... which allows me to use a single string to store all kinds of stuff.

Also, there is a global object but with the default security settings, only the document that set the value can retrieve the value.

try67
Community Expert
Community Expert
August 15, 2019

Yes, global.setPersistent(cVariable, bPersist). For example:

global.myText = "abc";

global.setPersistent("myText", true);

As for the array, that's true. You can only set string objects as persistent. You can use the toSource method to convert any object to a string, though, and then eval to convert it back to an object.

Joel Geraci
Community Expert
Joel GeraciCommunity Expert解決!
Community Expert
August 15, 2019

With Acrobat DC, you can use JSON.stringify() and JSON.parse() instead of toSource() and eval().

try67
Community Expert
Community Expert
August 15, 2019

I'm old-school...