How to Add 3 to 4 Lines of Watermark Text to PowerPoint Presentation?

Thank you andrey for update.Could you please let us know can we reduce space between one paragraph to another paragraph.please find the attached current and expected repsonse.
expected-response1.PNG (78.4 KB)
Current repsose1.PNG (15.5 KB)

@ssanex,
We will reply to you a bit later. Thank you for your patience.

thank you Andrey.

@ssanex,
To reduce the space between paragraphs, you can change the line spacing for them. The following code example shows you how to do this:

IParagraph paragraph = watermarkTextFrame.getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setSpaceWithin(40); // Set your value here.

Documents: Line Spacing of Paragraph
API Reference: IParagraphFormat interface

I think you mean locking the watermark shape against being modified. Could you please confirm?

Hi Andrey, I am locking the watermark shape after changing paraph and it is not applying line space.Could you please check the below code and help me on this.

Presentation pres = new Presentation("C:\\Users\\ssanex\\Downloads\\EclipseWorkSpace\\EclipseWorkSpace\\ORIGINAL-test.pptx");
		
		try {
		/*
		 * com.aspose.slides.License license = new com.aspose.slides.License();
		 * 
		 * license.setLicense(new java.io.FileInputStream("Aspose.Slides.Java.lic"));
		 */
			
			License license1 = new License();
			license1.setLicense(new java.io.FileInputStream("C:\\Users\\ssanex\\Downloads\\aspose-slides-22.7-java\\lib\\Aspose.Slides.Java.lic"));

			if (license1.isLicensed()) 
			{
			    System.out.println("License is Set!");
			}
		// Access master
		IMasterSlide master = pres.getMasters().get_Item(0);
		Point2D.Float center = new Point2D.Float((float) pres.getSlideSize().getSize().getWidth() / 2,
		(float) pres.getSlideSize().getSize().getHeight() / 2);
		float width = 300;
		float height = 150;
		float x = (float) center.getX() - width / 2;
		float y = (float) center.getY() - height / 2;
		// Add shape
		IAutoShape watermarkShape = master.getShapes().addAutoShape(ShapeType.Rectangle, x, y, width, height);
		// Set fill type
		watermarkShape.getFillFormat().setFillType(FillType.NoFill);
		watermarkShape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
		// Set rotation angle
		watermarkShape.setRotation(-45);
		// Set text
		//ITextFrame watermarkTextFrame = watermarkShape.addTextFrame("watermark3");
		//ITextFrame watermarkTextFrame = watermarkShape.addTextFrame("Text line 1\nText line 2\nCourtesy of Sravanreddy");
		//watermarkShape.addTextFrame("watermark2");
		ITextFrame watermarkTextFrame = watermarkShape.addTextFrame("");

		Paragraph textLine1 = new Paragraph();
		
		textLine1.setText("watermark Text line 1");
		textLine1.getParagraphFormat().setDepth((short)2);
		textLine1.getParagraphFormat().setSpaceWithin(5);
		textLine1.getParagraphFormat().setIndent(2);

		Paragraph textLine2 = new Paragraph();
		
		textLine2.setText("watermark Text line 2");
		textLine2.getParagraphFormat().setDepth((short)2);
		textLine1.getParagraphFormat().setSpaceWithin(5);
		textLine2.getParagraphFormat().setIndent(2);

		Paragraph textLine3 = new Paragraph();
		textLine3.setText("Courtesy of Sravanreddy");
		IParagraph paragraph = watermarkTextFrame.getParagraphs().get_Item(0);
		
		watermarkTextFrame.getParagraphs().add(textLine1);
		textLine1.getParagraphFormat().setSpaceWithin(10); 
		watermarkTextFrame.getParagraphs().add(new Paragraph());
		watermarkTextFrame.getParagraphs().add(textLine2);
		textLine2.getParagraphFormat().setSpaceWithin(10); 
		watermarkTextFrame.getParagraphs().add(new Paragraph());
		watermarkTextFrame.getParagraphs().add(textLine3);
		textLine3.getParagraphFormat().setSpaceWithin(10);
		// Set font and color
		IPortion watermarkPortion = watermarkTextFrame.getParagraphs().get_Item(0).getPortions().get_Item(0);
		watermarkPortion.getPortionFormat().setFontHeight(52);
		
		int alpha = 150, red = 200, green = 200, blue = 200;
		watermarkPortion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
		watermarkPortion.getPortionFormat().getFillFormat().getSolidFillColor()
		.setColor(new Color(red, green, blue, alpha));
		// Lock Shapes from modifying
		watermarkShape.getAutoShapeLock().setSelectLocked(true);
		watermarkShape.getAutoShapeLock().setSizeLocked(true);
		watermarkShape.getAutoShapeLock().setTextLocked(true);
		watermarkShape.getAutoShapeLock().setPositionLocked(true);
		watermarkShape.getAutoShapeLock().setGroupingLocked(true);
		// Save the presentation
		pres.save("C:\\Users\\ssanex\\Downloads\\EclipseWorkSpace\\EclipseWorkSpace\\watermarked-presentation_latest123.pptx", SaveFormat.Pptx);
		 Date end = new Date();
		System.out.println("end "+sdf.format(end));
		} finally {
		if (pres != null)
		pres.dispose();
		}

