密碼、安全性與元資料
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    // Import a PDF document or create a new PDF from Html
    const pdf = await PdfDocument.open("encrypted.pdf", "password");

    // Create an empty Map
    const newMetadata = new Map();

    // Add key-value pairs of metadata
    newMetadata.set("Author", "Satoshi Nakamoto");
    newMetadata.set("Keywords", "SEO, Friendly");

    await pdf.overrideMetadata(newMetadata);

    await pdf.removePasswordsAndEncryption();
    // Make PDF read-only
    await pdf.makePdfDocumentReadOnly("secret-key");

    // Configure permissions
    const permissions = {
        AllowAnnotations: false,
        AllowExtractContent: false,
        AllowFillForms: false,
        AllowPrint: true,
    };

    await pdf.setPermission(permissions);
    
    // Change or set the document encrpytion password
    await pdf.saveAs("secured.pdf", {
        ownerPassword: "top-secret",
        userPassword: "my-password",
    });
})();
npm i @ironsoftware/ironpdf
密碼、安全性與元資料

密碼、安全性與元資料

IronPDF 提供加密、解密、修改元資料,以及針對註解、內容複製貼上、表單欄位和列印設定特定權限的功能。

若要開啟受密碼保護的 PDF 文件,請使用 open 方法,並將密碼作為第二個參數傳入。 設定元資料需建立新的映射,並輸入對應於元資料資訊的鍵值對。 將新的元資料映射傳入 overrideMetadata 方法,以覆寫舊的元資料。 using removePasswordsAndEncryption 方法可從文件中移除任何密碼。 makePdfDocumentReadOnly 方法將使此 PDF 文件設為唯讀,以 128 位元加密內容,並禁止複製貼上內容、新增註解以及編輯表單。

透過建立包含權限設定的權限物件來配置權限,並將其傳遞給 setPermission 方法。

最後,saveAs 方法可讓物件分別設定 ownerPassword 和 userPassword 屬性。

如需進一步了解 IronPDF 的功能與應用,請造訪 IronPDF 產品頁面,或前往 Iron Software 官網探索更多產品資訊。

在 GitHub 上探索安全性與元資料範例
在 GitHub 上查看

準備好開始了嗎?

版本:2026.11剛剛發布