Sequential numbering - auto save upon open

May 01, 2018

Copy link to clipboard

Copied

I have the following Java script for a text element within my document.  The problem is that the sequential numbering does not work unless the document itself is saved.  The form is intended to serve as a master that would be "save as" after it is completed. To prevent user error, I'd like the document to immediately "save" itself after it is opened.  Of course there is still user error later if the user clicks save instead of save as - that's my next problem.

Ideally the behavior would be:

user opens master

document immediately saves itself (Java-driven)

user completes document

user SAVES AS a new document

master document is closed

**next time it is opened, the text tracking number updates sequentially

//-------------------------------------------------------------

//-----------------Do not edit the XML tags--------------------

//-------------------------------------------------------------

//<Document-Level>

//<ACRO_source>Document Number</ACRO_source>

//<ACRO_script>

/*********** belongs to: Document-Level:Document Number ***********/

var f = this.getField("Tracking Number");

if (f.value=="") f.value = "0001";

else f.value = util.printf("%04d", (Number(f.value)+1));

//</ACRO_script>

//</Document-Level>

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

There are lots of issues with creating unique, and especially sequential ID numbers for documents. You're methodology seems designed to address one of the biggest issues, which is having a master data repository for the ID number. Unfortunately this cannot be done entirely from inside a PDF because of both security issues and because the user has free will to save and move the document around.

Here is an article on saving a PDF from a script:

https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

It is not necessary to use a privileged folder level script for the save, it is also possible to save the PDF if it is certified with a digital signature that is enabled for scripting privilege. But either way, it is required that something is installed on the system where the form is used, which means the form is only useful within a known context, i.e. it gives you some control over how the form is used. You could also included code to disable the form is the correct script or signature is not present.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

157

Likes

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

Sequential numbering - auto save upon open

May 01, 2018

Copy link to clipboard

Copied

I have the following Java script for a text element within my document.  The problem is that the sequential numbering does not work unless the document itself is saved.  The form is intended to serve as a master that would be "save as" after it is completed. To prevent user error, I'd like the document to immediately "save" itself after it is opened.  Of course there is still user error later if the user clicks save instead of save as - that's my next problem.

Ideally the behavior would be:

user opens master

document immediately saves itself (Java-driven)

user completes document

user SAVES AS a new document

master document is closed

**next time it is opened, the text tracking number updates sequentially

//-------------------------------------------------------------

//-----------------Do not edit the XML tags--------------------

//-------------------------------------------------------------

//<Document-Level>

//<ACRO_source>Document Number</ACRO_source>

//<ACRO_script>

/*********** belongs to: Document-Level:Document Number ***********/

var f = this.getField("Tracking Number");

if (f.value=="") f.value = "0001";

else f.value = util.printf("%04d", (Number(f.value)+1));

//</ACRO_script>

//</Document-Level>

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

There are lots of issues with creating unique, and especially sequential ID numbers for documents. You're methodology seems designed to address one of the biggest issues, which is having a master data repository for the ID number. Unfortunately this cannot be done entirely from inside a PDF because of both security issues and because the user has free will to save and move the document around.

Here is an article on saving a PDF from a script:

https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

It is not necessary to use a privileged folder level script for the save, it is also possible to save the PDF if it is certified with a digital signature that is enabled for scripting privilege. But either way, it is required that something is installed on the system where the form is used, which means the form is only useful within a known context, i.e. it gives you some control over how the form is used. You could also included code to disable the form is the correct script or signature is not present.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

158

Likes

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
May 01, 2018 0
Adobe Community Professional ,
May 01, 2018

Copy link to clipboard

Copied

There are lots of issues with creating unique, and especially sequential ID numbers for documents. You're methodology seems designed to address one of the biggest issues, which is having a master data repository for the ID number. Unfortunately this cannot be done entirely from inside a PDF because of both security issues and because the user has free will to save and move the document around.

Here is an article on saving a PDF from a script:

https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

It is not necessary to use a privileged folder level script for the save, it is also possible to save the PDF if it is certified with a digital signature that is enabled for scripting privilege. But either way, it is required that something is installed on the system where the form is used, which means the form is only useful within a known context, i.e. it gives you some control over how the form is used. You could also included code to disable the form is the correct script or signature is not present.

Likes

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
Reply
Loading...
May 01, 2018 1