Free Support Forum - aspose.com

How can I insert watermark in every page

I use the JAVA language.
and I want to insert watermark(image) in every slide page.
I found only a way to use the loop. (after getting the each slide)
Is there a way to put background images(watermark) at once?
If it is possible, could you give me a sample code ?
Thanks

@kevinKang,

I have observed your requirements and suggest you to please try using following sample code to insert watermark.

public static void TestWatermark()
    {

        Presentation presentation = new Presentation();

        for (ISlide slide : presentation.getSlides())
        {

            IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 700, 100, 200, 80);
            shape.getFillFormat().setFillType(FillType.NoFill);
            slide.getShapes().reorder(0, shape);

            ITextFrame textFrame = shape.addTextFrame(" ");

            IPortion portion = textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0);//.PortionFormat;

            portion.setText( “Test Frame…water mark”);

            portion.getPortionFormat().getFillFormat().setFillType (FillType.Solid);

            java.awt.Color col= new java.awt.Color(255,0,0,30);
            //System.Drawing.Color.FromArgb(30, System.Drawing.Color.Silver)
            portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(col);
            
        }

        presentation.save(“D:\\Aspose Data\\Dest.pptx”, SaveFormat.Pptx);   
}
1 Like

I use the backgroud image.
How can I change the background image size?
and set the background image’s opacity?

I use below code.

public static void main(String[] args){
String pptPath = “c:\aspose\watermarkTest.pptx”;

	// load the file to be rendered
	Presentation pres = new Presentation(pptPath);
	
	// Set the background with Image
	pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
	pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Picture);
	pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
	
	// set the pictrue
	IPPImage imgx = null;
	try{
		imgx = pres.getImages().addImage(new FileInputStream(new File("c:\\watermark_big.gif")));
	}catch(Exception e){
		
	}
	// Add image to presentation's images collection
	pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().getPicture().setImage(imgx);
	
	pres.save("c:\\aspose\\watermark.pptx", SaveFormat.Pptx);
	
}

@kevinKang,

I have observed your following requirement

The slide background is set for entire slide size. However, you can add a picture frame your self and set the size of picture frame that can hold the image. This is possible option is to add PictureFrame and set the size accordingly.

I regret to share that there is no option to set image opacity in PowerPoint and Aspose.Slides. However, you can using any third party or Aspose.Imaging to set the opacity of image to be added and then add that in PowerPoint picture frame as above.

Thank you for your answer.
I’ll try to solve it.

Thank you very much:heart: