Copy link to clipboard
Copied
I have created a pdf file and I'd like to have a field with sequential numbers.
For instance, if I open my pdf now and it has number 1 in the field, 'd like to have number 2 in the field the next time that I open the file, and so on...
Go to Tools - JavaScript - Document JavaScripts and create a new script with the following code (remove any default code that's inside the window when you first open it):
var f = this.getField("Serial Number");
f.value = Number(f.value)+1;
f.defaultValue = f.value;
Of course, you'll might need to adjust the field name in the first line of code.
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for error messages after you open the file.
Copy link to clipboard
Copied
@try67 Dont know why but it is working now. Nothing changed on it but it is working. I appreciate you helping all of us!
Copy link to clipboard
Copied
I utilized the same script and it worked great to create the sequential number; however, the number changes in the Receipt every time I opened the saved completed form. How can I correct this?
Copy link to clipboard
Copied
Yes, the code is set to execute each time the file is opened. If you don't want that to happen you need to define some kind of condition to stop it from doing so, and then add that to the code.
Copy link to clipboard
Copied
Thank you for your expedient response. Whew - ceate a code. I'll see hat I can do! certainly not my expertise.
Ms. V
Copy link to clipboard
Copied
I am trying to do something similar, but more difficult. I need to print a 4 page PDF, it has a number field with a 3 digit number in the corner of the first page. I need the number to increase every time it prints, however, I print many copies at once, sometimes 50 to 100. Is there a way to set it to print that many copies and increase that number after each copy? Ive been trying to figure this out for about a year now, if anyone could help, please let me know.
Copy link to clipboard
Copied
If you tell the printer to print X copies, then it handles the printing, outside of Acrobat. The only way to modify a value on the PDF is to control the printing yourself. A script would do this easily from a Folder level script, Command Script, or the Console window.
Contact me if you'd like such a script written.
Copy link to clipboard
Copied
Well that would solve all my problems if I knew how to print outside of acrobat. Im using a Mac and Ive never printed a document outside of its program. My only other issue is being able to set print settings. Its not just a plain paper document, its an exam. Its printed on 11 x 17 cardstock then folded by the printer, so I would need to incorporate those print settings as well. Not sure if its doable, but I will keep trying to find a solution to this problem. I appreciate the response.
Copy link to clipboard
Copied
I think you misunderstood me. After you press the print button, Acrobat sends the print job off to the printer. This is what I meant by outside Acrobat. You always print outside Acrobat, because Acrobat is not a print driver.
Now what you want to do is write an Automation script in Acrobat that prints one copy at a time, changing the increment number each time.
Contact me if you want consulting/development on this issue, or post this question to a new thread if you want more free help.
Copy link to clipboard
Copied
Very usefull for me - thanks!
How can I modify script to do NOTHING, when field "Serial Number" is empty?
Copy link to clipboard
Copied
Change it to this:
var f = this.getField("Serial Number");
if (f.valueAsString!="") {
f.value = Number(f.value)+1;
f.defaultValue = f.value;
}
Copy link to clipboard
Copied
Thanks for Your reply, I used very similar code (from my friend):
var f = this.getField("Serial-Number");
if (f.value != "" && f.value != null) {
f.value = Number(f.value)+1;
f.defaultValue = f.value;
}
Works fine.
By the way, how can I tag code as “code“ :-), like You in Your last post?
Copy link to clipboard
Copied
I do it via the "Advanced Editor", but it's possible you won't have access to it...
Copy link to clipboard
Copied
I can get the sequential numbering to work if I keep using the last form that was saved.
The master form does not update.
Is there a way for the master form to update each time you open it?
I'm opening master form/adding my data/then save as with new file name/close tab/open original master form and number is the same.
Need a little help.
Copy link to clipboard
Copied
Save it over the "master form", then, not under a new name...
Copy link to clipboard
Copied
I was able to get it to work that way, but that seems counter intuitive. I don't want to have to rename the file after everytime.
There's gotta be another way?
I've seen these global object scripts, that apparently works when using just your own computer, but haven't had any success, although, I'm probably doing it wrong.
I tried to add a required one time click button to add +1 to current number, but not sure how to create a "one time" click funcion.
The only thing that I was able to make work is use the date and time to create a unique number, but then it's not really sequential.
I'm hoping to make the sequential number work somehow.
I'll keep trying.
Copy link to clipboard
Copied
Forgot to mention that I'm also trying to find a way to save the file as per one of the fields I'm using. Want it to save as per the customer name.
Copy link to clipboard
Copied
I have a similar question. I can get the sequential numbering to work. However, if I keep using the last form that was saved the pdf form updates each time it is opened and closed. Is there a way for the master form to update only when the document is opened? The master form is saved on a shared drive. In theory, I have designed a master form for all staff to utilize, type into, print, save as, and close. I would like a sequential number generated each time it is opened. Any help would be appreciated. Thank you.
Copy link to clipboard
Copied
A document level script runs everytime the document is opened. So put your increment code in a document level script and it will run everytime the document is opened.
Copy link to clipboard
Copied
Thanks Thom!
Below is my current document level script. Again, the problem that I am running into is that the PO advances each time the document is opened, printed and saved. I only want the PO number to advance when the document is opened. Also, the mater document is saved on a shared drive. Thank you again for your help!
var f = this.getField("PO");
f.value = Number(f.value)+1;
f.defaultValue = f.value;
elsef.value = util.printf("%06d", event.value) ;
Copy link to clipboard
Copied
that last line is an error, delete it.
This document level code is only run when the document is opened. Therefore you must have scripts in the Document Save and Print actions that are also setting the value. Or perhaps you have a calculation script somewhere that is setting the field value, but I can guarantee you that the document script is only run when the document is opened.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I have the sequential number field using this coding:
var num = this.getField("Text2");
num.value = Number(num.value)+1;
num.defaultValue = num.value;
BUT, I actually don't want the number to change after the doc is filled out. It's a work order so once the doc is opened, new number is generated, the rest of the form is completed and it's saved. I need this document to keep this same work order number idefinitely.
Is it possible to have a "Master" doc that generates sequential numbers but then once it's saved as a new name, the number stays the same? So employees can open a single Master doc when they get ready to provide an estimate and each time the work order generates a new +1 number. Then, once they save and rename the document, the number sequence no longer changes.
Copy link to clipboard
Copied
The best way to do that is to set the "master" file (and the folder where it's located) as read-only.
If you want to make it dependent on the file name, though, that's possible too.
Adjust the code like this:
if (this.documentFileName=="Original file name.pdf") {
var num = this.getField("Text2");
num.value = Number(num.value)+1;
num.defaultValue = num.value;
}
Copy link to clipboard
Copied
I have just added your java script to my form, but I would like to know if it can be modified to add a fixed numeric at the begin of the sequential number that will be created each time the form is open. For example, I would like to add 23 - to the beginning to signify the year 2023. Is there a way I can do this so that the 23 - is fixed in the code somewhere, and then I can go in and change it for 2024?
Thanks,
Nick