PDFium Delphi Component Docs

SaveSourceBytes method

Component: TPdf  ·  Unit: PDFium
Writes out the exact byte image the document is loaded from, with no native re-save

Syntax

function SaveSourceBytes(Stream: TStream): Boolean; overload;
function SaveSourceBytes(const FileName: string): Boolean; overload;

Description

Copies the retained source of the active document verbatim: the stream, buffer or file it was loaded from, or the bytes a library transaction reloaded it from

This is the save path for a signed document filled through SetFormFieldValues: the write appends one revision after the original signed bytes and reloads the instance from that result, so the copy keeps every earlier ByteRange segment byte-identical and the signatures stay valid

SaveAs and the repair writers serialise the document through PDFium instead; on a signed source they rewrite objects the signatures cover, so a reloaded result no longer validates. Since v3.382.3 an incremental save session started on a signed source appends after the same source bytes, so it is the way to add native edits after a signed fill

Parameters

StreamDestination stream; it is truncated and then receives the complete source bytes
FileNameDestination file; the bytes are written to a temporary file alongside it, which then replaces the target

Return value

True when the complete source was written; False when no complete source is retained, for example whilst a progressive document is still loading

Remarks

Example

var
  Requests: TPdfFormValueRequests;
  Report: TPdfFormValuesWriteReport;
begin
  Pdf1.FileName := 'signed-form.pdf';
  Pdf1.Active := True;
  SetLength(Requests, 1);
  Requests[0] := Default(TPdfFormValueRequest);
  Requests[0].Page := 1;
  Requests[0].FieldIndex := 0;
  Requests[0].Value.Kind := fvkText;
  Requests[0].Value.Text := 'Approved';
  if Pdf1.SetFormFieldValues(Requests, Report) then
    Pdf1.SaveSourceBytes('signed-form-filled.pdf')
  else
    ShowMessage(Report.ErrorMessage);
end;

See Also

SetFormFieldValues SaveAs ValidatePades AnalyzeSignatureRevisions