如何使用 C# 创建只读演示文稿

这篇非常简单的文章指导如何使用 C# 创建只读演示文稿。它封装了有关所需 Nuget 包的所有详细信息、突出显示程序逻辑的分步编程任务列表,以及用于创建只读演示文稿和 防止使用 C# 编辑 PPTX 的可运行示例代码。创建的应用程序可以在 Windows、macOS 和 Linux 中的任何 .NET 支持环境中使用。

使用 C# 创建只读演示文稿的步骤

  1. 配置 IDE 安装 Aspose.Slides for .NET 以使用 c# 创建只读 PPTX
  2. 使用 Presentation 类的实例打开所需的源 PPTX 演示文稿
  3. 访问演示文稿 ProtectionManger 类并将 ReadOnlyRecommended 属性设置为 true
  4. 将生成的只读演示文稿保存在磁盘上

上述步骤总结了使用简单的 API 调用在 C# 中使 PPTX 不可编辑的过程。该过程通过从磁盘访问源演示文稿文件或使用演示文稿类的实例从头开始创建新的演示文稿来开始。然后,通过访问演示文稿 ProtectionManager 类,将 ReadOnlyRecommended 属性设置为 true,这将使演示文稿成为只读。最后,将只读演示文稿保存在磁盘上。

使用 C# 使演示文稿不可编辑的代码

using System;
using Aspose.Slides;
using Aspose.Slides.Export;
namespace TestSlides
{
public class ReadonlyPresentation
{
public static void ApplyReadOnly()
{
String path = @"/Users/KnowledgeBase/TestData/";
// Setting the license for the product to make the presentation readonly
License SlidesLicense = new License();
SlidesLicense.SetLicense(path + "Conholdate.Total.Product.Family.lic");
// Load the source presentation file to make it readonly
using (Presentation presSecurity = new Presentation(path + "Source.pptx"))
{
// Set the presentation access to readonly
presSecurity.ProtectionManager.ReadOnlyRecommended = true;
// Save the readonly presentation on the disk
presSecurity.Save(path + "SecurePres.pptx", SaveFormat.Pptx);
}
}
}
}

此示例演示了使用 C#* 使演示文稿不可编辑的过程。 ProtectionManager 类用于保护演示文稿文件并公开不同的属性和方法,例如 EncryptionPassword、EncryptDocumentProperties、RemoveEncryption 和 SetWriteProtection 等。设置演示文稿的只读属性后,不可编辑的演示文稿将保存在磁盘上。

本文教会我们如何防止使用 C# 进行演示文稿编辑。如果您有兴趣了解删除演示文稿中文本的过程,请参阅 如何使用 C# 删除 PPTX 中的文本 上的文章。

 简体中文