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

Free Support Forum - aspose.com

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

We are planning to use Aspose.Slides for Java API to add watermark to (PowerPoint presentation)PPTX/PPT slides for our project. We used the free version of Aspose.Slides for Java to add watermark, but we are able add one line watermark text only to PowerPoint slides and we are planning to add 3 to 4 lines of watermark text to PowerPoint slides. and also if it possible to lock the power point presentation slides after adding watermark.Could you please help us to provide code for adding 3 to 4 lines of watermak and how to lock slides.
Note: we are using temporary license.
code snippet:

// 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 = 300;
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");

Regards,
Sravan.

@ssanex,
Thank you for posting your requirements. Please try using the code snippets to add watermarks as shown in this article:


If the issue persists, please describe in more detail what exactly you have failed. It would be great if you could share a sample presentation with the expected watermarks created in PowerPoint.

Unfortunately, I was unable to find such a feature in PowerPoint. Please share a sample presentation.

expected-response.PNG (62.6 KB)
current-response.PNG (53.1 KB)
Hi Andrey,
we are able to add single line watermark text and we are planning to add 3 lines of watermark.
i can see one line of watermark with the above mentioned link.please find the attached current and expected response screen shot.

code snippet:

ITextFrame watermarkTextFrame = watermarkShape.addTextFrame("watermark3");

Could you please help on this query.

i am not able to attached pptx format files here.

@ssanex,
You can zip the files and upload the archive here.

Please find the attached presentation file.

(Attachment watermarked-presentation_la.pptx is missing)

@ssanex,
I apologize for the misunderstanding. You can add 3 text lines to the watermark as shown below:

ITextFrame watermarkTextFrame = watermarkShape.addTextFrame("Text line 1\n\nText line 2\n\nText line 3");

or

ITextFrame watermarkTextFrame = watermarkShape.addTextFrame("");

Paragraph textLine1 = new Paragraph();
textLine1.setText("Text line 1");

Paragraph textLine2 = new Paragraph();
textLine2.setText("Text line 2");

Paragraph textLine3 = new Paragraph();
textLine3.setText("Text line 3");

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

Documents: Manage Paragraph
API Reference: IParagraphCollection interface | IParagraph interface

watermarked-presentation_la.zip (184.0 KB)
Hi Andrey,
Please find the attached zip file for sample pptx file for to lock presentation slide.
Regards,
Sravan.

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);