PDF控件Spire.PDF for .NET【安全】演示:更改 PDF 文档的安全权限

当您使用密码保护 PDF 文档时,您可以选择指定一组权限。权限决定用户如何与文件交互。例如,您可以对文档应用权限以禁止用户打印或使用剪切和粘贴操作。本文演示如何在C# 和 VB.NET中使用Spire.PDF for .NET更改 PDF 文档的安全权限。

Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。

E-iceblue功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.PDF for.net下载 Spire.PDF for java下载

安装适用于 .NET 的 Spire.PDF

首先,您需要将 Spire.PDF for .NET 包中包含的 DLL 文件添加为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过NuGet安装。

复制代码
PM> Install-Package Spire.PDF
更改 PDF 文档的安全权限

以下是使用 Spire.PDF for .NET 将安全权限应用于 PDF 文档的步骤。

  • 创建一个PdfDocument对象。
  • **使用PdfDocument.LoadFileFile()**方法加载示例 PDF 文件。
  • 指定打开密码和权限密码。打开密码可以设置为空,这样生成的文档就不需要密码打开。
  • 使用打开密码和权限密码对文档进行加密,并使用PdfDocument.Security.Encypt() 方法设置安全权限。该方法以PdfPermissionsFlags枚举作为参数,定义用户对加密文档的访问权限。
  • **使用PdfDocument.SaveToFile()**方法将文档保存到另一个 PDF 文件。

【C#】

复制代码
using Spire.Pdf;
using Spire.Pdf.Security;

namespace ChangeSecurityPermission
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a sample PDF file
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

//Specify open password
string openPsd = string.Empty;

//Specify permission password
string permissionPsd = "e-iceblue";

//Encrypt the document with open password and permission password, and set the permissions and encryption key size
doc.Security.Encrypt(openPsd, permissionPsd, PdfPermissionsFlags.FullQualityPrint, PdfEncryptionKeySize.Key128Bit);

//Save the document to another PDF file
doc.SaveToFile("SecurityPermissions.pdf");
}
}
}

VB.NET

复制代码
using Spire.Pdf;
using Spire.Pdf.Security;

namespace ChangeSecurityPermission
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a sample PDF file
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

//Specify open password
string openPsd = string.Empty;

//Specify permission password
string permissionPsd = "e-iceblue";

//Encrypt the document with open password and permission password, and set the permissions and encryption key size
doc.Security.Encrypt(openPsd, permissionPsd, PdfPermissionsFlags.FullQualityPrint, PdfEncryptionKeySize.Key128Bit);

//Save the document to another PDF file
doc.SaveToFile("SecurityPermissions.pdf");
}
}
}

以上便是如何使更改 PDF 文档的安全权限,如果您有其他问题也可以继续浏览本系列文章,获取相关教程~

相关推荐
星幻元宇VR7 分钟前
VR心理健康学习机|沉浸式心理教育新模式
科技·学习·安全·vr·虚拟现实
薛定猫AI14 分钟前
【深度解析】终端里的免费 AI 编程助手 Freebuff:多代理架构、模型路由与安全使用实战
人工智能·安全·架构
无心水8 小时前
【Hermes:安全、权限与生产环境】40、运行 Hermes 前的生命线:安全审计清单与 11 个必须检查的配置项
人工智能·安全·mcp协议·openclaw·养龙虾·hermes·honcho
@insist12311 小时前
信息安全工程师-测评核心知识框架与关键流程(上篇)
安全·软考·信息安全工程师·软件水平考试
lifejump11 小时前
Empire(帝国)CMS 7.5 XSS注入
前端·安全·xss
xixixi7777712 小时前
AI的“账号”与“钱包”:AWS与Circle同日出手,AI正从工具进化
人工智能·安全·ai·大模型·云计算·aws
JiaWen技术圈12 小时前
Web 安全深入审计检查清单
前端·安全
lifejump14 小时前
Dede(织梦)CMS渗透测试(all)
前端·网络·安全·web安全
星幻元宇VR14 小时前
VR文旅大空间|沉浸式体验重塑文旅新场景
科技·学习·安全·vr·虚拟现实
紫金桥软件14 小时前
组态软件新势力,安全可靠高性能经多行业认证紫金桥软件RealSCADA
安全·scada·组态软件·国产工业软件·监控组态软件