PDFium Delphi Component Docs

SaveAsEncryptedToStream-Methode

Komponente: TPdf  ·  Unit: PDFium
In-Memory-Variante von SaveAsEncrypted — schreibt die verschlüsselte PDF-Ausgabe direkt in einen suchbaren TStream, ohne den Umweg über die Festplatte zu nehmen

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 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

Remarks

Example

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;

See Also

SaveAsEncrypted, SaveAs