Adding watermark to images inside a document
Leave feedback
The most of the document formats allow you to place images inside a document. If you want to add watermark to images inside a document then it can be possible using GroupDocs.Watermark. Following are the steps to add watermark to the images of any document.
// Specify an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf"using(Watermarkerwatermarker=newWatermarker("document.pdf")){// Initialize text watermarkTextWatermarktextWatermark=newTextWatermark("Protected image",newFont("Arial",8));textWatermark.HorizontalAlignment=HorizontalAlignment.Center;textWatermark.VerticalAlignment=VerticalAlignment.Center;textWatermark.RotateAngle=45;textWatermark.SizingType=SizingType.ScaleToParentDimensions;textWatermark.ScaleFactor=1;// Initialize image watermarkusing(ImageWatermarkimageWatermark=newImageWatermark("protect.jpg")){imageWatermark.HorizontalAlignment=HorizontalAlignment.Center;imageWatermark.VerticalAlignment=VerticalAlignment.Center;imageWatermark.RotateAngle=-45;imageWatermark.SizingType=SizingType.ScaleToParentDimensions;imageWatermark.ScaleFactor=1;// Find all images in a documentWatermarkableImageCollectionimages=watermarker.GetImages();for(inti=0;i<images.Count;i++){if(images[i].Width>100&&images[i].Height>100){if(i%2==0){images[i].Add(textWatermark);}else{images[i].Add(imageWatermark);}}}}watermarker.Save("document.pdf");}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.