A post was split to a new topic: How to Instantiate a PowerPoint Presentation by URL?

@ssanex,
I will reply to you later.

@ssanex,
Please try using the following code snippet to set line spacing for your text lines:

Paragraph textLine1 = new Paragraph();
textLine1.setText("watermark Text line 1");
textLine1.getParagraphFormat().setSpaceWithin(60);

Paragraph textLine2 = new Paragraph();
textLine2.setText("watermark Text line 2");
textLine2.getParagraphFormat().setSpaceWithin(60);

Paragraph textLine3 = new Paragraph();
textLine3.setText("Courtesy of Sravanreddy");
textLine3.getParagraphFormat().setSpaceWithin(60);

watermarkTextFrame.getParagraphs().add(textLine1);
watermarkTextFrame.getParagraphs().add(textLine2);
watermarkTextFrame.getParagraphs().add(textLine3);

Hi Andrey,
Do you any update on to lock presentation slides based on that only we are going to purchnage for intel projects.it is critical for us to lock pptx slides for watermark.

Regards,
Sravan.

@ssanex,
You can lock the watermark shape as shown below:

watermarkShape.getShapeLock().setSelectLocked(true);
watermarkShape.getShapeLock().setSizeLocked(true);
watermarkShape.getShapeLock().setTextLocked(true);
watermarkShape.getShapeLock().setPositionLocked(true);
watermarkShape.getShapeLock().setGroupingLocked(true);

If this is not the case, please describe in more detail what exactly you mean by “to lock presentation slides”.

Hi Andrey,
We are looking for lock entire slides in the PPTX.Please find the attached output pptx files.

We are expecting output similar to attached PPTX file.

Regards,
Sravan.Agilex AA OPN Update - Customer.zip (1.0 MB)

@ssanex,
Thank you for the sample presentation. As far as you can see, the presentation slides do not contain any shapes, but only a background was set for each slide. slide.png (183.6 KB). This is why the presentation looks like its slides are locked.

You can convert any presentation to the “locked” presentation as shown below:

using var sourcePresentation = new Presentation("example.pptx");
var slideSize = sourcePresentation.SlideSize.Size;

// Prepare a new "locked" presentation.
using var lockedPresentation = new Presentation();
lockedPresentation.Slides.RemoveAt(0);
lockedPresentation.SlideSize.SetSize(slideSize.Width, slideSize.Height, SlideSizeScaleType.DoNotScale);

foreach (var slide in sourcePresentation.Slides)
{
    // Create an image of the original slide.
    using var slideImage = slide.GetThumbnail(1.5f, 1.5f);

    // Add the image to resources of the new presentation.
    var backgroundImage = lockedPresentation.Images.AddImage(slideImage);

    // Add an empty slide to the new presentation.
    var layout = lockedPresentation.LayoutSlides.First(layout => layout.Name == "Blank");
    var lockedSlide = lockedPresentation.Slides.AddEmptySlide(layout);

    // Set the slide image as a background for the empty slide.
    lockedSlide.Background.Type = BackgroundType.OwnBackground;
    lockedSlide.Background.FillFormat.FillType = FillType.Picture;
    lockedSlide.Background.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;
    lockedSlide.Background.FillFormat.PictureFillFormat.Picture.Image = backgroundImage;
}

lockedPresentation.Save("locked.pptx", SaveFormat.Pptx);

Documents: Presentation Background
API Reference: ISlide interface | IBackground interface

Hi Andrey,
Can you please provide Java code for same lock presentation.
Regards,
Sravan

@ssanex,
I apologize for the code example above. Please try using the following one in Java:

var sourcePresentation = new Presentation("example.pptx");
var slideSize = sourcePresentation.getSlideSize().getSize();
var slideWidth = (float) slideSize.getWidth();
var slideHeight = (float) slideSize.getHeight();

