feat(pdfengines): add watermark and stamp feature

This commit is contained in:
Julien Neuhart
2026-03-18 04:46:12 +01:00
parent 4ac493250c
commit 19db80bc2e
26 changed files with 1351 additions and 50 deletions

View File

@@ -17,9 +17,15 @@ import (
"github.com/gotenberg/gotenberg/v8/pkg/gotenberg"
)
// EmbedsFormField represents the form field name for embedding files.
const (
// EmbedsFormField represents the form field name for embedding files.
EmbedsFormField string = "embeds"
// WatermarksFormField represents the form field name for watermark files.
WatermarksFormField string = "watermarks"
// StampsFormField represents the form field name for stamp files.
StampsFormField string = "stamps"
)
// FormData is a helper for validating and hydrating values from a
@@ -406,17 +412,57 @@ func (form *FormData) MandatoryPaths(extensions []string, target *[]string) *For
return form
}
// Watermarks binds the absolute paths of form data files that should be
// used as watermark sources. Only files uploaded with the "watermarks"
// field name will be included.
func (form *FormData) Watermarks(target *[]string) *FormData {
if form.errors != nil {
return form
}
if paths, ok := form.filesByField[WatermarksFormField]; ok {
*target = append(*target, paths...)
}
return form
}
// Stamps binds the absolute paths of form data files that should be
// used as stamp sources. Only files uploaded with the "stamps"
// field name will be included.
func (form *FormData) Stamps(target *[]string) *FormData {
if form.errors != nil {
return form
}
if paths, ok := form.filesByField[StampsFormField]; ok {
*target = append(*target, paths...)
}
return form
}
// paths bind the absolute paths of form data files, according to a list of
// file extensions, to a string slice variable.
// embeds are excluded.
// embeds, watermarks, and stamps are excluded.
func (form *FormData) paths(extensions []string, target *[]string) *FormData {
embeds, ok := form.filesByField[EmbedsFormField]
watermarks, wmOk := form.filesByField[WatermarksFormField]
stamps, stOk := form.filesByField[StampsFormField]
for filename, path := range form.files {
if ok && slices.Contains(embeds, path) {
continue
}
if wmOk && slices.Contains(watermarks, path) {
continue
}
if stOk && slices.Contains(stamps, path) {
continue
}
for _, ext := range extensions {
// See https://github.com/gotenberg/gotenberg/issues/228.
if strings.ToLower(filepath.Ext(filename)) == ext {