PDFium Delphi Component Docs

SaveAsEncryptedToStream method

Component: TPdf  ·  Unit: PDFium
In-memory variant of SaveAsEncrypted — writes the encrypted PDF output into any seekable TStream without staging through disk

Syntax

function SaveAsEncryptedToStream(Stream: TStream; const Options: TPdfEncryptOptions): Boolean;

StreamTStream. The target stream that receives the encrypted bytes
OptionsTPdfEncryptOptions. Configuration record defining passwords, permissions, metadata encryption flags, and the encryption revision

Return Value

Returns True if the encrypted PDF was successfully written to the stream, or False on failure

Description

SaveAsEncryptedToStream 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

Remarks

Example

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;

See Also

SaveAsEncrypted, SaveAs