-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathAcro Sign PDF.ahk
174 lines (140 loc) · 4.69 KB
/
Acro Sign PDF.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;Sign PDF;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
actually I place sign as stamp so I made it sign pdf.. yah yah I know it should be stamp pdf
rectangle
when you enable acrobat edit mode and try to edit text you see text in rectangle
`rect` has rectangle coordinates of text
rect.left
rect.top
rect.right
rect.bottom
`l` `t` `r` `b` are the rectangle coordinate of stamp
left
top
bottom
right
sizing stamp may confuse you so here is the trick
Manupulating with `left` and `top` will defines intitial point of stamp like x1 and y1
Changing `bottom` and `right` defines how big or small stamp should be compare to text rectangle
;;;;;;;;;;;;;Dynamic PDF Stamps (DPS);;;;;;;;;;;;
How to Create a custom dynamic stamp using Acrobat DC
https://helpx.adobe.com/acrobat/using/adding-stamp-pdf.html
following link describes how to extract Custom DPS AP i.e my custom DPS AP is "#DqYJkNdha_RxWUIh-SVFVD"
https://acrobatusers.com/tutorials/print/dynamic_stamp_secrets/
OR if you know acroba console
1 . manually sign pdf using acrobat (or create custom stamp then sign)
2 . while stamp is selected
3 . open acrobat console called JavaScriptdebugger (tool >> Java Script >> JavaScriptdebugger)
4 . put the code `this.selectedAnnots[0].AP` into the console
5 . Press enter to go for next line AP will appear ; (take care cursor should be at the end of line)
;
; AP: "NotApproved"
*/
signpdf(rect,pagenum, l=0, t=0, r=50, b=50)
{
left := rect.left + l
top := rect.top + t
right := rect.right + r
bottom := rect.bottom - b
stamp1script =
(
var annot = this.addAnnot({
page: %pagenum%,
type: "Stamp",
author: "Yaseen",
name: "Yaseen",
rect: [%left%, %top%, %right%, %bottom%],
contents: "",
AP: "Approved"
});
)
CustomStamp2script =
(
var annot = this.addAnnot({
page: %pagenum%,
type: "Stamp",
author: "Yaseen",
name: "Yaseen",
rect: [%left%, %top%, %right%, %bottom%],
contents: "",
AP: "#DqYJkNdha_RxWUIh-SVFVD"
});
)
AForm := ComObjCreate("AFormAut.App")
;msgbox, % stampscript
AForm.Fields.ExecuteThisJavaScript(stamp1script) ; default stamp
}
/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;PDFtext;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
extracting text coordinates though Acrobat COM was way complicated than I imagine but in the end I found out who it works,
There are 2 rules...
1 . Text does not have rectangular coordinates
2 . Text selection has rectangular coordinates
so if I understand how to select required text then I got the coordinates
I read the whole idiotic API from "Acrobat Exchange COM API with QTP.pdf" which I do not remember from where It was downloaded
how it works
1 . find text on page if found the proceed further
2 . get total word from `.getPageNumWords`
3 . check text one by one `.objJSO.getPageNthWord(pagenumber, a_index)` amazingly its very very fast do not know why
4 . select text with `.SetTextSelection(` and I didn't know it was whole and different com object `"AcroExch.HiliteList"`
5 . get selection coordniates by `.GetBoundingRect`
*/
PDFtext(Inputfile,TextToFind)
{
objAcroApp := ComObjCreate("AcroExch.App")
;objAcroApp.Show()
objAcroAVDoc := ComObjCreate("AcroExch.AVDoc")
objAcroAVDoc.Open(Inputfile, "")
objAcroAVDoc.BringToFront()
objAcroAVDoc.Maximize( True )
objAcroPDDoc := objAcroAVDoc.GetPDDoc
objJSO := objAcroPDDoc.GetJSObject
i := objAcroAVDoc.FindText(TextToFind, 1, 0, 1)
if i
{
loop, % objAcroPDDoc.GetNumPages()
{
pagenumber := a_index - 1
acroPageView := objAcroAVDoc.GetAVPageView()
acroPageView.Goto( pagenumber )
acroHiList := ComObjCreate("AcroExch.HiliteList")
acroHiList.Add( 0, 32767 )
acroPDPage := acroPageView.GetPage()
acroPDTextSel := acroPDPage.CreateWordHilite( acroHiList )
If !acroPDTextSel
return
objAcroAVDoc.SetTextSelection( acroPDTextSel )
objAcroAVDoc.ShowTextSelect()
TotalWords := objJSO.getPageNumWords(pagenumber)
pdPage := objAcroPDDoc.AcquirePage( pagenumber )
acroPoint := pdPage.GetSize()
loop, %TotalWords%
{
if ( TextToFind = objJSO.getPageNthWord(pagenumber, a_index))
{
nword := a_index
nwordhtl := ComObjCreate("AcroExch.HiliteList")
nwordhtl.Add(nword, pagenumber)
nwordTextSel := pdPage.CreateWordHilite(nwordhtl)
objAcroAVDoc.SetTextSelection( nwordTextSel )
objAcroAVDoc.ShowTextSelect()
rect := nwordTextSel.GetBoundingRect
}
}
if rect.left
{
signpdf(rect,pagenumber)
}
}
}
objAcroPDDoc := objAcroPDDoc.save(1, Inputfile)
avdoc := objAcroAVDoc.Close(1)
avdoc := objAcroApp.Exit
objAcroPDDoc :=
objAcroAVDoc :=
objAcroApp :=
}