密码、安全性和元数据

IronPDF为开发人员提供了强大的PDF安全选项,支持自定义和设置PDF元数据、密码、权限等。 通过IronPDF的密码、安全和元数据选项,您可以创建自定义权限和安全级别,以满足PDF文档的需求。 这是通过使用诸如SecuritySettingsMetaData类实现的。 一些选项包括限制PDF文档不可打印、将其设置为只读、128位加密以及PDF文档的密码保护。

设置自定义元数据是通过实现MetaData类来访问各种PDF元数据选项,并用您的自定义值设置它们。 这包括更改作者、关键词、修改数据等。 设置自定义安全设置包括能够设置自定义用户和所有者密码、打印权限、只读模式等。

为了开始自定义PDF文档的安全性,您必须首先加载现有的PDF或创建一个新的。 在这里,我们加载了一个现有的密码保护的PDF文档,其中输入了打开PDF文档所需的密码。 Once the PDF is loaded, we then use pdf.MetaData.Keys to get the PDF's current metadata. To remove existing PDF metadata values, use the RemoveMetaDataKey method. To begin setting new metadata values, use pdf.MetaData.metadataField (e.g., pdf.MetaData.Keywords), and then just assign the new value to it. Metadata fields such as Title and Keywords take string values, whereas the ModifiedData field takes datetime values.

Next, we have set new security settings using the SecuritySettings class. 正如您所见,这里有各种各样的设置可以设置。 这使您能够完全控制每个PDF文档的权限和安全级别。 To access these settings, you just need to make sure you use pdf.SecuritySettings, followed by the setting you want to adjust. For example, the MakePdfDocumentReadOnly method sets the PDF document to be read-only, encrypting the content at 128-bit. Other options for SecuritySettings include:

  • AllowUserAnnotations: Controls whether or not users can annotate the PDF.
  • AllowUserPrinting: Controls printing permissions for the document.
  • AllowUserFormData: Sets the permissions for whether users can fill-in forms.
  • OwnerPassword: Sets the owner password for the PDF, which is used to disable or enable the other security settings.
  • UserPassword: Sets the user password for the PDF, which must be entered in order to open or print the document.

一旦为您的PDF文档设置了自定义元数据、密码和安全设置,请使用pdf.SaveAs方法将您的PDF保存到指定位置。

学习使用 IronPDF 处理 PDF 元数据

准备开始了吗?
Nuget 下载 17,012,929 | 版本: 2025.12 刚刚发布