0

我一直在尝试在 powerpoint 中创建水印我在下面有一个代码,我现在可以在其中添加图片我如何为图片创建透明度,使其看起来像水印

private void watermark_Click(object sender, RibbonControlEventArgs e)
{
    PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
    PowerPoint.SlideRange ppslr = ppApp.ActiveWindow.Selection.SlideRange;
    //ppApp.ActivePresentation.Slides.InsertFromFile("NepaSlide.pptx",2, 1,1);
    //PowerPoint.ShapeRange ppShR = ppApp.ActiveWindow.Selection.ShapeRange;
    int count= ppslr.Shapes.Count;

    PowerPoint.Shape shape = ppslr.Shapes[count];

    ppslr.Shapes.AddPicture("N-symbol.png",
            Microsoft.Office.Core.MsoTriState.msoFalse,
            Microsoft.Office.Core.MsoTriState.msoTrue,
            shape.Left, shape.Top, shape.Width, shape.Height);     
}
4

1 回答 1

2

我知道这是一个老问题,但我没有找到解决方案,所以我自己编写了代码。

public void AddWaterMarkToPowerPoint(string filePath)
        {
            string waterMarkText = "Top secret";

            PowerPoint.Application ppApp = new PowerPoint.Application();

            PowerPoint.Presentations pres = ppApp.Presentations;


            PowerPoint.Presentation pptPresentation = pres.Open(filePath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);


            for (int i = 1; i <= pptPresentation.Slides.Count; i++)
            {
                var test = pptPresentation.Slides[i].CustomLayout.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 200, 200, 600, 100);

                test.TextFrame.TextRange.Text = waterMarkText;
                test.Rotation = -45;
                test.TextFrame.TextRange.Font.Color.RGB = Color.LightGray.ToArgb();
                test.TextFrame.TextRange.Font.Size = 48;

            }

            pptPresentation.SaveAs(filePath);

            pptPresentation.Close();



        }

此代码将文本添加到演示文稿中的每张幻灯片。PowerPoint 没有添加水印的功能,所以我们必须通过添加浅灰色文本来制作水印。

于 2014-12-15T10:38:51.697 回答