Skip to main content
Known Participant
July 18, 2022
Answered

How to use Javascript to detect a signed Acrobat document?

  • July 18, 2022
  • 3 replies
  • 12892 views

Hi,

 

BACKGROUND:

I am using an Action Wizard in Adobe Acrobat Pro DC to automatically label a batch of pdf's. It has various steps: JavaScript (Initial Error Trapping) > Remove Hidden Information >  Reduce File Size > Save to "Prepped" Folder > Add Header & Footer > JaveScript (Adding incremental labels to all documents in "Prepped" Folder so if there are 4 documents, it will label them in sequence as EX01, EX02, EX03, and EX04).

 

REQUEST:

1) I need to bring up an error message for the user when a signed pdf is detected in the batch b/c once we upgraded to Adobe Acrobat Pro DC, such files are skipped and therefore, not processed. I researched this and found it is b/c a signature in the pdf makes it so "Changing the Document" is not allowed.

Note: In my example, Document 3 is the signed pdf and all the processing steps above are skipped and the file is not saved in the "Prepped" folder.

 

I tried the following to alert the user of a signed pdf but it did not work.

 

       if (securityhandler == null) {app.alert(event.target.documentFileName + " is signed and cannot be         labeled. It will be skipped.");}

 

2) As an added bonus, it would be great if you could give me an idea on how I can up the numbering by one once a signed pdf is detected (Can I just add "+1" to the iteration of "global.iteration++"?). Right now, the signed document is skipped and the next document gets assigned its number such that the numbering is off.

Note: In my example, Document 3 is the signed pdf and all the processing steps above are skipped and the file is not saved in the "Prepped" folder. Document 4 instead is labeled as EX03 instead of EX04.

 

Thanks so much!

Sue

This topic has been closed for replies.
Correct answer try67

Document 3 was digitally signed using certificates. Does that help? I have attached the sample files.


Try it with this code:

 

var isSigned = false;
for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.type=="signature" && f.value!="") {isSigned = true; break;}
}
if (isSigned) app.alert("This document is signed.");

 

The securityHandler property is for document encryption, not for signatures.

3 replies

JR Boulay
Community Expert
July 20, 2022

"I don't know how to deploy this in my action wizard. Can you advise?"

 

1.

 

2.

 

3.

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
July 19, 2022

You don't need JavaScript, you should start the Preflight process by using this check profile:

 

Acrobate du PDF, InDesigner et Photoshopographe
suemo22Author
Known Participant
July 19, 2022

Hmmm, I don't know how to deploy this in my action wizard. Can you advise? I am using an Action Wizard in Adobe Acrobat Pro DC to automatically label a batch of pdf's. It has various steps:

 

  1. JavaScript (Initial Error Trapping) 
  2. Remove Hidden Information 
  3. Reduce File Size
  4. Save to "Prepped" Folder
  5. Add Header & Footer 
  6. JavaScript (Adding incremental labels to all documents in "Prepped" Folder so if there are 4 documents, it will label them in sequence as EX01, EX02, EX03, and EX04).
try67
Community Expert
July 19, 2022

This is not possible. A script can't stop other (non-JS based) operations in your Action from taking place. The only thing it can do is stop the batch process entirely.

try67
Community Expert
July 19, 2022

It's important to spell things correctly when writing a script. Try this:

 

if (this.securityHandler == null) {app.alert(this.documentFileName + " is signed and cannot be labeled. It will be skipped.");}
else global.iteration++;
suemo22Author
Known Participant
July 19, 2022

Hi,

It is putting up this error for all documents, even the unsigned ones:

  • Document 1 (unsigned)
  • Document 2 (unsigned)
  • Document 3 (signed)
  • Document 4 (unsigned)

 

How do I specifically make it recognize the one that has a signature? Also, the iteration did not work. It still labeled Document 4 as EX03 instead of EX04.

 

Thanks in advance.

Sue

suemo22Author
Known Participant
July 20, 2022

You want to increment the value of the variable if the file is signed, or not?


Yes, I want to increment the value of the variable regardless of whether a document is signed or not. This way, the next document (document 4) will have the correct iteration of EX04. Otherwise, it gets assigned EX03 and the numbering is off.