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

Free Support Forum - aspose.com

Trying to add watermark to each slide in PPTX

I'm trying to add a watermark to each slide in a PPTX and I'm having three issues:

  1. I cannot figure out how to set the color of the text
  2. I cannot figure out how to set the background color - I want it transparent
  3. I cannot figure out how to put it behind the image on the slide and make it look like a watermark

Here is the code I'm using:

private void AddDraftWatermark2(PresentationEx pres)

{

int watermarkWidth = 250;

int watermarkHeight = 100;

System.Drawing.SizeF slideSize = pres.SlideSize.Size;

float xPos = (slideSize.Width / 2) - (watermarkWidth / 2);

float yPos = (slideSize.Height / 2) - (watermarkHeight / 2);

foreach (SlideEx slide in pres.Slides)

{

int idx = slide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, xPos, yPos, watermarkWidth, watermarkHeight);

AutoShapeEx shp = (AutoShapeEx)slide.Shapes[idx];

shp.ShapeLock.PositionLocked = true;

shp.ShapeLock.SelectLocked = true;

shp.ShapeLock.SizeLocked = true;

shp.AddTextFrame("Draft");

ParagraphEx para1 = shp.TextFrame.Paragraphs[0];

para1.ParagraphFormat.Alignment = TextAlignmentEx.Center;

para1.ParagraphFormat.FontAlignment = FontAlignmentEx.Center;

para1.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;

PortionEx port1 = shp.TextFrame.Paragraphs[0].Portions[0];

port1.RawLatinFont = new FontDataEx("Arial");

port1.RawFontHeight = 96;

port1.RawFontBold = NullableBool.True;

port1.FillFormat.SolidFillColor.Color = System.Drawing.Color.FromArgb(50, 236, 236, 236);

}

}

Hi Michael,


I have worked with the code snippet shared by you and have investigated the requirements shared by you. I have modified the code snippet shared by you and have added my comments for setting the font color, removing the shape background color and setting the z-order of the shape to toggle the shapes behind or in front of each other. Please share, if I may help you further in this regard.

public static void AddDraftWatermark2(PresentationEx pres)
{

int watermarkWidth = 250;

int watermarkHeight = 100;

System.Drawing.SizeF slideSize = pres.SlideSize.Size;

float xPos = (slideSize.Width / 2) - (watermarkWidth / 2);

float yPos = (slideSize.Height / 2) - (watermarkHeight / 2);

foreach (SlideEx slide in pres.Slides)
{

int idx = slide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, xPos, yPos, watermarkWidth, watermarkHeight);

AutoShapeEx shp = (AutoShapeEx)slide.Shapes[idx];
//Hide the Rectangle Borders
shp.LineFormat.FillFormat.FillType = FillTypeEx.NoFill;
shp.FillFormat.FillType = FillTypeEx.NoFill;
shp.ShapeLock.PositionLocked = true;

shp.ShapeLock.SelectLocked = true;

shp.ShapeLock.SizeLocked = true;

shp.AddTextFrame(“Draft”);

ParagraphEx para1 = shp.TextFrame.Paragraphs[0];

para1.ParagraphFormat.Alignment = TextAlignmentEx.Center;

para1.ParagraphFormat.FontAlignment = FontAlignmentEx.Center;

para1.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillTypeEx.Solid;

PortionEx port1 = shp.TextFrame.Paragraphs[0].Portions[0];
//Setting Font color

port1.PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
port1.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
port1.PortionFormat.FontHeight = 96;
port1.PortionFormat.FontBold = NullableBool.True;

port1.RawLatinFont = new FontDataEx(“Arial”);

//Applying Z-order of sahpe
slide.Shapes.Reorder(0, shp);

}

}

Many Thanks,