Skip to main content
Participant
May 1, 2018
Answered

Sequential numbering - auto save upon open

  • May 1, 2018
  • 1 reply
  • 819 views

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>

This topic has been closed for replies.
Correct answer Thom Parker

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.

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
May 1, 2018

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.

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