function SaveAsEncrypted(const FileName: string; const Options: TPdfEncryptOptions): Boolean;
| FileName | string. The target file path |
| Options | TPdfEncryptOptions. Configuration record defining passwords, permissions, metadata encryption flags, and the encryption revision |
True if the encrypted PDF was successfully saved, or False on failureSaveAsEncrypted supports AESV3-CBC security handlers R=5 and R=6 from ISO 32000-2 plus AESV4-GCM security handler R=7 from ISO/TS 32003
Set Options.Revision to erR7 for authenticated per-object encryption with unique 12-byte IVs and 16-byte tags
saRemoveSecurity to ensure plaintext objects are cleanly serialised before being encrypted by the post-save sweepDecryptAesGcmDocumentBytes before TPdf.LoadDocument
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;