Copy link to clipboard
Copied
I have multiple PDFs requiring an e-signature (not digital). However, the signature line isn't consistent across all PDFs. I need to search the PDF for a specific phrase, then insert the e-signature above that phrase. I have created a Action to watermark the signature, but since the signature line isn't consistent, this doesn't work. I understand this will take scripting to do and I've tried to find answers, however, every script I've found is applied to a static location and not a dynamic location. This script looks extremely promising (though it uses a digital signature, not an e-signature). Here's what I have so far:
var phrase = "Signature of: Name";
var currentPage = this.pageNum;
var found = this.getPageNthWord(currentPage, 0, phrase);
if (found.length > 0) {
var bbox = this.getPageNthWordQuads(currentPage, 0)[found[0]];
var x = bbox[0];
var y = bbox[1];
var signatureImage = this.addWatermarkFromFile("FILE LOCATION", { opacity: 1, onTop: true, bUseAsBackground: false, nRotation: 0 });
signatureImage.page = currentPage;
signatureImage.display = display.visible;
signatureImage.rect = [x, y - 20, x + 60, y];
signatureImage.borderWidth = 0;
Hi,
Sorry if I'm late for this answer.
Here is a script you can use for doing what you are looking for. It places the "Signature.pdf" above the top of the name. You will have to move it a bit if you wish. let me know if you need help.
var found=0;
for (var p=0; p<this.numPages; p++) {
var numWords=this.getPageNumWords(p);
for (var i=0; i<numWords-2; i++) {
if (this.getPageNthWord(p,i,true)=="Signature" && this.getPageNthWord(p,i+1,true)=="of") {
var q=this.getPageNthWordQuads(p,i+2);
var
...
Hi,
Use this new script if you want to add the signature every other time when it meets "SIGNATURE OF".
var found=0;
for (var p=0; p<this.numPages; p++) {
var numWords=this.getPageNumWords(p);
for (var i=0; i<numWords-2; i++) {
if (this.getPageNthWord(p,i,true)=="SIGNATURE" && this.getPageNthWord(p,i+1,true)=="OF") {
found++;
if (found%2!=0) {
var q=this.getPageNthWordQuads(p,i+2);
var m=(new Matrix2D).fromRotated(this,p);
var mInv=m.invert();
var r=mInv.transform(q);
...
Copy link to clipboard
Copied
None of these properties apply to a watermark. Are you trying to add a signature field, or a watermark? It's not clear.
Copy link to clipboard
Copied
I understand that my code doesn't apply the watermark or stamp of an e-signature. I do not want to create a signature field. I have to identify the correct coordinates first, then apply the watermark or stamp of the e-signature slightly above the identified coordinates. This is to automate signing multiple PDFs at one time.
The length of the PDF will vary (sometimes it's only 3 pages and sometimes it's 7 pages or more), the signature needs to be applied on page 1 and then for longer documents page 4, 8, etc. That's why I have to find where the signature line is since it moves up/down slightly on each page of the PDF and on different PDFs.
Also, I already tried using the Action Wizard to apply the signature as a watermark. That's how I discovered that the signature line isn't at the same coordinates for all of the PDFs to which I will apply the signature.
Copy link to clipboard
Copied
Hi,
Sorry if I'm late for this answer.
Here is a script you can use for doing what you are looking for. It places the "Signature.pdf" above the top of the name. You will have to move it a bit if you wish. let me know if you need help.
var found=0;
for (var p=0; p<this.numPages; p++) {
var numWords=this.getPageNumWords(p);
for (var i=0; i<numWords-2; i++) {
if (this.getPageNthWord(p,i,true)=="Signature" && this.getPageNthWord(p,i+1,true)=="of") {
var q=this.getPageNthWordQuads(p,i+2);
var m=(new Matrix2D).fromRotated(this,p);
var mInv=m.invert();
var r=mInv.transform(q);
var r=r.toString();
var r=r.split(",");
this.addWatermarkFromFile({
cDIPath: this.path.substring(0,this.path.length-this.documentFileName.length)+"Signature.pdf",
nSourcePage: 0,
nStart: p,
nEnd: p,
bOnTop: false,
bOnScreen: true,
bOnPrint: true,
nHorizAlign: app.constants.align.left,
nVertAlign: app.constants.align.bottom,
nHorizValue: r[0],
nVertValue: r[1],
bPercentage: false,
nScale: 0.85,
bFixedPrint: false,
nRotation: 0,
nOpacity: 0.75
});
found++;
break;
}
}
if (found) {
this.saveAs(this.path.replace(/.pdf$/i," \(With Signature\).pdf"));
break;
}
}
@+
Copy link to clipboard
Copied
Thank you! I will test it out and report back. I really appreciate the help!
Copy link to clipboard
Copied
Unfortunately, the signature is not appearing. I named my file Signature.pdf and placed it in the Watermark folder. I also placed Signature.pdf in the location of the PDFs that need the signature added. Additionally, I created a watermark and named it Signature, still no luck.
Copy link to clipboard
Copied
What kind of debug have you done? Are any error messages displayed in the Console window?
Do you even know if the "addWatermarkFromFile" code is ever run?
This script has some complexity and every step needs to be looked at individually to ensure it is operating as intended. I would suggest running this code from inside the Console in pieces.
Copy link to clipboard
Copied
With this script, the "Signature.pdf" file must be located in the same folder as the file you must sign.
Could you share a screenshot of the place where the signature must be applyed like the one below.
FYI, the signature above has been done with my script!
@+
Copy link to clipboard
Copied
Copy link to clipboard
Copied
So, you must write:
...
if (this.getPageNthWord(p,i,true)=="SIGNATURE" && this.getPageNthWord(p,i+1,true)=="OF") {
...
If that doesn't still work, let me know if you have a message in the console window.
@+
Copy link to clipboard
Copied
@bebarthit worked! I had changed it to SIGNATURE and OF, but added more conditions that broke it. Apologies for my ignorance getting in the way of your beautiful coding. Thank you for your help!
Copy link to clipboard
Copied
Hi,
Use this new script if you want to add the signature every other time when it meets "SIGNATURE OF".
var found=0;
for (var p=0; p<this.numPages; p++) {
var numWords=this.getPageNumWords(p);
for (var i=0; i<numWords-2; i++) {
if (this.getPageNthWord(p,i,true)=="SIGNATURE" && this.getPageNthWord(p,i+1,true)=="OF") {
found++;
if (found%2!=0) {
var q=this.getPageNthWordQuads(p,i+2);
var m=(new Matrix2D).fromRotated(this,p);
var mInv=m.invert();
var r=mInv.transform(q);
var r=r.toString();
var r=r.split(",");
this.addWatermarkFromFile({
cDIPath: this.path.substring(0,this.path.length-this.documentFileName.length)+"Signature.pdf",
nSourcePage: 0,
nStart: p,
nEnd: p,
bOnTop: false,
bOnScreen: true,
bOnPrint: true,
nHorizAlign: app.constants.align.left,
nVertAlign: app.constants.align.bottom,
nHorizValue: r[0],
nVertValue: r[1],
bPercentage: false,
nScale: 0.85,
bFixedPrint: false,
nRotation: 0,
nOpacity: 0.75
});
}
}
}
}
if (found) this.saveAs(this.path.replace(/.pdf$/i," \(With Signature\).pdf"));
Let me know.
@+
Copy link to clipboard
Copied
@bebarthWorked beautifully! Thank you very much for your assistance!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now