@@ -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