API referenceImages

pdfReplaceImage

Swap out an already-inserted image's underlying pixel data

C
BOOL32 __stdcall pdfReplaceImageA(PPDF IPDF, TPDFImage* Source, const char* Image, uint32_t Index, TExtColorSpace CS, int32_t CSHandle, TReplaceImageFlags Flags);
BOOL32 __stdcall pdfReplaceImageW(PPDF IPDF, TPDFImage* Source, const wchar_t* Image, uint32_t Index, TExtColorSpace CS, int32_t CSHandle, TReplaceImageFlags Flags);
BOOL32 __stdcall pdfReplaceImageEx(PPDF IPDF, TPDFImage* Source, void* Buffer, uint32_t BufSize, uint32_t Index, TExtColorSpace CS, int32_t CSHandle, TReplaceImageFlags Flags);
Delphi
function pdfReplaceImageA(const IPDF: PPDF; Source: PPDFImage; const Image: PAnsiChar; Index: Cardinal; CS: TExtColorSpace; CSHandle: Integer; Flags: TReplaceImageFlags): LongBool; stdcall;
function pdfReplaceImageW(const IPDF: PPDF; Source: PPDFImage; const Image: PWideChar; Index: Cardinal; CS: TExtColorSpace; CSHandle: Integer; Flags: TReplaceImageFlags): LongBool; stdcall;
function pdfReplaceImageEx(const IPDF: PPDF; Source: PPDFImage; Buffer: Pointer; BufSize: Cardinal; Index: Cardinal; CS: TExtColorSpace; CSHandle: Integer; Flags: TReplaceImageFlags): LongBool; stdcall;

Purpose. Swap out an already-inserted image's underlying pixel data for a new file/buffer, while every page reference to it (via the shared XObject alias) picks up the new content automatically.

Description. Verified major parameter reduction: despite the ABI accepting Source (a TPDFImage* — presumably meant as an alternative, struct-based way to identify the target image, alongside or instead of Index), CS/CSHandle (presumably meant to force the replacement into a specific color space), and Flags (a TReplaceImageFlags set, presumably selecting resize/aspect/re-encode behavior), none of Source, CS, CSHandle, or Flags is passed through to the underlying ReplaceImageFileH/ReplaceImageBufH implementation — only Index (the target image's handle) and the new file path/buffer actually reach the replace logic. The real implementation (ApplyLoadedImage) simply overwrites the target FImages entry's decoded pixel data, dimensions, and format flags in place, keeping the same handle/alias — no color-space conversion, resizing, or any Flags-driven behavior occurs regardless of what is passed for those four parameters.

Parameters.

ParameterDescription
IPDFDocument handle.
SourceAccepted but never read.
Image/BufferNew file path (A/W) or buffer bytes (Ex) to decode and substitute.
IndexThe target image's existing handle — this is the only "which image" parameter actually honored.
CS, CSHandleAccepted but never read — no color-space conversion occurs.
FlagsAccepted but never read — no flag-driven behavior occurs.

Return value. True if Index resolved to an existing image and the new file/buffer decoded successfully; False otherwise.

See also. pdfInsertImage.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
[return: MarshalAs(UnmanagedType.Bool)]
Area
Images
Category

Core

Exported names

pdfReplaceImageA pdfReplaceImageW

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.