IRONSOFTWAREHOME
Passwords, Security & Metadata

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.security.PdfPrintSecurity;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Date;

// Open an encrypted file (or create a new one from HTML)
PdfDocument pdf = PdfDocument.fromFile(Paths.get("assets/encrypted.pdf"), "password");

// Edit file metadata
MetadataManager metadata = pdf.getMetadata();
metadata.setAuthor("Satoshi Nakamoto");
metadata.setKeywords("SEO, Friendly");
metadata.setModifiedDate(new Date().toString());

// Edit file security settings
// The code below makes the PDF read only and disallows users to copy, paste, and print
SecurityOptions securityOptions = new SecurityOptions();
securityOptions.setAllowUserCopyPasteContent(false);
securityOptions.setAllowUserAnnotations(false);
securityOptions.setAllowUserPrinting(PdfPrintSecurity.FULL_PRINT_RIGHTS);
securityOptions.setAllowUserFormData(false);
securityOptions.setOwnerPassword("top-secret");
securityOptions.setUserPassword("sharable");

// Change or set the document encryption password
SecurityManager securityManager = pdf.getSecurity();
securityManager.removePasswordsAndEncryption();
securityManager.makePdfDocumentReadOnly("secret-key");


securityManager.setSecurityOptions(securityOptions);
pdf.saveAs(Paths.get("assets/secured.pdf"));
mvn install
Passwords, Security & Metadata

Passwords, Security & Metadata

IronPDF可以修改PDF的元資料和安全設定。 在安全性方面,這包括將PDF設為只讀、不可列印、密碼保護及加密。 對於元資料,這包括定義新屬性以及編輯現有屬性的能力。

要在IronPDF for Java中管理PDF的元資料,開發者首先須獲取對其MetadataManager的參照。 此類別提供方法以直接存取和修改PDF的元內容。 開發者可以使用同名的getter和setter快速讀取和編輯PDF文件上常定義的元屬性。

具有方便getter和setter的完整屬性列表如下:

  • Producer
  • CreationDate
  • Creator
  • Author
  • Keywords
  • Subject
  • Title
  • ModifiedDate

這個程式碼範例使用setModifiedDate方法來修改工作文件的作者、標題和關鍵字。

若要獲取和設置先前列表中未包含的屬性,請使用setAnyMetadata方法並填入所需屬性的名稱。

同樣,要存取和更改PDF文件的安全設置,必須透過SecurityManager進行。 在SecurityManager的參照,並根據預期用途限制存取PDF。

Java開發者可以使用SecurityOptions物件來更精細地控制PDF安全設定。

探索MetadataManager API以用於Java PDF管理
在 GitHub 查看

準備好開始了嗎?

版本:2026.6剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

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天試用金鑰
無需信用卡或帳戶建立