当前位置: 移动技术网 > IT编程>开发语言>.net > C# 处理PPT水印(二)——去除水印效果(文本水印、图片水印)

C# 处理PPT水印(二)——去除水印效果(文本水印、图片水印)

2018年10月14日  | 移动技术网IT编程  | 我要评论

侃侃照片,色图片蜜桃,六月的雨吉他谱

本文将对c#处理ppt幻灯片中的水印进一步说明和介绍。在c# 处理ppt水印(一)一文中,分享了如何插入水印效果的方法,包括插入文字水印效果、插入图片作为水印效果两种情况,那对于不需要水印效果的情况,要如何来去除ppt中已有的水印效果呢,具体实现步骤,可参考下面将要讲述的方法。

工具

ps:安装后,注意在编辑代码时,添加引用spire.presentation.dll(dll文件可在安装路径下的bin文件夹中获取)

代码示例(供参考)

【示例1】去除文字水印效果

测试文件中的文字水印效果如下:

 

步骤1 :实例化presentation类,加载含有水印效果的ppt文档

presentation ppt = new presentation();
ppt.loadfromfile("textwatermark.pptx");

步骤2 :遍历所有幻灯片,查找包含水印字样的shape,并删除

for (int i = 0; i < ppt.slides.count; i++)
{
    for (int j = 0; j < ppt.slides[i].shapes.count; j++)
    {
        if (ppt.slides[i].shapes[j] is iautoshape)
        {
            iautoshape shape = ppt.slides[i].shapes[j] as iautoshape;
            if (shape.textframe.text.contains("内部资料"))
            {
                ppt.slides[i].shapes.remove(shape);
            }
        }
    }
}

步骤3:保存文档并打开

ppt.savetofile("removetextwatermak.pptx", fileformat.pptx2010);
system.diagnostics.process.start("removetextwatermak.pptx");

 

文字水印去除效果:

 

全部代码:

using spire.presentation;

namespace deletetextwatermark_ppt
{
    class program
    {
        static void main(string[] args)
        {
            //实例化presentation类,加载有水印的powerpoint文档
            presentation ppt = new presentation();
            ppt.loadfromfile("textwatermark.pptx");

            //遍历每一张幻灯片, 查找水印文字内容所在的形状并删除
            for (int i = 0; i < ppt.slides.count; i++)
            {
                for (int j = 0; j < ppt.slides[i].shapes.count; j++)
                {
                    if (ppt.slides[i].shapes[j] is iautoshape)
                    {
                        iautoshape shape = ppt.slides[i].shapes[j] as iautoshape;
                        if (shape.textframe.text.contains("内部资料"))
                        {
                            ppt.slides[i].shapes.remove(shape);
                        }
                    }
                }
            }

            //保存并打开文档
            ppt.savetofile("removetextwatermak.pptx", fileformat.pptx2010);
            system.diagnostics.process.start("removetextwatermak.pptx");
        }
    }
}
view code

 

【示例2】去除图片水印效果

测试文件中的图片水印效果如下:

步骤1 :实例化presentation类,加载测试文档

presentation ppt = new presentation();
ppt.loadfromfile("imagewatermark.pptx");

步骤2 :遍历每一张幻灯片, 设置背景填充类型为none

for (int i = 0; i < ppt.slides.count; i++)
{
    ppt.slides[0].slidebackground.fill.filltype = fillformattype.none;
}

步骤3 :保存文档并打开

ppt.savetofile("removepicwatermak.pptx", fileformat.pptx2010);
system.diagnostics.process.start("removepicwatermak.pptx");

图片水印去除效果:

全部代码:

using spire.presentation;
using spire.presentation.drawing;

namespace deleteimagewatermark_ppt
{
    class program
    {
        static void main(string[] args)
        {
            //实例化presentation类,加载有图片水印的powerpoint文档
            presentation ppt = new presentation();
            ppt.loadfromfile("imagewatermark.pptx");

            //遍历每一张幻灯片, 设置背景填充类型为none
            for (int i = 0; i < ppt.slides.count; i++)
            {
                ppt.slides[0].slidebackground.fill.filltype = fillformattype.none;
            }

            //保存结果文档到本地并打开
            ppt.savetofile("removepicwatermak.pptx", fileformat.pptx2010);
            system.diagnostics.process.start("removepicwatermak.pptx");
        }
    }
}
view code

 

以上是关于c# 去除ppt水印效果的方法介绍。

(本文完)

转载请注明出处!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网