We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

How to dynamic add image watermark when rendering

I would like to use GroupDocs.Viewer-for-.NET-UI as codebase and reivse it for our customer need. How to dynamic add image watermark(not text watermark) to each view page(png view) when rendering?


Adding image watermark is not supported out of the box but since you’re going to use Viewer UI as a code base you can add image watermark with a bit of custom code in this method. There are two parameters that you can use page number and page stream. Viewer populates a page stream and then calls this method. You can read the stream, apply image watermark and write the data back to the same stream similar to:

var viewOptions = new PngViewOptions(_ => pageStream,
    (int pageNumber, Stream stream) =>
        // 1. read `stream`

        // 2. apply watermark

        // 3. write data back to `stream`

        //NOTE: do not dispose/close stream here

You can also implement IPageStreamFactory interface and pass the instance as PngViewOptions constructor parameter instead of using delegates.