PDFium Delphi Component Docs

SaveAsEncrypted method

Component: TPdf  ·  Unit: PDFium
Saves the active PDF with AES-256-CBC or ISO/TS 32003 AES-256-GCM encryption selected by TPdfEncryptOptions

Syntax

function SaveAsEncrypted(const FileName: string; const Options: TPdfEncryptOptions): Boolean;

FileNamestring. The target file path
OptionsTPdfEncryptOptions. Configuration record defining passwords, permissions, metadata encryption flags, and the encryption revision

Return Value

Returns True if the encrypted PDF was successfully saved, or False on failure

Description

SaveAsEncrypted 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

Remarks

Example

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;

See Also

SaveAsEncryptedToStream, SaveAs