365体育网投for .NET来针对PPT添加水印。那么什么样为幻灯片插入图片以及导出图片为。

对文档添加水印可以中声明与维护文档,是保护重要文件的章程有。在PPT文档中一致也得以设置水印,包括文件水印以及图纸水印,本文将叙如何通过Spire.Presentation
for .NET来针对PPT添加水印,下载安装Free Spire.Presentationfor
.NET晚,添加引用dll文件,参考下面的操作步骤,完成水印添加。

PowerPoint演示文稿是咱司空见惯工作备受常用之办公室软件之一,而图片则是PowerPoint文档的重要片段,那么如何为幻灯片插入图片及导出图片为?本文自拿于大家享用如何行使一个免费版PowerPoint组件—Free
Spire.Presentation,以C#/VB.NET编程的道来迅速地落实即点儿个作用。我们可以自官网下载Free
Spire.Presentation,创建项目后补偿加此DLL作为援。

1.添加文书水印

插入图片

手续一样:初始化Presentation类实例,并加载文档

为PPT文档插入图片时,这里自己选择插入鲜张图及不同的有数摆放幻灯片中。

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

具体步骤:

手续二:初始化一个Font类实例,并实例化字体格式

当头里要加上以下命名空间:

Font stringFont = new Font("Arial", 90);
Size size = TextRenderer.MeasureText("内部资料", stringFont);
using Spire.Presentation;
using Spire.Presentation.Drawing;

手续三:绘制一个shape并点名大小、填充颜色、边框颜色及转角度

步骤1:新建一个PPT文档。

RectangleF rect = new RectangleF((ppt.SlideSize.Size.Width - size.Width) / 2, (ppt.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height);
IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Rotation = -45;
Presentation presentation = new Presentation();

presentation.Slides.Append();

步骤四:设定形状属性也保障属性

步骤2:插入第一摆放图纸及第一布置幻灯片

shape.Locking.SelectionProtection = true;
shape.Line.FillType = FillFormatType.None;
string ImageFile = @"C:\Users\Administrator\Pictures\01.jpg";
RectangleF rect = new RectangleF(350, 100, 300, 250);     
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

步骤五:设置文本大小、颜色

步骤3:补偿加形状,再续加文本到形状里面。

shape.TextFrame.Text = "内部资料";
TextRange textRange = shape.TextFrame.TextRange;
textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.Gray);
textRange.FontHeight = 45;
RectangleF rect2 = new RectangleF(50, 100, 300, 250);
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect2);
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;

//添加文本到形状中
shape.TextFrame.Text = "大熊猫是哺乳动物,已在地球上生存了至少800万年,被誉为活化石和中国国宝,世界自然基金会的形象大使,是世界生物多样性保护的旗舰物种。据第三次全国大熊猫野外种群调查,全世界野生大熊猫已不足1600只,属于中国国家一级保护动物。";
TextRange textRange = shape.TextFrame.TextRange;
shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;


//设置文本字体
textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.Black;
textRange.LatinFont = new TextFont("Arial Black"

手续六:保存文档

步骤4:平,插入第二摆设图及第二摆设幻灯片,添加形状,再上加文本到形状里面。最后保存文档。

ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2010);
presentation.SaveToFile(@"C:\Users\Administrator\Desktop\result.pptx ", FileFormat.Pptx2010);
System.Diagnostics.Process.Start(@"C:\Users\Administrator\Desktop\result.pptx ");

好上述代码步骤后,调试运行项目先后,生成文书(可每当拖欠种文件中bin>Debug中查阅),如下图所示:

效果图:

 365体育网投 1

365体育网投 2

周代码:

 全部代码:

365体育网投 3365体育网投 4

365体育网投 5365体育网投 6

using System;
using System.Text;
using Spire.Presentation;
using System.Drawing;
using Spire.Presentation.Drawing;
using System.Windows.Forms;

