IRONSOFTWAREHOME
密码、安全性和元数据
using IronPdf;

// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

// Get file metadata
System.Collections.Generic.List<string> metadatakeys = pdf.MetaData.Keys(); // returns {"Title", "Creator", ...}

// Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title");
metadatakeys = pdf.MetaData.Keys(); // return {"Creator", ...} // title was deleted

// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = System.DateTime.Now;

// The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret"; // password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable"; // password to open the pdf
pdf.SaveAs("secured.pdf");
Imports IronPdf

' Open an Encrypted File, alternatively create a new PDF from Html
Dim pdf = PdfDocument.FromFile("encrypted.pdf", "password")

' Get file metadata
Dim metadatakeys As System.Collections.Generic.List(Of String) = pdf.MetaData.Keys() ' returns {"Title", "Creator", ...}

' Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title")
metadatakeys = pdf.MetaData.Keys() ' return {"Creator", ...} ' title was deleted

' Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = System.DateTime.Now

' The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights

' Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret" ' password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable" ' password to open the pdf
pdf.SaveAs("secured.pdf")
NuGet Download
PM > Install-Package IronPdf
密码、安全性和元数据

密码、安全性和元数据

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

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

为了开始自定义PDF文档的安全性,您必须首先加载现有的PDF或创建一个新的。 在这里,我们加载了一个现有的密码保护的PDF文档,其中输入了打开PDF文档所需的密码。 一旦PDF加载完成,我们就用pdf.MetaData.Keys来获取PDF的当前元数据。 要移除现有的PDF元数据值,请使用RemoveMetaDataKey方法。 要开始设置新的元数据值,请使用pdf.MetaData.Keywords),然后只需为其分配新的值。 像ModifiedData字段采用日期时间值。

接下来,我们使用SecuritySettings类设置新的安全设置。 正如您所见,这里有各种各样的设置可以设置。 这使您能够完全控制每个PDF文档的权限和安全级别。 要访问这些设置,您只需确保使用MakePdfDocumentReadOnly方法将PDF文档设置为只读,以128位加密内容。 其他的SecuritySettings选项包括:

  • AllowUserAnnotations: 控制用户是否可以对PDF进行注释。
  • AllowUserPrinting: 控制文档的打印权限。
  • AllowUserFormData: 设置用户是否可以填写表单的权限。
  • OwnerPassword: 设置PDF的拥有者密码,用于禁用或启用其他安全设置。
  • UserPassword: 设置PDF的用户密码,必须输入此密码才能打开或打印文档。

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

学习使用 IronPDF 处理 PDF 元数据
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 21,105,021版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥。

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

OR
bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥。
无需信用卡或创建账户
C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索 “IronPDF”
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

或在此处下载 Windows 安装程序。

  1. 下载并解压 IronPDF 到您的解决方案目录中的 ~/Libs 之类的位置
  2. 在 Visual Studio 解决方案资源管理器中,右键点击引用。选择浏览,“IronPDF.dll”

$999 起