Copy link to clipboard
Copied
Hi all,
I have a PDF form with 2 action buttons, one to save document with changes made & a second to clear the form & save as a fresh blank document (reason for this is I have a counter in a text field that adds 1 when the form is reopened).
First button has a simple execute "SaveAs" but I want it to also determin the file name from a text field ("CN1")...is this possible?
Second button has a simple execute "Reset a form" but I also need it to save as the original to allow my counter to move up 1 number the next time the form is opened...again, is this posible. Thank you for any assistance, greatly apreciated - Marco
Here is an article on exactly this topic:
https://www.pdfscripting.com/public/How-to-Save-a-PDF-2.cfm
Copy link to clipboard
Copied
I think this may require deocument level scripting and some advanced knowledge of how Acrobat JavaScript interacts with the operating system in a privileged context (but I may be wrong).
Copy link to clipboard
Copied
What do you mean by "to allow my counter to move up 1 number the next time the form is opened", exactly?
What is this "counter"? Is it a text field? If so, why not change its value when the Reset button is clicked?
Copy link to clipboard
Copied
It's a text field correct, it generates the next invoice number when the form is opened, run by a small piece of Javascript & works perfectly, no need to fix thanks
"var v = +this.getField("CN1").valueAsString;
this.getField("CN1").value = util.printf("%04d", (v+1));"
Copy link to clipboard
Copied
There are two issues with usig code like this to create consecutive numbers.
1) The value needs to be initialized manually, and the current value can be lost through a reset or not saving the form.
2) Forms used by different people will be out of sync.
Basically it's set up to only work for one person in one location, who carefully manages it. Not a problem if this is the situation, but just keep these issues in mind if it ever needs to be used by someone else.
Copy link to clipboard
Copied
Hi Thom,
Just used by one individual luckily, however at some point next year our company will move over to SharePoint & this form could be used by other branches...& now you mention it...as a contingency what other options would I have? I could generate a master for each branch I guess, with their own number sequence, your thoughts Thom? Thanks for the feedback, really appreciated - Marc
Copy link to clipboard
Copied
This is a well worn topic without any particularly happy/easy solutions. The only way to guarentee unique consecutive numbers is to get them from a central source. You can find lots of posts here on the topic by searching for "consecutive number". If there is a way to share a file system drive, then the number could be kept in a common PDF file. This does have an access issue (two people updating at the same time), but as long as it's not heavily used it's not a big deal. A more general, safe, and robust solution is to create a server script to return the number from a DB.
If each branch having thier own sequence is acceptable, then all you need to do is fix up the code a bit to make it more user-proof. Maybe give each branch a unique prefix, so they can be easily differentiated.
Copy link to clipboard
Copied
Yeah, I reckon the latter would initially be my best option, we have branches in Melbourne, Sydney, Newcastle, all over the country, I could use a prefix like Mel_0001 or Syd_0001 possibly...to save me headscratching & Google searching for a week, how would you adapt the code below to achieve this prefix?
"var v = +this.getField("CN1").valueAsString;
this.getField("CN1").value = util.printf("%04d", (v+1));"
Thanks again Thom - Marc
Copy link to clipboard
Copied
this.getField("CN1").value = "Mel_" + util.printf("%04d", (v+1));
Copy link to clipboard
Copied
Perfect, thank you try67! Works like a charm 🙂
Copy link to clipboard
Copied
Or, put he prefix in the PDF Info (the custom metadata)
this.getField("CN1").value = info.prefix + util.printf("%04d", (v+1));
Copy link to clipboard
Copied
Yea that way I just need 1 master copy, great idea...or a simple dropdown with the branch prefix prior to the number. One issue I am having is with the saved form (not the original), as this is not saved as a "flattened" copy because there are signatures that are required after, if opened, edited/signed & saved again, the next time it's opened it changes the number up 1 again. Is there a way to add to the "SaveAs" code that will lock the number cell so it can't be changed without locking the whole form? Thanks again guys 🙂
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Here is an article on exactly this topic:
https://www.pdfscripting.com/public/How-to-Save-a-PDF-2.cfm
Copy link to clipboard
Copied
Cheers Thom,
Perct, I'll give this a whirl later today 🙂