API referenceImages

pdfInsertImageEx

Load an image file (format auto-detected from content) and

C
int32_t __stdcall pdfInsertImage(PPDF IPDF, double PosX, double PosY, double ScaleWidth, double ScaleHeight, const char* AFile);
int32_t __stdcall pdfInsertImageExA(PPDF IPDF, double PosX, double PosY, double ScaleWidth, double ScaleHeight, const char* Image, uint32_t Index);
int32_t __stdcall pdfInsertImageExW(PPDF IPDF, double PosX, double PosY, double ScaleWidth, double ScaleHeight, const wchar_t* Image, uint32_t Index);
Delphi
function pdfInsertImage(const IPDF: PPDF; PosX, PosY, ScaleWidth, ScaleHeight: Double; const AFile: PAnsiChar): Integer; stdcall;
function pdfInsertImageExA(const IPDF: PPDF; PosX, PosY, ScaleWidth, ScaleHeight: Double; const Image: PAnsiChar; Index: Cardinal): Integer; stdcall;
function pdfInsertImageExW(const IPDF: PPDF; PosX, PosY, ScaleWidth, ScaleHeight: Double; const Image: PWideChar; Index: Cardinal): Integer; stdcall;

Purpose. Load an image file (format auto-detected from content) and place it on the current page in one call.

Description. Decodes the file via LoadImageFile, registers a new FImages entry (auto-allocated handle, alias ImN), and immediately places it on the current page's content stream at PosX/PosY sized ScaleWidth/ScaleHeight (a <= 0 scale value defaults to the image's native pixel dimensions). pdfInsertImageEx's Index parameter — meant to select a specific frame/page within a multi-frame format such as multi-page TIFF — is accepted by the ABI but never passed through to InsertFileImage, which has no frame-index parameter at all. Regardless of what Index is set to, the same (first, or only-decoded) frame is always loaded; there is no way to reach frame 2+ of a multi-frame TIFF through this entry point. The plain pdfInsertImage has no Index parameter to begin with and shares the identical underlying limitation.

Parameters.

ParameterDescription
IPDFDocument handle.
PosX, PosY, ScaleWidth, ScaleHeightPlacement box; a <= 0 scale dimension defaults to the image's native pixel size.
AFile/ImagePath to the image file.
Index*(Ex only)* Accepted but silently dropped — has no effect; always loads the same single frame regardless of value.

Return value. The new image handle on success; 0 if IPDF is invalid, there is no current page, or the file could not be loaded/decoded (a load failure also raises E_FILE_ERROR via the error-log mechanism — see Errors, Diagnostics, Licensing & Engine Services).

See also. pdfInsertImageFromBuffer, pdfCreateImage (stage without placing).

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfInsertImageEx(IntPtr IPDF, double PosX, double PosY, double ScaleWidth, double ScaleHeight, [MarshalAs(UnmanagedType.LPStr)] string AFile, uint Index);
public static extern int pdfInsertImageExW(IntPtr IPDF, double PosX, double PosY, double ScaleWidth, double ScaleHeight, [MarshalAs(UnmanagedType.LPWStr)] string Image, uint Index);
public static extern int pdfInsertImageExA(IntPtr IPDF, double PosX, double PosY, double ScaleWidth, double ScaleHeight, [MarshalAs(UnmanagedType.LPStr)] string Image, uint Index);
Area
Images
Category

Images

Exported names

pdfInsertImageEx pdfInsertImageExW pdfInsertImageExA

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.