Skip to content

Commit

Permalink
Add support for multi-page signature stamping
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jan 13, 2020
1 parent 528c0c5 commit 6d4dea7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
44 changes: 25 additions & 19 deletions internal/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ type SignStyle struct {

// SignCoords holds the signature annotation co-ordinates.
type SignCoords struct {
X1 float64 `json:"x1"`
X2 float64 `json:"x2"`
Y1 float64 `json:"y1"`
Y2 float64 `json:"y2"`
Pages []int `json:"pages"`
X1 float64 `json:"x1"`
X2 float64 `json:"x2"`
Y1 float64 `json:"y1"`
Y2 float64 `json:"y2"`
}

// SignProps represents signature properties that are required to do
Expand All @@ -54,7 +55,7 @@ type SignProps struct {

Annotations []map[string]string `json:"annotations"`
Style SignStyle `json:"style"`
Coords SignCoords `json:"coords"`
Coords []SignCoords `json:"coords"`
}

// Job represents a queued doc sign job. This is used in bulk processing
Expand Down Expand Up @@ -354,20 +355,25 @@ func (p *Processor) signPDF(cert *Certificate, pr SignProps, rd *model.PdfReader
}
}

// Create signature field and appearance.
opts := annotator.NewSignatureFieldOpts()
opts.FontSize = pr.Style.FontSize
opts.TextColor = &pr.Style.FontColorRGBA
opts.FillColor = &pr.Style.BgColorRGBA
opts.BorderColor = &pr.Style.BorderColorRGBA
opts.BorderSize = pr.Style.BorderSize
opts.Rect = []float64{pr.Coords.X1, pr.Coords.X2, pr.Coords.Y1, pr.Coords.Y1}
opts.AutoSize = pr.Style.AutoSize
field, err := annotator.NewSignatureField(sig, lines, opts)
field.T = core.MakeString("")

if err = ap.Sign(1, field); err != nil {
return nil, err
// Go through each set of coordinates and within that, each page number.
for _, c := range pr.Coords {
// Create signature field and appearance.
opts := annotator.NewSignatureFieldOpts()
opts.FontSize = pr.Style.FontSize
opts.TextColor = &pr.Style.FontColorRGBA
opts.FillColor = &pr.Style.BgColorRGBA
opts.BorderColor = &pr.Style.BorderColorRGBA
opts.BorderSize = pr.Style.BorderSize
opts.AutoSize = pr.Style.AutoSize
opts.Rect = []float64{c.X1, c.Y1, c.X2, c.Y2}

field, err := annotator.NewSignatureField(sig, lines, opts)
field.T = core.MakeString("")
for _, p := range c.Pages {
if err = ap.Sign(p, field); err != nil {
return nil, err
}
}
}

return ap, nil
Expand Down
21 changes: 15 additions & 6 deletions props.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@
{ "Something": "Else" },
{ "Date": "2020-01-01" }
],
"coords": {
"x1": 10,
"x2": 25,
"y1": 75,
"y2": 100
},
"coords": [{
"pages": [1, 2],
"x1": 80,
"y1": 80,
"x2": 300,
"y2": 150
},
{
"pages": [3],
"x1": 200,
"y1": 80,
"x2": 300,
"y2": 150
}
],
"style": {
"autoSize": false,
"fontSize": 12,
Expand Down

0 comments on commit 6d4dea7

Please sign in to comment.