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"
Watermarkerwatermarker=newWatermarker("document.pdf");// Initialize text watermark
TextWatermarktextWatermark=newTextWatermark("Protected image",newFont("Arial",8));textWatermark.setHorizontalAlignment(HorizontalAlignment.Center);textWatermark.setVerticalAlignment(VerticalAlignment.Center);textWatermark.setRotateAngle(45);textWatermark.setSizingType(SizingType.ScaleToParentDimensions);textWatermark.setScaleFactor(1);// Initialize image watermark
ImageWatermarkimageWatermark=newImageWatermark("protect.jpg");imageWatermark.setHorizontalAlignment(HorizontalAlignment.Center);imageWatermark.setVerticalAlignment(VerticalAlignment.Center);imageWatermark.setRotateAngle(-45);imageWatermark.setSizingType(SizingType.ScaleToParentDimensions);imageWatermark.setScaleFactor(1);// Find all images in a document
WatermarkableImageCollectionimages=watermarker.getImages();for(inti=0;i<images.getCount();i++){if(images.get_Item(i).getWidth()>100&&images.get_Item(i).getHeight()>100){if(i%2==0){images.get_Item(i).add(textWatermark);}else{images.get_Item(i).add(imageWatermark);}}}imageWatermark.close();watermarker.save("document.pdf");watermarker.close();
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.