Skip to content

Commit 21e193e

Browse files
committed
Simplified pdf_watermark_image.go
1 parent 4051b33 commit 21e193e

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

image/pdf_watermark_image.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/unidoc/unipdf/v3/common"
1515
"github.com/unidoc/unipdf/v3/common/license"
16-
"github.com/unidoc/unipdf/v3/creator"
1716
"github.com/unidoc/unipdf/v3/model"
1817
)
1918

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

53-
c := creator.New()
54-
5552
// Create the watermark image from file.
5653
wImgFile, err := os.Open(watermarkPath)
5754
if err != nil {
@@ -99,17 +96,17 @@ func addWatermarkImage(inputPath string, outputPath string, watermarkPath string
9996

10097
// Add watermark with options.
10198
page.AddWatermarkImage(xImage, model.WatermarkImageOptions{Alpha: 0.5, FitToWidth: true})
102-
103-
// Add to creator.
104-
c.AddPage(page)
10599
}
106100

107-
// Add reader outline tree to the creator.
108-
c.SetOutlineTree(pdfReader.GetOutlineTree())
109-
110-
// Add reader AcroForm to the creator.
111-
c.SetForms(pdfReader.AcroForm)
101+
// Generate a PDFWriter from PDFReader.
102+
pdfWriter, err := pdfReader.ToWriter(nil)
103+
if err != nil {
104+
return err
105+
}
112106

113-
err = c.WriteToFile(outputPath)
114-
return err
107+
err = pdfWriter.WriteToFile(outputPath)
108+
if err != nil {
109+
return err
110+
}
111+
return nil
115112
}

0 commit comments

Comments
 (0)