Setting background image at different location in slides

Hi Team I have a requirement where i need to set a background image at the top position of the slide. Can you please let me know how i can achieve this from the code using aspose.slides.dll
Hi Team,

I have a requirement where i need to set a background image at the top, bottom, Top and Bottom and diagonally center of the slides. Can you please let me know how i can achieve this from the code using aspose.slides.dll

Thanks in Advance,
Chandra.

Hi Chandra,

I have observed the requirement shared by you and request you to please share the sample presentation with us that you want to generate using Aspose.Slides for desired set of images. I will investigate the issue further on my end to help you out.

Many Thanks,

Hi Team,


We need to place the background in the positions as shown in these attachments. Please help us in achieving the same programatically using Aspose.Slides .

Thanks,
Chandra.


Hi Chandra,

I have observed the presentation files shared by you and it seems that you are interested in adding watermark shapes inside your presentation. I like to share that Aspose.Slides offers shapes locking feature that you can used to set the watermark of the presentation. I have created a sample application for your convenience that you can use and tailor as per your requirement.

public static void AddDraftWatermark2()
{

Presentation pres = new Presentation();
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 (ISlide slide in pres.Slides)
{


IAutoShape shp = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 0, yPos, slideSize.Width, watermarkHeight);

//Hide the Rectangle Borders
shp.LineFormat.FillFormat.FillType = FillType.NoFill;
shp.FillFormat.FillType = FillType.NoFill;

shp.ShapeLock.PositionLocked = true;

shp.ShapeLock.SelectLocked = true;

shp.ShapeLock.SizeLocked = true;

shp.AddTextFrame(“Draft”);

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

para1.ParagraphFormat.Alignment = TextAlignment.Center;

para1.ParagraphFormat.FontAlignment = FontAlignment.Center;

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

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

port1.Text = “My Custom Watermak text_long My Custom Watermak text_long Chandra_Billable Project/12:12:2014 09:03 chandub1985@gmail.com/10.78.114.63”;

//Setting Font color

port1.PortionFormat.FillFormat.FillType = FillType.Solid;
port1.PortionFormat.FillFormat.SolidFillColor.Color = Color.Gray;

port1.PortionFormat.FontHeight = 24;

port1.PortionFormat.FontBold = NullableBool.True;

port1.PortionFormat.LatinFont = new FontData(“Arial”);

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

}

pres.Save(“D:\Aspose Data\Watermarked.pptx”, SaveFormat.Pptx);

}

Please share if I may help you further in this regard.

Many Thanks,

Hi Team,


Thank you so much for you reply. It helped us in setting the image background for PPTX format. But when we applied the same code to PPT, it is just rotating the frame, but not the image.

string imagefile = “D:\Chandra\MyWatermark.jpeg”;
System.Drawing.Bitmap myPPTBitMap = new System.Drawing.Bitmap(imagefile);
System.Drawing.Image img = (System.Drawing.Image)myPPTBitMap;
Presentation pres = new Presentation(file)
imgx = pres.Images.AddImage(img);

foreach (Slide sld in pres.Slides)
{
IAutoShape shp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 30, 200, myImageWidth, myImageHeight, false);
shp.Rotation = -35;
// shp.Width = imgx.Width;
// shp.Height = imgx.Height;
// Set the fill type to Picture
shp.FillFormat.FillType = FillType.Picture;

//Set the picture fill mode
shp.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;

shp.FillFormat.PictureFillFormat.Picture.Image = imgx;

shp.ShapeLock.PositionLocked = true;

shp.ShapeLock.SelectLocked = true;

shp.ShapeLock.SizeLocked = true;
sld.Shapes.Reorder(0, shp);
}
if (extn.ToLower() == “.ppt”)
{
pres.Save(file, Aspose.Slides.Export.SaveFormat.Ppt);
}
else if (extn.ToLower() == “.pptx”)
{
pres.Save(file, Aspose.Slides.Export.SaveFormat.Pptx);
}

Can you please let me know why it is happening so.

Thanks,
Chandra.

Hi Chandra,

I have worked over the scenario shared by you and have modified the sample code as per your requirement. Please try the following sample code to serve the purpose on your end using Aspose.Slides for .NET 14.10.0.

public static void testImageWatermark()
{
String path=@“D:\Aspose Data”;
string imagefile = path+“MyWatermark.jpg”;
System.Drawing.Bitmap myPPTBitMap = new System.Drawing.Bitmap(imagefile);
System.Drawing.Image img = (System.Drawing.Image)myPPTBitMap;

Presentation pres = new Presentation();
var imgx = pres.Images.AddImage(img);

foreach (Slide sld in pres.Slides)
{

// IAutoShape shp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 30, 200, (float)img.Width/4, (float)img.Height/4, false);
IPictureFrame shp = sld.Shapes.AddPictureFrame(ShapeType.Rectangle, 30, 200, (float)img.Width/4, (float)img.Height/4, imgx);
shp.Rotation = -35;
// shp.Width = imgx.Width;
// shp.Height = imgx.Height;
// Set the fill type to Picture
shp.FillFormat.FillType = FillType.Picture;

//Set the picture fill mode
shp.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;

shp.FillFormat.PictureFillFormat.Picture.Image = imgx;


shp.ShapeLock.PositionLocked = true;

shp.ShapeLock.SelectLocked = true;

shp.ShapeLock.SizeLocked = true;

sld.Shapes.Reorder(0, shp);

}
pres.Save(path + “TestWatermark.ppt”, SaveFormat.Ppt);
}

Many Thanks,