Skip to main content
Blueprint-Pre-Press
Participating Frequently
December 18, 2019
解決済み

Can Acrobat auto populate a Name field upon digital signature of a form?

  • December 18, 2019
  • 返信数 2.
  • 8591 ビュー

I know you can auto populate a Date Field upon Digital Signature from a form but I'd also like to auto populate a Name Field. I am making a form which requires a Digital Signature for approval, along with the client's Name and Date of Approval. I have added the required Java script to generate the Date but I was wondering is there a way to generate the Name based on the name information from the digital signature?

このトピックへの返信は締め切られました。
解決に役立った回答 ls_rbls

Extracting from ls_rbls - this is what worked perfectly for me.
When signed, the document fills out a date stamp next to it automatically.


Insert Text Box next to Signature > Right-click the Text Box > Properties > mark Read Only and close.


Script: Right-click the Signature > Properties > Signed > Edit > Paste the following:

var f = event.target;

var sigInfo = f.signatureInfo();

this.getField("Text34").value = util.printd("yyyymmdd", new Date((util.scand("ddd mmm dd yyyy HH:MM:ss ZZ", sigInfo.date ))));

if (f.signatureValidate()==4);

 

... but ... Hahah.

 

If I remove the signature, how do I delete the data without changing the box to NOT be Read-Only.


Great!

 

And thank you for sharing this.

 

To clear the contents of the date field when the signature field is cleared, you may use a custom validation script or custom calculation script executed directly from the date field.

 

Something like this:

 

 

if(this.getField("mySignatureField").value == "") event.value = "";

 

 

OR,

 

You may also add a Mouse Exit event to the signature field:

 

 

if(event.target.value =="") this.getField("Text34").value = "";

}

 

 

With the latter script, when the signature field is cleared and the mouse pointer is moved outside of that field it will set the date field to a blank value.

 

返信数 2

try67
Community Expert
Community Expert
December 28, 2019

You can use this code to do it (as the Signed script of your signature field):

 

var f = event.target;
if (f.signatureValidate()==4) {
	var Info = f.signatureInfo();
	this.getField("SigName").value = "Signed by: " + Info.name;
	this.getField("SigDate").value = "Signed on: " + Info.date;
} else {
	this.getField("SigName").value = "";
	this.getField("SigDate").value = "";
}
Blueprint-Pre-Press
Participating Frequently
January 3, 2020

This is an excellent piece of code! I was wondering if I can restrict the amount of information in the Name field to just the name (and remove the Signed By: and Email address - see attached screen shot). Thank you either way!

 

Jeff2838873357lc
Participant
February 13, 2023

Please disregard my last post as it doesn't answer your question and I am still working on this script.

 

To extract the date as it appears in the digital certificate you need to use a combination of util.scand() method with util.printd() method, and new Date().

 

The date and 24 hour clock time (that such certificate also use with a Gregorian calendar format (as I am reading))  is expressed in Zulu time , which observes Daylight Savings time; also referred to as UTC for Universal Coordinated Time.

 

UTC is basically a timezone (Greenwich Mean Time, in London I believe) that helps separates (or identify) the East and West geographical regions based on Sunrise and Sunset, for example, to include moonrise and moonset.

 

This is important to know because when  you're performing  a forensic analysis of a signature date and time stamps, You'll notice that the signature timestamp won't match that of the textfield where it is copied to (like the minutes and seconds,  and the Zulu timezones).

 

This is due to the script that was used which only takes the current time from the computer's  system clock at signing time, not from the digital certificate that was used with the certificate-based digital signature.

 

I am taking the time to explain all of this because I've noticed that most developers in the Acrobat forums use the "new Date()" method to get the current date at signing time, but this is not correct and it is not the same as extracting the exact Zulu date and time that is embedded in the digital signature (which is also filtered by the signature field's securtiy handler mechanism).  

 

I work a lot with government forms. And from a security and validation standpoint, when I examine a digitally signed PDF, if  the date that was extracted onto another textfield doesn't have the same number of minutes and seconds, it basically invalidates the whole document during an audit.

 

