翻譯|使用教程|編輯:李顯亮|2021-07-15 10:05:50.977|閱讀 524 次
概述:在本文中,將演示如何通過以編程方式應用水印來保護 PowerPoint 演示文稿。特別是,將學習如何使用 C# 向 PowerPoint 幻燈片添加文本或圖像水印。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
水印通常用于指定所有權或防止未經授權使用文檔。此外,它們還用于顯示文檔的狀態,例如手稿、草稿等。在本文中,將演示如何通過以編程方式應用水印來保護 PowerPoint 演示文稿。特別是,將學習如何使用 C# 向 PowerPoint 幻燈片添加文本或圖像水印。
為了給 PowerPoint 幻燈片添加水印,我們將使用Aspose.Slides for .NET它是一個功能豐富的 API,可讓您從 .NET 應用程序中創建演示文檔。此外,它還允許您操作現有的演示文件。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
以下是使用 C# 為 PowerPoint 幻燈片添加文本水印的步驟。
以下代碼示例展示了如何向 PowerPoint 幻燈片添加文本水印。
// Load presentation Presentation presentation = new Presentation("presentation.pptx"); // Get reference of the slide ISlide slide = presentation.Slides[0]; // Get the center of the slide and calculate watermark's position PointF center = new PointF(presentation.SlideSize.Size.Width / 2, presentation.SlideSize.Size.Height / 2); float width = 300; float height = 300; float x = center.X - width / 2; float y = center.Y - height / 2; // Add watermark shape IAutoShape watermarkShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, x, y, width, height); // Set fill type watermarkShape.FillFormat.FillType = FillType.NoFill; watermarkShape.LineFormat.FillFormat.FillType = FillType.NoFill; // Set rotation angle watermarkShape.Rotation = -45; // Set text ITextFrame watermarkTextFrame = watermarkShape.AddTextFrame("Watermark"); IPortion watermarkPortion = watermarkTextFrame.Paragraphs[0].Portions[0]; // Set font size and fill type of the watermark watermarkPortion.PortionFormat.FontHeight = 52; watermarkPortion.PortionFormat.FillFormat.FillType = FillType.Solid; int alpha = 150, red = 200, green = 200, blue = 200; watermarkPortion.PortionFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.FromArgb(alpha, red, green, blue); // Lock Shapes from modifying watermarkShape.ShapeLock.SelectLocked = true; watermarkShape.ShapeLock.SizeLocked = true; watermarkShape.ShapeLock.TextLocked = true; watermarkShape.ShapeLock.PositionLocked = true; watermarkShape.ShapeLock.GroupingLocked = true; // Save the presentation presentation.Save("watermarked-presentation.pptx", SaveFormat.Pptx);
以下是在 C# 中為 PowerPoint 幻燈片添加圖像水印的步驟。
以下代碼示例展示了如何向 PowerPoint 幻燈片添加圖像水印。
// Load presentation Presentation presentation = new Presentation("presentation.pptx"); // Get reference of the slide ISlide slide = presentation.Slides[0]; // Get the center of the slide and calculate watermark's position PointF center = new PointF(presentation.SlideSize.Size.Width / 2, presentation.SlideSize.Size.Height / 2); float width = 300; float height = 300; float x = center.X - width / 2; float y = center.Y - height / 2; // Load image IPPImage image = presentation.Images.AddImage(File.ReadAllBytes("watermark.png")); // Add watermark shape and set image IAutoShape watermarkShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, x, y, width, height); watermarkShape.FillFormat.FillType = FillType.Picture; watermarkShape.FillFormat.PictureFillFormat.Picture.Image = image; watermarkShape.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch; watermarkShape.LineFormat.FillFormat.FillType = FillType.NoFill; // Lock Shapes from modifying watermarkShape.ShapeLock.SelectLocked = true; watermarkShape.ShapeLock.SizeLocked = true; watermarkShape.ShapeLock.TextLocked = true; watermarkShape.ShapeLock.PositionLocked = true; watermarkShape.ShapeLock.GroupingLocked = true; // Save the presentation presentation.Save("watermarked-presentation.pptx", SaveFormat.Pptx);
如果你想試用Aspose的全部完整功能,可 聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn