密碼、安全性與元資料

IronPDF 為開發人員提供強大的 PDF 安全性選項,支援自訂與設定 PDF 元資料、密碼、權限等。 透過 IronPDF 的密碼、安全性及元資料選項,您可以建立自訂權限與安全性層級,以符合您的 PDF 文件需求。 這得益於使用 SecuritySettingsMetaData 等類別。 可選方案包括將 PDF 文件設為不可列印、設定為唯讀模式、採用 128 位元加密,以及為您的 PDF 文件設定密碼保護。

設定自訂元資料的方式是透過實作 MetaData 類別來存取各種 PDF 元資料選項,並將其設定為您自訂的值。 這包括修改作者、關鍵字、修改日期等資訊。 自訂安全性設定包含設定自訂使用者與擁有者密碼、列印權限、唯讀模式等功能。

若要開始自訂 PDF 文件的安全性,您必須先載入現有的 PDF 檔案或建立一個新的 PDF 檔案。 在此,我們已載入一份現有的受密碼保護的 PDF 文件,並已輸入開啟該 PDF 文件所需的密碼。 載入 PDF 後,我們會使用 pdf.MetaData.Keys 來取得 PDF 的當前元資料。 若要移除現有的 PDF 元資料值,請使用 RemoveMetaDataKey 方法。 若要開始設定新的元資料值,請使用 pdf.MetaData.metadataField(例如 pdf.MetaData.Keywords),然後將新值賦予該變數即可。 元資料欄位如 TitleKeywords 接受字串值,而 ModifiedData 欄位則接受日期時間值。

接著,我們已使用 SecuritySettings 類別設定了新的安全性設定。 如您所見,此處提供多種可設定的選項。 這讓您能完全掌控所處理的每份 PDF 文件的權限與安全性等級。 若要存取這些設定,您只需確保使用 MakePdfDocumentReadOnly 方法會將 PDF 文件設為唯讀,並以 128 位元加密內容。 SecuritySettings 的其他選項包括:

  • 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 下載 19,014,616 | 版本: 2026.5 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronPdf
執行範例 觀看您的 HTML 轉為 PDF。