In occasions, I have to kick it back the PDF for corrections because it looks fishy (specially on inspectable paper trail,  and more specifically even if the creator of the form didn't do this intentionally).

 

But in my experience, it just so happens that a lot of people in an office space are always trying to mess around with the wrong hacks in an attempt to make their lives easier at work. I hope that you're not one of those.

 

And to be honest I am starting to regret the fact of sharing so much info here in the forums for free. What I am about to share with you should be a paid-for solution.

 

Anyway,  to avoid this problem for good, you NEED to use this method: 

 

 

 

var f = event.target;

var sigInfo = f.signatureInfo();


//THIS WILL GET THE EMAIL

var Email = this.getField("sigInfo4").value = sigInfo.name.split(">")[1]+sigInfo.name.split("<")[1].split(">")[0];


//THIS WILL GET THE COMMON NAME OF THE SUBJECT

var SubjectName = this.getField("sigInfo3").value = sigInfo.name.split("<")[0];


//THIS WILL GET THE DATE AND TIME FROM THE SIGNATURE AND POPULATE IN ANOTHER FIELD IN ZULU TIME 

this.getField("myDateField").value = util.printd("ddd mmm dd yyyy HH:MM:ss ZZ", new Date((util.scand("ddd mmm dd yyyy HH:MM:ss ZZ", sigInfo.date )) ) );

/* NOTE: TO CHANGE THE DATE TO ANOTHER DATE FORMAT JUST CHANGE THE PART INSIDE THE QUOTES OF  util.printd("ddd-mm-yyyy",  FOR EXAMPLE BUT LEAVE EVERYTHING ELSE UNCHANGED IN THAT LINE OF CODE. ALSO, DO NOT DECLARE A VARIABLE WITH THE LINE OF CODEABOVE FOR util.printd(), IT WILL THROW AN ERROR WITH THE new Date() FUNCTION*/  




//GET THE VALIDATION STAUS OF THE SIGNATURE FIELD, IT CHANGES WHEN IT IS UNSIGNED AND CHANGE AGAIN WHEN THE SIGNATURE IS APPLIED

if (f.signatureValidate()==4) {


//PERFORM THE EXTRACTIONS FOR THE COMMON NAME AND EMAIL

 this.getField("myNameField").value = SubjectName;

 this.getField("myEmailField").value = Email; 


}

 

 

 

Note also that the line of code that I used for the extraction of the date is outside of the "signatureValidate()" function condition.

 

You have to run it outside of this validation or you will not get the date when a user signs with a smart card. 

 

Using the code like this allows to extract the date from both a self-signed certificate or a smart card-based certificate(s). 


Extracting from ls_rbls - this is what worked perfectly for me.
When signed, the document fills out a date stamp next to it automatically.


Insert Text Box next to Signature > Right-click the Text Box > Properties > mark Read Only and close.


Script: Right-click the Signature > Properties > Signed > Edit > Paste the following:

var f = event.target;

var sigInfo = f.signatureInfo();

this.getField("Text34").value = util.printd("yyyymmdd", new Date((util.scand("ddd mmm dd yyyy HH:MM:ss ZZ", sigInfo.date ))));

if (f.signatureValidate()==4);

 

... but ... Hahah.

 

If I remove the signature, how do I delete the data without changing the box to NOT be Read-Only.

ls_rbls
Community Expert
Community Expert
December 18, 2019

Hi,

 

I've been trying to work on similar with  a PDF form of my own.

 

I've recently came accross this possible solution but I haven't tested it on my end:

 

https://experienceleaguecommunities.adobe.com/t5/Adobe-LiveCycle-Questions/Create-digital-initials-after-signing-a-form-using-a-signature/qaq-p/158630 

 

 

This is an old thread for the date , there is a very short script that works for me for the date part:

 

https://community.adobe.com/t5/acrobat/can-acrobat-auto-populate-a-date-field-upon-digital-signature-of-a-form/td-p/4524073 

 

 

Si when you say digital signature I assume you're referring to electronic signature in the context of digital certificates by which certificate validation and encryption are involved.

 

You may also need to dig deeper on how to use signatureInfo part in your script to get first, middle, last names appropriately from  such digital certificate signatures.

 

 

Blueprint-Pre-Press
Participating Frequently
December 19, 2019

Just to clarify, I already have this script in the: Digital Signature Properties > Signed > This script executes when field is signed >

// JavaScript code to add the date at signing time var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var signingTime = day +"/"+month+"/"+year //Modify into your preferred format var f = this.getField("Date1_af_date"); //Modify the field name as necessary f.value = signingTime;

Which propagates the correct date in the Date Approved filed of my form when the Signature is actioned. There's also a Approved By field where the user enters their Name. I was hoping the name supplied in the digital signature could be used here but I have no idea what script to use. And, even if there was a script would it clash with what's already there for the date action?

 

ls_rbls
Community Expert
Community Expert
December 19, 2019

in the first link  that I posted earlier above you can use that one to grab the name.

 

Here is how I would do it:

 

  • To avoid the two scripts clashing you don't need to use the same ApprovedBy field; use two fields instead but make it seemless to the user by marking them as readonly.

 

 

So again, a quick easy solution is to create two read-only text form fields (one that will grab the date from the signature field and the other one to grab the name ).

 

All you have to do is add a custom calculation script in both of those text form fields like:

 

for the date try this:

var grabdate = this.getField("yoursignaturefieldname").valueAsString;

 

if (grabdate=="") event.value ="";

 

or use this other method if you choose to use a datefield where the date will be pulled from the signature field with this other method: https://stackoverflow.com/questions/35232909/how-do-i-trigger-javascript-events-when-a-signature-is-cleared-in-acrobat-11 

 

And for the field that will pull the name portion of the signature field use  the same script  above that I just typed as a reference in the custom calculation script section of that text field:

 

(getField("mySig").value !== '') // signature is present    getField("myDate").value = global.getCurDate(); // custom function for a mm/dd/yyyy date
else    getField("myDate").value = '';

 but change the global ogject  from global.getCurDate to the appropriate

 

global.get object of the API reference