diff --git a/image/pdf_watermark_image.go b/image/pdf_watermark_image.go index 7892baf7..313b9a23 100644 --- a/image/pdf_watermark_image.go +++ b/image/pdf_watermark_image.go @@ -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" ) @@ -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 { @@ -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 }