Free Spire.Presentation for .NET 3.3 (社区版)
Visual Studio
using Spire.Presentation;namespace Encrypt{ class Program { static void Main(string[] args) { //新建Presentation对象 Presentation presentation = new Presentation(); //加载文档 presentation.LoadFromFile('sample.pptx'); //设置密码 presentation.Encrypt('test'); //保存并打开文档 presentation.SaveToFile('encrypt.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('encrypt.pptx'); } }}
调试运行程序后,测试文档将受密码保护。打开文件时,须正确输入密码。如下图:
using Spire.Presentation;namespace EditProtection{ class Program { static void Main(string[] args) { //新建Presentation对象 Presentation presentation = new Presentation(); //加载文档 presentation.LoadFromFile('sample.pptx'); //设置启用编辑PPT的密码 presentation.Protect('keytoedit'); //保存并打开文档 presentation.SaveToFile('readonly.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('readonly.pptx'); } }}
编辑权限设置结果:
using Spire.Presentation;namespace RemoveEncryption{ class Program { static void Main(string[] args) { // 新建Presentation 对象并加载文档 Presentation presentation = new Presentation(); presentation.LoadFromFile('encrypt.pptx', 'test'); //解除密码 presentation.RemoveEncryption(); //保存文档 presentation.SaveToFile('result.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('result.pptx'); } }}
调试运行程序后,原来有密码保护的PPT文档将不再受密码保护。
using Spire.Presentation;namespace Modify{ class Program { static void Main(string[] args) { // 新建Presentation 对象并加载文档 Presentation presentation = new Presentation(); presentation.LoadFromFile('encrypt.pptx', FileFormat.Pptx2010, 'test'); //删除旧密码,设置新密码 presentation.RemoveEncryption(); presentation.Protect('newpassword'); //保存并打开文档 presentation.SaveToFile('result.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('result.pptx'); } }}
运行程序,原有文件中的密码将被修改成新密码。
using Spire.Presentation;namespace Down{ class Program { static void Main(string[] args) { // 新建Presentation 对象并加载文档 Presentation ppt = new Presentation(); ppt.LoadFromFile('sample.pptx', FileFormat.Pptx2010); //标记为最终状态 ppt.DocumentProperty['_MarkAsFinal'] = true; //保存并打开文档 ppt.SaveToFile('output.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('output.pptx'); } }}
调试程序,生成文档: