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.10剛剛發布