function SaveAsEncryptedToStream(Stream: TStream; const Options: TPdfEncryptOptions): Boolean;
| Stream | TStream. The target stream that receives the encrypted bytes |
| Options | TPdfEncryptOptions. Configuration record defining passwords, permissions, metadata encryption flags, and the encryption revision |
True if the encrypted PDF was successfully written to the stream, or False on failureSaveAsEncryptedToStream is the streaming counterpart to SaveAsEncrypted — it applies AESV3-CBC or ISO/TS 32003 AESV4-GCM encryption and writes the result directly into a seekable TStream instead of staging through a file path
Write and Seek operationssaRemoveSecurity to ensure plaintext objects are cleanly serialised before being encrypted by the post-save sweep
var
Stream: TMemoryStream;
Opts: TPdfEncryptOptions;
begin
Stream := TMemoryStream.Create;
try
Opts := TPdfEncryptOptions.Default;
Opts.UserPassword := 'user123';
Opts.OwnerPassword := 'owner123';
Opts.Permissions := $FFFFFFFC;
Opts.EncryptMetadata := True;
Opts.Revision := erR7;
if Pdf1.SaveAsEncryptedToStream(Stream, Opts) then
begin
Stream.Position := 0;
SendToNetwork(Stream);
end;
finally
Stream.Free;
end;
end;