Skip to content

Commit

Permalink
Simplified pdf_watermark_image.go
Browse files Browse the repository at this point in the history
  • Loading branch information
anovik committed Dec 16, 2024
1 parent 4051b33 commit 21e193e
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions image/pdf_watermark_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/unidoc/unipdf/v3/common"
"github.com/unidoc/unipdf/v3/common/license"
"github.com/unidoc/unipdf/v3/creator"
"github.com/unidoc/unipdf/v3/model"
)

Expand Down Expand Up @@ -50,8 +49,6 @@ func addWatermarkImage(inputPath string, outputPath string, watermarkPath string
common.Log.Debug("Input PDF: %v", inputPath)
common.Log.Debug("Watermark image: %s", watermarkPath)

c := creator.New()

// Create the watermark image from file.
wImgFile, err := os.Open(watermarkPath)
if err != nil {
Expand Down Expand Up @@ -99,17 +96,17 @@ func addWatermarkImage(inputPath string, outputPath string, watermarkPath string

// Add watermark with options.
page.AddWatermarkImage(xImage, model.WatermarkImageOptions{Alpha: 0.5, FitToWidth: true})

// Add to creator.
c.AddPage(page)
}

// Add reader outline tree to the creator.
c.SetOutlineTree(pdfReader.GetOutlineTree())

// Add reader AcroForm to the creator.
c.SetForms(pdfReader.AcroForm)
// Generate a PDFWriter from PDFReader.
pdfWriter, err := pdfReader.ToWriter(nil)
if err != nil {
return err
}

err = c.WriteToFile(outputPath)
return err
err = pdfWriter.WriteToFile(outputPath)
if err != nil {
return err
}
return nil
}

0 comments on commit 21e193e

Please sign in to comment.