namespace InsertWatermark_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化一个Presentation类实例并加载文档
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

            //初始化一个Font类字体实例并实例化字体格式
            Font stringFont = new Font("Arial", 90);
            Size size = TextRenderer.MeasureText("内部资料", stringFont);

            //绘制一个Shape并指定大小、填充颜色、边框颜色和旋转度
            RectangleF rect = new RectangleF((ppt.SlideSize.Size.Width - size.Width) / 2, (ppt.SlideSize.Size.Height - size.Height) / 2, size.Width, size.Height);
            IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.Rotation = -45;

            //设定形状属性为保护属性
            shape.Locking.SelectionProtection = true;
            shape.Line.FillType = FillFormatType.None;

            //设置文本大小、颜色
            shape.TextFrame.Text = "内部资料";
            TextRange textRange = shape.TextFrame.TextRange;
            textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            textRange.Fill.SolidColor.Color = Color.FromArgb(150, Color.LightBlue);
            textRange.FontHeight = 90;

            //保存文档
            ppt.SaveToFile("TextWatermark.pptx", FileFormat.Pptx2010);
        }
    }
 1 using System;
 2 using System.Drawing;
 3 using System.Windows.Forms;
 4 using Spire.Presentation;
 5 using Spire.Presentation.Drawing;
 6 
 7 namespace InsertimageinPowerPointFille
 8 {
 9     public partial class Form1 : Form
10     {
11         public Form1()
12         {
13             InitializeComponent();
14         }
15 
16         private void button1_Click(object sender, EventArgs e)
17         {
18             //新建PPT
19             Presentation presentation = new Presentation();
20             presentation.Slides.Append();
21 
22             //插入第一张图片到第一张幻灯片
23             string ImageFile = @"C:\Users\Administrator\Pictures\01.jpg";
24             RectangleF rect = new RectangleF(350, 100, 300, 250);
25             presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
26             presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
27 
28             //添加形状
29             RectangleF rect2 = new RectangleF(50, 100, 300, 250);
30             IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect2);
31             shape.Fill.FillType = FillFormatType.None;
32             shape.ShapeStyle.LineColor.Color = Color.White;
33 
34             //添加文本到形状中
35             shape.TextFrame.Text = "大熊猫是哺乳动物,已在地球上生存了至少800万年,被誉为活化石和中国国宝,世界自然基金会的形象大使,是世界生物多样性保护的旗舰物种。据第三次全国大熊猫野外种群调查,全世界野生大熊猫已不足1600只,属于中国国家一级保护动物。";
36             TextRange textRange = shape.TextFrame.TextRange;
37             shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
38 
39             //设置文本字体
40             textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
41             textRange.Fill.SolidColor.Color = Color.Black;
42             textRange.LatinFont = new TextFont("Arial Black");
43 
44             //插入第二张图片到第二张幻灯片
45             string ImageFile1 = @"C:\Users\Administrator\Pictures\02.jpg";
46             RectangleF rect1 = new RectangleF(80, 100, 500, 400);
47             presentation.Slides[1].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile1, rect1);
48             presentation.Slides[1].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
49 
50             //添加形状
51             RectangleF rect3 = new RectangleF(30, 40, 630, 50);
52             IAutoShape shape1 = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, rect3);
53             shape1.Fill.FillType = FillFormatType.Solid;
54             shape1.Fill.FillType = FillFormatType.None;
55             shape1.ShapeStyle.LineColor.Color = Color.White;
56 
57             //添加文本到形状中
58             shape1.TextFrame.Text = "黑白相间的外表,有利隐蔽在密林的树上和积雪的地面而不易被天敌发现。相对锋利的爪和发达有力的前后肢,有利于大熊猫能快速爬上高大的乔木。";
59             TextRange textRange1 = shape1.TextFrame.TextRange;
60 
61             //设置文本字体
62             textRange1.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
63             textRange1.Fill.SolidColor.Color = Color.Blue;
64             textRange1.LatinFont = new TextFont("Arial Black");
65 
66             //保存文件
67             presentation.SaveToFile(@"C:\Users\Administrator\Desktop\result.pptx ", FileFormat.Pptx2010);
68             System.Diagnostics.Process.Start(@"C:\Users\Administrator\Desktop\result.pptx ");
69         }
70     }
71 }

View full Code

View Code

 

从今上面的代码可以窥见,其实通过是组件,我们还可肆意地设置我们想只要之象、文本、字体、颜色等等,用起来确实方便而火速。感兴趣的言辞可试试一下外增长的职能。

2.添加图片水印

导出图片

步骤同:初始化一个Presentation类实例并加载文档

今天,我们导出上述运行后文档的图样。

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

具体步骤:

步骤二: 为第一摆放幻灯片设置背景图片类型以及体

同上加如下命名空间:

ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
using Spire.Presentation;

步骤三:加载图片并也第一张幻灯片设置水印

步骤1: 新建一个Presentation对象,并加载Presentation文件。

Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\images\1.jpg");
IImageData image = ppt.Images.Append(img);
ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\result.pptx");

步骤四:保存文档

 步骤2:遍历PPT文档所有的图样,并保留也.png格式。

 ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);
for (int i = 0; i < ppt.Images.Count; i++)

            {

                Image image = ppt.Images[i].Image;

                image.Save(string.Format(@"..\..\Images{0}.png", i));

            }

365体育网投 7

效果图:

满代码:

365体育网投 8

365体育网投 9365体育网投 10

浑代码:

using System;
using System.Drawing;
using Spire.Presentation;
using Spire.Presentation.Drawing;

namespace ImageWatermark_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //初始化一个Presentation类实例并加载文档
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx", FileFormat.Pptx2010);

            //为第一张幻灯片设置背景图片类型和样式
            ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
            ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
            ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;

            //加载图片并为第一张幻灯片设置水印效果
            Image img = Image.FromFile(@"C:\Users\Administrator\Desktop\images\1.jpg");
            IImageData image = ppt.Images.Append(img);
            ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

            //保存文档
            ppt.SaveToFile("ImageWatermark1.pptx", FileFormat.Pptx2010);
        }
    }
}

365体育网投 11365体育网投 12

View full Code

 1 using System;
 2 using System.Drawing;
 3 using System.Windows.Forms;
 4 using Spire.Presentation;
 5 
 6 namespace ExtractImagesfromPPT
 7 {
 8     public partial class Form1 : Form
 9     {
10         public Form1()
11         {
12             InitializeComponent();
13         }
14 
15         private void button1_Click(object sender, EventArgs e)
16         {
17             Presentation ppt = new Presentation();
18             ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\result.pptx");
19             for (int i = 0; i < ppt.Images.Count; i++)
20             {
21                 Image image = ppt.Images[i].Image;
22                 image.Save(string.Format(@"..\..\Images{0}.png", i));
23 
24             }
25         }
26     }
27 }

 

View Code

 

多谢浏览!

以上是对准PPT添加水印的代码操作,希望该法会提供援助,感谢阅读!

相关文章