密碼、安全性和元數據

IronPDF 為開發者提供強大的 PDF 安全選項,支援自訂和設定 PDF 元資料、密碼、權限等。 IronPDF 的密碼、安全性和元資料選項,可讓您建立自訂權限和安全級別,以滿足 PDF 文件的需求。 這是透過使用SecuritySettings類別和MetaData類別等類別來實現的。 一些選項包括限制 PDF 文件不可列印、設定為唯讀、128 位元加密以及對 PDF 文件進行密碼保護。

設定自訂元資料的方法是實作MetaData類別來存取各種 PDF 元資料選項,並使用自訂值設定它們。 這包括更改作者、關鍵字、修改數據等等。 自訂安全設定包括設定自訂使用者和所有者密碼、列印權限、唯讀模式等。

要開始自訂 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 剛剛發布