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 AES-256-CBC encryption conforming to ISO 32000-2 §7.6, but writes the results directly into any seekable TStream (such as TMemoryStream or TFileStream) instead of staging through a file path
Write and Seek operationssaRemoveSecurity to ensure plaintext objects are cleanly serialized 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 := $FFFFFFF0;
Opts.EncryptMetadata := True;
Opts.Revision := erR6;
if Pdf1.SaveAsEncryptedToStream(Stream, Opts) then
begin
Stream.Position := 0;
SendToNetwork(Stream);
end;
finally
Stream.Free;
end;
end;