function SaveAsEncrypted(const FileName: string; const Options: TPdfEncryptOptions): Boolean;
| FileName | string. 目標檔案路徑 |
| Options | TPdfEncryptOptions. 定義密碼、權限、中繼資料加密旗標與加密修訂版的組態記錄 |
True,失敗則傳回 FalseSaveAsEncrypted 支援 ISO 32000-2 的 AESV3-CBC 安全性處理器 R=5 與 R=6,以及 ISO/TS 32003 的 AESV4-GCM 安全性處理器 R=7
將 Options.Revision 設為 erR7 可進行帶認證的逐物件加密,使用唯一的 12 位元組 IV 與 16 位元組標籤
saRemoveSecurity 暫時移除既有的安全性,確保明文物件在被儲存後掃加密前能乾淨地序列化TPdf.LoadDocument 之前先使用 DecryptAesGcmDocumentBytes
var
Opts: TPdfEncryptOptions;
begin
Opts := TPdfEncryptOptions.Default;
Opts.UserPassword := 'user123';
Opts.OwnerPassword := 'owner123';
Opts.Permissions := $FFFFFFFC;
Opts.EncryptMetadata := True;
Opts.Revision := erR7;
if Pdf1.SaveAsEncrypted('encrypted.pdf', Opts) then
ShowMessage('Encrypted PDF saved successfully');
end;