There are multiple parts to making this process work. Each users system will need to be setup for it.
Since the number is incremented on Print, the script is placed in the "WillPrint" script on the PDF that will display the sequential number. .
But the first thing to do is to create the PDF where the number is stored. Call it the "Number PDF". In the simplest case this is a one page, blank, PDF containing a single form field. Call it "SeqNum". If you want to capture other information, such as the last date/time used, user name, or anything else, then you'll need more fields. It also might help if there was some explanatory text on the page. And finally, add this line of code to a document level script.
this.disclosed = true;
It's also helpful if the Number PDF contains a document level function for performing the necessary increment opertation.
For example:
function GetSeqNum(){
var nSeq = Number(this.getField("SeqNum").value) + 1;
this.getField("SeqNum").value = nSeq;
return nSeq;
}
This is just an example. The function could be expanded to include some validation and to store other information.
Next, add a WillPrint script to the target PDF form. This script opens the Number PDF from a hard coded location, as a hidden file. Acquires the number using the "GetSeqNum()" function, then saves and closes the file.
This is were it gets tricky. Saving a PDF requires a privileged context. There are a few ways to add privilege, but the simplest is to add a special folder level Acrobat script to each user's system. You can read about it here:
https://www.pdfscripting.com/public/How-to-Save-a-PDF-2.cfm
... View more