PDFium Delphi Component Docs

SaveAs method

Component: TPdf  ·  Unit: PDFium
Saves a copy of the PDF document to the specified stream or file with explicit PDF 1.3 through PDF 1.7 normalisation and conformance checks

Syntax

function SaveAs(Stream: TStream; Option: TSaveOption = saNone; PdfVersion: TPdfVersion = pvUnknown): Boolean;

StreamTStream value that receives the PDF data
OptionTSaveOption. Save option: saNone for a normal save, saIncremental for an incremental update, saNoIncremental to force a full rewrite, or saRemoveSecurity to remove security while saving
PdfVersionTPdfVersion target; use pvUnknown to preserve the current version

 

function SaveAs(const FileName: string; Option: TSaveOption = saNone; PdfVersion: TPdfVersion = pvUnknown): Boolean;

FileNamestring. The output file path. A sibling temporary file is completed first, then atomically replaces the destination
OptionTSaveOption. Save option: saNone, saIncremental, saNoIncremental, or saRemoveSecurity
PdfVersionTPdfVersion target; use pvUnknown to preserve the current version

Return Value

Returns True if the document was saved successfully, or False on failure

Description

Saves the current document to a file path or a TStream

The PdfVersion parameter specifies the output PDF version; pass pvUnknown to keep the document's existing version

The Compressed property controls stream compression. Hybrid-reference, xref-stream and object-stream inputs are preserved when a classic-xref rewrite cannot retain their complete cross-reference semantics

Every full (non-incremental) save repairs subset-font ToUnicode CMaps whose array range entries contradict their character mappings, so a reloaded document extracts the original spaces and hyphens rather than U+00A0 and U+00AD; incremental revisions, sparse updates and cross-reference-stream documents pass through unchanged

Explicit PDF-version checks follow the active cross-reference revision chain and active object-stream members, so stale or unreferenced object bodies do not affect the requested version gate

The file overload leaves an existing destination unchanged if compression, post-processing or version validation fails

The v3.125.2 Windows V8 update repairs exact field-value persistence for the tested packet arrays and the supported single-stream XDP subset; older runtimes can discard single-stream edits or introduce extra newlines

Reopen the XFA output and compare the required field values exactly before accepting it; do not trim whitespace to disguise a persistence difference

Conformance behaviour

Example

// Save to file
Pdf.SaveAs('output.pdf');

// Save to stream
var MS: TMemoryStream;
MS := TMemoryStream.Create;
try
  Pdf.SaveAs(MS);
  MS.SaveToFile('output.pdf');
finally
  MS.Free;
end;

See Also

LoadDocument, Compressed, CreateDocument