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 20,990,528版本: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 IronPDF
預訂您的免費現場演示
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