// Prepare a new "locked" presentation.
var lockedPresentation = new Presentation();
lockedPresentation.getSlides().removeAt(0);
lockedPresentation.getSlideSize().setSize(slideWidth, slideHeight, SlideSizeScaleType.DoNotScale);

for (var slide : sourcePresentation.getSlides())
{
    // Create an image of the original slide.
    var slideImage = slide.getThumbnail(1.5f, 1.5f);

    // Add the image to resources of the new presentation.
    var backgroundImage = lockedPresentation.getImages().addImage(slideImage);

    // Add an empty slide to the new presentation.
    var layout = lockedPresentation.getLayoutSlides().getByType(SlideLayoutType.Blank);
    var lockedSlide = lockedPresentation.getSlides().addEmptySlide(layout);

    // Set the slide image as a background for the empty slide.
    lockedSlide.getBackground().setType(BackgroundType.OwnBackground);
    var fillFormat = lockedSlide.getBackground().getFillFormat();
    fillFormat.setFillType(FillType.Picture);
    fillFormat.getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
    fillFormat.getPictureFillFormat().getPicture().setImage(backgroundImage);
}

lockedPresentation.save("locked.pptx", SaveFormat.Pptx);
lockedPresentation.dispose();

sourcePresentation.dispose();

Documents: Presentation Background
API Reference: ISlide interface | IBackground interface

Hi Andrey,
This is don net code not a java code.Could you please provide Java code for same lock presentation.
Regards,
Sravan.

@ssanex,
This is Java code that compiles successfully with JDK 11 and language level 11. Could you please specify the Java language level used in your app?

Hi Andrey,
We are using java 1.8 version.
Regards,
Sravan.

@ssanex,
The following code example shows you how to do the same conversion using JDK 1.8 and Java language level 8:

Presentation sourcePresentation = new Presentation("example.pptx");
Dimension2D slideSize = sourcePresentation.getSlideSize().getSize();
float slideWidth = (float) slideSize.getWidth();
float slideHeight = (float) slideSize.getHeight();

// Prepare a new "locked" presentation.
Presentation lockedPresentation = new Presentation();
lockedPresentation.getSlides().removeAt(0);
lockedPresentation.getSlideSize().setSize(slideWidth, slideHeight, SlideSizeScaleType.DoNotScale);

for (ISlide slide : sourcePresentation.getSlides())
{
    // Create an image of the original slide.
    BufferedImage slideImage = slide.getThumbnail(1.5f, 1.5f);

    // Add the image to resources of the new presentation.
    IPPImage backgroundImage = lockedPresentation.getImages().addImage(slideImage);

    // Add an empty slide to the new presentation.
    ILayoutSlide layout = lockedPresentation.getLayoutSlides().getByType(SlideLayoutType.Blank);
    ISlide lockedSlide = lockedPresentation.getSlides().addEmptySlide(layout);

    // Set the slide image as a background for the empty slide.
    lockedSlide.getBackground().setType(BackgroundType.OwnBackground);
    IFillFormat fillFormat = lockedSlide.getBackground().getFillFormat();
    fillFormat.setFillType(FillType.Picture);
    fillFormat.getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
    fillFormat.getPictureFillFormat().getPicture().setImage(backgroundImage);
}

lockedPresentation.save("locked.pptx", SaveFormat.Pptx);
lockedPresentation.dispose();

sourcePresentation.dispose();

Hi Andrey,
1.We have implemented lock code and watermark slides for PPTx files.After implementing lock functionality it took more time to generate watermark pptx files it took around 2 half minute to generate 91 slides presentation file.Generally we will upload 90 to 150 slides watermark PPTx.It should not take more than 1 mins otherwise our application will not process watermark file since we have limitation to 1 min.
2.We are trying to add watermark text to PPTx files.when we have images in slides watermark is not appearing for plain text it appearing fine. you can refer slide 3,slide 5 and slide 7 we have added watermark text but not appearing in slide 3,slide 5 and slide 7.
and slide 2,slide 4,slide 8 and slide 9 watermark text is coming partially.
Can you please look the above scenarios.watermarked-presentation_latest_url_locked - Copy.zip (2.7 MB)

@ssanex,

PowerPoint documents do not allow you to lock slides. The code example above was suggested simply as a workaround to achieve the same result as demonstrated in the presentation you provided earlier. You can try another way: set locking options for all slide shapes in the original presentation. It should work faster.

It looks like the watermark text was placed behind the images. Please make sure the watermark text is added as a last shape on the slides.