• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Sequential numbering - auto save upon open

New Here ,
May 01, 2018 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>

TOPICS
Acrobat SDK and JavaScript , Windows

Views

437

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
community guidelines

correct answers 1 Correct answer

Community Expert , May 01, 2018 May 01, 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

...

Votes

Translate

Translate
Community Expert ,
May 01, 2018 May 01, 2018

Copy link to clipboard

Copied

LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines